Changeset 5c7f28d in network-game for client/Client/main.cpp
- Timestamp:
- Jan 26, 2014, 9:45:30 PM (11 years ago)
- Branches:
- master
- Children:
- c51da03
- Parents:
- 9ee50ce
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
r9ee50ce r5c7f28d 57 57 void initWinSock(); 58 58 void shutdownWinSock(); 59 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, 60 map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId); 59 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId); 61 60 int getRefreshRate(int width, int height); 62 61 void drawMessageStatus(ALLEGRO_FONT* font); … … 136 135 bool key[4] = { false, false, false, false }; 137 136 map<unsigned int, Player*> mapPlayers; 138 map<unsigned int, Projectile> mapProjectiles;139 137 unsigned int curPlayerId = -1; 140 138 ofstream outputLog; … … 371 369 case ALLEGRO_KEY_D: // drop the current item 372 370 if (state == STATE_GAME) { 373 Player* p = NULL;374 371 try { 375 p = mapPlayers.at(curPlayerId); 376 } catch (const out_of_range& ex) {} 377 378 if (p != NULL) { 372 Player* p = mapPlayers.at(curPlayerId); 379 373 int flagType = OBJECT_NONE; 380 374 … … 389 383 msgProcessor.sendMessage(&msgTo, &server); 390 384 } 391 } 385 } catch (const out_of_range& ex) {} 392 386 } 393 387 break; … … 428 422 for(it = playersInGame.begin(); it != playersInGame.end(); it++) 429 423 { 430 // need to check if the right-click was actually on this player431 // right now, this code will target all players other than the current one432 424 target = it->second; 433 425 cout << "set target" << endl; … … 459 451 460 452 if (msgProcessor.receiveMessage(&msgFrom, &from) >= 0) 461 processMessage(msgFrom, state, chatConsole, mapPlayers, mapProjectiles,curPlayerId);453 processMessage(msgFrom, state, chatConsole, mapPlayers, curPlayerId); 462 454 463 455 if (redraw) … … 631 623 } 632 624 633 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, 634 map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId) 625 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId) 635 626 { 636 627 // this is outdated since most messages now don't contain just a text string … … 790 781 break; 791 782 } 792 case MSG_TYPE_PROJECTILE:793 {794 cout << "Received a PROJECTILE message" << endl;795 796 unsigned int id, x, y, targetId;797 798 memcpy(&id, msg.buffer, 4);799 memcpy(&x, msg.buffer+4, 4);800 memcpy(&y, msg.buffer+8, 4);801 memcpy(&targetId, msg.buffer+12, 4);802 803 cout << "id: " << id << endl;804 cout << "x: " << x << endl;805 cout << "y: " << y << endl;806 cout << "Target: " << targetId << endl;807 808 Projectile proj(x, y, targetId, 0);809 proj.setId(id);810 811 mapProjectiles[id] = proj;812 813 break;814 }815 case MSG_TYPE_REMOVE_PROJECTILE:816 {817 cout << "Received a REMOVE_PROJECTILE message" << endl;818 819 int id;820 memcpy(&id, msg.buffer, 4);821 822 mapProjectiles.erase(id);823 824 break;825 }826 783 case MSG_TYPE_GAME_INFO: 827 784 { … … 971 928 else 972 929 mapPlayers[p.getId()] = new Player(p); 930 931 break; 932 } 933 case MSG_TYPE_LOGOUT: 934 { 935 cout << "Got a logout message" << endl; 936 937 int playerId; 938 939 // Check if it's about you or another player 940 memcpy(&playerId, msg.buffer, 4); 941 response = string(msg.buffer+4); 942 943 if (playerId == curPlayerId) 944 cout << "Received MSG_TYPE_LOGOUT for self in STATE_GAME. This shouldn't happen." << endl; 945 else 946 delete mapPlayers[playerId]; 973 947 974 948 break;
Note:
See TracChangeset
for help on using the changeset viewer.