source: network-game/common/MessageContainer.h@ 929b4e0

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

Added a Game class and new messages types for creating, joining, and leaving games

  • 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
37typedef struct
38{
39 unsigned int id;
40 unsigned short type;
41 char buffer[256];
42} NETWORK_MSG;
43
44class MessageContainer {
45private:
46 NETWORK_MSG msg;
47 struct sockaddr_in clientAddr;
48 bool isAcked;
49 unsigned long long timeAcked;
50
51public:
52 MessageContainer();
53 MessageContainer(const MessageContainer& mc);
54 MessageContainer(NETWORK_MSG msg, struct sockaddr_in clientAddr);
55 ~MessageContainer();
56
57 bool getAcked();
58 unsigned long long getTimeAcked();
59 NETWORK_MSG* getMessage();
60
61 void setAcked(bool acked);
62 void setTimeAcked(unsigned long long time);
63
64 static string getMsgTypeString(int msgType) {
65 switch(msgType) {
66 case MSG_TYPE_ACK: return "MSG_TYPE_ACK";
67 case MSG_TYPE_REGISTER: return "MSG_TYPE_REGISTER";
68 case MSG_TYPE_LOGIN: return "MSG_TYPE_LOGIN";
69 case MSG_TYPE_LOGOUT: return "MSG_TYPE_LOGOUT";
70 case MSG_TYPE_CHAT: return "MSG_TYPE_CHAT";
71 case MSG_TYPE_PLAYER: return "MSG_TYPE_PLAYER";
72 case MSG_TYPE_PLAYER_MOVE: return "MSG_TYPE_PLAYER_MOVE";
73 case MSG_TYPE_OBJECT: return "MSG_TYPE_OBJECT";
74 case MSG_TYPE_REMOVE_OBJECT: return "MSG_TYPE_REMOVE_OBJECT";
75 case MSG_TYPE_PICKUP_FLAG: return "MSG_TYPE_PICKUP_FLAG";
76 case MSG_TYPE_DROP_FLAG: return "MSG_TYPE_DROP_FLAG";
77 case MSG_TYPE_SCORE: return "MSG_TYPE_SCORE";
78 case MSG_TYPE_START_ATTACK: return "MSG_TYPE_START_ATACK";
79 case MSG_TYPE_ATTACK: return "MSG_TYPE_ATTACK";
80 case MSG_TYPE_PROJECTILE: return "MSG_TYPE_PROJECTILE";
81 case MSG_TYPE_REMOVE_PROJECTILE: return "MSG_TYPE_REMOVE_PROJECTILE";
82 default: return "Unknown";
83 }
84 }
85};
86
87#endif
Note: See TracBrowser for help on using the repository browser.