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

Last change on this file since 6319311 was 6319311, checked in by Dmitry Portnoy <dportnoy@…>, 11 years ago

Some redfinition issues related to winsock2 are fixed and a few allegro rendering functions are now in GameRender

  • Property mode set to 100644
File size: 2.7 KB
Line 
1#ifndef _MESSAGE_CONTAINER_H
2#define _MESSAGE_CONTAINER_H
3
4#include <string>
5
6#include "Common.h"
7
8using namespace std;
9
10#define MSG_TYPE_ACK 1
11#define MSG_TYPE_REGISTER 2
12#define MSG_TYPE_LOGIN 3
13#define MSG_TYPE_LOGOUT 4
14#define MSG_TYPE_CHAT 5
15#define MSG_TYPE_PLAYER 6 // server sends this to update player positions
16#define MSG_TYPE_PLAYER_MOVE 7 // client sends this when a player wants to move
17#define MSG_TYPE_OBJECT 8
18#define MSG_TYPE_REMOVE_OBJECT 9
19#define MSG_TYPE_PICKUP_FLAG 10
20#define MSG_TYPE_DROP_FLAG 11
21#define MSG_TYPE_SCORE 12
22#define MSG_TYPE_START_ATTACK 13
23#define MSG_TYPE_ATTACK 14
24#define MSG_TYPE_PROJECTILE 15
25#define MSG_TYPE_REMOVE_PROJECTILE 16
26#define MSG_TYPE_CREATE_GAME 17
27#define MSG_TYPE_JOIN_GAME 18
28#define MSG_TYPE_LEAVE_GAME 19
29#define MSG_TYPE_GAME_INFO 20
30#define MSG_TYPE_JOIN_GAME_SUCCESS 21
31#define MSG_TYPE_JOIN_GAME_FAILURE 22
32#define MSG_TYPE_JOIN_GAME_ACK 23
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.