source: network-game/common/MessageProcessor.h@ 5a64bea

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

Completed initial version of MessageProcessor

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#ifndef _MESSAGE_PROCESSOR_H
2#define _MESSAGE_PROCESSOR_H
3
4#include <map>
5
6#include "Compiler.h"
7
8#include "Message.h"
9
10#if defined WINDOWS
11 #include <winsock2.h>
12 #include <WS2tcpip.h>
13#elif defined LINUX
14 #include <netinet/in.h>
15#endif
16
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
34typedef struct
35{
36 short type;
37 char buffer[256];
38} NETWORK_MSG;
39*/
40
41using namespace std;
42
43class MessageProcessor {
44public:
45 MessageProcessor();
46 ~MessageProcessor();
47
48 int sendMessage(NETWORK_MSG *msg, int sock, struct sockaddr_in *dest);
49 int receiveMessage(NETWORK_MSG *msg, int sock, struct sockaddr_in *dest);
50 void resendUnackedMessages(int sock);
51 void cleanAckedMessages();
52
53private:
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->id = mc.id;
62 this->clientAddr = mc.clientAddr;
63 this->msg = mc.msg;
64 this->ackReceived = mc.ackReceived;
65 }
66
67 MessageContainer(NETWORK_MSG msg, struct sockaddr_in clientAddr) {
68 this->clientAddr = clientAddr;
69 this->msg = msg;
70 }
71
72 ~MessageContainer() {
73 }
74
75 int id;
76 struct sockaddr_in clientAddr;
77 NETWORK_MSG msg;
78 bool ackReceived;
79 };
80
81 int lastUsedId;
82 map<int, MessageContainer> sentMessages;
83};
84
85#endif
Note: See TracBrowser for help on using the repository browser.