Changeset 6ba31d2 in network-game for server/server.cpp


Ignore:
Timestamp:
Feb 2, 2015, 12:53:42 AM (10 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
master
Children:
d58e3c3
Parents:
85da778
Message:

When a game start, message all clients not in the game so they remove it from their lobby game lists. When a game ends, only message game perticipants about the results.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    r85da778 r6ba31d2  
    221221               memcpy(serverMsg.buffer, &numPlayers, 4);
    222222               strcpy(serverMsg.buffer+4, game->getName().c_str());
    223                msgProcessor.broadcastMessage(serverMsg, mapPlayers);
     223
     224               // only send this to players in the game
     225               msgProcessor.broadcastMessage(serverMsg, game->getPlayers());
    224226
    225227               delete itGames->second;
     
    840842         msgProcessor.broadcastMessage(serverMsg, players);
    841843
     844         // send a GAME_INFO message to all players not in the game so they delete it from their lobby
     845         map<unsigned int, Player*> playersNotInGame;
     846         map<unsigned int, Player*>::iterator it;
     847         
     848         for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) {
     849             if (players.count(it->first) == 0)
     850                 playersNotInGame[it->first] = it->second;
     851         }
     852
     853         cout << "Sending game info to " << playersNotInGame.size() << " players not in the currently started game" << endl;
     854
     855         int numPlayers = 0;
     856         serverMsg.type = MSG_TYPE_GAME_INFO;
     857         memcpy(serverMsg.buffer, &numPlayers, 4);
     858         strcpy(serverMsg.buffer+4, p->currentGame->getName().c_str());
     859
     860         msgProcessor.broadcastMessage(serverMsg, playersNotInGame);
     861
    842862         break;
    843863      }
Note: See TracChangeset for help on using the changeset viewer.