2 Copyright (C) 1996-1997 Id Software, Inc.
3 Copyright (C) 2002 Mathieu Olivier
4 Copyright (C) 2003 Forest Hale
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 See the GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #define MASTER_PORT 27950
28 // note this defaults on for dedicated servers, off for listen servers
29 cvar_t sv_public = {0, "sv_public", "0"};
30 static cvar_t sv_heartbeatperiod = {CVAR_SAVE, "sv_heartbeatperiod", "120"};
32 // FIXME: resolve DNS on masters whenever their value changes and cache it (to avoid major delays in active servers when they heartbeat)
33 static cvar_t sv_masters [] =
35 {CVAR_SAVE, "sv_master1", ""},
36 {CVAR_SAVE, "sv_master2", ""},
37 {CVAR_SAVE, "sv_master3", ""},
38 {CVAR_SAVE, "sv_master4", ""},
39 {0, "sv_masterextra1", "ghdigital.com"}, //69.59.212.88
40 {0, "sv_masterextra2", "dpmaster.deathmask.net"}, //64.253.41.49
41 {0, "sv_masterextra3", "12.166.196.192"}, //blaze.mindphukd.org (doesn't resolve currently but works as an ip)
45 static double nextheartbeattime = 0;
47 sizebuf_t net_message;
48 static unsigned char net_message_buf[NET_MAXMESSAGE];
50 cvar_t net_messagetimeout = {0, "net_messagetimeout","300"};
51 cvar_t net_messagerejointimeout = {0, "net_messagerejointimeout","10"};
52 cvar_t net_connecttimeout = {0, "net_connecttimeout","10"};
53 cvar_t hostname = {CVAR_SAVE, "hostname", "UNNAMED"};
54 cvar_t developer_networking = {0, "developer_networking", "0"};
56 cvar_t cl_netlocalping = {0, "cl_netlocalping","0"};
57 static cvar_t cl_netpacketloss = {0, "cl_netpacketloss","0"};
58 static cvar_t net_slist_queriespersecond = {0, "net_slist_queriespersecond", "20"};
59 static cvar_t net_slist_queriesperframe = {0, "net_slist_queriesperframe", "4"};
60 static cvar_t net_slist_timeout = {0, "net_slist_timeout", "4"};
61 static cvar_t net_slist_maxtries = {0, "net_slist_maxtries", "3"};
63 /* statistic counters */
64 static int packetsSent = 0;
65 static int packetsReSent = 0;
66 static int packetsReceived = 0;
67 static int receivedDuplicateCount = 0;
68 static int droppedDatagrams = 0;
70 static int unreliableMessagesSent = 0;
71 static int unreliableMessagesReceived = 0;
72 static int reliableMessagesSent = 0;
73 static int reliableMessagesReceived = 0;
75 double masterquerytime = -1000;
76 int masterquerycount = 0;
77 int masterreplycount = 0;
78 int serverquerycount = 0;
79 int serverreplycount = 0;
81 // this is only false if there are still servers left to query
82 int serverlist_querysleep = true;
84 static unsigned char sendbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
85 static unsigned char readbuffer[NET_HEADERSIZE+NET_MAXMESSAGE];
88 lhnetsocket_t *cl_sockets[16];
90 lhnetsocket_t *sv_sockets[16];
92 netconn_t *netconn_list = NULL;
93 mempool_t *netconn_mempool = NULL;
95 cvar_t cl_netport = {0, "cl_port", "0"};
96 cvar_t sv_netport = {0, "port", "26000"};
97 cvar_t net_address = {0, "net_address", "0.0.0.0"};
98 //cvar_t net_netaddress_ipv6 = {0, "net_address_ipv6", "[0:0:0:0:0:0:0:0]"};
100 // ServerList interface
101 serverlist_mask_t serverlist_andmasks[SERVERLIST_ANDMASKCOUNT];
102 serverlist_mask_t serverlist_ormasks[SERVERLIST_ORMASKCOUNT];
104 serverlist_infofield_t serverlist_sortbyfield;
105 qboolean serverlist_sortdescending;
107 int serverlist_viewcount = 0;
108 serverlist_entry_t *serverlist_viewlist[SERVERLIST_VIEWLISTSIZE];
110 int serverlist_cachecount;
111 serverlist_entry_t serverlist_cache[SERVERLIST_TOTALSIZE];
113 qboolean serverlist_consoleoutput;
115 // helper function to insert a value into the viewset
116 // spare entries will be removed
117 static void _ServerList_ViewList_Helper_InsertBefore( int index, serverlist_entry_t *entry )
120 if( serverlist_viewcount < SERVERLIST_VIEWLISTSIZE ) {
121 i = serverlist_viewcount++;
123 i = SERVERLIST_VIEWLISTSIZE - 1;
126 for( ; i > index ; i-- )
127 serverlist_viewlist[ i ] = serverlist_viewlist[ i - 1 ];
129 serverlist_viewlist[index] = entry;
132 // we suppose serverlist_viewcount to be valid, ie > 0
133 static void _ServerList_ViewList_Helper_Remove( int index )
135 serverlist_viewcount--;
136 for( ; index < serverlist_viewcount ; index++ )
137 serverlist_viewlist[index] = serverlist_viewlist[index + 1];
140 // returns true if A should be inserted before B
141 static qboolean _ServerList_Entry_Compare( serverlist_entry_t *A, serverlist_entry_t *B )
143 int result = 0; // > 0 if for numbers A > B and for text if A < B
145 switch( serverlist_sortbyfield ) {
147 result = A->info.ping - B->info.ping;
149 case SLIF_MAXPLAYERS:
150 result = A->info.maxplayers - B->info.maxplayers;
152 case SLIF_NUMPLAYERS:
153 result = A->info.numplayers - B->info.numplayers;
156 result = A->info.protocol - B->info.protocol;
159 result = strcmp( B->info.cname, A->info.cname );
162 result = strcmp( B->info.game, A->info.game );
165 result = strcmp( B->info.map, A->info.map );
168 result = strcmp( B->info.mod, A->info.mod );
171 result = strcmp( B->info.name, A->info.name );
174 Con_DPrint( "_ServerList_Entry_Compare: Bad serverlist_sortbyfield!\n" );
178 if( serverlist_sortdescending )
183 static qboolean _ServerList_CompareInt( int A, serverlist_maskop_t op, int B )
185 // This should actually be done with some intermediate and end-of-function return
197 case SLMO_GREATEREQUAL:
199 case SLMO_NOTCONTAIN:
202 Con_DPrint( "_ServerList_CompareInt: Bad op!\n" );
207 static qboolean _ServerList_CompareStr( const char *A, serverlist_maskop_t op, const char *B )
210 char bufferA[ 256 ], bufferB[ 256 ]; // should be more than enough
211 for (i = 0;i < (int)sizeof(bufferA)-1 && A[i];i++)
212 bufferA[i] = (A[i] >= 'A' && A[i] <= 'Z') ? (A[i] + 'a' - 'A') : A[i];
214 for (i = 0;i < (int)sizeof(bufferB)-1 && B[i];i++)
215 bufferB[i] = (B[i] >= 'A' && B[i] <= 'Z') ? (B[i] + 'a' - 'A') : B[i];
218 // Same here, also using an intermediate & final return would be more appropriate
222 return *bufferB && !!strstr( bufferA, bufferB ); // we want a real bool
223 case SLMO_NOTCONTAIN:
224 return !*bufferB || !strstr( bufferA, bufferB );
226 return strcmp( bufferA, bufferB ) < 0;
228 return strcmp( bufferA, bufferB ) <= 0;
230 return strcmp( bufferA, bufferB ) == 0;
232 return strcmp( bufferA, bufferB ) > 0;
234 return strcmp( bufferA, bufferB ) != 0;
235 case SLMO_GREATEREQUAL:
236 return strcmp( bufferA, bufferB ) >= 0;
238 Con_DPrint( "_ServerList_CompareStr: Bad op!\n" );
243 static qboolean _ServerList_Entry_Mask( serverlist_mask_t *mask, serverlist_info_t *info )
245 if( !_ServerList_CompareInt( info->ping, mask->tests[SLIF_PING], mask->info.ping ) )
247 if( !_ServerList_CompareInt( info->maxplayers, mask->tests[SLIF_MAXPLAYERS], mask->info.maxplayers ) )
249 if( !_ServerList_CompareInt( info->numplayers, mask->tests[SLIF_NUMPLAYERS], mask->info.numplayers ) )
251 if( !_ServerList_CompareInt( info->protocol, mask->tests[SLIF_PROTOCOL], mask->info.protocol ))
253 if( *mask->info.cname
254 && !_ServerList_CompareStr( info->cname, mask->tests[SLIF_CNAME], mask->info.cname ) )
257 && !_ServerList_CompareStr( info->game, mask->tests[SLIF_GAME], mask->info.game ) )
260 && !_ServerList_CompareStr( info->mod, mask->tests[SLIF_MOD], mask->info.mod ) )
263 && !_ServerList_CompareStr( info->map, mask->tests[SLIF_MAP], mask->info.map ) )
266 && !_ServerList_CompareStr( info->name, mask->tests[SLIF_NAME], mask->info.name ) )
271 static void ServerList_ViewList_Insert( serverlist_entry_t *entry )
275 // FIXME: change this to be more readable (...)
276 // now check whether it passes through the masks
277 for( start = 0 ; serverlist_andmasks[start].active && start < SERVERLIST_ANDMASKCOUNT ; start++ )
278 if( !_ServerList_Entry_Mask( &serverlist_andmasks[start], &entry->info ) )
281 for( start = 0 ; serverlist_ormasks[start].active && start < SERVERLIST_ORMASKCOUNT ; start++ )
282 if( _ServerList_Entry_Mask( &serverlist_ormasks[start], &entry->info ) )
284 if( start == SERVERLIST_ORMASKCOUNT || (start > 0 && !serverlist_ormasks[start].active) )
287 if( !serverlist_viewcount ) {
288 _ServerList_ViewList_Helper_InsertBefore( 0, entry );
291 // ok, insert it, we just need to find out where exactly:
294 // check whether to insert it as new first item
295 if( _ServerList_Entry_Compare( entry, serverlist_viewlist[0] ) ) {
296 _ServerList_ViewList_Helper_InsertBefore( 0, entry );
298 } // check whether to insert it as new last item
299 else if( !_ServerList_Entry_Compare( entry, serverlist_viewlist[serverlist_viewcount - 1] ) ) {
300 _ServerList_ViewList_Helper_InsertBefore( serverlist_viewcount, entry );
304 end = serverlist_viewcount - 1;
305 while( end > start + 1 )
307 mid = (start + end) / 2;
308 // test the item that lies in the middle between start and end
309 if( _ServerList_Entry_Compare( entry, serverlist_viewlist[mid] ) )
310 // the item has to be in the upper half
313 // the item has to be in the lower half
316 _ServerList_ViewList_Helper_InsertBefore( start + 1, entry );
319 static void ServerList_ViewList_Remove( serverlist_entry_t *entry )
322 for( i = 0; i < serverlist_viewcount; i++ )
324 if (serverlist_viewlist[i] == entry)
326 _ServerList_ViewList_Helper_Remove(i);
332 void ServerList_RebuildViewList(void)
336 serverlist_viewcount = 0;
337 for( i = 0 ; i < serverlist_cachecount ; i++ )
338 if( serverlist_cache[i].query == SQS_QUERIED )
339 ServerList_ViewList_Insert( &serverlist_cache[i] );
342 void ServerList_ResetMasks(void)
344 memset( &serverlist_andmasks, 0, sizeof( serverlist_andmasks ) );
345 memset( &serverlist_ormasks, 0, sizeof( serverlist_ormasks ) );
349 static void _ServerList_Test(void)
352 for( i = 0 ; i < 1024 ; i++ ) {
353 memset( &serverlist_cache[serverlist_cachecount], 0, sizeof( serverlist_entry_t ) );
354 serverlist_cache[serverlist_cachecount].info.ping = 1000 + 1024 - i;
355 dpsnprintf( serverlist_cache[serverlist_cachecount].info.name, 128, "Black's ServerList Test %i", i );
356 serverlist_cache[serverlist_cachecount].finished = true;
357 sprintf( serverlist_cache[serverlist_cachecount].line1, "%i %s", serverlist_cache[serverlist_cachecount].info.ping, serverlist_cache[serverlist_cachecount].info.name );
358 ServerList_ViewList_Insert( &serverlist_cache[serverlist_cachecount] );
359 serverlist_cachecount++;
364 void ServerList_QueryList(void)
366 masterquerytime = realtime;
367 masterquerycount = 0;
368 masterreplycount = 0;
369 serverquerycount = 0;
370 serverreplycount = 0;
371 serverlist_cachecount = 0;
372 serverlist_viewcount = 0;
373 serverlist_consoleoutput = false;
375 //_ServerList_Test();
377 NetConn_QueryMasters();
382 int NetConn_Read(lhnetsocket_t *mysocket, void *data, int maxlength, lhnetaddress_t *peeraddress)
384 int length = LHNET_Read(mysocket, data, maxlength, peeraddress);
388 if (cl_netpacketloss.integer)
389 for (i = 0;i < cl_numsockets;i++)
390 if (cl_sockets[i] == mysocket && (rand() % 100) < cl_netpacketloss.integer)
392 if (developer_networking.integer)
394 char addressstring[128], addressstring2[128];
395 LHNETADDRESS_ToString(LHNET_AddressFromSocket(mysocket), addressstring, sizeof(addressstring), true);
398 LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
399 Con_Printf("LHNET_Read(%p (%s), %p, %i, %p) = %i from %s:\n", mysocket, addressstring, data, maxlength, peeraddress, length, addressstring2);
400 Com_HexDumpToConsole((unsigned char *)data, length);
403 Con_Printf("LHNET_Read(%p (%s), %p, %i, %p) = %i\n", mysocket, addressstring, data, maxlength, peeraddress, length);
408 int NetConn_Write(lhnetsocket_t *mysocket, const void *data, int length, const lhnetaddress_t *peeraddress)
412 if (cl_netpacketloss.integer)
413 for (i = 0;i < cl_numsockets;i++)
414 if (cl_sockets[i] == mysocket && (rand() % 100) < cl_netpacketloss.integer)
416 ret = LHNET_Write(mysocket, data, length, peeraddress);
417 if (developer_networking.integer)
419 char addressstring[128], addressstring2[128];
420 LHNETADDRESS_ToString(LHNET_AddressFromSocket(mysocket), addressstring, sizeof(addressstring), true);
421 LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
422 Con_Printf("LHNET_Write(%p (%s), %p, %i, %p (%s)) = %i%s\n", mysocket, addressstring, data, length, peeraddress, addressstring2, length, ret == length ? "" : " (ERROR)");
423 Com_HexDumpToConsole((unsigned char *)data, length);
428 int NetConn_WriteString(lhnetsocket_t *mysocket, const char *string, const lhnetaddress_t *peeraddress)
430 // note this does not include the trailing NULL because we add that in the parser
431 return NetConn_Write(mysocket, string, (int)strlen(string), peeraddress);
434 int NetConn_SendReliableMessage(netconn_t *conn, sizebuf_t *data)
436 unsigned int packetLen;
437 unsigned int dataLen;
439 unsigned int *header;
442 if (data->cursize == 0)
444 Con_Printf ("Datagram_SendMessage: zero length message\n");
448 if (data->cursize > (int)sizeof(conn->sendMessage))
450 Con_Printf ("Datagram_SendMessage: message too big (%u > %u)\n", data->cursize, sizeof(conn->sendMessage));
454 if (conn->canSend == false)
456 Con_Printf ("SendMessage: called with canSend == false\n");
461 memcpy(conn->sendMessage, data->data, data->cursize);
462 conn->sendMessageLength = data->cursize;
464 if (conn->sendMessageLength <= MAX_PACKETFRAGMENT)
466 dataLen = conn->sendMessageLength;
471 dataLen = MAX_PACKETFRAGMENT;
475 packetLen = NET_HEADERSIZE + dataLen;
477 header = (unsigned int *)sendbuffer;
478 header[0] = BigLong(packetLen | (NETFLAG_DATA | eom));
479 header[1] = BigLong(conn->sendSequence);
480 memcpy(sendbuffer + NET_HEADERSIZE, conn->sendMessage, dataLen);
482 conn->sendSequence++;
483 conn->canSend = false;
485 if (NetConn_Write(conn->mysocket, (void *)&sendbuffer, packetLen, &conn->peeraddress) != (int)packetLen)
488 conn->lastSendTime = realtime;
490 reliableMessagesSent++;
494 static void NetConn_SendMessageNext(netconn_t *conn)
496 unsigned int packetLen;
497 unsigned int dataLen;
499 unsigned int *header;
501 if (conn->sendMessageLength && !conn->canSend && conn->sendNext)
503 if (conn->sendMessageLength <= MAX_PACKETFRAGMENT)
505 dataLen = conn->sendMessageLength;
510 dataLen = MAX_PACKETFRAGMENT;
514 packetLen = NET_HEADERSIZE + dataLen;
516 header = (unsigned int *)sendbuffer;
517 header[0] = BigLong(packetLen | (NETFLAG_DATA | eom));
518 header[1] = BigLong(conn->sendSequence);
519 memcpy(sendbuffer + NET_HEADERSIZE, conn->sendMessage, dataLen);
521 conn->sendSequence++;
522 conn->sendNext = false;
524 if (NetConn_Write(conn->mysocket, (void *)&sendbuffer, packetLen, &conn->peeraddress) != (int)packetLen)
527 conn->lastSendTime = realtime;
532 static void NetConn_ReSendMessage(netconn_t *conn)
534 unsigned int packetLen;
535 unsigned int dataLen;
537 unsigned int *header;
539 if (conn->sendMessageLength && !conn->canSend && (realtime - conn->lastSendTime) > 1.0)
541 if (conn->sendMessageLength <= MAX_PACKETFRAGMENT)
543 dataLen = conn->sendMessageLength;
548 dataLen = MAX_PACKETFRAGMENT;
552 packetLen = NET_HEADERSIZE + dataLen;
554 header = (unsigned int *)sendbuffer;
555 header[0] = BigLong(packetLen | (NETFLAG_DATA | eom));
556 header[1] = BigLong(conn->sendSequence - 1);
557 memcpy(sendbuffer + NET_HEADERSIZE, conn->sendMessage, dataLen);
559 conn->sendNext = false;
561 if (NetConn_Write(conn->mysocket, (void *)&sendbuffer, packetLen, &conn->peeraddress) != (int)packetLen)
564 conn->lastSendTime = realtime;
569 qboolean NetConn_CanSendMessage(netconn_t *conn)
571 return conn->canSend;
574 int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data)
577 unsigned int *header;
579 packetLen = NET_HEADERSIZE + data->cursize;
582 if (data->cursize == 0)
584 Con_Printf ("Datagram_SendUnreliableMessage: zero length message\n");
588 if (packetLen > (int)sizeof(sendbuffer))
590 Con_Printf ("Datagram_SendUnreliableMessage: message too big %u\n", data->cursize);
595 header = (unsigned int *)sendbuffer;
596 header[0] = BigLong(packetLen | NETFLAG_UNRELIABLE);
597 header[1] = BigLong(conn->unreliableSendSequence);
598 memcpy(sendbuffer + NET_HEADERSIZE, data->data, data->cursize);
600 conn->unreliableSendSequence++;
602 if (NetConn_Write(conn->mysocket, (void *)&sendbuffer, packetLen, &conn->peeraddress) != (int)packetLen)
606 unreliableMessagesSent++;
610 void NetConn_CloseClientPorts(void)
612 for (;cl_numsockets > 0;cl_numsockets--)
613 if (cl_sockets[cl_numsockets - 1])
614 LHNET_CloseSocket(cl_sockets[cl_numsockets - 1]);
617 void NetConn_OpenClientPort(const char *addressstring, int defaultport)
619 lhnetaddress_t address;
621 char addressstring2[1024];
622 if (LHNETADDRESS_FromString(&address, addressstring, defaultport))
624 if ((s = LHNET_OpenSocket_Connectionless(&address)))
626 cl_sockets[cl_numsockets++] = s;
627 LHNETADDRESS_ToString(LHNET_AddressFromSocket(s), addressstring2, sizeof(addressstring2), true);
628 Con_Printf("Client opened a socket on address %s\n", addressstring2);
632 LHNETADDRESS_ToString(&address, addressstring2, sizeof(addressstring2), true);
633 Con_Printf("Client failed to open a socket on address %s\n", addressstring2);
637 Con_Printf("Client unable to parse address %s\n", addressstring);
640 void NetConn_OpenClientPorts(void)
643 NetConn_CloseClientPorts();
644 port = bound(0, cl_netport.integer, 65535);
645 if (cl_netport.integer != port)
646 Cvar_SetValueQuick(&cl_netport, port);
647 Con_Printf("Client using port %i\n", port);
648 NetConn_OpenClientPort("local:2", 0);
649 NetConn_OpenClientPort(net_address.string, port);
650 //NetConn_OpenClientPort(net_address_ipv6.string, port);
653 void NetConn_CloseServerPorts(void)
655 for (;sv_numsockets > 0;sv_numsockets--)
656 if (sv_sockets[sv_numsockets - 1])
657 LHNET_CloseSocket(sv_sockets[sv_numsockets - 1]);
660 void NetConn_OpenServerPort(const char *addressstring, int defaultport)
662 lhnetaddress_t address;
665 char addressstring2[1024];
667 for (port = defaultport; port <= defaultport + 100; port++)
669 if (LHNETADDRESS_FromString(&address, addressstring, port))
671 if ((s = LHNET_OpenSocket_Connectionless(&address)))
673 sv_sockets[sv_numsockets++] = s;
674 LHNETADDRESS_ToString(LHNET_AddressFromSocket(s), addressstring2, sizeof(addressstring2), true);
675 Con_Printf("Server listening on address %s\n", addressstring2);
680 LHNETADDRESS_ToString(&address, addressstring2, sizeof(addressstring2), true);
681 Con_Printf("Server failed to open socket on address %s\n", addressstring2);
686 Con_Printf("Server unable to parse address %s\n", addressstring);
687 // if it cant parse one address, it wont be able to parse another for sure
693 static void NetConn_UpdateServerStuff(void);
694 void NetConn_OpenServerPorts(int opennetports)
697 NetConn_CloseServerPorts();
698 NetConn_UpdateServerStuff();
699 port = bound(0, sv_netport.integer, 65535);
702 Con_Printf("Server using port %i\n", port);
703 if (sv_netport.integer != port)
704 Cvar_SetValueQuick(&sv_netport, port);
705 if (cls.state != ca_dedicated)
706 NetConn_OpenServerPort("local:1", 0);
709 NetConn_OpenServerPort(net_address.string, port);
710 //NetConn_OpenServerPort(net_address_ipv6.string, port);
712 if (sv_numsockets == 0)
713 Host_Error("NetConn_OpenServerPorts: unable to open any ports!");
716 lhnetsocket_t *NetConn_ChooseClientSocketForAddress(lhnetaddress_t *address)
718 int i, a = LHNETADDRESS_GetAddressType(address);
719 for (i = 0;i < cl_numsockets;i++)
720 if (cl_sockets[i] && LHNETADDRESS_GetAddressType(LHNET_AddressFromSocket(cl_sockets[i])) == a)
721 return cl_sockets[i];
725 lhnetsocket_t *NetConn_ChooseServerSocketForAddress(lhnetaddress_t *address)
727 int i, a = LHNETADDRESS_GetAddressType(address);
728 for (i = 0;i < sv_numsockets;i++)
729 if (sv_sockets[i] && LHNETADDRESS_GetAddressType(LHNET_AddressFromSocket(sv_sockets[i])) == a)
730 return sv_sockets[i];
734 netconn_t *NetConn_Open(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress)
737 conn = (netconn_t *)Mem_Alloc(netconn_mempool, sizeof(*conn));
738 conn->mysocket = mysocket;
739 conn->peeraddress = *peeraddress;
740 conn->canSend = true;
741 conn->lastMessageTime = realtime;
742 // LordHavoc: (inspired by ProQuake) use a short connect timeout to
743 // reduce effectiveness of connection request floods
744 conn->timeout = realtime + net_connecttimeout.value;
745 LHNETADDRESS_ToString(&conn->peeraddress, conn->address, sizeof(conn->address), true);
746 conn->next = netconn_list;
751 void NetConn_Close(netconn_t *conn)
754 // remove connection from list
755 if (conn == netconn_list)
756 netconn_list = conn->next;
759 for (c = netconn_list;c;c = c->next)
763 c->next = conn->next;
767 // not found in list, we'll avoid crashing here...
775 static int clientport = -1;
776 static int clientport2 = -1;
777 static int hostport = -1;
778 static void NetConn_UpdateServerStuff(void)
780 if (cls.state != ca_dedicated)
782 if (clientport2 != cl_netport.integer)
784 clientport2 = cl_netport.integer;
785 if (cls.state == ca_connected)
786 Con_Print("Changing \"cl_port\" will not take effect until you reconnect.\n");
788 if (cls.state == ca_disconnected && clientport != clientport2)
790 clientport = clientport2;
791 NetConn_CloseClientPorts();
793 if (cl_numsockets == 0)
794 NetConn_OpenClientPorts();
797 if (hostport != sv_netport.integer)
799 hostport = sv_netport.integer;
801 Con_Print("Changing \"port\" will not take effect until \"map\" command is executed.\n");
805 int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int length)
809 unsigned int sequence;
814 qlength = (unsigned int)BigLong(((int *)data)[0]);
815 flags = qlength & ~NETFLAG_LENGTH_MASK;
816 qlength &= NETFLAG_LENGTH_MASK;
817 // control packets were already handled
818 if (!(flags & NETFLAG_CTL) && qlength == length)
820 sequence = BigLong(((int *)data)[1]);
824 if (flags & NETFLAG_UNRELIABLE)
826 if (sequence >= conn->unreliableReceiveSequence)
828 if (sequence > conn->unreliableReceiveSequence)
830 count = sequence - conn->unreliableReceiveSequence;
831 droppedDatagrams += count;
832 Con_DPrintf("Dropped %u datagram(s)\n", count);
834 conn->unreliableReceiveSequence = sequence + 1;
835 conn->lastMessageTime = realtime;
836 conn->timeout = realtime + net_messagetimeout.value;
837 unreliableMessagesReceived++;
840 SZ_Clear(&net_message);
841 SZ_Write(&net_message, data, length);
847 Con_DPrint("Got a stale datagram\n");
850 else if (flags & NETFLAG_ACK)
852 if (sequence == (conn->sendSequence - 1))
854 if (sequence == conn->ackSequence)
857 if (conn->ackSequence != conn->sendSequence)
858 Con_DPrint("ack sequencing error\n");
859 conn->lastMessageTime = realtime;
860 conn->timeout = realtime + net_messagetimeout.value;
861 conn->sendMessageLength -= MAX_PACKETFRAGMENT;
862 if (conn->sendMessageLength > 0)
864 memcpy(conn->sendMessage, conn->sendMessage+MAX_PACKETFRAGMENT, conn->sendMessageLength);
865 conn->sendNext = true;
866 NetConn_SendMessageNext(conn);
870 conn->sendMessageLength = 0;
871 conn->canSend = true;
875 Con_DPrint("Duplicate ACK received\n");
878 Con_DPrint("Stale ACK received\n");
881 else if (flags & NETFLAG_DATA)
883 unsigned int temppacket[2];
884 temppacket[0] = BigLong(8 | NETFLAG_ACK);
885 temppacket[1] = BigLong(sequence);
886 NetConn_Write(conn->mysocket, (unsigned char *)temppacket, 8, &conn->peeraddress);
887 if (sequence == conn->receiveSequence)
889 conn->lastMessageTime = realtime;
890 conn->timeout = realtime + net_messagetimeout.value;
891 conn->receiveSequence++;
892 if( conn->receiveMessageLength + length <= (int)sizeof( conn->receiveMessage ) ) {
893 memcpy(conn->receiveMessage + conn->receiveMessageLength, data, length);
894 conn->receiveMessageLength += length;
896 Con_Printf( "Reliable message (seq: %i) too big for message buffer!\n"
897 "Dropping the message!\n", sequence );
898 conn->receiveMessageLength = 0;
901 if (flags & NETFLAG_EOM)
903 reliableMessagesReceived++;
904 length = conn->receiveMessageLength;
905 conn->receiveMessageLength = 0;
908 SZ_Clear(&net_message);
909 SZ_Write(&net_message, conn->receiveMessage, length);
916 receivedDuplicateCount++;
924 void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress)
926 cls.connect_trying = false;
927 M_Update_Return_Reason("");
928 // the connection request succeeded, stop current connection and set up a new connection
930 // if we're connecting to a remote server, shut down any local server
931 if (LHNETADDRESS_GetAddressType(peeraddress) != LHNETADDRESSTYPE_LOOP && sv.active)
932 Host_ShutdownServer (false);
933 // allocate a net connection to keep track of things
934 cls.netcon = NetConn_Open(mysocket, peeraddress);
935 Con_Printf("Connection accepted to %s\n", cls.netcon->address);
938 cls.demonum = -1; // not in the demo loop now
939 cls.state = ca_connected;
940 cls.signon = 0; // need all the signon messages before playing
943 int NetConn_IsLocalGame(void)
945 if (cls.state == ca_connected && sv.active && cl.maxclients == 1)
950 int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *data, int length, lhnetaddress_t *peeraddress)
954 char *string, addressstring2[128], cname[128], ipstring[32];
955 char stringbuf[16384];
957 if (length >= 5 && data[0] == 255 && data[1] == 255 && data[2] == 255 && data[3] == 255)
959 // received a command string - strip off the packaging and put it
960 // into our string buffer with NULL termination
963 length = min(length, (int)sizeof(stringbuf) - 1);
964 memcpy(stringbuf, data, length);
965 stringbuf[length] = 0;
968 if (developer.integer)
970 LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
971 Con_Printf("NetConn_ClientParsePacket: %s sent us a command:\n", addressstring2);
972 Com_HexDumpToConsole(data, length);
975 if (length > 10 && !memcmp(string, "challenge ", 10) && cls.connect_trying)
977 char protocolnames[1400];
978 Protocol_Names(protocolnames, sizeof(protocolnames));
979 LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
980 Con_Printf("\"%s\" received, sending connect request back to %s\n", string, addressstring2);
981 M_Update_Return_Reason("Got challenge response");
982 NetConn_WriteString(mysocket, va("\377\377\377\377connect\\protocol\\darkplaces 3\\protocols\\%s\\challenge\\%s", protocolnames, string + 10), peeraddress);
985 if (length == 6 && !memcmp(string, "accept", 6) && cls.connect_trying)
987 M_Update_Return_Reason("Accepted");
988 NetConn_ConnectionEstablished(mysocket, peeraddress);
991 if (length > 7 && !memcmp(string, "reject ", 7) && cls.connect_trying)
993 char rejectreason[32];
994 cls.connect_trying = false;
996 length = max(length - 7, (int)sizeof(rejectreason) - 1);
997 memcpy(rejectreason, string, length);
998 rejectreason[length] = 0;
999 M_Update_Return_Reason(rejectreason);
1002 if (length >= 13 && !memcmp(string, "infoResponse\x0A", 13))
1004 serverlist_info_t *info;
1009 // serverlist only uses text addresses
1010 LHNETADDRESS_ToString(peeraddress, cname, sizeof(cname), true);
1011 // search the cache for this server and update it
1012 for( n = 0; n < serverlist_cachecount; n++ )
1013 if( !strcmp( cname, serverlist_cache[n].info.cname ) )
1015 if( n == serverlist_cachecount ) {
1016 // LAN search doesnt require an answer from the master server so we wont
1017 // know the ping nor will it be initialized already...
1020 if( serverlist_cachecount == SERVERLIST_TOTALSIZE )
1023 memset(&serverlist_cache[serverlist_cachecount], 0, sizeof(serverlist_cache[serverlist_cachecount]));
1024 // store the data the engine cares about (address and ping)
1025 strlcpy (serverlist_cache[serverlist_cachecount].info.cname, cname, sizeof (serverlist_cache[serverlist_cachecount].info.cname));
1026 serverlist_cache[serverlist_cachecount].info.ping = 100000;
1027 serverlist_cache[serverlist_cachecount].querytime = realtime;
1028 // if not in the slist menu we should print the server to console
1029 if (serverlist_consoleoutput) {
1030 Con_Printf("querying %s\n", ipstring);
1033 ++serverlist_cachecount;
1036 info = &serverlist_cache[n].info;
1037 if ((s = SearchInfostring(string, "gamename" )) != NULL) strlcpy(info->game, s, sizeof (info->game));else info->game[0] = 0;
1038 if ((s = SearchInfostring(string, "modname" )) != NULL) strlcpy(info->mod , s, sizeof (info->mod ));else info->mod[0] = 0;
1039 if ((s = SearchInfostring(string, "mapname" )) != NULL) strlcpy(info->map , s, sizeof (info->map ));else info->map[0] = 0;
1040 if ((s = SearchInfostring(string, "hostname" )) != NULL) strlcpy(info->name, s, sizeof (info->name));else info->name[0] = 0;
1041 if ((s = SearchInfostring(string, "protocol" )) != NULL) info->protocol = atoi(s);else info->protocol = -1;
1042 if ((s = SearchInfostring(string, "clients" )) != NULL) info->numplayers = atoi(s);else info->numplayers = 0;
1043 if ((s = SearchInfostring(string, "sv_maxclients")) != NULL) info->maxplayers = atoi(s);else info->maxplayers = 0;
1045 if (info->ping == 100000)
1048 pingtime = (int)((realtime - serverlist_cache[n].querytime) * 1000.0);
1049 pingtime = bound(0, pingtime, 9999);
1051 info->ping = pingtime;
1053 // legacy/old stuff move it to the menu ASAP
1055 // build description strings for the things users care about
1056 dpsnprintf(serverlist_cache[n].line1, sizeof(serverlist_cache[n].line1), "%5d%c%3u/%3u %-65.65s", (int)pingtime, info->protocol != NET_PROTOCOL_VERSION ? '*' : ' ', info->numplayers, info->maxplayers, info->name);
1057 dpsnprintf(serverlist_cache[n].line2, sizeof(serverlist_cache[n].line2), "%-21.21s %-19.19s %-17.17s %-20.20s", info->cname, info->game, info->mod, info->map);
1058 // if ping is especially high, display it as such
1059 if (pingtime >= 300)
1061 // orange numbers (lower block)
1062 for (i = 0;i < 5;i++)
1063 if (serverlist_cache[n].line1[i] != ' ')
1064 serverlist_cache[n].line1[i] += 128;
1066 else if (pingtime >= 200)
1068 // yellow numbers (in upper block)
1069 for (i = 0;i < 5;i++)
1070 if (serverlist_cache[n].line1[i] != ' ')
1071 serverlist_cache[n].line1[i] -= 30;
1073 if( serverlist_cache[n].query == SQS_QUERIED ) {
1074 ServerList_ViewList_Remove( &serverlist_cache[n] );
1076 // if not in the slist menu we should print the server to console (if wanted)
1077 else if( serverlist_consoleoutput )
1078 Con_Printf("%s\n%s\n", serverlist_cache[n].line1, serverlist_cache[n].line2);
1079 // and finally, update the view set
1080 ServerList_ViewList_Insert( &serverlist_cache[n] );
1081 serverlist_cache[n].query = SQS_QUERIED;
1085 if (!strncmp(string, "getserversResponse\\", 19) && serverlist_cachecount < SERVERLIST_TOTALSIZE)
1087 // Extract the IP addresses
1091 if (serverlist_consoleoutput)
1092 Con_Print("received server list...\n");
1093 while (length >= 7 && data[0] == '\\' && (data[1] != 0xFF || data[2] != 0xFF || data[3] != 0xFF || data[4] != 0xFF) && data[5] * 256 + data[6] != 0)
1097 dpsnprintf (ipstring, sizeof (ipstring), "%u.%u.%u.%u:%u", data[1], data[2], data[3], data[4], (data[5] << 8) | data[6]);
1098 if (developer.integer)
1099 Con_Printf("Requesting info from server %s\n", ipstring);
1100 // ignore the rest of the message if the serverlist is full
1101 if( serverlist_cachecount == SERVERLIST_TOTALSIZE )
1103 // also ignore it if we have already queried it (other master server response)
1104 for( n = 0 ; n < serverlist_cachecount ; n++ )
1105 if( !strcmp( ipstring, serverlist_cache[ n ].info.cname ) )
1107 if( n >= serverlist_cachecount )
1111 memset(&serverlist_cache[serverlist_cachecount], 0, sizeof(serverlist_cache[serverlist_cachecount]));
1112 // store the data the engine cares about (address and ping)
1113 strlcpy (serverlist_cache[serverlist_cachecount].info.cname, ipstring, sizeof (serverlist_cache[serverlist_cachecount].info.cname));
1114 serverlist_cache[serverlist_cachecount].info.ping = 100000;
1115 serverlist_cache[serverlist_cachecount].query = SQS_QUERYING;
1117 ++serverlist_cachecount;
1120 // move on to next address in packet
1124 // begin or resume serverlist queries
1125 serverlist_querysleep = false;
1129 if (!strncmp(string, "ping", 4))
1131 if (developer.integer)
1132 Con_Printf("Received ping from %s, sending ack\n", UDP_AddrToString(readaddr));
1133 NetConn_WriteString(mysocket, "\377\377\377\377ack", peeraddress);
1136 if (!strncmp(string, "ack", 3))
1139 // we may not have liked the packet, but it was a command packet, so
1140 // we're done processing this packet now
1143 // netquake control packets, supported for compatibility only
1144 if (length >= 5 && (control = BigLong(*((int *)data))) && (control & (~NETFLAG_LENGTH_MASK)) == (int)NETFLAG_CTL && (control & NETFLAG_LENGTH_MASK) == length)
1149 LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
1153 if (developer.integer)
1154 Con_Printf("Datagram_ParseConnectionless: received CCREP_ACCEPT from %s.\n", addressstring2);
1155 if (cls.connect_trying)
1157 lhnetaddress_t clientportaddress;
1158 clientportaddress = *peeraddress;
1161 unsigned int port = (data[0] << 0) | (data[1] << 8) | (data[2] << 16) | (data[3] << 24);
1164 LHNETADDRESS_SetPort(&clientportaddress, port);
1166 M_Update_Return_Reason("Accepted");
1167 NetConn_ConnectionEstablished(mysocket, &clientportaddress);
1171 if (developer.integer)
1172 Con_Printf("Datagram_ParseConnectionless: received CCREP_REJECT from %s.\n", addressstring2);
1173 cls.connect_trying = false;
1174 M_Update_Return_Reason((char *)data);
1177 case CCREP_SERVER_INFO:
1178 if (developer.integer)
1179 Con_Printf("Datagram_ParseConnectionless: received CCREP_SERVER_INFO from %s.\n", addressstring2);
1180 if (cls.state != ca_dedicated)
1182 // LordHavoc: because the UDP driver reports 0.0.0.0:26000 as the address
1183 // string we just ignore it and keep the real address
1185 // serverlist only uses text addresses
1186 cname = UDP_AddrToString(readaddr);
1187 // search the cache for this server
1188 for (n = 0; n < hostCacheCount; n++)
1189 if (!strcmp(cname, serverlist[n].cname))
1192 if (n == hostCacheCount && hostCacheCount < SERVERLISTSIZE)
1195 memset(&serverlist[n], 0, sizeof(serverlist[n]));
1196 strlcpy (serverlist[n].name, MSG_ReadString(), sizeof (serverlist[n].name));
1197 strlcpy (serverlist[n].map, MSG_ReadString(), sizeof (serverlist[n].map));
1198 serverlist[n].users = MSG_ReadByte();
1199 serverlist[n].maxusers = MSG_ReadByte();
1201 if (c != NET_PROTOCOL_VERSION)
1203 strlcpy (serverlist[n].cname, serverlist[n].name, sizeof (serverlist[n].cname));
1204 strcpy(serverlist[n].name, "*");
1205 strlcat (serverlist[n].name, serverlist[n].cname, sizeof(serverlist[n].name));
1207 strlcpy (serverlist[n].cname, cname, sizeof (serverlist[n].cname));
1211 case CCREP_PLAYER_INFO:
1212 // we got a CCREP_PLAYER_INFO??
1213 //if (developer.integer)
1214 Con_Printf("Datagram_ParseConnectionless: received CCREP_PLAYER_INFO from %s.\n", addressstring2);
1216 case CCREP_RULE_INFO:
1217 // we got a CCREP_RULE_INFO??
1218 //if (developer.integer)
1219 Con_Printf("Datagram_ParseConnectionless: received CCREP_RULE_INFO from %s.\n", addressstring2);
1225 // we may not have liked the packet, but it was a valid control
1226 // packet, so we're done processing this packet now
1230 if (length >= (int)NET_HEADERSIZE && cls.netcon && mysocket == cls.netcon->mysocket && !LHNETADDRESS_Compare(&cls.netcon->peeraddress, peeraddress) && (ret = NetConn_ReceivedMessage(cls.netcon, data, length)) == 2)
1231 CL_ParseServerMessage();
1235 void NetConn_QueryQueueFrame(void)
1241 static double querycounter = 0;
1243 if (serverlist_querysleep)
1246 // each time querycounter reaches 1.0 issue a query
1247 querycounter += host_realframetime * net_slist_queriespersecond.value;
1248 maxqueries = (int)querycounter;
1249 maxqueries = bound(0, maxqueries, net_slist_queriesperframe.integer);
1250 querycounter -= maxqueries;
1252 if( maxqueries == 0 ) {
1256 // scan serverlist and issue queries as needed
1257 serverlist_querysleep = true;
1259 timeouttime = realtime - net_slist_timeout.value;
1260 for( index = 0, queries = 0 ; index < serverlist_cachecount && queries < maxqueries ; index++ )
1262 serverlist_entry_t *entry = &serverlist_cache[ index ];
1263 if( entry->query != SQS_QUERYING )
1268 serverlist_querysleep = false;
1269 if( entry->querycounter != 0 && entry->querytime > timeouttime )
1274 if( entry->querycounter != (unsigned) net_slist_maxtries.integer )
1276 lhnetaddress_t address;
1279 LHNETADDRESS_FromString(&address, entry->info.cname, 0);
1280 for (socket = 0; socket < cl_numsockets ; socket++) {
1281 NetConn_WriteString(cl_sockets[socket], "\377\377\377\377getinfo", &address);
1284 entry->querytime = realtime;
1285 entry->querycounter++;
1287 // if not in the slist menu we should print the server to console
1288 if (serverlist_consoleoutput)
1289 Con_Printf("querying %25s (%i. try)\n", entry->info.cname, entry->querycounter);
1295 entry->query = SQS_TIMEDOUT;
1300 void NetConn_ClientFrame(void)
1303 lhnetaddress_t peeraddress;
1305 NetConn_UpdateServerStuff();
1306 if (cls.connect_trying && cls.connect_nextsendtime < realtime)
1308 if (cls.connect_remainingtries == 0)
1309 M_Update_Return_Reason("Connect: Waiting 10 seconds for reply");
1310 cls.connect_nextsendtime = realtime + 1;
1311 cls.connect_remainingtries--;
1312 if (cls.connect_remainingtries <= -10)
1314 cls.connect_trying = false;
1315 M_Update_Return_Reason("Connect: Failed");
1318 // try challenge first (newer server)
1319 NetConn_WriteString(cls.connect_mysocket, "\377\377\377\377getchallenge", &cls.connect_address);
1320 // then try netquake as a fallback (old server, or netquake)
1321 SZ_Clear(&net_message);
1322 // save space for the header, filled in later
1323 MSG_WriteLong(&net_message, 0);
1324 MSG_WriteByte(&net_message, CCREQ_CONNECT);
1325 MSG_WriteString(&net_message, "QUAKE");
1326 MSG_WriteByte(&net_message, NET_PROTOCOL_VERSION);
1327 *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
1328 NetConn_Write(cls.connect_mysocket, net_message.data, net_message.cursize, &cls.connect_address);
1329 SZ_Clear(&net_message);
1331 for (i = 0;i < cl_numsockets;i++) {
1332 while (cl_sockets[i] && (length = NetConn_Read(cl_sockets[i], readbuffer, sizeof(readbuffer), &peeraddress)) > 0) {
1333 NetConn_ClientParsePacket(cl_sockets[i], readbuffer, length, &peeraddress);
1336 NetConn_QueryQueueFrame();
1337 if (cls.netcon && realtime > cls.netcon->timeout)
1339 Con_Print("Connection timed out\n");
1341 Host_ShutdownServer (false);
1343 for (conn = netconn_list;conn;conn = conn->next)
1344 NetConn_ReSendMessage(conn);
1347 #define MAX_CHALLENGES 128
1350 lhnetaddress_t address;
1354 challenge[MAX_CHALLENGES];
1356 static void NetConn_BuildChallengeString(char *buffer, int bufferlength)
1360 for (i = 0;i < bufferlength - 1;i++)
1364 c = rand () % (127 - 33) + 33;
1365 } while (c == '\\' || c == ';' || c == '"' || c == '%' || c == '/');
1371 static qboolean NetConn_BuildStatusResponse(const char* challenge, char* out_msg, size_t out_size, qboolean fullstatus)
1373 unsigned int nb_clients = 0, i;
1376 // How many clients are there?
1377 for (i = 0;i < (unsigned int)svs.maxclients;i++)
1378 if (svs.clients[i].active)
1381 // TODO: we should add more information for the full status string
1382 length = dpsnprintf(out_msg, out_size,
1383 "\377\377\377\377%s\x0A"
1384 "\\gamename\\%s\\modname\\%s\\sv_maxclients\\%d"
1385 "\\clients\\%d\\mapname\\%s\\hostname\\%s""\\protocol\\%d"
1388 fullstatus ? "statusResponse" : "infoResponse",
1389 gamename, com_modname, svs.maxclients,
1390 nb_clients, sv.name, hostname.string, NET_PROTOCOL_VERSION,
1391 challenge ? "\\challenge\\" : "", challenge ? challenge : "",
1392 fullstatus ? "\n" : "");
1394 // Make sure it fits in the buffer
1403 ptr = out_msg + length;
1404 left = (int)out_size - length;
1406 for (i = 0;i < (unsigned int)svs.maxclients;i++)
1408 client_t *cl = &svs.clients[i];
1411 int nameind, cleanind;
1413 char cleanname [sizeof(cl->name)];
1415 // Remove all characters '"' and '\' in the player name
1420 curchar = cl->name[nameind++];
1421 if (curchar != '"' && curchar != '\\')
1423 cleanname[cleanind++] = curchar;
1424 if (cleanind == sizeof(cleanname) - 1)
1427 } while (curchar != '\0');
1429 length = dpsnprintf(ptr, left, "%d %d \"%s\"\n",
1431 (int)(cl->ping * 1000.0f),
1444 extern void SV_SendServerinfo (client_t *client);
1445 int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *data, int length, lhnetaddress_t *peeraddress)
1447 int i, ret, clientnum, best;
1451 char *s, *string, response[512], addressstring2[128], stringbuf[16384];
1455 if (length >= 5 && data[0] == 255 && data[1] == 255 && data[2] == 255 && data[3] == 255)
1457 // received a command string - strip off the packaging and put it
1458 // into our string buffer with NULL termination
1461 length = min(length, (int)sizeof(stringbuf) - 1);
1462 memcpy(stringbuf, data, length);
1463 stringbuf[length] = 0;
1466 if (developer.integer)
1468 LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
1469 Con_Printf("NetConn_ServerParsePacket: %s sent us a command:\n", addressstring2);
1470 Com_HexDumpToConsole(data, length);
1473 if (length >= 12 && !memcmp(string, "getchallenge", 12))
1475 for (i = 0, best = 0, besttime = realtime;i < MAX_CHALLENGES;i++)
1477 if (!LHNETADDRESS_Compare(peeraddress, &challenge[i].address))
1479 if (besttime > challenge[i].time)
1480 besttime = challenge[best = i].time;
1482 // if we did not find an exact match, choose the oldest and
1483 // update address and string
1484 if (i == MAX_CHALLENGES)
1487 challenge[i].address = *peeraddress;
1488 NetConn_BuildChallengeString(challenge[i].string, sizeof(challenge[i].string));
1490 challenge[i].time = realtime;
1491 // send the challenge
1492 NetConn_WriteString(mysocket, va("\377\377\377\377challenge %s", challenge[i].string), peeraddress);
1495 if (length > 8 && !memcmp(string, "connect\\", 8))
1499 if ((s = SearchInfostring(string, "challenge")))
1501 // validate the challenge
1502 for (i = 0;i < MAX_CHALLENGES;i++)
1503 if (!LHNETADDRESS_Compare(peeraddress, &challenge[i].address) && !strcmp(challenge[i].string, s))
1505 if (i < MAX_CHALLENGES)
1507 // check engine protocol
1508 if (strcmp(SearchInfostring(string, "protocol"), "darkplaces 3"))
1510 if (developer.integer)
1511 Con_Printf("Datagram_ParseConnectionless: sending \"reject Wrong game protocol.\" to %s.\n", addressstring2);
1512 NetConn_WriteString(mysocket, "\377\377\377\377reject Wrong game protocol.", peeraddress);
1516 // see if this is a duplicate connection request
1517 for (clientnum = 0, client = svs.clients;clientnum < svs.maxclients;clientnum++, client++)
1518 if (client->netconnection && LHNETADDRESS_Compare(peeraddress, &client->netconnection->peeraddress) == 0)
1520 if (clientnum < svs.maxclients && realtime - client->connecttime < net_messagerejointimeout.value)
1522 // client is still trying to connect,
1523 // so we send a duplicate reply
1524 if (developer.integer)
1525 Con_Printf("Datagram_ParseConnectionless: sending duplicate accept to %s.\n", addressstring2);
1526 NetConn_WriteString(mysocket, "\377\377\377\377accept", peeraddress);
1529 else if (clientnum < svs.maxclients)
1531 if (realtime - client->netconnection->lastMessageTime >= net_messagerejointimeout.value)
1533 // client crashed and is coming back, keep their stuff intact
1534 SV_SendServerinfo(client);
1535 //host_client = client;
1536 //SV_DropClient (true);
1543 // this is a new client, find a slot
1544 for (clientnum = 0, client = svs.clients;clientnum < svs.maxclients;clientnum++, client++)
1545 if (!client->active)
1547 if (clientnum < svs.maxclients)
1549 // prepare the client struct
1550 if ((conn = NetConn_Open(mysocket, peeraddress)))
1552 // allocated connection
1553 LHNETADDRESS_ToString(peeraddress, conn->address, sizeof(conn->address), true);
1554 if (developer.integer)
1555 Con_Printf("Datagram_ParseConnectionless: sending \"accept\" to %s.\n", conn->address);
1556 NetConn_WriteString(mysocket, "\377\377\377\377accept", peeraddress);
1557 // now set up the client
1558 SV_ConnectClient(clientnum, conn);
1559 NetConn_Heartbeat(1);
1565 if (developer.integer)
1566 Con_Printf("Datagram_ParseConnectionless: sending \"reject Server is full.\" to %s.\n", addressstring2);
1567 NetConn_WriteString(mysocket, "\377\377\377\377reject Server is full.", peeraddress);
1575 if (length >= 7 && !memcmp(string, "getinfo", 7))
1577 const char *challenge = NULL;
1579 // If there was a challenge in the getinfo message
1580 if (length > 8 && string[7] == ' ')
1581 challenge = string + 8;
1583 if (NetConn_BuildStatusResponse(challenge, response, sizeof(response), false))
1585 if (developer.integer)
1586 Con_Printf("Sending reply to master %s - %s\n", addressstring2, response);
1587 NetConn_WriteString(mysocket, response, peeraddress);
1591 if (length >= 9 && !memcmp(string, "getstatus", 9))
1593 const char *challenge = NULL;
1595 // If there was a challenge in the getinfo message
1596 if (length > 10 && string[9] == ' ')
1597 challenge = string + 10;
1599 if (NetConn_BuildStatusResponse(challenge, response, sizeof(response), true))
1601 if (developer.integer)
1602 Con_Printf("Sending reply to client %s - %s\n", addressstring2, response);
1603 NetConn_WriteString(mysocket, response, peeraddress);
1608 if (!strncmp(string, "ping", 4))
1610 if (developer.integer)
1611 Con_Printf("Received ping from %s, sending ack\n", UDP_AddrToString(readaddr));
1612 NetConn_WriteString(mysocket, "\377\377\377\377ack", peeraddress);
1615 if (!strncmp(string, "ack", 3))
1618 // we may not have liked the packet, but it was a command packet, so
1619 // we're done processing this packet now
1622 // LordHavoc: disabled netquake control packet support in server
1626 // netquake control packets, supported for compatibility only
1627 if (length >= 5 && (control = BigLong(*((int *)data))) && (control & (~NETFLAG_LENGTH_MASK)) == (int)NETFLAG_CTL && (control & NETFLAG_LENGTH_MASK) == length)
1632 LHNETADDRESS_ToString(peeraddress, addressstring2, sizeof(addressstring2), true);
1636 //if (developer.integer)
1637 Con_Printf("Datagram_ParseConnectionless: received CCREQ_CONNECT from %s.\n", addressstring2);
1638 if (length >= (int)strlen("QUAKE") + 1 + 1)
1640 if (memcmp(data, "QUAKE", strlen("QUAKE") + 1) != 0 || (int)data[strlen("QUAKE") + 1] != NET_PROTOCOL_VERSION)
1642 if (developer.integer)
1643 Con_Printf("Datagram_ParseConnectionless: sending CCREP_REJECT \"Incompatible version.\" to %s.\n", addressstring2);
1644 SZ_Clear(&net_message);
1645 // save space for the header, filled in later
1646 MSG_WriteLong(&net_message, 0);
1647 MSG_WriteByte(&net_message, CCREP_REJECT);
1648 MSG_WriteString(&net_message, "Incompatible version.\n");
1649 *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
1650 NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
1651 SZ_Clear(&net_message);
1655 // see if this is a duplicate connection request
1656 for (clientnum = 0, client = svs.clients;clientnum < svs.maxclients;clientnum++, client++)
1657 if (client->netconnection && LHNETADDRESS_Compare(peeraddress, &client->netconnection->peeraddress) == 0)
1659 if (clientnum < svs.maxclients)
1661 // duplicate connection request
1662 if (realtime - client->connecttime < 2.0)
1664 // client is still trying to connect,
1665 // so we send a duplicate reply
1666 if (developer.integer)
1667 Con_Printf("Datagram_ParseConnectionless: sending duplicate CCREP_ACCEPT to %s.\n", addressstring2);
1668 SZ_Clear(&net_message);
1669 // save space for the header, filled in later
1670 MSG_WriteLong(&net_message, 0);
1671 MSG_WriteByte(&net_message, CCREP_ACCEPT);
1672 MSG_WriteLong(&net_message, LHNETADDRESS_GetPort(LHNET_AddressFromSocket(client->netconnection->mysocket)));
1673 *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
1674 NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
1675 SZ_Clear(&net_message);
1678 else if (realtime - client->netconnection->lastMessageTime >= net_messagerejointimeout.value)
1680 SV_SendServerinfo(client);
1681 // the old client hasn't sent us anything
1682 // in quite a while, so kick off and let
1683 // the retry take care of it...
1684 //host_client = client;
1685 //SV_DropClient (true);
1691 // this is a new client, find a slot
1692 for (clientnum = 0, client = svs.clients;clientnum < svs.maxclients;clientnum++, client++)
1693 if (!client->active)
1695 if (clientnum < svs.maxclients && (client->netconnection = conn = NetConn_Open(mysocket, peeraddress)) != NULL)
1697 // connect to the client
1698 // everything is allocated, just fill in the details
1699 strlcpy (conn->address, addressstring2, sizeof (conn->address));
1700 if (developer.integer)
1701 Con_Printf("Datagram_ParseConnectionless: sending CCREP_ACCEPT to %s.\n", addressstring2);
1702 // send back the info about the server connection
1703 SZ_Clear(&net_message);
1704 // save space for the header, filled in later
1705 MSG_WriteLong(&net_message, 0);
1706 MSG_WriteByte(&net_message, CCREP_ACCEPT);
1707 MSG_WriteLong(&net_message, LHNETADDRESS_GetPort(LHNET_AddressFromSocket(conn->mysocket)));
1708 *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
1709 NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
1710 SZ_Clear(&net_message);
1711 // now set up the client struct
1712 SV_ConnectClient(clientnum, conn);
1713 NetConn_Heartbeat(1);
1717 //if (developer.integer)
1718 Con_Printf("Datagram_ParseConnectionless: sending CCREP_REJECT \"Server is full.\" to %s.\n", addressstring2);
1719 // no room; try to let player know
1720 SZ_Clear(&net_message);
1721 // save space for the header, filled in later
1722 MSG_WriteLong(&net_message, 0);
1723 MSG_WriteByte(&net_message, CCREP_REJECT);
1724 MSG_WriteString(&net_message, "Server is full.\n");
1725 *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
1726 NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
1727 SZ_Clear(&net_message);
1734 case CCREQ_SERVER_INFO:
1735 if (developer.integer)
1736 Con_Printf("Datagram_ParseConnectionless: received CCREQ_SERVER_INFO from %s.\n", addressstring2);
1737 if (sv.active && !strcmp(MSG_ReadString(), "QUAKE"))
1739 if (developer.integer)
1740 Con_Printf("Datagram_ParseConnectionless: sending CCREP_SERVER_INFO to %s.\n", addressstring2);
1741 SZ_Clear(&net_message);
1742 // save space for the header, filled in later
1743 MSG_WriteLong(&net_message, 0);
1744 MSG_WriteByte(&net_message, CCREP_SERVER_INFO);
1745 UDP_GetSocketAddr(UDP_acceptSock, &newaddr);
1746 MSG_WriteString(&net_message, UDP_AddrToString(&newaddr));
1747 MSG_WriteString(&net_message, hostname.string);
1748 MSG_WriteString(&net_message, sv.name);
1749 MSG_WriteByte(&net_message, net_activeconnections);
1750 MSG_WriteByte(&net_message, svs.maxclients);
1751 MSG_WriteByte(&net_message, NET_PROTOCOL_VERSION);
1752 *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
1753 NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
1754 SZ_Clear(&net_message);
1757 case CCREQ_PLAYER_INFO:
1758 if (developer.integer)
1759 Con_Printf("Datagram_ParseConnectionless: received CCREQ_PLAYER_INFO from %s.\n", addressstring2);
1762 int playerNumber, activeNumber, clientNumber;
1765 playerNumber = MSG_ReadByte();
1767 for (clientNumber = 0, client = svs.clients; clientNumber < svs.maxclients; clientNumber++, client++)
1768 if (client->active && ++activeNumber == playerNumber)
1770 if (clientNumber != svs.maxclients)
1772 SZ_Clear(&net_message);
1773 // save space for the header, filled in later
1774 MSG_WriteLong(&net_message, 0);
1775 MSG_WriteByte(&net_message, CCREP_PLAYER_INFO);
1776 MSG_WriteByte(&net_message, playerNumber);
1777 MSG_WriteString(&net_message, client->name);
1778 MSG_WriteLong(&net_message, client->colors);
1779 MSG_WriteLong(&net_message, (int)client->edict->fields.server->frags);
1780 MSG_WriteLong(&net_message, (int)(realtime - client->connecttime));
1781 MSG_WriteString(&net_message, client->netconnection ? client->netconnection->address : "botclient");
1782 *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
1783 NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
1784 SZ_Clear(&net_message);
1788 case CCREQ_RULE_INFO:
1789 if (developer.integer)
1790 Con_Printf("Datagram_ParseConnectionless: received CCREQ_RULE_INFO from %s.\n", addressstring2);
1796 // find the search start location
1797 prevCvarName = MSG_ReadString();
1798 var = Cvar_FindVarAfter(prevCvarName, CVAR_NOTIFY);
1800 // send the response
1801 SZ_Clear(&net_message);
1802 // save space for the header, filled in later
1803 MSG_WriteLong(&net_message, 0);
1804 MSG_WriteByte(&net_message, CCREP_RULE_INFO);
1807 MSG_WriteString(&net_message, var->name);
1808 MSG_WriteString(&net_message, var->string);
1810 *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
1811 NetConn_Write(mysocket, net_message.data, net_message.cursize, peeraddress);
1812 SZ_Clear(&net_message);
1819 // we may not have liked the packet, but it was a valid control
1820 // packet, so we're done processing this packet now
1825 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1827 if (host_client->netconnection && host_client->netconnection->mysocket == mysocket && !LHNETADDRESS_Compare(&host_client->netconnection->peeraddress, peeraddress))
1829 if ((ret = NetConn_ReceivedMessage(host_client->netconnection, data, length)) == 2)
1830 SV_ReadClientMessage();
1838 void NetConn_ServerFrame(void)
1841 lhnetaddress_t peeraddress;
1843 NetConn_UpdateServerStuff();
1844 for (i = 0;i < sv_numsockets;i++)
1845 while (sv_sockets[i] && (length = NetConn_Read(sv_sockets[i], readbuffer, sizeof(readbuffer), &peeraddress)) > 0)
1846 NetConn_ServerParsePacket(sv_sockets[i], readbuffer, length, &peeraddress);
1847 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1849 // never timeout loopback connections
1850 if (host_client->netconnection && realtime > host_client->netconnection->timeout && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP)
1852 Con_Printf("Client \"%s\" connection timed out\n", host_client->name);
1853 SV_DropClient(false);
1856 for (conn = netconn_list;conn;conn = conn->next)
1857 NetConn_ReSendMessage(conn);
1860 void NetConn_QueryMasters(void)
1864 lhnetaddress_t masteraddress;
1865 lhnetaddress_t broadcastaddress;
1868 if (serverlist_cachecount >= SERVERLIST_TOTALSIZE)
1871 // 26000 is the default quake server port, servers on other ports will not
1873 // note this is IPv4-only, I doubt there are IPv6-only LANs out there
1874 LHNETADDRESS_FromString(&broadcastaddress, "255.255.255.255", 26000);
1876 for (i = 0;i < cl_numsockets;i++)
1880 // search LAN for Quake servers
1881 SZ_Clear(&net_message);
1882 // save space for the header, filled in later
1883 MSG_WriteLong(&net_message, 0);
1884 MSG_WriteByte(&net_message, CCREQ_SERVER_INFO);
1885 MSG_WriteString(&net_message, "QUAKE");
1886 MSG_WriteByte(&net_message, NET_PROTOCOL_VERSION);
1887 *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK));
1888 NetConn_Write(cl_sockets[i], net_message.data, net_message.cursize, &broadcastaddress);
1889 SZ_Clear(&net_message);
1891 // search LAN for DarkPlaces servers
1892 NetConn_WriteString(cl_sockets[i], "\377\377\377\377getinfo", &broadcastaddress);
1894 // build the getservers message to send to the master servers
1895 dpsnprintf(request, sizeof(request), "\377\377\377\377getservers %s %u empty full\x0A", gamename, NET_PROTOCOL_VERSION);
1898 for (masternum = 0;sv_masters[masternum].name;masternum++)
1900 if (sv_masters[masternum].string && LHNETADDRESS_FromString(&masteraddress, sv_masters[masternum].string, MASTER_PORT) && LHNETADDRESS_GetAddressType(&masteraddress) == LHNETADDRESS_GetAddressType(LHNET_AddressFromSocket(cl_sockets[i])))
1903 NetConn_WriteString(cl_sockets[i], request, &masteraddress);
1908 if (!masterquerycount)
1910 Con_Print("Unable to query master servers, no suitable network sockets active.\n");
1911 M_Update_Return_Reason("No network");
1915 void NetConn_Heartbeat(int priority)
1917 lhnetaddress_t masteraddress;
1919 lhnetsocket_t *mysocket;
1921 // if it's a state change (client connected), limit next heartbeat to no
1922 // more than 30 sec in the future
1923 if (priority == 1 && nextheartbeattime > realtime + 30.0)
1924 nextheartbeattime = realtime + 30.0;
1926 // limit heartbeatperiod to 30 to 270 second range,
1927 // lower limit is to avoid abusing master servers with excess traffic,
1928 // upper limit is to avoid timing out on the master server (which uses
1930 if (sv_heartbeatperiod.value < 30)
1931 Cvar_SetValueQuick(&sv_heartbeatperiod, 30);
1932 if (sv_heartbeatperiod.value > 270)
1933 Cvar_SetValueQuick(&sv_heartbeatperiod, 270);
1935 // make advertising optional and don't advertise singleplayer games, and
1936 // only send a heartbeat as often as the admin wants
1937 if (sv.active && sv_public.integer && svs.maxclients >= 2 && (priority > 1 || realtime > nextheartbeattime))
1939 nextheartbeattime = realtime + sv_heartbeatperiod.value;
1940 for (masternum = 0;sv_masters[masternum].name;masternum++)
1941 if (sv_masters[masternum].string && LHNETADDRESS_FromString(&masteraddress, sv_masters[masternum].string, MASTER_PORT) && (mysocket = NetConn_ChooseServerSocketForAddress(&masteraddress)))
1942 NetConn_WriteString(mysocket, "\377\377\377\377heartbeat DarkPlaces\x0A", &masteraddress);
1946 int NetConn_SendToAll(sizebuf_t *data, double blocktime)
1949 unsigned char sent[MAX_SCOREBOARD];
1951 memset(sent, 0, sizeof(sent));
1953 // simultaneously wait for the first CanSendMessage and send the message,
1954 // then wait for a second CanSendMessage (verifying it was received), or
1955 // the client drops and is no longer counted
1956 // the loop aborts when either it runs out of clients to send to, or a
1958 blocktime += Sys_DoubleTime();
1962 NetConn_ClientFrame();
1963 NetConn_ServerFrame();
1964 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1966 if (host_client->netconnection)
1968 if (NetConn_CanSendMessage(host_client->netconnection))
1971 NetConn_SendReliableMessage(host_client->netconnection, data);
1974 if (!NetConn_CanSendMessage(host_client->netconnection))
1979 while (count && Sys_DoubleTime() < blocktime);
1983 static void Net_Heartbeat_f(void)
1986 NetConn_Heartbeat(2);
1988 Con_Print("No server running, can not heartbeat to master server.\n");
1991 void PrintStats(netconn_t *conn)
1993 Con_Printf("address=%21s canSend=%u sendSeq=%6u recvSeq=%6u\n", conn->address, conn->canSend, conn->sendSequence, conn->receiveSequence);
1996 void Net_Stats_f(void)
1999 Con_Printf("unreliable messages sent = %i\n", unreliableMessagesSent);
2000 Con_Printf("unreliable messages recv = %i\n", unreliableMessagesReceived);
2001 Con_Printf("reliable messages sent = %i\n", reliableMessagesSent);
2002 Con_Printf("reliable messages received = %i\n", reliableMessagesReceived);
2003 Con_Printf("packetsSent = %i\n", packetsSent);
2004 Con_Printf("packetsReSent = %i\n", packetsReSent);
2005 Con_Printf("packetsReceived = %i\n", packetsReceived);
2006 Con_Printf("receivedDuplicateCount = %i\n", receivedDuplicateCount);
2007 Con_Printf("droppedDatagrams = %i\n", droppedDatagrams);
2008 Con_Print("connections =\n");
2009 for (conn = netconn_list;conn;conn = conn->next)
2013 void Net_Slist_f(void)
2015 ServerList_ResetMasks();
2016 serverlist_sortbyfield = SLIF_PING;
2017 serverlist_sortdescending = false;
2018 if (m_state != m_slist) {
2019 Con_Print("Sending requests to master servers\n");
2020 ServerList_QueryList();
2021 serverlist_consoleoutput = true;
2022 Con_Print("Listening for replies...\n");
2024 ServerList_QueryList();
2027 void NetConn_Init(void)
2030 lhnetaddress_t tempaddress;
2031 netconn_mempool = Mem_AllocPool("network connections", 0, NULL);
2032 Cmd_AddCommand("net_stats", Net_Stats_f);
2033 Cmd_AddCommand("net_slist", Net_Slist_f);
2034 Cmd_AddCommand("heartbeat", Net_Heartbeat_f);
2035 Cvar_RegisterVariable(&net_slist_queriespersecond);
2036 Cvar_RegisterVariable(&net_slist_queriesperframe);
2037 Cvar_RegisterVariable(&net_slist_timeout);
2038 Cvar_RegisterVariable(&net_slist_maxtries);
2039 Cvar_RegisterVariable(&net_messagetimeout);
2040 Cvar_RegisterVariable(&net_messagerejointimeout);
2041 Cvar_RegisterVariable(&net_connecttimeout);
2042 Cvar_RegisterVariable(&cl_netlocalping);
2043 Cvar_RegisterVariable(&cl_netpacketloss);
2044 Cvar_RegisterVariable(&hostname);
2045 Cvar_RegisterVariable(&developer_networking);
2046 Cvar_RegisterVariable(&cl_netport);
2047 Cvar_RegisterVariable(&sv_netport);
2048 Cvar_RegisterVariable(&net_address);
2049 //Cvar_RegisterVariable(&net_address_ipv6);
2050 Cvar_RegisterVariable(&sv_public);
2051 Cvar_RegisterVariable(&sv_heartbeatperiod);
2052 for (i = 0;sv_masters[i].name;i++)
2053 Cvar_RegisterVariable(&sv_masters[i]);
2054 // COMMANDLINEOPTION: Server: -ip <ipaddress> sets the ip address of this machine for purposes of networking (default 0.0.0.0 also known as INADDR_ANY), use only if you have multiple network adapters and need to choose one specifically.
2055 if ((i = COM_CheckParm("-ip")) && i + 1 < com_argc)
2057 if (LHNETADDRESS_FromString(&tempaddress, com_argv[i + 1], 0) == 1)
2059 Con_Printf("-ip option used, setting net_address to \"%s\"\n");
2060 Cvar_SetQuick(&net_address, com_argv[i + 1]);
2063 Con_Printf("-ip option used, but unable to parse the address \"%s\"\n", com_argv[i + 1]);
2065 // COMMANDLINEOPTION: Server: -port <portnumber> sets the port to use for a server (default 26000, the same port as QUAKE itself), useful if you host multiple servers on your machine
2066 if (((i = COM_CheckParm("-port")) || (i = COM_CheckParm("-ipport")) || (i = COM_CheckParm("-udpport"))) && i + 1 < com_argc)
2068 i = atoi(com_argv[i + 1]);
2069 if (i >= 0 && i < 65536)
2071 Con_Printf("-port option used, setting port cvar to %i\n", i);
2072 Cvar_SetValueQuick(&sv_netport, i);
2075 Con_Printf("-port option used, but %i is not a valid port number\n", i);
2079 net_message.data = net_message_buf;
2080 net_message.maxsize = sizeof(net_message_buf);
2081 net_message.cursize = 0;
2085 void NetConn_Shutdown(void)
2087 NetConn_CloseClientPorts();
2088 NetConn_CloseServerPorts();