Changeset df74597 in network-game


Ignore:
Timestamp:
Dec 25, 2013, 4:44:20 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
257de75
Parents:
e0fd377
Message:

Server-side logic for handling a game victory is fixed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    re0fd377 rdf74597  
    216216         for (itGames = mapGames.begin(); itGames != mapGames.end();) {
    217217            if (handleGameEvents(itGames->second, mapPlayers, msgProcessor)) {
     218               delete itGames->second;
    218219               mapGames.erase(itGames++);
    219                delete itGames->second;
    220220            }else
    221221               itGames++;
     
    831831   NETWORK_MSG serverMsg;
    832832   map<unsigned int, Player*>::iterator it;
     833   bool gameFinished = false;
    833834
    834835   for (it = game->getPlayers().begin(); it != game->getPlayers().end(); it++)
    835836   {
    836       if (handlePlayerEvents(it->second, game, msgProcessor)) {
    837                 // send a GAME_INFO message with 0 players to force clients to delete the game
    838          int numPlayers = 0;
    839          serverMsg.type = MSG_TYPE_GAME_INFO;
    840          memcpy(serverMsg.buffer, &numPlayers, 4);
    841          broadcastMessage(msgProcessor, serverMsg, mapPlayers);
    842 
    843          return true;
    844       }else
    845          return false;
    846    }
     837      gameFinished = gameFinished ||
     838         handlePlayerEvents(it->second, game, msgProcessor);
     839   }
     840
     841   // set each player's current game to null
     842   if (gameFinished) {
     843      // send a GAME_INFO message with 0 players to force clients to delete the game
     844      int numPlayers = 0;
     845      serverMsg.type = MSG_TYPE_GAME_INFO;
     846      memcpy(serverMsg.buffer, &numPlayers, 4);
     847      broadcastMessage(msgProcessor, serverMsg, mapPlayers);
     848
     849      for (it = game->getPlayers().begin(); it != game->getPlayers().end(); it++)
     850      {
     851         it->second->currentGame = NULL;
     852      }
     853   }
     854
     855   return gameFinished;
    847856}
    848857
     
    10971106      broadcastMessage(msgProcessor, serverMsg, playersInGame);
    10981107   }
     1108
     1109   return gameFinished;
    10991110}
    11001111
Note: See TracChangeset for help on using the changeset viewer.