Changeset 453087e in network-game


Ignore:
Timestamp:
Dec 17, 2013, 11:35:52 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
6012178
Parents:
31b347a
Message:

PLAYER_JOIN_GAME messages, rather than PLAYER ones, are now sent to indicate players joining specific matches. The server also sends a player just joining a match all players currently in the match, including the new player

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • common/MessageContainer.h

    r31b347a r453087e  
    3737#define MSG_TYPE_JOIN_GAME_FAILURE 22
    3838#define MSG_TYPE_JOIN_GAME_ACK     23
     39#define MSG_TYPE_PLAYER_JOIN_GAME  24
    3940
    4041typedef struct
  • server/server.cpp

    r31b347a r453087e  
    11031103         p->currentGame = g; // should have been done in JOIN_GAME, so not necessary
    11041104
    1105          map<unsigned int, Player*>& otherPlayers = g->getPlayers();
    1106 
    1107          // tell the new player about all the existing players
    1108          cout << "Sending other players to new player" << endl;
    1109          serverMsg.type = MSG_TYPE_PLAYER;
    1110 
    1111          map<unsigned int, Player*>::iterator it;
    1112          for (it = otherPlayers.begin(); it != otherPlayers.end(); it++)
    1113          {
    1114             it->second->serialize(serverMsg.buffer);
    1115 
    1116             cout << "sending info about " << it->second->name  << endl;
    1117             cout << "sending id " << it->second->id  << endl;
    1118             if ( msgProcessor.sendMessage(&serverMsg, sock, &from, &outputLog) < 0 )
    1119                error("sendMessage");
    1120          }
    1121 
    11221105         // tell the new player about all map objects
    11231106         // (currently just the flags)
     
    11461129            error("sendMessage");
    11471130
    1148          serverMsg.type = MSG_TYPE_PLAYER;
     1131         serverMsg.type = MSG_TYPE_PLAYER_JOIN_GAME;
    11491132         p->serialize(serverMsg.buffer);
    11501133         cout << "Should be broadcasting the message" << endl;
    11511134
     1135         map<unsigned int, Player*>& otherPlayers = g->getPlayers();
    11521136         for (it = otherPlayers.begin(); it != otherPlayers.end(); it++)
    11531137         {
     
    11581142
    11591143         g->addPlayer(p);
     1144
     1145         map<unsigned int, Player*>& allPlayers = g->getPlayers();
     1146
     1147         // tell the new player about all the players in the game (including himself)
     1148         cout << "Sending other players to new player" << endl;
     1149         serverMsg.type = MSG_TYPE_PLAYER_JOIN_GAME;
     1150
     1151         map<unsigned int, Player*>::iterator it;
     1152         for (it = allPlayers.begin(); it != allPlayers.end(); it++)
     1153         {
     1154            it->second->serialize(serverMsg.buffer);
     1155
     1156            cout << "sending info about " << it->second->name  << endl;
     1157            cout << "sending id " << it->second->id  << endl;
     1158            if ( msgProcessor.sendMessage(&serverMsg, sock, &from, &outputLog) < 0 )
     1159               error("sendMessage");
     1160         }
     1161
    11601162         int numPlayers = g->getNumPlayers();
    11611163
Note: See TracChangeset for help on using the changeset viewer.