Changeset ab8fd40 in network-game
- Timestamp:
- Sep 27, 2013, 7:55:50 PM (11 years ago)
- Branches:
- master
- Children:
- 3ef8cf4
- Parents:
- 03ba5e3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
common/Game.cpp
r03ba5e3 rab8fd40 21 21 Game::~Game() { 22 22 delete this->worldMap; 23 } 24 25 string Game::getName() { 26 return this->name; 23 27 } 24 28 -
common/Game.h
r03ba5e3 rab8fd40 34 34 ~Game(); 35 35 36 string getName(); 36 37 int getNumPlayers(); 37 38 map<unsigned int, Player*>& getPlayers(); -
server/server.cpp
r03ba5e3 rab8fd40 991 991 break; 992 992 } 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 } 993 1023 case MSG_TYPE_JOIN_GAME_ACK: 994 1024 { … … 1072 1102 strcpy(serverMsg.buffer+4, gameName.c_str()); 1073 1103 broadcastResponse = true; 1104 1074 1105 break; 1075 1106 }
Note:
See TracChangeset
for help on using the changeset viewer.