- Timestamp:
- May 25, 2013, 11:51:29 PM (12 years ago)
- Branches:
- master
- Children:
- 15efb4e
- Parents:
- 5c84d54
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
r5c84d54 rb8601ee 38 38 // from used to be const. Removed that so I could take a reference 39 39 // and use it to send messages 40 bool processMessage(const NETWORK_MSG &clientMsg, struct sockaddr_in &from, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedId, NETWORK_MSG &serverMsg, int sock );40 bool processMessage(const NETWORK_MSG &clientMsg, struct sockaddr_in &from, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedId, NETWORK_MSG &serverMsg, int sock, int &scoreBlue, int &scoreRed); 41 41 42 42 void updateUnusedId(unsigned int& id, map<unsigned int, Player>& mapPlayers); … … 84 84 map<unsigned int, Player> mapPlayers; 85 85 unsigned int unusedId = 1; 86 int scoreBlue, scoreRed; 87 88 scoreBlue = 0; 89 scoreRed = 0; 86 90 87 91 //SSL_load_error_strings(); … … 176 180 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_RED_FLAG); 177 181 flagTurnedIn = true; 182 scoreBlue++; 178 183 } 179 184 … … 188 193 pos = gameMap->getStructureLocation(WorldMap::STRUCTURE_BLUE_FLAG); 189 194 flagTurnedIn = true; 195 scoreRed++; 190 196 } 191 197 … … 204 210 205 211 map<unsigned int, Player>::iterator it2; 212 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 213 { 214 if ( sendMessage(&serverMsg, sock, &(it2->second.addr)) < 0 ) 215 error("sendMessage"); 216 } 217 218 serverMsg.type = MSG_TYPE_SCORE; 219 memcpy(serverMsg.buffer, &scoreBlue, 4); 220 memcpy(serverMsg.buffer+4, &scoreRed, 4); 221 206 222 for (it2 = mapPlayers.begin(); it2 != mapPlayers.end(); it2++) 207 223 { … … 233 249 234 250 if (n >= 0) { 235 broadcastResponse = processMessage(clientMsg, from, mapPlayers, gameMap, unusedId, serverMsg, sock );251 broadcastResponse = processMessage(clientMsg, from, mapPlayers, gameMap, unusedId, serverMsg, sock, scoreBlue, scoreRed); 236 252 237 253 // probably replace this with a function that prints based on the … … 263 279 } 264 280 265 bool processMessage(const NETWORK_MSG& clientMsg, struct sockaddr_in& from, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedId, NETWORK_MSG& serverMsg, int sock )281 bool processMessage(const NETWORK_MSG& clientMsg, struct sockaddr_in& from, map<unsigned int, Player>& mapPlayers, WorldMap* gameMap, unsigned int& unusedId, NETWORK_MSG& serverMsg, int sock, int &scoreBlue, int &scoreRed) 266 282 { 267 283 DataAccess da; … … 355 371 } 356 372 373 // send the current score 374 serverMsg.type = MSG_TYPE_SCORE; 375 memcpy(serverMsg.buffer, &scoreBlue, 4); 376 memcpy(serverMsg.buffer+4, &scoreRed, 4); 377 if ( sendMessage(&serverMsg, sock, &from) < 0 ) 378 error("sendMessage"); 379 380 serverMsg.type = MSG_TYPE_PLAYER; 357 381 p->serialize(serverMsg.buffer); 358 382 cout << "Should be broadcasting the message" << endl;
Note:
See TracChangeset
for help on using the changeset viewer.