Changeset e5b96e2 in network-game for server


Ignore:
Timestamp:
Dec 23, 2013, 5:26:01 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
3b6f46b
Parents:
ad1e2fc
Message:

When a team scores 3 points, the server sends FINISH_GAME messages to the participants, GAME_INFO messages to everyone to indicate the game is done, and destroys the relevant game object

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    rad1e2fc re5b96e2  
    230230         Game* game = NULL;
    231231         WorldMap* gameMap = NULL;
    232 
    233          for (itGames = mapGames.begin(); itGames != mapGames.end(); itGames++) {
     232         bool gameFinished;
     233
     234         for (itGames = mapGames.begin(); itGames != mapGames.end();) {
    234235            game = itGames->second;
    235236            gameMap = game->getMap();
    236237            map<unsigned int, Player*>& playersInGame = game->getPlayers();
     238            gameFinished = false;
    237239
    238240            for (it = game->getPlayers().begin(); it != game->getPlayers().end(); it++)
     
    363365                     }
    364366
    365                      /*
     367                     // check to see if the game should end
     368                     // move to its own method
    366369                     if (scoreBlue == 3 || scoreRed == 3) {
    367                         gameOver = true;
     370                        gameFinished = true;
    368371
    369372                        unsigned int winningTeam;
     
    377380                        memcpy(serverMsg.buffer+4, &scoreBlue, 4);
    378381                        memcpy(serverMsg.buffer+8, &scoreRed, 4);
    379 
    380                         for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++)
    381                         {
    382                            if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
    383                               error("sendMessage");
    384                         }
    385 
    386                         // send a GAME_INFO message with 0 players to force clients to delete the game
    387                         int numPlayers = 0;
    388                         serverMsg.type = MSG_TYPE_GAME_INFO;
    389                         memcpy(serverMsg.buffer, &numPlayers, 4);
    390382
    391383                        for (it2 = playersInGame.begin(); it2 != playersInGame.end(); it2++)
     
    395387                        }
    396388                     }
    397                      */
    398389
    399390                     // this means a PLAYER message will be sent
     
    539530               }
    540531            }
     532
     533            if (gameFinished) {
     534                // send a GAME_INFO message with 0 players to force clients to delete the game
     535               int numPlayers = 0;
     536               serverMsg.type = MSG_TYPE_GAME_INFO;
     537               memcpy(serverMsg.buffer, &numPlayers, 4);
     538
     539               map<unsigned int, Player*>::iterator it2;
     540               for (it2 = mapPLayers.begin(); it2 != mapPLayers.end(); it2++)
     541               {
     542                  if ( msgProcessor.sendMessage(&serverMsg, sock, &(it2->second->addr), &outputLog) < 0 )
     543                     error("sendMessage");
     544               }
     545
     546               // erase game from server
     547               mapGames.erase(itGames);
     548            }else
     549               itGames++;
    541550         }
    542551
Note: See TracChangeset for help on using the changeset viewer.