Changeset 46d6469 in network-game for common/MessageProcessor.h
- Timestamp:
- Jul 26, 2013, 6:28:39 PM (12 years ago)
- Branches:
- master
- Children:
- 9fe1807
- Parents:
- 411c1ae
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
common/MessageProcessor.h
r411c1ae r46d6469 4 4 #include <map> 5 5 6 #include "Compiler.h" 7 8 #if defined WINDOWS 9 #include <winsock2.h> 10 #include <WS2tcpip.h> 11 #elif defined LINUX 12 #include <netinet/in.h> 13 #endif 14 15 #define MSG_TYPE_ACK 1 16 #define MSG_TYPE_REGISTER 2 17 #define MSG_TYPE_LOGIN 3 18 #define MSG_TYPE_LOGOUT 4 19 #define MSG_TYPE_CHAT 5 20 #define MSG_TYPE_PLAYER 6 // server sends this to update player positions 21 #define MSG_TYPE_PLAYER_MOVE 7 // client sends this when a player wants to move 22 #define MSG_TYPE_OBJECT 8 23 #define MSG_TYPE_REMOVE_OBJECT 9 24 #define MSG_TYPE_PICKUP_FLAG 10 25 #define MSG_TYPE_DROP_FLAG 11 26 #define MSG_TYPE_SCORE 12 27 #define MSG_TYPE_START_ATTACK 13 28 #define MSG_TYPE_ATTACK 14 29 #define MSG_TYPE_PROJECTILE 15 30 #define MSG_TYPE_REMOVE_PROJECTILE 16 31 32 typedef struct 33 { 34 unsigned int id; 35 unsigned short type; 36 char buffer[256]; 37 } NETWORK_MSG; 6 #include "MessageContainer.h" 38 7 39 8 using namespace std; 40 9 41 10 class MessageProcessor { 11 private: 12 int lastUsedId; 13 14 // map from message ids to maps from player addresses to message info 15 map<int, map<unsigned long, MessageContainer> > sentMessages; 16 17 // map from message ids to the time each mesage was acked 18 map<unsigned int, unsigned long long> ackedMessages; 19 20 unsigned long pid; 21 42 22 public: 43 23 MessageProcessor(); … … 48 28 void resendUnackedMessages(int sock); 49 29 void cleanAckedMessages(); 50 51 private:52 // this should eventually just replace the Message struct53 class MessageContainer {54 public:55 MessageContainer() {56 }57 58 MessageContainer(const MessageContainer& mc) {59 this->msg = mc.msg;60 this->clientAddr = mc.clientAddr;61 }62 63 MessageContainer(NETWORK_MSG msg, struct sockaddr_in clientAddr) {64 this->clientAddr = clientAddr;65 this->msg = msg;66 }67 68 ~MessageContainer() {69 }70 71 NETWORK_MSG msg;72 struct sockaddr_in clientAddr;73 bool isAcked;74 unsigned long long timeAcked;75 };76 77 int lastUsedId;78 79 // map from message ids to maps from player addresses to message info80 map<int, map<unsigned long, MessageContainer> > sentMessages;81 82 // map from message ids to the time each mesage was acked83 map<unsigned int, unsigned long long> ackedMessages;84 30 }; 85 31
Note:
See TracChangeset
for help on using the changeset viewer.