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

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

The code that processes player movement, attacks, and flag captures has been restructured to work on a per-game basis

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