Changeset ab8fd40 in network-game for server


Ignore:
Timestamp:
Sep 27, 2013, 7:55:50 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
3ef8cf4
Parents:
03ba5e3
Message:

The server can process LEAVE_GAME messages

File:
1 edited

Legend:

Unmodified
Added
Removed
  • server/server.cpp

    r03ba5e3 rab8fd40  
    991991         break;
    992992      }
     993      case MSG_TYPE_LEAVE_GAME:
     994      {
     995         cout << "Received a LEAVE_GAME message" << endl;
     996
     997         Player* p = findPlayerByAddr(mapPlayers, from);
     998         Game* g = p->currentGame;
     999
     1000         if (g == NULL) {
     1001            cout << "Player " << p->name << " is trying to leave a game, but is not currently in a game." << endl;
     1002
     1003            /// should send a response back, maybe a new message type is needed
     1004
     1005            break;
     1006         }
     1007
     1008         cout << "Game name: " << g->getName() << endl;
     1009         //p->currentGame = NULL;
     1010
     1011         // broadcast a messsage to other players so they know someone left the game
     1012         // also, check if the game has any players left. If not, remove it and send everyone a message so the game is gone from their lobby list
     1013
     1014         int numPlayers = g->getNumPlayers();
     1015
     1016         serverMsg.type = MSG_TYPE_GAME_INFO;
     1017         memcpy(serverMsg.buffer, &numPlayers, 4);
     1018         strcpy(serverMsg.buffer+4, g->getName().c_str());
     1019         broadcastResponse = true;
     1020
     1021         break;
     1022      }
    9931023      case MSG_TYPE_JOIN_GAME_ACK:
    9941024      {
     
    10721102         strcpy(serverMsg.buffer+4, gameName.c_str());
    10731103         broadcastResponse = true;
     1104
    10741105         break;
    10751106      }
Note: See TracChangeset for help on using the changeset viewer.