source: network-game/common/MessageContainer.h@ 1f6233e

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

The ATTACK message has been removed and the START_ATTACK message has been renamed to ATTACK

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