DDraceNetwork Docs
network.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef ENGINE_SHARED_NETWORK_H
4#define ENGINE_SHARED_NETWORK_H
5
6#include "ringbuffer.h"
7#include "stun.h"
8
9#include <base/math.h>
10#include <base/system.h>
11
12class CHuffman;
13class CNetBan;
14class CPacker;
15
16/*
17
18CURRENT:
19 packet header: 3 bytes
20 unsigned char flags_ack; // 6bit flags, 2bit ack
21 0.6: ORNCaaAA
22 0.6.5: ORNCTUAA
23 0.7: --NORCAA
24
25 unsigned char ack; // 8 bit ack
26 unsigned char num_chunks; // 8 bit chunks
27
28 (unsigned char padding[3]) // 24 bit extra in case it's a connection less packet
29 // this is to make sure that it's compatible with the
30 // old protocol
31
32 chunk header: 2-3 bytes
33 unsigned char flags_size; // 2bit flags, 6 bit size
34 unsigned char size_seq; // 4bit size, 4bit seq
35 (unsigned char seq;) // 8bit seq, if vital flag is set
36*/
37
38enum
39{
45
49
52};
53
54enum
55{
57
66
73
80 // NOT SENT VIA THE NETWORK DIRECTLY:
82
85
92
94
96
98};
99enum
100{
101 NET_TOKEN_MAX = 0xffffffff,
104
106};
107
108typedef int SECURITY_TOKEN;
109typedef unsigned int TOKEN;
110
111SECURITY_TOKEN ToSecurityToken(const unsigned char *pData);
112void WriteSecurityToken(unsigned char *pData, SECURITY_TOKEN Token);
113
114extern const unsigned char SECURITY_TOKEN_MAGIC[4];
115
116enum
117{
120};
121
122typedef int (*NETFUNC_DELCLIENT)(int ClientId, const char *pReason, void *pUser);
123typedef int (*NETFUNC_NEWCLIENT_CON)(int ClientId, void *pUser);
124typedef int (*NETFUNC_NEWCLIENT)(int ClientId, void *pUser, bool Sixup);
125typedef int (*NETFUNC_NEWCLIENT_NOAUTH)(int ClientId, void *pUser);
126typedef int (*NETFUNC_CLIENTREJOIN)(int ClientId, void *pUser);
127
129{
130 // -1 means that it's a stateless packet
131 // 0 on the client means the server
133 NETADDR m_Address; // only used when client_id == -1
136 const void *m_pData;
137 // only used if the flags contain NETSENDFLAG_EXTENDED and NETSENDFLAG_CONNLESS
138 unsigned char m_aExtraData[4];
139};
140
142{
143public:
147
148 unsigned char *Pack(unsigned char *pData, int Split = 4) const;
149 unsigned char *Unpack(unsigned char *pData, int Split = 4);
150};
151
153{
154public:
157 unsigned char *m_pData;
158
162};
163
165{
166public:
168 int m_Ack;
172 unsigned char m_aExtraData[4];
173};
174
175enum class CONNECTIVITY
176{
177 UNKNOWN,
178 CHECKING,
180 REACHABLE,
182};
183
184class CStun
185{
187 {
191 bool m_HaveStunServer = false;
193 bool m_HaveAddr = false;
195 int64_t m_LastResponse = -1;
196 int64_t m_NextTry = -1;
198
199 public:
200 CProtocol(int Index, NETSOCKET Socket);
201 void FeedStunServer(NETADDR StunServer);
202 void Refresh();
203 void Update();
204 bool OnPacket(NETADDR Addr, unsigned char *pData, int DataSize);
206 };
208
209public:
210 CStun(NETSOCKET Socket);
211 void FeedStunServer(NETADDR StunServer);
212 void Refresh();
213 void Update();
214 bool OnPacket(NETADDR Addr, unsigned char *pData, int DataSize);
215 CONNECTIVITY GetConnectivity(int NetType, NETADDR *pGlobalAddr);
216};
217
219{
220 // TODO: is this needed because this needs to be aware of
221 // the ack sequencing number and is also responible for updating
222 // that. this should be fixed.
223 friend class CNetRecvUnpacker;
224
225private:
226 unsigned short m_Sequence;
227 unsigned short m_Ack;
228 unsigned short m_PeerAck;
229 unsigned m_State;
230
231public:
233
234private:
238
240
244
245 char m_aErrorString[256];
246
248
254
256 // client 0.7
257 static TOKEN GenerateToken7(const NETADDR *pPeerAddr);
259 bool IsSixup() { return m_Sixup; }
260
261 //
262 void ResetStats();
263 void SetError(const char *pString);
264 void AckChunks(int Ack);
265
266 int QueueChunkEx(int Flags, int DataSize, const void *pData, int Sequence);
267 void SendConnect();
268 void SendControl(int ControlMsg, const void *pExtra, int ExtraSize);
269 void SendControlWithToken7(int ControlMsg, SECURITY_TOKEN ResponseToken);
270 void ResendChunk(CNetChunkResend *pResend);
271 void Resend();
272
273public:
276
277 void SetToken7(TOKEN Token);
278
279 void Reset(bool Rejoin = false);
280 void Init(NETSOCKET Socket, bool BlockCloseMsg);
281 int Connect(const NETADDR *pAddr, int NumAddrs);
282 int Connect7(const NETADDR *pAddr, int NumAddrs);
283 void Disconnect(const char *pReason);
284
285 int Update();
286 int Flush();
287
289 int QueueChunk(int Flags, int DataSize, const void *pData);
290
291 const char *ErrorString();
292 void SignalResend();
293 int State() const { return m_State; }
294 const NETADDR *PeerAddress() const { return &m_PeerAddr; }
295 const char (*PeerAddressString() const)[NETADDR_MAXSTRSIZE] { return &m_aPeerAddrStr; }
296 void ConnectAddresses(const NETADDR **ppAddrs, int *pNumAddrs) const
297 {
298 *ppAddrs = m_aConnectAddrs;
299 *pNumAddrs = m_NumConnectAddrs;
300 }
301
303 const char *ErrorString() const { return m_aErrorString; }
304
305 // Needed for GotProblems in NetClient
306 int64_t LastRecvTime() const { return m_LastRecvTime; }
307 int64_t ConnectTime() const { return m_LastUpdateTime; }
308
309 int AckSequence() const { return m_Ack; }
310 int SeqSequence() const { return m_Sequence; }
311 int SecurityToken() const { return m_SecurityToken; }
313
314 void SetTimedOut(const NETADDR *pAddr, int Sequence, int Ack, SECURITY_TOKEN SecurityToken, CStaticRingBuffer<CNetChunkResend, NET_CONN_BUFFERSIZE> *pResendBuffer, bool Sixup);
315
316 // anti spoof
317 void DirectInit(const NETADDR &Addr, SECURITY_TOKEN SecurityToken, SECURITY_TOKEN Token, bool Sixup);
318 void SetUnknownSeq() { m_UnknownSeq = true; }
319 void SetSequence(int Sequence) { m_Sequence = Sequence; }
320
323};
324
326{
327private:
329
332
335
336 char m_aErrorString[256];
337
340
341public:
342 void Init(NETSOCKET Socket, const NETADDR *pAddr);
343 void Disconnect(const char *pReason);
344
345 int State() const { return m_State; }
346 const NETADDR *PeerAddress() const { return &m_PeerAddr; }
347 const char *ErrorString() const { return m_aErrorString; }
348
349 void Reset();
350 int Update();
351 int Send(const char *pLine);
352 int Recv(char *pLine, int MaxLength);
353};
354
356{
357public:
359
366
368 void Clear();
369 void Start(const NETADDR *pAddr, CNetConnection *pConnection, int ClientId);
370 int FetchChunk(CNetChunk *pChunk);
371};
372
373// server side
375{
376 struct CSlot
377 {
378 public:
380 };
381
383 {
385 int64_t m_Time;
387 };
388
395
400 void *m_pUser;
401
402 int m_NumConAttempts; // log flooding attacks
404 unsigned char m_aSecurityTokenSeed[16];
405
406 // vanilla connect flood detection
409
411
413
414 void OnTokenCtrlMsg(NETADDR &Addr, int ControlMsg, const CNetPacketConstruct &Packet);
415 int OnSixupCtrlMsg(NETADDR &Addr, CNetChunk *pChunk, int ControlMsg, const CNetPacketConstruct &Packet, SECURITY_TOKEN &ResponseToken, SECURITY_TOKEN Token);
416 void OnPreConnMsg(NETADDR &Addr, CNetPacketConstruct &Packet);
417 void OnConnCtrlMsg(NETADDR &Addr, int ClientId, int ControlMsg, const CNetPacketConstruct &Packet);
418 bool ClientExists(const NETADDR &Addr) { return GetClientSlot(Addr) != -1; }
419 int GetClientSlot(const NETADDR &Addr);
420 void SendControl(NETADDR &Addr, int ControlMsg, const void *pExtra, int ExtraSize, SECURITY_TOKEN SecurityToken);
421
422 int TryAcceptClient(NETADDR &Addr, SECURITY_TOKEN SecurityToken, bool VanillaAuth = false, bool Sixup = false, SECURITY_TOKEN Token = 0);
423 int NumClientsWithAddr(NETADDR Addr);
424 bool Connlimit(NETADDR Addr);
425 void SendMsgs(NETADDR &Addr, const CPacker **ppMsgs, int Num);
426
427public:
428 int SetCallbacks(NETFUNC_NEWCLIENT pfnNewClient, NETFUNC_DELCLIENT pfnDelClient, void *pUser);
429 int SetCallbacks(NETFUNC_NEWCLIENT pfnNewClient, NETFUNC_NEWCLIENT_NOAUTH pfnNewClientNoAuth, NETFUNC_CLIENTREJOIN pfnClientRejoin, NETFUNC_DELCLIENT pfnDelClient, void *pUser);
430
431 //
432 bool Open(NETADDR BindAddr, CNetBan *pNetBan, int MaxClients, int MaxClientsPerIp);
433 int Close();
434
435 //
436 int Recv(CNetChunk *pChunk, SECURITY_TOKEN *pResponseToken);
437 int Send(CNetChunk *pChunk);
438 int Update();
439
440 //
441 int Drop(int ClientId, const char *pReason);
442
443 // status requests
444 const NETADDR *ClientAddr(int ClientId) const { return m_aSlots[ClientId].m_Connection.PeerAddress(); }
445 const char (*ClientAddrString(int ClientID) const)[NETADDR_MAXSTRSIZE] { return m_aSlots[ClientID].m_Connection.PeerAddressString(); }
446 bool HasSecurityToken(int ClientId) const { return m_aSlots[ClientId].m_Connection.SecurityToken() != NET_SECURITY_TOKEN_UNSUPPORTED; }
447 NETADDR Address() const { return m_Address; }
448 NETSOCKET Socket() const { return m_Socket; }
449 CNetBan *NetBan() const { return m_pNetBan; }
450 int NetType() const { return net_socket_type(m_Socket); }
451 int MaxClients() const { return m_MaxClients; }
452
453 void SendTokenSixup(NETADDR &Addr, SECURITY_TOKEN Token);
454 int SendConnlessSixup(CNetChunk *pChunk, SECURITY_TOKEN ResponseToken);
455
456 //
457 void SetMaxClientsPerIp(int Max);
458 bool SetTimedOut(int ClientId, int OrigId);
459 void SetTimeoutProtected(int ClientId);
460
461 int ResetErrorString(int ClientId);
462 const char *ErrorString(int ClientId);
463
464 // anti spoof
466 SECURITY_TOKEN GetToken(const NETADDR &Addr);
467 // vanilla token/gametick shouldn't be negative
469};
470
472{
473 struct CSlot
474 {
476 };
477
481
484 void *m_pUser;
485
487
488public:
489 void SetCallbacks(NETFUNC_NEWCLIENT_CON pfnNewClient, NETFUNC_DELCLIENT pfnDelClient, void *pUser);
490
491 //
492 bool Open(NETADDR BindAddr, CNetBan *pNetBan);
493 int Close();
494
495 //
496 int Recv(char *pLine, int MaxLength, int *pClientId = nullptr);
497 int Send(int ClientId, const char *pLine);
498 int Update();
499
500 //
501 int AcceptClient(NETSOCKET Socket, const NETADDR *pAddr);
502 int Drop(int ClientId, const char *pReason);
503
504 // status requests
505 const NETADDR *ClientAddr(int ClientId) const { return m_aSlots[ClientId].m_Connection.PeerAddress(); }
506 CNetBan *NetBan() const { return m_pNetBan; }
507};
508
509// client side
511{
514
515 CStun *m_pStun = nullptr;
516
517public:
519 // openness
520 bool Open(NETADDR BindAddr);
521 int Close();
522
523 // connection state
524 int Disconnect(const char *pReason);
525 int Connect(const NETADDR *pAddr, int NumAddrs);
526 int Connect7(const NETADDR *pAddr, int NumAddrs);
527
528 // communication
529 int Recv(CNetChunk *pChunk, SECURITY_TOKEN *pResponseToken, bool Sixup);
530 int Send(CNetChunk *pChunk);
531
532 // pumping
533 int Update();
534 int Flush();
535
536 int ResetErrorString();
537
538 // error and state
539 int NetType() const { return net_socket_type(m_Socket); }
540 int State();
541 const NETADDR *ServerAddress() const { return m_Connection.PeerAddress(); }
542 void ConnectAddresses(const NETADDR **ppAddrs, int *pNumAddrs) const { m_Connection.ConnectAddresses(ppAddrs, pNumAddrs); }
543 int GotProblems(int64_t MaxLatency) const;
544 const char *ErrorString() const;
545
546 // stun
547 void FeedStunServer(NETADDR StunServer);
548 void RefreshStun();
549 CONNECTIVITY GetConnectivity(int NetType, NETADDR *pGlobalAddr);
550};
551
552// TODO: both, fix these. This feels like a junk class for stuff that doesn't fit anywhere
554{
558
559public:
560 static void OpenLog(IOHANDLE DataLogSent, IOHANDLE DataLogRecv);
561 static void CloseLog();
562 static void Init();
563 static int Compress(const void *pData, int DataSize, void *pOutput, int OutputSize);
564 static int Decompress(const void *pData, int DataSize, void *pOutput, int OutputSize);
565
566 static void SendControlMsg(NETSOCKET Socket, NETADDR *pAddr, int Ack, int ControlMsg, const void *pExtra, int ExtraSize, SECURITY_TOKEN SecurityToken, bool Sixup = false);
567 static void SendControlMsgWithToken7(NETSOCKET Socket, NETADDR *pAddr, TOKEN Token, int Ack, int ControlMsg, TOKEN MyToken, bool Extended);
568 static void SendPacketConnless(NETSOCKET Socket, NETADDR *pAddr, const void *pData, int DataSize, bool Extended, unsigned char aExtra[4]);
569 static void SendPacket(NETSOCKET Socket, NETADDR *pAddr, CNetPacketConstruct *pPacket, SECURITY_TOKEN SecurityToken, bool Sixup = false, bool NoCompress = false);
570
571 static int UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct *pPacket, bool &Sixup, SECURITY_TOKEN *pSecurityToken = nullptr, SECURITY_TOKEN *pResponseToken = nullptr);
572
573 // The backroom is ack-NET_MAX_SEQUENCE/2. Used for knowing if we acked a packet or not
574 static bool IsSeqInBackroom(int Seq, int Ack);
575};
576
577#endif
Definition: network.h:326
bool m_LineEndingDetected
Definition: network.h:338
int State() const
Definition: network.h:345
int m_BufferOffset
Definition: network.h:334
int Send(const char *pLine)
Definition: network_console_conn.cpp:152
char m_aBuffer[NET_MAX_PACKETSIZE]
Definition: network.h:333
char m_aErrorString[256]
Definition: network.h:336
void Reset()
Definition: network_console_conn.cpp:6
const NETADDR * PeerAddress() const
Definition: network.h:346
NETSOCKET m_Socket
Definition: network.h:331
void Disconnect(const char *pReason)
Definition: network_console_conn.cpp:39
char m_aLineEnding[3]
Definition: network.h:339
const char * ErrorString() const
Definition: network.h:347
int Recv(char *pLine, int MaxLength)
Definition: network_console_conn.cpp:89
void Init(NETSOCKET Socket, const NETADDR *pAddr)
Definition: network_console_conn.cpp:28
int Update()
Definition: network_console_conn.cpp:52
int m_State
Definition: network.h:328
NETADDR m_PeerAddr
Definition: network.h:330
Definition: huffman.h:7
Definition: netban.h:27
Definition: network.h:554
static void SendControlMsgWithToken7(NETSOCKET Socket, NETADDR *pAddr, TOKEN Token, int Ack, int ControlMsg, TOKEN MyToken, bool Extended)
Definition: network.cpp:342
static int Decompress(const void *pData, int DataSize, void *pOutput, int OutputSize)
Definition: network.cpp:445
static void Init()
Definition: network.cpp:450
static int UnpackPacket(unsigned char *pBuffer, int Size, CNetPacketConstruct *pPacket, bool &Sixup, SECURITY_TOKEN *pSecurityToken=nullptr, SECURITY_TOKEN *pResponseToken=nullptr)
Definition: network.cpp:206
static void SendPacketConnless(NETSOCKET Socket, NETADDR *pAddr, const void *pData, int DataSize, bool Extended, unsigned char aExtra[4])
Definition: network.cpp:106
static void SendPacket(NETSOCKET Socket, NETADDR *pAddr, CNetPacketConstruct *pPacket, SECURITY_TOKEN SecurityToken, bool Sixup=false, bool NoCompress=false)
Definition: network.cpp:124
static void SendControlMsg(NETSOCKET Socket, NETADDR *pAddr, int Ack, int ControlMsg, const void *pExtra, int ExtraSize, SECURITY_TOKEN SecurityToken, bool Sixup=false)
Definition: network.cpp:327
static IOHANDLE ms_DataLogSent
Definition: network.h:555
static bool IsSeqInBackroom(int Seq, int Ack)
Definition: network.cpp:381
static int Compress(const void *pData, int DataSize, void *pOutput, int OutputSize)
Definition: network.cpp:440
static void CloseLog()
Definition: network.cpp:423
static IOHANDLE ms_DataLogRecv
Definition: network.h:556
static CHuffman ms_Huffman
Definition: network.h:557
static void OpenLog(IOHANDLE DataLogSent, IOHANDLE DataLogRecv)
Definition: network.cpp:404
Definition: network.h:142
int m_Size
Definition: network.h:145
int m_Flags
Definition: network.h:144
int m_Sequence
Definition: network.h:146
unsigned char * Unpack(unsigned char *pData, int Split=4)
Definition: network.cpp:368
unsigned char * Pack(unsigned char *pData, int Split=4) const
Definition: network.cpp:355
Definition: network.h:153
int m_Flags
Definition: network.h:155
int64_t m_FirstSendTime
Definition: network.h:161
int m_Sequence
Definition: network.h:159
unsigned char * m_pData
Definition: network.h:157
int64_t m_LastSendTime
Definition: network.h:160
int m_DataSize
Definition: network.h:156
Definition: network.h:511
int State()
Definition: network_client.cpp:153
const char * ErrorString() const
Definition: network_client.cpp:174
int Disconnect(const char *pReason)
Definition: network_client.cpp:37
int ResetErrorString()
Definition: network_client.cpp:65
int Update()
Definition: network_client.cpp:44
int Connect7(const NETADDR *pAddr, int NumAddrs)
Definition: network_client.cpp:59
NETSOCKET m_Socket
Definition: network.h:518
int Connect(const NETADDR *pAddr, int NumAddrs)
Definition: network_client.cpp:53
CStun * m_pStun
Definition: network.h:515
int Close()
Definition: network_client.cpp:25
int Flush()
Definition: network_client.cpp:162
void RefreshStun()
Definition: network_client.cpp:184
CONNECTIVITY GetConnectivity(int NetType, NETADDR *pGlobalAddr)
Definition: network_client.cpp:189
CNetRecvUnpacker m_RecvUnpacker
Definition: network.h:513
int Send(CNetChunk *pChunk)
Definition: network_client.cpp:123
CNetConnection m_Connection
Definition: network.h:512
void FeedStunServer(NETADDR StunServer)
Definition: network_client.cpp:179
int GotProblems(int64_t MaxLatency) const
Definition: network_client.cpp:167
const NETADDR * ServerAddress() const
Definition: network.h:541
int Recv(CNetChunk *pChunk, SECURITY_TOKEN *pResponseToken, bool Sixup)
Definition: network_client.cpp:71
bool Open(NETADDR BindAddr)
Definition: network_client.cpp:6
void ConnectAddresses(const NETADDR **ppAddrs, int *pNumAddrs) const
Definition: network.h:542
int NetType() const
Definition: network.h:539
Definition: network.h:219
void SendControl(int ControlMsg, const void *pExtra, int ExtraSize)
Definition: network_conn.cpp:173
const NETADDR * PeerAddress() const
Definition: network.h:294
void SetError(const char *pString)
Definition: network_conn.cpp:52
void SetToken7(TOKEN Token)
Definition: network_conn.cpp:243
void Disconnect(const char *pReason)
Definition: network_conn.cpp:258
bool m_UnknownSeq
Definition: network.h:237
void SendConnect()
Definition: network_conn.cpp:163
int Connect7(const NETADDR *pAddr, int NumAddrs)
Definition: network_conn.cpp:220
void DirectInit(const NETADDR &Addr, SECURITY_TOKEN SecurityToken, SECURITY_TOKEN Token, bool Sixup)
Definition: network_conn.cpp:284
void SignalResend()
Definition: network_conn.cpp:82
int State() const
Definition: network.h:293
const char * ErrorString() const
Definition: network.h:303
void Resend()
Definition: network_conn.cpp:186
bool IsSixup()
Definition: network.h:259
void ResendChunk(CNetChunkResend *pResend)
Definition: network_conn.cpp:180
void ConnectAddresses(const NETADDR **ppAddrs, int *pNumAddrs) const
Definition: network.h:296
NETADDR m_PeerAddr
Definition: network.h:251
NETADDR m_aConnectAddrs[16]
Definition: network.h:249
int Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr, SECURITY_TOKEN SecurityToken=NET_SECURITY_TOKEN_UNSUPPORTED, SECURITY_TOKEN ResponseToken=NET_SECURITY_TOKEN_UNSUPPORTED)
Definition: network_conn.cpp:304
void AckChunks(int Ack)
Definition: network_conn.cpp:67
void ResetStats()
Definition: network_conn.cpp:7
int64_t m_LastRecvTime
Definition: network.h:242
int Flush()
Definition: network_conn.cpp:87
const char(* PeerAddressString() const)[NETADDR_MAXSTRSIZE]
Definition: network.h:295
char m_aErrorString[256]
Definition: network.h:245
int QueueChunkEx(int Flags, int DataSize, const void *pData, int Sequence)
Definition: network_conn.cpp:105
unsigned short m_Ack
Definition: network.h:227
NETSTATS m_Stats
Definition: network.h:253
CStaticRingBuffer< CNetChunkResend, NET_CONN_BUFFERSIZE > * ResendBuffer()
Definition: network.h:312
void SetTimedOut(const NETADDR *pAddr, int Sequence, int Ack, SECURITY_TOKEN SecurityToken, CStaticRingBuffer< CNetChunkResend, NET_CONN_BUFFERSIZE > *pResendBuffer, bool Sixup)
Definition: network_conn.cpp:570
int64_t m_LastSendTime
Definition: network.h:243
void SendControlWithToken7(int ControlMsg, SECURITY_TOKEN ResponseToken)
Definition: network_conn.cpp:213
unsigned short m_Sequence
Definition: network.h:226
void Reset(bool Rejoin=false)
Definition: network_conn.cpp:15
SECURITY_TOKEN m_Token
Definition: network.h:322
int m_NumConnectAddrs
Definition: network.h:250
void ResetErrorString()
Definition: network.h:302
int Update()
Definition: network_conn.cpp:496
int SecurityToken() const
Definition: network.h:311
NETSOCKET m_Socket
Definition: network.h:252
int AckSequence() const
Definition: network.h:309
char m_aPeerAddrStr[NETADDR_MAXSTRSIZE]
Definition: network.h:255
int64_t m_LastUpdateTime
Definition: network.h:241
void SetSequence(int Sequence)
Definition: network.h:319
bool m_BlockCloseMsg
Definition: network.h:236
bool m_TimeoutSituation
Definition: network.h:275
int64_t ConnectTime() const
Definition: network.h:307
unsigned short m_PeerAck
Definition: network.h:228
CStaticRingBuffer< CNetChunkResend, NET_CONN_BUFFERSIZE > m_Buffer
Definition: network.h:239
unsigned m_State
Definition: network.h:229
class CNetBase * m_pNetBase
Definition: network.h:258
int Connect(const NETADDR *pAddr, int NumAddrs)
Definition: network_conn.cpp:192
const char * ErrorString()
Definition: network_conn.cpp:47
int SeqSequence() const
Definition: network.h:310
int64_t LastRecvTime() const
Definition: network.h:306
static TOKEN GenerateToken7(const NETADDR *pPeerAddr)
Definition: network_conn.cpp:251
bool m_Sixup
Definition: network.h:321
SECURITY_TOKEN m_SecurityToken
Definition: network.h:232
CNetPacketConstruct m_Construct
Definition: network.h:247
int m_RemoteClosed
Definition: network.h:235
void Init(NETSOCKET Socket, bool BlockCloseMsg)
Definition: network_conn.cpp:57
void SetUnknownSeq()
Definition: network.h:318
int QueueChunk(int Flags, int DataSize, const void *pData)
Definition: network_conn.cpp:156
bool m_TimeoutProtected
Definition: network.h:274
Definition: network.h:472
CNetBan * m_pNetBan
Definition: network.h:479
CNetBan * NetBan() const
Definition: network.h:506
int Drop(int ClientId, const char *pReason)
Definition: network_console.cpp:45
void SetCallbacks(NETFUNC_NEWCLIENT_CON pfnNewClient, NETFUNC_DELCLIENT pfnDelClient, void *pUser)
Definition: network_console.cpp:28
int Close()
Definition: network_console.cpp:35
CNetRecvUnpacker m_RecvUnpacker
Definition: network.h:486
int Send(int ClientId, const char *pLine)
Definition: network_console.cpp:138
int Update()
Definition: network_console.cpp:94
NETSOCKET m_Socket
Definition: network.h:478
int AcceptClient(NETSOCKET Socket, const NETADDR *pAddr)
Definition: network_console.cpp:55
NETFUNC_DELCLIENT m_pfnDelClient
Definition: network.h:483
NETFUNC_NEWCLIENT_CON m_pfnNewClient
Definition: network.h:482
int Recv(char *pLine, int MaxLength, int *pClientId=nullptr)
Definition: network_console.cpp:124
void * m_pUser
Definition: network.h:484
CSlot m_aSlots[NET_MAX_CONSOLE_CLIENTS]
Definition: network.h:480
bool Open(NETADDR BindAddr, CNetBan *pNetBan)
Definition: network_console.cpp:8
const NETADDR * ClientAddr(int ClientId) const
Definition: network.h:505
Definition: network.h:165
int m_Ack
Definition: network.h:168
int m_DataSize
Definition: network.h:170
int m_NumChunks
Definition: network.h:169
unsigned char m_aExtraData[4]
Definition: network.h:172
unsigned char m_aChunkData[NET_MAX_PAYLOAD]
Definition: network.h:171
int m_Flags
Definition: network.h:167
Definition: network.h:356
bool m_Valid
Definition: network.h:358
void Start(const NETADDR *pAddr, CNetConnection *pConnection, int ClientId)
Definition: network.cpp:26
int FetchChunk(CNetChunk *pChunk)
Definition: network.cpp:36
int m_ClientId
Definition: network.h:363
void Clear()
Definition: network.cpp:21
NETADDR m_Addr
Definition: network.h:360
CNetRecvUnpacker()
Definition: network.h:367
int m_CurrentChunk
Definition: network.h:362
unsigned char m_aBuffer[NET_MAX_PACKETSIZE]
Definition: network.h:365
CNetPacketConstruct m_Data
Definition: network.h:364
CNetConnection * m_pConnection
Definition: network.h:361
Definition: network.h:375
int TryAcceptClient(NETADDR &Addr, SECURITY_TOKEN SecurityToken, bool VanillaAuth=false, bool Sixup=false, SECURITY_TOKEN Token=0)
Definition: network_server.cpp:200
NETFUNC_NEWCLIENT m_pfnNewClient
Definition: network.h:396
CNetBan * NetBan() const
Definition: network.h:449
int m_MaxClients
Definition: network.h:393
void SendMsgs(NETADDR &Addr, const CPacker **ppMsgs, int Num)
Definition: network_server.cpp:270
const char(* ClientAddrString(int ClientID) const)[NETADDR_MAXSTRSIZE]
Definition: network.h:445
bool Connlimit(NETADDR Addr)
Definition: network_server.cpp:167
int GetClientSlot(const NETADDR &Addr)
Definition: network_server.cpp:574
NETFUNC_CLIENTREJOIN m_pfnClientRejoin
Definition: network.h:399
int MaxClients() const
Definition: network.h:451
int Close()
Definition: network_server.cpp:88
int64_t m_VConnFirst
Definition: network.h:407
unsigned char m_aSecurityTokenSeed[16]
Definition: network.h:404
CSlot m_aSlots[NET_MAX_CLIENTS]
Definition: network.h:392
CNetBan * m_pNetBan
Definition: network.h:391
int ResetErrorString(int ClientId)
Definition: network_server.cpp:807
int Update()
Definition: network_server.cpp:107
int SetCallbacks(NETFUNC_NEWCLIENT pfnNewClient, NETFUNC_DELCLIENT pfnDelClient, void *pUser)
Definition: network_server.cpp:70
int NumClientsWithAddr(NETADDR Addr)
Definition: network_server.cpp:149
void SetMaxClientsPerIp(int Max)
Definition: network_server.cpp:781
int NetType() const
Definition: network.h:450
CSpamConn m_aSpamConns[NET_CONNLIMIT_IPS]
Definition: network.h:410
NETFUNC_NEWCLIENT_NOAUTH m_pfnNewClientNoAuth
Definition: network.h:397
bool Open(NETADDR BindAddr, CNetBan *pNetBan, int MaxClients, int MaxClientsPerIp)
Definition: network_server.cpp:39
int OnSixupCtrlMsg(NETADDR &Addr, CNetChunk *pChunk, int ControlMsg, const CNetPacketConstruct &Packet, SECURITY_TOKEN &ResponseToken, SECURITY_TOKEN Token)
Definition: network_server.cpp:538
int Drop(int ClientId, const char *pReason)
Definition: network_server.cpp:95
int Send(CNetChunk *pChunk)
Definition: network_server.cpp:720
int Recv(CNetChunk *pChunk, SECURITY_TOKEN *pResponseToken)
Definition: network_server.cpp:614
NETSOCKET m_Socket
Definition: network.h:390
int m_NumConAttempts
Definition: network.h:402
NETADDR m_Address
Definition: network.h:389
void OnTokenCtrlMsg(NETADDR &Addr, int ControlMsg, const CNetPacketConstruct &Packet)
Definition: network_server.cpp:500
int m_VConnNum
Definition: network.h:408
bool HasSecurityToken(int ClientId) const
Definition: network.h:446
void * m_pUser
Definition: network.h:400
NETADDR Address() const
Definition: network.h:447
bool ClientExists(const NETADDR &Addr)
Definition: network.h:418
SECURITY_TOKEN GetGlobalToken()
Definition: network_server.cpp:123
void SetTimeoutProtected(int ClientId)
Definition: network_server.cpp:802
int SendConnlessSixup(CNetChunk *pChunk, SECURITY_TOKEN ResponseToken)
Definition: network_server.cpp:765
const char * ErrorString(int ClientId)
Definition: network_server.cpp:813
NETSOCKET Socket() const
Definition: network.h:448
void OnConnCtrlMsg(NETADDR &Addr, int ClientId, int ControlMsg, const CNetPacketConstruct &Packet)
Definition: network_server.cpp:463
const NETADDR * ClientAddr(int ClientId) const
Definition: network.h:444
void SendControl(NETADDR &Addr, int ControlMsg, const void *pExtra, int ExtraSize, SECURITY_TOKEN SecurityToken)
Definition: network_server.cpp:144
NETFUNC_DELCLIENT m_pfnDelClient
Definition: network.h:398
bool SetTimedOut(int ClientId, int OrigId)
Definition: network_server.cpp:792
SECURITY_TOKEN GetVanillaToken(const NETADDR &Addr)
Definition: network.h:468
void OnPreConnMsg(NETADDR &Addr, CNetPacketConstruct &Packet)
Definition: network_server.cpp:294
SECURITY_TOKEN GetToken(const NETADDR &Addr)
Definition: network_server.cpp:128
void SendTokenSixup(NETADDR &Addr, SECURITY_TOKEN Token)
Definition: network_server.cpp:756
int m_MaxClientsPerIp
Definition: network.h:394
CNetRecvUnpacker m_RecvUnpacker
Definition: network.h:412
int64_t m_TimeNumConAttempts
Definition: network.h:403
Definition: packer.h:7
Definition: stun.h:8
Definition: network.h:187
int m_Index
Definition: network.h:188
bool m_HaveStunServer
Definition: network.h:191
CProtocol(int Index, NETSOCKET Socket)
Definition: network_stun.cpp:36
void FeedStunServer(NETADDR StunServer)
Definition: network_stun.cpp:46
void Refresh()
Definition: network_stun.cpp:58
NETADDR m_StunServer
Definition: network.h:192
int64_t m_LastResponse
Definition: network.h:195
CONNECTIVITY GetConnectivity(NETADDR *pGlobalAddr)
Definition: network_stun.cpp:111
NETADDR m_Addr
Definition: network.h:194
bool OnPacket(NETADDR Addr, unsigned char *pData, int DataSize)
Definition: network_stun.cpp:81
NETSOCKET m_Socket
Definition: network.h:189
int m_NumUnsuccessfulTries
Definition: network.h:197
int64_t m_NextTry
Definition: network.h:196
bool m_HaveAddr
Definition: network.h:193
CStunData m_Stun
Definition: network.h:190
void Update()
Definition: network_stun.cpp:63
Definition: network.h:185
CProtocol m_aProtocols[2]
Definition: network.h:207
void Update()
Definition: network_stun.cpp:162
bool OnPacket(NETADDR Addr, unsigned char *pData, int DataSize)
Definition: network_stun.cpp:170
void Refresh()
Definition: network_stun.cpp:154
CONNECTIVITY GetConnectivity(int NetType, NETADDR *pGlobalAddr)
Definition: network_stun.cpp:180
CStun(NETSOCKET Socket)
Definition: network_stun.cpp:139
void FeedStunServer(NETADDR StunServer)
Definition: network_stun.cpp:144
void * IOHANDLE
Definition: logger.h:11
constexpr T absolute(T a)
Definition: math.h:140
int(* NETFUNC_NEWCLIENT_CON)(int ClientId, void *pUser)
Definition: network.h:123
@ NET_TOKEN_NONE
Definition: network.h:102
@ NET_TOKEN_MAX
Definition: network.h:101
@ NET_TOKENREQUEST_DATASIZE
Definition: network.h:105
@ NET_TOKEN_MASK
Definition: network.h:103
@ NET_CTRLMSG_KEEPALIVE
Definition: network.h:86
@ NET_ENUM_TERMINATOR
Definition: network.h:97
@ NET_CONNSTATE_ONLINE
Definition: network.h:71
@ NET_CONNLIMIT_IPS
Definition: network.h:95
@ NET_VERSION
Definition: network.h:56
@ NET_CHUNKFLAG_RESEND
Definition: network.h:84
@ NET_PACKETFLAG_COMPRESSION
Definition: network.h:79
@ NET_CONNSTATE_TOKEN
Definition: network.h:68
@ NET_MAX_CONSOLE_CLIENTS
Definition: network.h:63
@ NET_PACKETFLAG_CONNLESS
Definition: network.h:77
@ NET_CONNSTATE_ERROR
Definition: network.h:72
@ NET_SEQUENCE_MASK
Definition: network.h:65
@ NET_CTRLMSG_CLOSE
Definition: network.h:90
@ NET_MAX_CLIENTS
Definition: network.h:62
@ NET_MAX_PACKETSIZE
Definition: network.h:58
@ NET_PACKETFLAG_RESEND
Definition: network.h:78
@ NET_CHUNKFLAG_VITAL
Definition: network.h:83
@ NET_MAX_PAYLOAD
Definition: network.h:59
@ NET_CTRLMSG_CONNECT
Definition: network.h:87
@ NET_PACKETFLAG_CONTROL
Definition: network.h:76
@ NET_CONNSTATE_PENDING
Definition: network.h:70
@ NET_CONNSTATE_CONNECT
Definition: network.h:69
@ NET_CTRLMSG_CONNECTACCEPT
Definition: network.h:88
@ NET_PACKETFLAG_UNUSED
Definition: network.h:74
@ NET_MAX_SEQUENCE
Definition: network.h:64
@ NET_PACKETFLAG_TOKEN
Definition: network.h:75
@ NET_CTRLMSG_ACCEPT
Definition: network.h:89
@ NET_PACKETHEADERSIZE
Definition: network.h:61
@ NET_PACKETFLAG_EXTENDED
Definition: network.h:81
@ NET_CTRLMSG_TOKEN
Definition: network.h:91
@ NET_CONN_BUFFERSIZE
Definition: network.h:93
@ NET_MAX_CHUNKHEADERSIZE
Definition: network.h:60
@ NET_CONNSTATE_OFFLINE
Definition: network.h:67
void WriteSecurityToken(unsigned char *pData, SECURITY_TOKEN Token)
Definition: network.cpp:16
int(* NETFUNC_DELCLIENT)(int ClientId, const char *pReason, void *pUser)
Definition: network.h:122
int(* NETFUNC_NEWCLIENT)(int ClientId, void *pUser, bool Sixup)
Definition: network.h:124
int SECURITY_TOKEN
Definition: network.h:108
const unsigned char SECURITY_TOKEN_MAGIC[4]
Definition: network.cpp:9
unsigned int TOKEN
Definition: network.h:109
@ NET_SECURITY_TOKEN_UNKNOWN
Definition: network.h:118
@ NET_SECURITY_TOKEN_UNSUPPORTED
Definition: network.h:119
CONNECTIVITY
Definition: network.h:176
int(* NETFUNC_CLIENTREJOIN)(int ClientId, void *pUser)
Definition: network.h:126
SECURITY_TOKEN ToSecurityToken(const unsigned char *pData)
Definition: network.cpp:11
@ NETSTATE_CONNECTING
Definition: network.h:47
@ NETSENDFLAG_EXTENDED
Definition: network.h:44
@ NETFLAG_ALLOWSTATELESS
Definition: network.h:40
@ NETSENDFLAG_VITAL
Definition: network.h:41
@ NETSTATE_OFFLINE
Definition: network.h:46
@ NETSENDFLAG_CONNLESS
Definition: network.h:42
@ NETSTATE_ONLINE
Definition: network.h:48
@ NETBANTYPE_DROP
Definition: network.h:51
@ NETBANTYPE_SOFT
Definition: network.h:50
@ NETSENDFLAG_FLUSH
Definition: network.h:43
int(* NETFUNC_NEWCLIENT_NOAUTH)(int ClientId, void *pUser)
Definition: network.h:125
Definition: network.h:129
unsigned char m_aExtraData[4]
Definition: network.h:138
int m_DataSize
Definition: network.h:135
const void * m_pData
Definition: network.h:136
NETADDR m_Address
Definition: network.h:133
int m_Flags
Definition: network.h:134
int m_ClientId
Definition: network.h:132
Definition: network.h:474
CConsoleNetConnection m_Connection
Definition: network.h:475
Definition: network.h:377
CNetConnection m_Connection
Definition: network.h:379
Definition: network.h:383
NETADDR m_Addr
Definition: network.h:384
int m_Conns
Definition: network.h:386
int64_t m_Time
Definition: network.h:385
Definition: types.h:67
Definition: system.cpp:110
Definition: system.h:2170
int net_socket_type(NETSOCKET sock)
Definition: system.cpp:1531
@ NETADDR_MAXSTRSIZE
Definition: types.h:45