source: network-game/common/MessageProcessor.h@ 4dbac87

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

MessageProcessor keeps track messages it has acked, so it doesn't send acks to multiple copies of the same message

  • 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->msg = mc.msg;
62 this->clientAddr = mc.clientAddr;
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;
74 struct sockaddr_in clientAddr;
75 bool isAcked;
76 unsigned long long timeAcked;
77 };
78
79 int lastUsedId;
80 map<int, MessageContainer> sentMessages;
81 map<unsigned int, unsigned long long> ackedMessages;
82};
83
84#endif
Note: See TracBrowser for help on using the repository browser.