Changeset b35b2b2 in network-game for common


Ignore:
Timestamp:
Jul 29, 2013, 10:32:59 PM (11 years ago)
Author:
dportnoy <dmp1488@…>
Branches:
master
Children:
d05086b
Parents:
297682c
Message:

Added a basic ingame debug console

Location:
common
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • common/MessageContainer.cpp

    r297682c rb35b2b2  
    4848   this->timeAcked = time;
    4949}
     50
     51/*
     52string getMsgTypeString(int msgType) {
     53   switch(msgType) {
     54      case MSG_TYPE_ACK: return "MSG_TYPE_ACK";
     55      case MSG_TYPE_REGISTER: return "MSG_TYPE_REGISTER";
     56      case MSG_TYPE_LOGIN: return "MSG_TYPE_LOGIN";
     57      case MSG_TYPE_LOGOUT: return "MSG_TYPE_LOGOUT";
     58      case MSG_TYPE_CHAT: return "MSG_TYPE_CHAT";
     59      case MSG_TYPE_PLAYER: return "MSG_TYPE_PLAYER";
     60      case MSG_TYPE_PLAYER_MOVE: return "MSG_TYPE_PLAYER_MOVE";
     61      case MSG_TYPE_OBJECT: return "MSG_TYPE_OBJECT";
     62      case MSG_TYPE_REMOVE_OBJECT: return "MSG_TYPE_REMOVE_OBJECT";
     63      case MSG_TYPE_PICKUP_FLAG: return "MSG_TYPE_PICKUP_FLAG";
     64      caseMSG_TYPE_DROP_FLAG: return "MSG_TYPE_DROP_FLAG";
     65      case MSG_TYPE_SCORE: return "MSG_TYPE_SCORE";
     66      case MSG_TYPE_START_ATTACK: return "MSG_TYPE_START_ATACK";
     67      case MSG_TYPE_ATTACK: return "MSG_TYPE_ATTACK";
     68      case MSG_TYPE_PROJECTILE: return "MSG_TYPE_PROJECTILE";
     69      case MSG_TYPE_REMOVE_PROJECTILE: return "MSG_TYPE_REMOVE_PROJECTILE";
     70      default: return "Unknown";
     71   }
     72}
     73*/
  • common/MessageContainer.h

    r297682c rb35b2b2  
    33
    44#include "Compiler.h"
     5
     6#include <string>
    57
    68#if defined WINDOWS
     
    1012   #include <netinet/in.h>
    1113#endif
     14
     15using namespace std;
    1216
    1317#define MSG_TYPE_ACK               1
     
    5458   void setAcked(bool acked);
    5559   void setTimeAcked(unsigned long long time);
     60
     61   static string getMsgTypeString(int msgType) {
     62      switch(msgType) {
     63         case MSG_TYPE_ACK: return "MSG_TYPE_ACK";
     64         case MSG_TYPE_REGISTER: return "MSG_TYPE_REGISTER";
     65         case MSG_TYPE_LOGIN: return "MSG_TYPE_LOGIN";
     66         case MSG_TYPE_LOGOUT: return "MSG_TYPE_LOGOUT";
     67         case MSG_TYPE_CHAT: return "MSG_TYPE_CHAT";
     68         case MSG_TYPE_PLAYER: return "MSG_TYPE_PLAYER";
     69         case MSG_TYPE_PLAYER_MOVE: return "MSG_TYPE_PLAYER_MOVE";
     70         case MSG_TYPE_OBJECT: return "MSG_TYPE_OBJECT";
     71         case MSG_TYPE_REMOVE_OBJECT: return "MSG_TYPE_REMOVE_OBJECT";
     72         case MSG_TYPE_PICKUP_FLAG: return "MSG_TYPE_PICKUP_FLAG";
     73         case MSG_TYPE_DROP_FLAG: return "MSG_TYPE_DROP_FLAG";
     74         case MSG_TYPE_SCORE: return "MSG_TYPE_SCORE";
     75         case MSG_TYPE_START_ATTACK: return "MSG_TYPE_START_ATACK";
     76         case MSG_TYPE_ATTACK: return "MSG_TYPE_ATTACK";
     77         case MSG_TYPE_PROJECTILE: return "MSG_TYPE_PROJECTILE";
     78         case MSG_TYPE_REMOVE_PROJECTILE: return "MSG_TYPE_REMOVE_PROJECTILE";
     79         default: return "Unknown";
     80      }
     81   }
    5682};
    5783
  • common/MessageProcessor.cpp

    r297682c rb35b2b2  
    5252         cout << "Got message of type " << msg->type << endl;
    5353
    54       ackedMessages[msg->id] = getCurrentMillis();
     54      ackedMessages[msg->id] = MessageContainer(*msg, *source);
     55      ackedMessages[msg->id].setAcked(true);
     56      ackedMessages[msg->id].setTimeAcked(getCurrentMillis());
    5557
    5658      NETWORK_MSG ack;
     
    6870
    6971void MessageProcessor::resendUnackedMessages(int sock) {
    70    map<int, map<unsigned long, MessageContainer> >::iterator it;
     72   map<unsigned int, map<unsigned long, MessageContainer> >::iterator it;
    7173   map<unsigned long, MessageContainer>::iterator it2;
    7274   map<unsigned long, MessageContainer> sentMsg;
     
    8385
    8486void MessageProcessor::cleanAckedMessages() {
    85    map<int, map<unsigned long, MessageContainer> >::iterator it = sentMessages.begin();
     87   map<unsigned int, map<unsigned long, MessageContainer> >::iterator it = sentMessages.begin();
    8688   map<unsigned long, MessageContainer>::iterator it2;
    8789
     
    104106   }
    105107
     108   /*
    106109   map<unsigned int, unsigned long long>::iterator it3 = ackedMessages.begin();
    107110
     
    112115         it3++;
    113116   }
     117   */
    114118}
     119
     120map<unsigned int, map<unsigned long, MessageContainer> >& MessageProcessor::getSentMessages() {
     121   return this->sentMessages;
     122}
     123
     124map<unsigned int, MessageContainer>& MessageProcessor::getAckedMessages() {
     125   return this->ackedMessages;
     126}
  • common/MessageProcessor.h

    r297682c rb35b2b2  
    1313
    1414   // map from message ids to maps from player addresses to message info
    15    map<int, map<unsigned long, MessageContainer> > sentMessages;
     15   map<unsigned int, map<unsigned long, MessageContainer> > sentMessages;
    1616
    1717   // map from message ids to the time each mesage was acked
    18    map<unsigned int, unsigned long long> ackedMessages;
     18   map<unsigned int, MessageContainer> ackedMessages;
    1919
    2020   unsigned long pid;
     
    2828   void resendUnackedMessages(int sock);
    2929   void cleanAckedMessages();
     30
     31   map<unsigned int, map<unsigned long, MessageContainer> >& getSentMessages();
     32   map<unsigned int, MessageContainer>& getAckedMessages();
    3033};
    3134
Note: See TracChangeset for help on using the changeset viewer.