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

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

PLAYER_JOIN_GAME messages, rather than PLAYER ones, are now sent to indicate players joining specific matches. The server also sends a player just joining a match all players currently in the match, including the new player

  • 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
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);
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_START_ATTACK: return "MSG_TYPE_START_ATACK";
83 case MSG_TYPE_ATTACK: return "MSG_TYPE_ATTACK";
84 case MSG_TYPE_PROJECTILE: return "MSG_TYPE_PROJECTILE";
85 case MSG_TYPE_REMOVE_PROJECTILE: return "MSG_TYPE_REMOVE_PROJECTILE";
86 default: return "Unknown";
87 }
88 }
89};
90
91#endif
Note: See TracBrowser for help on using the repository browser.