Changes in client/Client/main.cpp [1e250bf:5c7f28d] in network-game


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • client/Client/main.cpp

    r1e250bf r5c7f28d  
    1515#include <cstdio>
    1616#include <cstdlib>
    17 //#include <cmath>
     17#include <cmath>
    1818#include <sys/types.h>
    1919#include <string>
     
    5757void initWinSock();
    5858void 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);
     59void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId);
    6160int getRefreshRate(int width, int height);
    6261void drawMessageStatus(ALLEGRO_FONT* font);
     
    134133   ALLEGRO_EVENT_QUEUE *event_queue = NULL;
    135134   ALLEGRO_TIMER *timer = NULL;
     135   bool key[4] = { false, false, false, false };
    136136   map<unsigned int, Player*> mapPlayers;
    137    map<unsigned int, Projectile> mapProjectiles;
    138137   unsigned int curPlayerId = -1;
    139138   ofstream outputLog;
     
    370369            case ALLEGRO_KEY_D:  // drop the current item
    371370               if (state == STATE_GAME) {
    372                   Player* p = NULL;
    373371                  try {
    374                      p = mapPlayers.at(curPlayerId);
    375                   } catch (const out_of_range& ex) {}
    376 
    377                   if (p != NULL) {
     372                     Player* p = mapPlayers.at(curPlayerId);
    378373                     int flagType = OBJECT_NONE;
    379374
     
    388383                        msgProcessor.sendMessage(&msgTo, &server);
    389384                     }
    390                   }
     385                  } catch (const out_of_range& ex) {}
    391386               }
    392387               break;
     
    427422               for(it = playersInGame.begin(); it != playersInGame.end(); it++)
    428423               {
    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
    431424                  target = it->second;
    432425                  cout << "set target" << endl;
     
    458451
    459452      if (msgProcessor.receiveMessage(&msgFrom, &from) >= 0)
    460          processMessage(msgFrom, state, chatConsole, mapPlayers, mapProjectiles, curPlayerId);
     453         processMessage(msgFrom, state, chatConsole, mapPlayers, curPlayerId);
    461454
    462455      if (redraw)
     
    630623}
    631624
    632 void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers,
    633                     map<unsigned int, Projectile>& mapProjectiles, unsigned int& curPlayerId)
     625void processMessage(NETWORK_MSG &msg, int &state, chat &chatConsole, map<unsigned int, Player*>& mapPlayers, unsigned int& curPlayerId)
    634626{
    635627   // this is outdated since most messages now don't contain just a text string
     
    705697               cout << "Got a logout message" << endl;
    706698
    707                unsigned int playerId;
     699               int playerId;
    708700
    709701               // Check if it's about you or another player
     
    789781               break;
    790782            }
    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             }
    825783            case MSG_TYPE_GAME_INFO:
    826784            {
     
    970928               else
    971929                  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];
    972947
    973948               break;
Note: See TracChangeset for help on using the changeset viewer.