- Timestamp:
- May 25, 2013, 6:04:08 PM (12 years ago)
- Branches:
- master
- Children:
- 7511a2b
- Parents:
- 626e5b0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
server/server.cpp
r626e5b0 re487381 161 161 } 162 162 163 vector<WorldMap::Object> vctObjects = gameMap->getObjects();163 vector<WorldMap::Object>* vctObjects = gameMap->getObjects(); 164 164 vector<WorldMap::Object>::iterator itObjects; 165 165 166 for (itObjects = vctObjects .begin(); itObjects != vctObjects.end(); itObjects++) {166 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end();) { 167 167 POSITION pos = itObjects->pos; 168 168 if (posDistance(it->second.pos, pos.toFloat()) < 10) { … … 180 180 } 181 181 182 // send a MSG_TYPE_REMOVE_OBJECT message183 182 serverMsg.type = MSG_TYPE_REMOVE_OBJECT; 184 183 memcpy(serverMsg.buffer, &itObjects->id, 4); … … 190 189 error("sendMessage"); 191 190 } 191 192 // remove the object form the server-side map 193 cout << "size before: " << gameMap->getObjects()->size() << endl; 194 itObjects = vctObjects->erase(itObjects); 195 cout << "size after: " << gameMap->getObjects()->size() << endl; 192 196 } 197 else 198 itObjects++; 193 199 } 194 200 … … 323 329 // (currently just the flags) 324 330 serverMsg.type = MSG_TYPE_OBJECT; 325 vector<WorldMap::Object> vctObjects = gameMap->getObjects();331 vector<WorldMap::Object>* vctObjects = gameMap->getObjects(); 326 332 vector<WorldMap::Object>::iterator itObjects; 327 333 cout << "sending items" << endl; 328 for (itObjects = vctObjects .begin(); itObjects != vctObjects.end(); itObjects++) {334 for (itObjects = vctObjects->begin(); itObjects != vctObjects->end(); itObjects++) { 329 335 itObjects->serialize(serverMsg.buffer); 330 336 cout << "sending item id " << itObjects->id << endl; … … 408 414 case MSG_TYPE_PLAYER_MOVE: 409 415 { 410 istringstream iss;411 iss.str(clientMsg.buffer);412 413 416 cout << "PLAYER_MOVE" << endl; 414 417 … … 451 454 break; 452 455 } 456 case MSG_TYPE_DROP_FLAG: 457 { 458 // may want to check the id matches the sender, just like for PLAYER_NOVE 459 cout << "DROP_FLAG" << endl; 460 461 int id; 462 463 memcpy(&id, clientMsg.buffer, 4); 464 cout << "id: " << id << endl; 465 466 WorldMap::ObjectType flagType = WorldMap::OBJECT_NONE; 467 if (mapPlayers[id].hasBlueFlag) 468 flagType = WorldMap::OBJECT_BLUE_FLAG; 469 else if (mapPlayers[id].hasRedFlag) 470 flagType = WorldMap::OBJECT_RED_FLAG; 471 472 gameMap->addObject(flagType, mapPlayers[id].pos.x, mapPlayers[id].pos.y); 473 474 // need to send the OBJECT message too 475 serverMsg.type = MSG_TYPE_OBJECT; 476 gameMap->getObjects()->back().serialize(serverMsg.buffer); 477 478 map<unsigned int, Player>::iterator it; 479 for (it = mapPlayers.begin(); it != mapPlayers.end(); it++) 480 { 481 if ( sendMessage(&serverMsg, sock, &(it->second.addr)) < 0 ) 482 error("sendMessage"); 483 } 484 485 mapPlayers[id].hasBlueFlag = false; 486 mapPlayers[id].hasRedFlag = false; 487 488 serverMsg.type = MSG_TYPE_PLAYER; 489 mapPlayers[id].serialize(serverMsg.buffer); 490 491 map<unsigned int, Player>::iterator it2; 492 broadcastResponse = true; 493 494 break; 495 } 453 496 default: 454 497 {
Note:
See TracChangeset
for help on using the changeset viewer.