source: network-game/common/MessageContainer.h@ b35b2b2

Last change on this file since b35b2b2 was b35b2b2, checked in by dportnoy <dmp1488@…>, 11 years ago

Added a basic ingame debug console

  • Property mode set to 100644
File size: 2.6 KB
Line 
1#ifndef _MESSAGE_CONTAINER_H
2#define _MESSAGE_CONTAINER_H
3
4#include "Compiler.h"
5
6#include <string>
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
15using namespace std;
16
17#define MSG_TYPE_ACK 1
18#define MSG_TYPE_REGISTER 2
19#define MSG_TYPE_LOGIN 3
20#define MSG_TYPE_LOGOUT 4
21#define MSG_TYPE_CHAT 5
22#define MSG_TYPE_PLAYER 6 // server sends this to update player positions
23#define MSG_TYPE_PLAYER_MOVE 7 // client sends this when a player wants to move
24#define MSG_TYPE_OBJECT 8
25#define MSG_TYPE_REMOVE_OBJECT 9
26#define MSG_TYPE_PICKUP_FLAG 10
27#define MSG_TYPE_DROP_FLAG 11
28#define MSG_TYPE_SCORE 12
29#define MSG_TYPE_START_ATTACK 13
30#define MSG_TYPE_ATTACK 14
31#define MSG_TYPE_PROJECTILE 15
32#define MSG_TYPE_REMOVE_PROJECTILE 16
33
34typedef struct
35{
36 unsigned int id;
37 unsigned short type;
38 char buffer[256];
39} NETWORK_MSG;
40
41class MessageContainer {
42private:
43 NETWORK_MSG msg;
44 struct sockaddr_in clientAddr;
45 bool isAcked;
46 unsigned long long timeAcked;
47
48public:
49 MessageContainer();
50 MessageContainer(const MessageContainer& mc);
51 MessageContainer(NETWORK_MSG msg, struct sockaddr_in clientAddr);
52 ~MessageContainer();
53
54 bool getAcked();
55 unsigned long long getTimeAcked();
56 NETWORK_MSG* getMessage();
57
58 void setAcked(bool acked);
59 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 }
82};
83
84#endif
Note: See TracBrowser for help on using the repository browser.