-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathPacketController.h
143 lines (108 loc) · 3.34 KB
/
PacketController.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#pragma once
class FragmentStack;
typedef std::list<BlobPacket_s *> BlobList;
typedef std::list<FragmentStack *> FragmentList;
#ifdef _DEBUG
#define FlagEvilClient() EvilClient( __FILE__, __LINE__, FALSE )
#else
#define FlagEvilClient() EvilClient( NULL, NULL, TRUE )
#endif
#pragma pack(push, 4)
struct EventHeader
{
DWORD dwF7B0;
DWORD dwPlayer;
DWORD dwSequence;
};
#pragma pack(pop)
class CNetwork;
class CPacketController : public CKillable
{
public:
CPacketController(CClient *);
~CPacketController();
void Think(void); //Generic work cycle.
void ThinkInbound(void);
void ThinkOutbound(void);
BOOL HasConnection();
void IncomingBlob(BlobPacket_s *);
DWORD GetNextSequence(void);
DWORD GetLastSequence(void);
DWORD GetNextEvent(void);
DWORD GetLastEvent(void);
void ResetEvent(void);
BOOL SendNetMessage(void *data, DWORD length, WORD group);
template<class T>
void EraseInternal(T *data);
template<class T>
void EraseInternalA(T *data);
private:
WORD GetElapsedTime(void);
void Cleanup(void);
void FlushFragments(void);
void FlushPeerCache(void);
void PerformLoginSync();
void UpdatePeerTime(void);
void UpdateCharacters(void);
void ProcessMessage(BYTE *data, DWORD length, WORD);
void ProcessBlob(BlobPacket_s *);
void EvilClient(const char* szSource, DWORD dwLine, BOOL bKill);
void ResendBlob(BlobPacket_s *);
void SendGenericBlob(BlobPacket_s *, DWORD dwFlags, DWORD dwSequence);
void SendFragmentBlob(BlobPacket_s *);
void QueueFragment(FragHeader_s *header, BYTE *data);
CClient *m_pClient;
SOCKADDR_IN *m_pPeer;
BOOL m_bEvil;
struct InputPCVars_t
{
InputPCVars_t()
{
logintime = g_pGlobals->Time();
lastactivity = g_pGlobals->Time();
lastrequest = g_pGlobals->Time();
sequence = 0;
activesequence = 1;
flushsequence = 0;
}
double logintime; // When the client connected. Used for time subtraction.
double lastactivity; // When the last SUCCESSFUL packet received.
double lastrequest; //When the last lost packets request was made.
//Sequencing.
DWORD sequence; //The blob counter. The last one we know the client sent.
DWORD activesequence; //The blob counter. The last sequence we processed.
DWORD flushsequence; //The last sequence the client processed.
//CRC
DWORD clientcrc[3];
std::list<FragmentStack *> fragstack; // All incomplete messages stack here.
std::list<BlobPacket_s *> blobstack; // All queued blobs wait here. (for sequencing)
} m_in;
struct OutputPCVars_t
{
//Network variables for outgoing data.
OutputPCVars_t()
{
lastflush = g_pGlobals->Time();
lasttimeupdate = -1000.0; // g_pGlobals->Time();
lastloginsync = 0;
loginsyncs = 0; // -1;
sequence = 1;
fragment_counter = 1;
event_counter = 0;
initchars = FALSE;
}
double lastflush; //Used to clean the peer's blob cache.
double lasttimeupdate; //Used to correct the client's time.
double lastloginsync; //Used to sync the time at login.
long loginsyncs; //The number of login syncs performed.
BOOL initchars;
//Sequencing.
DWORD sequence; //The blob counter.
DWORD fragment_counter; //The fragment counter.
DWORD event_counter; //The game event counter.
//CRC
DWORD servercrc[3];
std::list<FragPacket_s *> fragqueue; //All fragments to be sent will wait here.
std::list<BlobPacket_s *> blobcache; //Remember blobs until the client receives them.
} m_out;
};