[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] | 14 | using 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
|
---|
| 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
|
---|
[f419b09] | 32 | #define MSG_TYPE_CREATE_GAME 17
|
---|
| 33 | #define MSG_TYPE_JOIN_GAME 18
|
---|
| 34 | #define MSG_TYPE_LEAVE_GAME 19
|
---|
[bbebe9c] | 35 | #define MSG_TYPE_GAME_INFO 20
|
---|
[7d8d5d3] | 36 | #define MSG_TYPE_JOIN_GAME_SUCCESS 21
|
---|
[b48ef09] | 37 | #define MSG_TYPE_JOIN_GAME_FAILURE 22
|
---|
| 38 | #define MSG_TYPE_JOIN_GAME_ACK 23
|
---|
[46d6469] | 39 |
|
---|
| 40 | typedef struct
|
---|
| 41 | {
|
---|
| 42 | unsigned int id;
|
---|
| 43 | unsigned short type;
|
---|
| 44 | char buffer[256];
|
---|
| 45 | } NETWORK_MSG;
|
---|
| 46 |
|
---|
| 47 | class MessageContainer {
|
---|
| 48 | private:
|
---|
| 49 | NETWORK_MSG msg;
|
---|
| 50 | struct sockaddr_in clientAddr;
|
---|
| 51 | bool isAcked;
|
---|
| 52 | unsigned long long timeAcked;
|
---|
| 53 |
|
---|
| 54 | public:
|
---|
| 55 | MessageContainer();
|
---|
| 56 | MessageContainer(const MessageContainer& mc);
|
---|
| 57 | MessageContainer(NETWORK_MSG msg, struct sockaddr_in clientAddr);
|
---|
| 58 | ~MessageContainer();
|
---|
| 59 |
|
---|
| 60 | bool getAcked();
|
---|
| 61 | unsigned long long getTimeAcked();
|
---|
| 62 | NETWORK_MSG* getMessage();
|
---|
| 63 |
|
---|
| 64 | void setAcked(bool acked);
|
---|
| 65 | void setTimeAcked(unsigned long long time);
|
---|
[b35b2b2] | 66 |
|
---|
| 67 | static string getMsgTypeString(int msgType) {
|
---|
| 68 | switch(msgType) {
|
---|
| 69 | case MSG_TYPE_ACK: return "MSG_TYPE_ACK";
|
---|
| 70 | case MSG_TYPE_REGISTER: return "MSG_TYPE_REGISTER";
|
---|
| 71 | case MSG_TYPE_LOGIN: return "MSG_TYPE_LOGIN";
|
---|
| 72 | case MSG_TYPE_LOGOUT: return "MSG_TYPE_LOGOUT";
|
---|
| 73 | case MSG_TYPE_CHAT: return "MSG_TYPE_CHAT";
|
---|
| 74 | case MSG_TYPE_PLAYER: return "MSG_TYPE_PLAYER";
|
---|
| 75 | case MSG_TYPE_PLAYER_MOVE: return "MSG_TYPE_PLAYER_MOVE";
|
---|
| 76 | case MSG_TYPE_OBJECT: return "MSG_TYPE_OBJECT";
|
---|
| 77 | case MSG_TYPE_REMOVE_OBJECT: return "MSG_TYPE_REMOVE_OBJECT";
|
---|
| 78 | case MSG_TYPE_PICKUP_FLAG: return "MSG_TYPE_PICKUP_FLAG";
|
---|
| 79 | case MSG_TYPE_DROP_FLAG: return "MSG_TYPE_DROP_FLAG";
|
---|
| 80 | case MSG_TYPE_SCORE: return "MSG_TYPE_SCORE";
|
---|
| 81 | case MSG_TYPE_START_ATTACK: return "MSG_TYPE_START_ATACK";
|
---|
| 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";
|
---|
| 85 | default: return "Unknown";
|
---|
| 86 | }
|
---|
| 87 | }
|
---|
[46d6469] | 88 | };
|
---|
| 89 |
|
---|
| 90 | #endif
|
---|