[1a3c42d] | 1 | #ifndef _MESSAGE_PROCESSOR_H
|
---|
| 2 | #define _MESSAGE_PROCESSOR_H
|
---|
| 3 |
|
---|
[5a64bea] | 4 | #include <map>
|
---|
| 5 |
|
---|
| 6 | #include "Compiler.h"
|
---|
| 7 |
|
---|
[1a3c42d] | 8 | #include "Message.h"
|
---|
| 9 |
|
---|
[5a64bea] | 10 | #if defined WINDOWS
|
---|
| 11 | #include <winsock2.h>
|
---|
| 12 | #include <WS2tcpip.h>
|
---|
| 13 | #elif defined LINUX
|
---|
| 14 | #include <netinet/in.h>
|
---|
| 15 | #endif
|
---|
| 16 |
|
---|
[1a3c42d] | 17 | /*
|
---|
| 18 | #define MSG_TYPE_REGISTER 1
|
---|
| 19 | #define MSG_TYPE_LOGIN 2
|
---|
| 20 | #define MSG_TYPE_LOGOUT 3
|
---|
| 21 | #define MSG_TYPE_CHAT 4
|
---|
| 22 | #define MSG_TYPE_PLAYER 5 // server sends this to update player positions
|
---|
| 23 | #define MSG_TYPE_PLAYER_MOVE 6 // client sends this when a player wants to move
|
---|
| 24 | #define MSG_TYPE_OBJECT 7
|
---|
| 25 | #define MSG_TYPE_REMOVE_OBJECT 8
|
---|
| 26 | #define MSG_TYPE_PICKUP_FLAG 9
|
---|
| 27 | #define MSG_TYPE_DROP_FLAG 10
|
---|
| 28 | #define MSG_TYPE_SCORE 11
|
---|
| 29 | #define MSG_TYPE_START_ATTACK 12
|
---|
| 30 | #define MSG_TYPE_ATTACK 13
|
---|
| 31 | #define MSG_TYPE_PROJECTILE 14
|
---|
| 32 | #define MSG_TYPE_REMOVE_PROJECTILE 15
|
---|
| 33 |
|
---|
| 34 | typedef struct
|
---|
| 35 | {
|
---|
| 36 | short type;
|
---|
| 37 | char buffer[256];
|
---|
| 38 | } NETWORK_MSG;
|
---|
| 39 | */
|
---|
| 40 |
|
---|
[5a64bea] | 41 | using namespace std;
|
---|
| 42 |
|
---|
[1a3c42d] | 43 | class MessageProcessor {
|
---|
| 44 | public:
|
---|
[5a64bea] | 45 | MessageProcessor();
|
---|
| 46 | ~MessageProcessor();
|
---|
| 47 |
|
---|
[1a3c42d] | 48 | int sendMessage(NETWORK_MSG *msg, int sock, struct sockaddr_in *dest);
|
---|
| 49 | int receiveMessage(NETWORK_MSG *msg, int sock, struct sockaddr_in *dest);
|
---|
[5a64bea] | 50 | void resendUnackedMessages(int sock);
|
---|
[1a3c42d] | 51 | void cleanAckedMessages();
|
---|
| 52 |
|
---|
| 53 | private:
|
---|
[5a64bea] | 54 | // this should eventually just replace the Message struct
|
---|
| 55 | class MessageContainer {
|
---|
| 56 | public:
|
---|
| 57 | MessageContainer() {
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | MessageContainer(const MessageContainer& mc) {
|
---|
| 61 | this->msg = mc.msg;
|
---|
[9b5d30b] | 62 | this->clientAddr = mc.clientAddr;
|
---|
[5a64bea] | 63 | }
|
---|
| 64 |
|
---|
| 65 | MessageContainer(NETWORK_MSG msg, struct sockaddr_in clientAddr) {
|
---|
| 66 | this->clientAddr = clientAddr;
|
---|
| 67 | this->msg = msg;
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | ~MessageContainer() {
|
---|
| 71 | }
|
---|
| 72 |
|
---|
| 73 | NETWORK_MSG msg;
|
---|
[9b5d30b] | 74 | struct sockaddr_in clientAddr;
|
---|
[198cf2d] | 75 | bool isAcked;
|
---|
| 76 | unsigned long long timeAcked;
|
---|
[5a64bea] | 77 | };
|
---|
| 78 |
|
---|
| 79 | int lastUsedId;
|
---|
| 80 | map<int, MessageContainer> sentMessages;
|
---|
[4dbac87] | 81 | map<unsigned int, unsigned long long> ackedMessages;
|
---|
[1a3c42d] | 82 | };
|
---|
| 83 |
|
---|
| 84 | #endif
|
---|