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