source: network-game/common/MessageContainer.h@ 373089e

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

The server compiles

  • Property mode set to 100644
File size: 2.8 KB
Line 
1#ifndef _MESSAGE_CONTAINER_H
2#define _MESSAGE_CONTAINER_H
3
4#include <string>
5
6#include "Common.h"
7
8#if defined LINUX
9 #include <netinet/in.h>
10#endif
11
12using namespace std;
13
14#define MSG_TYPE_ACK 1
15#define MSG_TYPE_REGISTER 2
16#define MSG_TYPE_LOGIN 3
17#define MSG_TYPE_LOGOUT 4
18#define MSG_TYPE_CHAT 5
19#define MSG_TYPE_PLAYER 6 // server sends this to update player positions
20#define MSG_TYPE_PLAYER_MOVE 7 // client sends this when a player wants to move
21#define MSG_TYPE_OBJECT 8
22#define MSG_TYPE_REMOVE_OBJECT 9
23#define MSG_TYPE_PICKUP_FLAG 10
24#define MSG_TYPE_DROP_FLAG 11
25#define MSG_TYPE_SCORE 12
26#define MSG_TYPE_START_ATTACK 13
27#define MSG_TYPE_ATTACK 14
28#define MSG_TYPE_PROJECTILE 15
29#define MSG_TYPE_REMOVE_PROJECTILE 16
30#define MSG_TYPE_CREATE_GAME 17
31#define MSG_TYPE_JOIN_GAME 18
32#define MSG_TYPE_LEAVE_GAME 19
33#define MSG_TYPE_GAME_INFO 20
34#define MSG_TYPE_JOIN_GAME_SUCCESS 21
35#define MSG_TYPE_JOIN_GAME_FAILURE 22
36#define MSG_TYPE_JOIN_GAME_ACK 23
37
38typedef struct
39{
40 unsigned int id;
41 unsigned short type;
42 char buffer[256];
43} NETWORK_MSG;
44
45class MessageContainer {
46private:
47 NETWORK_MSG msg;
48 struct sockaddr_in clientAddr;
49 bool isAcked;
50 unsigned long long timeAcked;
51
52public:
53 MessageContainer();
54 MessageContainer(const MessageContainer& mc);
55 MessageContainer(NETWORK_MSG msg, struct sockaddr_in clientAddr);
56 ~MessageContainer();
57
58 bool getAcked();
59 unsigned long long getTimeAcked();
60 NETWORK_MSG* getMessage();
61
62 void setAcked(bool acked);
63 void setTimeAcked(unsigned long long time);
64
65 static string getMsgTypeString(int msgType) {
66 switch(msgType) {
67 case MSG_TYPE_ACK: return "MSG_TYPE_ACK";
68 case MSG_TYPE_REGISTER: return "MSG_TYPE_REGISTER";
69 case MSG_TYPE_LOGIN: return "MSG_TYPE_LOGIN";
70 case MSG_TYPE_LOGOUT: return "MSG_TYPE_LOGOUT";
71 case MSG_TYPE_CHAT: return "MSG_TYPE_CHAT";
72 case MSG_TYPE_PLAYER: return "MSG_TYPE_PLAYER";
73 case MSG_TYPE_PLAYER_MOVE: return "MSG_TYPE_PLAYER_MOVE";
74 case MSG_TYPE_OBJECT: return "MSG_TYPE_OBJECT";
75 case MSG_TYPE_REMOVE_OBJECT: return "MSG_TYPE_REMOVE_OBJECT";
76 case MSG_TYPE_PICKUP_FLAG: return "MSG_TYPE_PICKUP_FLAG";
77 case MSG_TYPE_DROP_FLAG: return "MSG_TYPE_DROP_FLAG";
78 case MSG_TYPE_SCORE: return "MSG_TYPE_SCORE";
79 case MSG_TYPE_START_ATTACK: return "MSG_TYPE_START_ATACK";
80 case MSG_TYPE_ATTACK: return "MSG_TYPE_ATTACK";
81 case MSG_TYPE_PROJECTILE: return "MSG_TYPE_PROJECTILE";
82 case MSG_TYPE_REMOVE_PROJECTILE: return "MSG_TYPE_REMOVE_PROJECTILE";
83 default: return "Unknown";
84 }
85 }
86};
87
88#endif
Note: See TracBrowser for help on using the repository browser.