Changes in client/Client/main.cpp [1e250bf:5c7f28d] in network-game
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
r1e250bf r5c7f28d 15 15 #include <cstdio> 16 16 #include <cstdlib> 17 //#include <cmath>17 #include <cmath> 18 18 #include <sys/types.h> 19 19 #include <string> … … 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); … … 134 133 ALLEGRO_EVENT_QUEUE *event_queue = NULL; 135 134 ALLEGRO_TIMER *timer = NULL; 135 bool key[4] = { false, false, false, false }; 136 136 map<unsigned int, Player*> mapPlayers; 137 map<unsigned int, Projectile> mapProjectiles;138 137 unsigned int curPlayerId = -1; 139 138 ofstream outputLog; … … 370 369 case ALLEGRO_KEY_D: // drop the current item 371 370 if (state == STATE_GAME) { 372 Player* p = NULL;373 371 try { 374 p = mapPlayers.at(curPlayerId); 375 } catch (const out_of_range& ex) {} 376 377 if (p != NULL) { 372 Player* p = mapPlayers.at(curPlayerId); 378 373 int flagType = OBJECT_NONE; 379 374 … … 388 383 msgProcessor.sendMessage(&msgTo, &server); 389 384 } 390 } 385 } catch (const out_of_range& ex) {} 391 386 } 392 387 break; … … 427 422 for(it = playersInGame.begin(); it != playersInGame.end(); it++) 428 423 { 429 // need to check if the right-click was actually on this player430 // right now, this code will target all players other than the current one431 424 target = it->second; 432 425 cout << "set target" << endl; … … 458 451 459 452 if (msgProcessor.receiveMessage(&msgFrom, &from) >= 0) 460 processMessage(msgFrom, state, chatConsole, mapPlayers, mapProjectiles,curPlayerId);453 processMessage(msgFrom, state, chatConsole, mapPlayers, curPlayerId); 461 454 462 455 if (redraw) … … 630 623 } 631 624 632 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, 633 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) 634 626 { 635 627 // this is outdated since most messages now don't contain just a text string … … 705 697 cout << "Got a logout message" << endl; 706 698 707 unsignedint playerId;699 int playerId; 708 700 709 701 // Check if it's about you or another player … … 789 781 break; 790 782 } 791 case MSG_TYPE_PROJECTILE:792 {793 cout << "Received a PROJECTILE message" << endl;794 795 unsigned int id, x, y, targetId;796 797 memcpy(&id, msg.buffer, 4);798 memcpy(&x, msg.buffer+4, 4);799 memcpy(&y, msg.buffer+8, 4);800 memcpy(&targetId, msg.buffer+12, 4);801 802 cout << "id: " << id << endl;803 cout << "x: " << x << endl;804 cout << "y: " << y << endl;805 cout << "Target: " << targetId << endl;806 807 Projectile proj(x, y, targetId, 0);808 proj.setId(id);809 810 mapProjectiles[id] = proj;811 812 break;813 }814 case MSG_TYPE_REMOVE_PROJECTILE:815 {816 cout << "Received a REMOVE_PROJECTILE message" << endl;817 818 int id;819 memcpy(&id, msg.buffer, 4);820 821 mapProjectiles.erase(id);822 823 break;824 }825 783 case MSG_TYPE_GAME_INFO: 826 784 { … … 970 928 else 971 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]; 972 947 973 948 break;
Note:
See TracChangeset
for help on using the changeset viewer.