source: network-game/common/MessageContainer.h@ 321fbbc

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

Clients send game join and creation messages to server and new message type has been added

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