Changes in client/Client/main.cpp [5c7f28d:1e250bf] in network-game
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
client/Client/main.cpp
r5c7f28d r1e250bf 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, unsigned int& curPlayerId); 59 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, 60 map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId); 60 61 int getRefreshRate(int width, int height); 61 62 void drawMessageStatus(ALLEGRO_FONT* font); … … 133 134 ALLEGRO_EVENT_QUEUE *event_queue = NULL; 134 135 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; 137 138 unsigned int curPlayerId = -1; 138 139 ofstream outputLog; … … 369 370 case ALLEGRO_KEY_D: // drop the current item 370 371 if (state == STATE_GAME) { 372 Player* p = NULL; 371 373 try { 372 Player* p = mapPlayers.at(curPlayerId); 374 p = mapPlayers.at(curPlayerId); 375 } catch (const out_of_range& ex) {} 376 377 if (p != NULL) { 373 378 int flagType = OBJECT_NONE; 374 379 … … 383 388 msgProcessor.sendMessage(&msgTo, &server); 384 389 } 385 } catch (const out_of_range& ex) {}390 } 386 391 } 387 392 break; … … 422 427 for(it = playersInGame.begin(); it != playersInGame.end(); it++) 423 428 { 429 // need to check if the right-click was actually on this player 430 // right now, this code will target all players other than the current one 424 431 target = it->second; 425 432 cout << "set target" << endl; … … 451 458 452 459 if (msgProcessor.receiveMessage(&msgFrom, &from) >= 0) 453 processMessage(msgFrom, state, chatConsole, mapPlayers, curPlayerId);460 processMessage(msgFrom, state, chatConsole, mapPlayers, mapProjectiles, curPlayerId); 454 461 455 462 if (redraw) … … 623 630 } 624 631 625 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId) 632 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, 633 map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId) 626 634 { 627 635 // this is outdated since most messages now don't contain just a text string … … 697 705 cout << "Got a logout message" << endl; 698 706 699 int playerId;707 unsigned int playerId; 700 708 701 709 // Check if it's about you or another player … … 781 789 break; 782 790 } 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 } 783 825 case MSG_TYPE_GAME_INFO: 784 826 { … … 928 970 else 929 971 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 player940 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 else946 delete mapPlayers[playerId];947 972 948 973 break;
Note:
See TracChangeset
for help on using the changeset viewer.