X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=netconn.c;h=661455b9d5951d321cb518941ff409cc70b0e51d;hb=eb59c580e111af2abb37775ef320151776fe84d1;hp=8ddc8aa59d3de099f0f82bd39615150f1e371301;hpb=1a473289e63fa85c6edce042060fd2a4ac1ed4bc;p=xonotic%2Fdarkplaces.git diff --git a/netconn.c b/netconn.c index 8ddc8aa5..661455b9 100755 --- a/netconn.c +++ b/netconn.c @@ -27,7 +27,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define DPMASTER_PORT 27950 // note this defaults on for dedicated servers, off for listen servers -cvar_t sv_public = {0, "sv_public", "0", "advertises this server on the master server (so that players can find it in the server browser)"}; +cvar_t sv_public = {0, "sv_public", "0", "1: advertises this server on the master server (so that players can find it in the server browser); 0: allow direct queries only; -1: do not respond to direct queries; -2: do not allow anyone to connect"}; static cvar_t sv_heartbeatperiod = {CVAR_SAVE, "sv_heartbeatperiod", "120", "how often to send heartbeat in seconds (only used if sv_public is 1)"}; static cvar_t sv_masters [] = @@ -38,8 +38,7 @@ static cvar_t sv_masters [] = {CVAR_SAVE, "sv_master4", "", "user-chosen master server 4"}, {0, "sv_masterextra1", "ghdigital.com", "default master server 1 (admin: LordHavoc)"}, // admin: LordHavoc {0, "sv_masterextra2", "dpmaster.deathmask.net", "default master server 2 (admin: Willis)"}, // admin: Willis - {0, "sv_masterextra3", "12.166.196.192", "default master server 3 (admin: Venim)"}, // admin: Venim - {0, "sv_masterextra4", "excalibur.nvg.ntnu.no", "default master server 4 (admin: tChr)"}, // admin: tChr + {0, "sv_masterextra3", "dpmaster.tchr.no", "default master server 3 (admin: tChr)"}, // admin: tChr {0, NULL, NULL, NULL} }; @@ -49,19 +48,11 @@ static cvar_t sv_qwmasters [] = {CVAR_SAVE, "sv_qwmaster2", "", "user-chosen qwmaster server 2"}, {CVAR_SAVE, "sv_qwmaster3", "", "user-chosen qwmaster server 3"}, {CVAR_SAVE, "sv_qwmaster4", "", "user-chosen qwmaster server 4"}, - {0, "sv_qwmasterextra1", "192.246.40.37:27000", "id Limbo (admin: id Software)"}, - {0, "sv_qwmasterextra2", "192.246.40.37:27002", "id CTF (admin: id Software)"}, - {0, "sv_qwmasterextra3", "192.246.40.37:27003", "id TeamFortress (admin: id Software)"}, - {0, "sv_qwmasterextra4", "192.246.40.37:27004", "id Miscilaneous (admin: id Software)"}, - {0, "sv_qwmasterextra5", "192.246.40.37:27006", "id Deathmatch Only (admin: id Software)"}, - {0, "sv_qwmasterextra6", "150.254.66.120:27000", "Poland's master server. (admin: unknown)"}, - {0, "sv_qwmasterextra7", "62.112.145.129:27000", "Ocrana master server. (admin: unknown)"}, - {0, "sv_qwmasterextra8", "master.edome.net", "edome master server. (admin: unknown)"}, - {0, "sv_qwmasterextra9", "qwmaster.barrysworld.com", "barrysworld master server. (admin: unknown)"}, - {0, "sv_qwmasterextra10", "qwmaster.ocrana.de:27000", "Ocrana2 master server. (admin: unknown)"}, - {0, "sv_qwmasterextra11", "213.221.174.165:27000", "unknown1 master server. (admin: unknown)"}, - {0, "sv_qwmasterextra12", "195.74.0.8", "unknown2 master server. (admin: unknown)"}, - {0, "sv_qwmasterextra13", "204.182.161.2", "unknown3 master server. (admin: unknown)"}, + {0, "sv_qwmasterextra1", "master.quakeservers.net:27000", "Global master server. (admin: unknown)"}, + {0, "sv_qwmasterextra2", "asgaard.morphos-team.net:27000", "Global master server. (admin: unknown)"}, + {0, "sv_qwmasterextra3", "qwmaster.ocrana.de:27000", "German master server. (admin: unknown)"}, + {0, "sv_qwmasterextra4", "masterserver.exhale.de:27000", "German master server. (admin: unknown)"}, + {0, "sv_qwmasterextra5", "kubus.rulez.pl:27000", "Poland master server. (admin: unknown)"}, {0, NULL, NULL, NULL} }; @@ -77,13 +68,17 @@ cvar_t hostname = {CVAR_SAVE, "hostname", "UNNAMED", "server message to show in cvar_t developer_networking = {0, "developer_networking", "0", "prints all received and sent packets (recommended only for debugging)"}; cvar_t cl_netlocalping = {0, "cl_netlocalping","0", "lags local loopback connection by this much ping time (useful to play more fairly on your own server with people with higher pings)"}; -static cvar_t cl_netpacketloss = {0, "cl_netpacketloss","0", "drops this percentage of packets (incoming and outgoing), useful for testing network protocol robustness (effects failing to start, sounds failing to play, etc)"}; +static cvar_t cl_netpacketloss_send = {0, "cl_netpacketloss_send","0", "drops this percentage of outgoing packets, useful for testing network protocol robustness (jerky movement, prediction errors, etc)"}; +static cvar_t cl_netpacketloss_receive = {0, "cl_netpacketloss_receive","0", "drops this percentage of incoming packets, useful for testing network protocol robustness (jerky movement, effects failing to start, sounds failing to play, etc)"}; static cvar_t net_slist_queriespersecond = {0, "net_slist_queriespersecond", "20", "how many server information requests to send per second"}; static cvar_t net_slist_queriesperframe = {0, "net_slist_queriesperframe", "4", "maximum number of server information requests to send each rendered frame (guards against low framerates causing problems)"}; static cvar_t net_slist_timeout = {0, "net_slist_timeout", "4", "how long to listen for a server information response before giving up"}; +static cvar_t net_slist_pause = {0, "net_slist_pause", "0", "when set to 1, the server list won't update until it is set back to 0"}; static cvar_t net_slist_maxtries = {0, "net_slist_maxtries", "3", "how many times to ask the same server for information (more times gives better ping reports but takes longer)"}; static cvar_t gameversion = {0, "gameversion", "0", "version of game data (mod-specific), when client and server gameversion mismatch in the server browser the server is shown as incompatible"}; +static cvar_t rcon_restricted_password = {CVAR_PRIVATE, "rcon_restricted_password", "", "password to authenticate rcon commands in restricted mode"}; +static cvar_t rcon_restricted_commands = {0, "rcon_restricted_commands", "", "allowed commands for rcon when the restricted mode password was used"}; /* statistic counters */ static int packetsSent = 0; @@ -105,6 +100,7 @@ int serverreplycount = 0; // this is only false if there are still servers left to query static qboolean serverlist_querysleep = true; +static qboolean serverlist_paused = false; // this is pushed a second or two ahead of realtime whenever a master server // reply is received, to avoid issuing queries while master replies are still // flooding in (which would make a mess of the ping times) @@ -126,6 +122,10 @@ cvar_t sv_netport = {0, "port", "26000", "server port for players to connect to" cvar_t net_address = {0, "net_address", "0.0.0.0", "network address to open ports on"}; //cvar_t net_netaddress_ipv6 = {0, "net_address_ipv6", "[0:0:0:0:0:0:0:0]", "network address to open ipv6 ports on"}; +char net_extresponse[NET_EXTRESPONSE_MAX][1400]; +int net_extresponse_count = 0; +int net_extresponse_last = 0; + // ServerList interface serverlist_mask_t serverlist_andmasks[SERVERLIST_ANDMASKCOUNT]; serverlist_mask_t serverlist_ormasks[SERVERLIST_ORMASKCOUNT]; @@ -181,6 +181,15 @@ static qboolean _ServerList_Entry_Compare( serverlist_entry_t *A, serverlist_ent case SLIF_NUMPLAYERS: result = A->info.numplayers - B->info.numplayers; break; + case SLIF_NUMBOTS: + result = A->info.numbots - B->info.numbots; + break; + case SLIF_NUMHUMANS: + result = A->info.numhumans - B->info.numhumans; + break; + case SLIF_FREESLOTS: + result = A->info.freeslots - B->info.freeslots; + break; case SLIF_PROTOCOL: result = A->info.protocol - B->info.protocol; break; @@ -188,16 +197,22 @@ static qboolean _ServerList_Entry_Compare( serverlist_entry_t *A, serverlist_ent result = strcmp( B->info.cname, A->info.cname ); break; case SLIF_GAME: - result = strcmp( B->info.game, A->info.game ); + result = strcasecmp( B->info.game, A->info.game ); break; case SLIF_MAP: - result = strcmp( B->info.map, A->info.map ); + result = strcasecmp( B->info.map, A->info.map ); break; case SLIF_MOD: - result = strcmp( B->info.mod, A->info.mod ); + result = strcasecmp( B->info.mod, A->info.mod ); break; case SLIF_NAME: - result = strcmp( B->info.name, A->info.name ); + result = strcasecmp( B->info.name, A->info.name ); + break; + case SLIF_QCSTATUS: + result = strcasecmp( B->info.qcstatus, A->info.qcstatus ); // not really THAT useful, though + break; + case SLIF_PLAYERS: + result = strcasecmp( B->info.players, A->info.qcstatus ); // not really THAT useful, though break; default: Con_DPrint( "_ServerList_Entry_Compare: Bad serverlist_sortbyfield!\n" ); @@ -231,6 +246,8 @@ static qboolean _ServerList_CompareInt( int A, serverlist_maskop_t op, int B ) case SLMO_GREATEREQUAL: case SLMO_CONTAINS: case SLMO_NOTCONTAIN: + case SLMO_STARTSWITH: + case SLMO_NOTSTARTSWITH: return A >= B; default: Con_DPrint( "_ServerList_CompareInt: Bad op!\n" ); @@ -241,9 +258,10 @@ static qboolean _ServerList_CompareInt( int A, serverlist_maskop_t op, int B ) static qboolean _ServerList_CompareStr( const char *A, serverlist_maskop_t op, const char *B ) { int i; - char bufferA[ 256 ], bufferB[ 256 ]; // should be more than enough - for (i = 0;i < (int)sizeof(bufferA)-1 && A[i];i++) - bufferA[i] = (A[i] >= 'A' && A[i] <= 'Z') ? (A[i] + 'a' - 'A') : A[i]; + char bufferA[ 1400 ], bufferB[ 1400 ]; // should be more than enough + COM_StringDecolorize(A, 0, bufferA, sizeof(bufferA), false); + for (i = 0;i < (int)sizeof(bufferA)-1 && bufferA[i];i++) + bufferA[i] = (bufferA[i] >= 'A' && bufferA[i] <= 'Z') ? (bufferA[i] + 'a' - 'A') : bufferA[i]; bufferA[i] = 0; for (i = 0;i < (int)sizeof(bufferB)-1 && B[i];i++) bufferB[i] = (B[i] >= 'A' && B[i] <= 'Z') ? (B[i] + 'a' - 'A') : B[i]; @@ -256,6 +274,11 @@ static qboolean _ServerList_CompareStr( const char *A, serverlist_maskop_t op, c return *bufferB && !!strstr( bufferA, bufferB ); // we want a real bool case SLMO_NOTCONTAIN: return !*bufferB || !strstr( bufferA, bufferB ); + case SLMO_STARTSWITH: + //Con_Printf("startsWith: %s %s\n", bufferA, bufferB); + return *bufferB && !memcmp(bufferA, bufferB, strlen(bufferB)); + case SLMO_NOTSTARTSWITH: + return !*bufferB || memcmp(bufferA, bufferB, strlen(bufferB)); case SLMO_LESS: return strcmp( bufferA, bufferB ) < 0; case SLMO_LESSEQUAL: @@ -282,6 +305,12 @@ static qboolean _ServerList_Entry_Mask( serverlist_mask_t *mask, serverlist_info return false; if( !_ServerList_CompareInt( info->numplayers, mask->tests[SLIF_NUMPLAYERS], mask->info.numplayers ) ) return false; + if( !_ServerList_CompareInt( info->numbots, mask->tests[SLIF_NUMBOTS], mask->info.numbots ) ) + return false; + if( !_ServerList_CompareInt( info->numhumans, mask->tests[SLIF_NUMHUMANS], mask->info.numhumans ) ) + return false; + if( !_ServerList_CompareInt( info->freeslots, mask->tests[SLIF_FREESLOTS], mask->info.freeslots ) ) + return false; if( !_ServerList_CompareInt( info->protocol, mask->tests[SLIF_PROTOCOL], mask->info.protocol )) return false; if( *mask->info.cname @@ -299,6 +328,12 @@ static qboolean _ServerList_Entry_Mask( serverlist_mask_t *mask, serverlist_info if( *mask->info.name && !_ServerList_CompareStr( info->name, mask->tests[SLIF_NAME], mask->info.name ) ) return false; + if( *mask->info.qcstatus + && !_ServerList_CompareStr( info->qcstatus, mask->tests[SLIF_QCSTATUS], mask->info.qcstatus ) ) + return false; + if( *mask->info.players + && !_ServerList_CompareStr( info->players, mask->tests[SLIF_PLAYERS], mask->info.players ) ) + return false; return true; } @@ -312,11 +347,11 @@ static void ServerList_ViewList_Insert( serverlist_entry_t *entry ) // FIXME: change this to be more readable (...) // now check whether it passes through the masks - for( start = 0 ; serverlist_andmasks[start].active && start < SERVERLIST_ANDMASKCOUNT ; start++ ) + for( start = 0 ; start < SERVERLIST_ANDMASKCOUNT && serverlist_andmasks[start].active; start++ ) if( !_ServerList_Entry_Mask( &serverlist_andmasks[start], &entry->info ) ) return; - for( start = 0 ; serverlist_ormasks[start].active && start < SERVERLIST_ORMASKCOUNT ; start++ ) + for( start = 0 ; start < SERVERLIST_ORMASKCOUNT && serverlist_ormasks[start].active ; start++ ) if( _ServerList_Entry_Mask( &serverlist_ormasks[start], &entry->info ) ) break; if( start == SERVERLIST_ORMASKCOUNT || (start > 0 && !serverlist_ormasks[start].active) ) @@ -372,15 +407,41 @@ void ServerList_RebuildViewList(void) int i; serverlist_viewcount = 0; - for( i = 0 ; i < serverlist_cachecount ; i++ ) - if( serverlist_cache[i].query == SQS_QUERIED ) - ServerList_ViewList_Insert( &serverlist_cache[i] ); + for( i = 0 ; i < serverlist_cachecount ; i++ ) { + serverlist_entry_t *entry = &serverlist_cache[i]; + // also display entries that are currently being refreshed [11/8/2007 Black] + if( entry->query == SQS_QUERIED || entry->query == SQS_REFRESHING ) + ServerList_ViewList_Insert( entry ); + } } void ServerList_ResetMasks(void) { + int i; + memset( &serverlist_andmasks, 0, sizeof( serverlist_andmasks ) ); memset( &serverlist_ormasks, 0, sizeof( serverlist_ormasks ) ); + // numbots needs to be compared to -1 to always succeed + for(i = 0; i < SERVERLIST_ANDMASKCOUNT; ++i) + serverlist_andmasks[i].info.numbots = -1; + for(i = 0; i < SERVERLIST_ORMASKCOUNT; ++i) + serverlist_ormasks[i].info.numbots = -1; +} + +void ServerList_GetPlayerStatistics(int *numplayerspointer, int *maxplayerspointer) +{ + int i; + int numplayers = 0, maxplayers = 0; + for (i = 0;i < serverlist_cachecount;i++) + { + if (serverlist_cache[i].query == SQS_QUERIED) + { + numplayers += serverlist_cache[i].info.numhumans; + maxplayers += serverlist_cache[i].info.maxplayers; + } + } + *numplayerspointer = numplayers; + *maxplayerspointer = maxplayers; } #if 0 @@ -392,24 +453,33 @@ static void _ServerList_Test(void) serverlist_cache[serverlist_cachecount].info.ping = 1000 + 1024 - i; dpsnprintf( serverlist_cache[serverlist_cachecount].info.name, sizeof(serverlist_cache[serverlist_cachecount].info.name), "Black's ServerList Test %i", i ); serverlist_cache[serverlist_cachecount].finished = true; - sprintf( serverlist_cache[serverlist_cachecount].line1, "%i %s", serverlist_cache[serverlist_cachecount].info.ping, serverlist_cache[serverlist_cachecount].info.name ); + dpsnprintf( serverlist_cache[serverlist_cachecount].line1, sizeof(serverlist_cache[serverlist_cachecount].info.line1), "%i %s", serverlist_cache[serverlist_cachecount].info.ping, serverlist_cache[serverlist_cachecount].info.name ); ServerList_ViewList_Insert( &serverlist_cache[serverlist_cachecount] ); serverlist_cachecount++; } } #endif -void ServerList_QueryList(qboolean querydp, qboolean queryqw) +void ServerList_QueryList(qboolean resetcache, qboolean querydp, qboolean queryqw, qboolean consoleoutput) { - //masterquerytime = realtime; - masterquerytime = Sys_DoubleTime(); + masterquerytime = realtime; masterquerycount = 0; masterreplycount = 0; - serverquerycount = 0; - serverreplycount = 0; - serverlist_cachecount = 0; - serverlist_viewcount = 0; - serverlist_consoleoutput = false; + if( resetcache ) { + serverquerycount = 0; + serverreplycount = 0; + serverlist_cachecount = 0; + serverlist_viewcount = 0; + } else { + // refresh all entries + int n; + for( n = 0 ; n < serverlist_cachecount ; n++ ) { + serverlist_entry_t *entry = &serverlist_cache[ n ]; + entry->query = SQS_REFRESHING; + entry->querycounter = 0; + } + } + serverlist_consoleoutput = consoleoutput; //_ServerList_Test(); @@ -424,9 +494,9 @@ int NetConn_Read(lhnetsocket_t *mysocket, void *data, int maxlength, lhnetaddres int i; if (length == 0) return 0; - if (cl_netpacketloss.integer) + if (cl_netpacketloss_receive.integer) for (i = 0;i < cl_numsockets;i++) - if (cl_sockets[i] == mysocket && (rand() % 100) < cl_netpacketloss.integer) + if (cl_sockets[i] == mysocket && (rand() % 100) < cl_netpacketloss_receive.integer) return 0; if (developer_networking.integer) { @@ -448,9 +518,9 @@ int NetConn_Write(lhnetsocket_t *mysocket, const void *data, int length, const l { int ret; int i; - if (cl_netpacketloss.integer) + if (cl_netpacketloss_send.integer) for (i = 0;i < cl_numsockets;i++) - if (cl_sockets[i] == mysocket && (rand() % 100) < cl_netpacketloss.integer) + if (cl_sockets[i] == mysocket && (rand() % 100) < cl_netpacketloss_send.integer) return length; ret = LHNET_Write(mysocket, data, length, peeraddress); if (developer_networking.integer) @@ -470,8 +540,31 @@ int NetConn_WriteString(lhnetsocket_t *mysocket, const char *string, const lhnet return NetConn_Write(mysocket, string, (int)strlen(string), peeraddress); } -int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolversion_t protocol) +qboolean NetConn_CanSend(netconn_t *conn) { + conn->outgoing_packetcounter = (conn->outgoing_packetcounter + 1) % NETGRAPH_PACKETS; + conn->outgoing_unreliablesize[conn->outgoing_packetcounter] = NETGRAPH_NOPACKET; + conn->outgoing_reliablesize[conn->outgoing_packetcounter] = NETGRAPH_NOPACKET; + conn->outgoing_acksize[conn->outgoing_packetcounter] = NETGRAPH_NOPACKET; + if (realtime > conn->cleartime) + return true; + else + { + conn->outgoing_unreliablesize[conn->outgoing_packetcounter] = NETGRAPH_CHOKEDPACKET; + return false; + } +} + +int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolversion_t protocol, int rate, qboolean quakesignon_suppressreliables) +{ + int totallen = 0; + + // if this packet was supposedly choked, but we find ourselves sending one + // anyway, make sure the size counting starts at zero + // (this mostly happens on level changes and disconnects and such) + if (conn->outgoing_unreliablesize[conn->outgoing_packetcounter] == NETGRAPH_CHOKEDPACKET) + conn->outgoing_unreliablesize[conn->outgoing_packetcounter] = NETGRAPH_NOPACKET; + if (protocol == PROTOCOL_QUAKEWORLD) { int packetLen; @@ -494,34 +587,40 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers sendreliable = true; } // outgoing unreliable packet number, and outgoing reliable packet number (0 or 1) - *((int *)(sendbuffer + 0)) = LittleLong((unsigned int)conn->qw.outgoing_sequence | ((unsigned int)sendreliable<<31)); + *((int *)(sendbuffer + 0)) = LittleLong((unsigned int)conn->outgoing_unreliable_sequence | ((unsigned int)sendreliable<<31)); // last received unreliable packet number, and last received reliable packet number (0 or 1) *((int *)(sendbuffer + 4)) = LittleLong((unsigned int)conn->qw.incoming_sequence | ((unsigned int)conn->qw.incoming_reliable_sequence<<31)); packetLen = 8; - conn->qw.outgoing_sequence++; + conn->outgoing_unreliable_sequence++; // client sends qport in every packet if (conn == cls.netcon) { *((short *)(sendbuffer + 8)) = LittleShort(cls.qw_qport); packetLen += 2; // also update cls.qw_outgoing_sequence - cls.qw_outgoing_sequence = conn->qw.outgoing_sequence; + cls.qw_outgoing_sequence = conn->outgoing_unreliable_sequence; } if (packetLen + (sendreliable ? conn->sendMessageLength : 0) > 1400) { Con_Printf ("NetConn_SendUnreliableMessage: reliable message too big %u\n", data->cursize); return -1; } + + conn->outgoing_unreliablesize[conn->outgoing_packetcounter] += packetLen; + // add the reliable message if there is one if (sendreliable) { + conn->outgoing_reliablesize[conn->outgoing_packetcounter] += conn->sendMessageLength; memcpy(sendbuffer + packetLen, conn->sendMessage, conn->sendMessageLength); packetLen += conn->sendMessageLength; - conn->qw.last_reliable_sequence = conn->qw.outgoing_sequence; + conn->qw.last_reliable_sequence = conn->outgoing_unreliable_sequence; } + // add the unreliable message if possible if (packetLen + data->cursize <= 1400) { + conn->outgoing_unreliablesize[conn->outgoing_packetcounter] += data->cursize; memcpy(sendbuffer + packetLen, data->data, data->cursize); packetLen += data->cursize; } @@ -531,10 +630,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers packetsSent++; unreliableMessagesSent++; - // delay later packets to obey rate limit - conn->qw.cleartime = max(conn->qw.cleartime, realtime) + packetLen * conn->qw.rate; - - return 0; + totallen += packetLen + 28; } else { @@ -564,19 +660,23 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers header[1] = BigLong(conn->nq.sendSequence - 1); memcpy(sendbuffer + NET_HEADERSIZE, conn->sendMessage, dataLen); + conn->outgoing_reliablesize[conn->outgoing_packetcounter] += packetLen; + if (NetConn_Write(conn->mysocket, (void *)&sendbuffer, packetLen, &conn->peeraddress) == (int)packetLen) { conn->lastSendTime = realtime; packetsReSent++; } + + totallen += packetLen + 28; } // if we have a new reliable message to send, do so - if (!conn->sendMessageLength && conn->message.cursize) + if (!conn->sendMessageLength && conn->message.cursize && !quakesignon_suppressreliables) { if (conn->message.cursize > (int)sizeof(conn->sendMessage)) { - Con_Printf("NetConn_SendUnreliableMessage: reliable message too big (%u > %u)\n", conn->message.cursize, sizeof(conn->sendMessage)); + Con_Printf("NetConn_SendUnreliableMessage: reliable message too big (%u > %u)\n", conn->message.cursize, (int)sizeof(conn->sendMessage)); conn->message.overflowed = true; return -1; } @@ -611,11 +711,15 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers conn->nq.sendSequence++; + conn->outgoing_reliablesize[conn->outgoing_packetcounter] += packetLen; + NetConn_Write(conn->mysocket, (void *)&sendbuffer, packetLen, &conn->peeraddress); conn->lastSendTime = realtime; packetsSent++; reliableMessagesSent++; + + totallen += packetLen + 28; } // if we have an unreliable message to send, do so @@ -631,18 +735,40 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers header = (unsigned int *)sendbuffer; header[0] = BigLong(packetLen | NETFLAG_UNRELIABLE); - header[1] = BigLong(conn->nq.unreliableSendSequence); + header[1] = BigLong(conn->outgoing_unreliable_sequence); memcpy(sendbuffer + NET_HEADERSIZE, data->data, data->cursize); - conn->nq.unreliableSendSequence++; + conn->outgoing_unreliable_sequence++; + + conn->outgoing_unreliablesize[conn->outgoing_packetcounter] += packetLen; NetConn_Write(conn->mysocket, (void *)&sendbuffer, packetLen, &conn->peeraddress); packetsSent++; unreliableMessagesSent++; + + totallen += packetLen + 28; } - return 0; } + + // delay later packets to obey rate limit + if (conn->cleartime < realtime - 0.1) + conn->cleartime = realtime - 0.1; + conn->cleartime = conn->cleartime + (double)totallen / (double)rate; + if (conn->cleartime < realtime) + conn->cleartime = realtime; + + return 0; +} + +qboolean NetConn_HaveClientPorts(void) +{ + return !!cl_numsockets; +} + +qboolean NetConn_HaveServerPorts(void) +{ + return !!sv_numsockets; } void NetConn_CloseClientPorts(void) @@ -682,7 +808,10 @@ void NetConn_OpenClientPorts(void) port = bound(0, cl_netport.integer, 65535); if (cl_netport.integer != port) Cvar_SetValueQuick(&cl_netport, port); - Con_Printf("Client using port %i\n", port); + if(port == 0) + Con_Printf("Client using an automatically assigned port\n"); + else + Con_Printf("Client using port %i\n", port); NetConn_OpenClientPort("local:2", 0); NetConn_OpenClientPort(net_address.string, port); //NetConn_OpenClientPort(net_address_ipv6.string, port); @@ -848,11 +977,10 @@ void NetConn_UpdateSockets(void) static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int length, protocolversion_t protocol, double newtimeout) { + int originallength = length; if (length < 8) return 0; - // TODO: add netgraph stuff rather than just packetloss counting... - if (protocol == PROTOCOL_QUAKEWORLD) { int sequence, sequence_ack; @@ -893,12 +1021,16 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len //Con_DPrintf("Dropped %u datagram(s)\n", count); while (count--) { - conn->packetlost[conn->packetlostcounter] = true; - conn->packetlostcounter = (conn->packetlostcounter + 1) % 100; + conn->incoming_packetcounter = (conn->incoming_packetcounter + 1) % NETGRAPH_PACKETS; + conn->incoming_unreliablesize[conn->incoming_packetcounter] = NETGRAPH_LOSTPACKET; + conn->incoming_reliablesize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET; + conn->incoming_acksize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET; } } - conn->packetlost[conn->packetlostcounter] = false; - conn->packetlostcounter = (conn->packetlostcounter + 1) % 100; + conn->incoming_packetcounter = (conn->incoming_packetcounter + 1) % NETGRAPH_PACKETS; + conn->incoming_unreliablesize[conn->incoming_packetcounter] = originallength; + conn->incoming_reliablesize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET; + conn->incoming_acksize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET; if (reliable_ack == conn->qw.reliable_sequence) { // received, now we will be able to send another reliable message @@ -948,12 +1080,16 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len //Con_DPrintf("Dropped %u datagram(s)\n", count); while (count--) { - conn->packetlost[conn->packetlostcounter] = true; - conn->packetlostcounter = (conn->packetlostcounter + 1) % 100; + conn->incoming_packetcounter = (conn->incoming_packetcounter + 1) % NETGRAPH_PACKETS; + conn->incoming_unreliablesize[conn->incoming_packetcounter] = NETGRAPH_LOSTPACKET; + conn->incoming_reliablesize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET; + conn->incoming_acksize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET; } } - conn->packetlost[conn->packetlostcounter] = false; - conn->packetlostcounter = (conn->packetlostcounter + 1) % 100; + conn->incoming_packetcounter = (conn->incoming_packetcounter + 1) % NETGRAPH_PACKETS; + conn->incoming_unreliablesize[conn->incoming_packetcounter] = originallength; + conn->incoming_reliablesize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET; + conn->incoming_acksize[conn->incoming_packetcounter] = NETGRAPH_NOPACKET; conn->nq.unreliableReceiveSequence = sequence + 1; conn->lastMessageTime = realtime; conn->timeout = realtime + newtimeout; @@ -972,6 +1108,7 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len } else if (flags & NETFLAG_ACK) { + conn->incoming_acksize[conn->incoming_packetcounter] += originallength; if (sequence == (conn->nq.sendSequence - 1)) { if (sequence == conn->nq.ackSequence) @@ -989,7 +1126,7 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len unsigned int *header; conn->sendMessageLength -= MAX_PACKETFRAGMENT; - memcpy(conn->sendMessage, conn->sendMessage+MAX_PACKETFRAGMENT, conn->sendMessageLength); + memmove(conn->sendMessage, conn->sendMessage+MAX_PACKETFRAGMENT, conn->sendMessageLength); if (conn->sendMessageLength <= MAX_PACKETFRAGMENT) { @@ -1030,6 +1167,8 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len else if (flags & NETFLAG_DATA) { unsigned int temppacket[2]; + conn->incoming_reliablesize[conn->incoming_packetcounter] += originallength; + conn->outgoing_acksize[conn->outgoing_packetcounter] += 8; temppacket[0] = BigLong(8 | NETFLAG_ACK); temppacket[1] = BigLong(sequence); NetConn_Write(conn->mysocket, (unsigned char *)temppacket, 8, &conn->peeraddress); @@ -1088,6 +1227,8 @@ void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_t *peer cls.state = ca_connected; cls.signon = 0; // need all the signon messages before playing cls.protocol = initialprotocol; + // reset move sequence numbering on this new connection + cls.servermovesequence = 0; if (cls.protocol == PROTOCOL_QUAKEWORLD) Cmd_ForwardStringToServer("new"); if (cls.protocol == PROTOCOL_QUAKE) @@ -1100,7 +1241,7 @@ void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_t *peer msg.data = buf; msg.maxsize = sizeof(buf); MSG_WriteChar(&msg, clc_nop); - NetConn_SendUnreliableMessage(cls.netcon, &msg, cls.protocol); + NetConn_SendUnreliableMessage(cls.netcon, &msg, cls.protocol, 10000, false); } } @@ -1115,10 +1256,15 @@ static int NetConn_ClientParsePacket_ServerList_ProcessReply(const char *address { int n; int pingtime; + serverlist_entry_t *entry = NULL; + // search the cache for this server and update it - for (n = 0;n < serverlist_cachecount;n++) - if (!strcmp(addressstring, serverlist_cache[n].info.cname)) + for (n = 0;n < serverlist_cachecount;n++) { + entry = &serverlist_cache[ n ]; + if (!strcmp(addressstring, entry->info.cname)) break; + } + if (n == serverlist_cachecount) { // LAN search doesnt require an answer from the master server so we wont @@ -1128,44 +1274,93 @@ static int NetConn_ClientParsePacket_ServerList_ProcessReply(const char *address if (serverlist_cachecount == SERVERLIST_TOTALSIZE) return -1; - memset(&serverlist_cache[serverlist_cachecount], 0, sizeof(serverlist_cache[serverlist_cachecount])); + entry = &serverlist_cache[n]; + + memset(entry, 0, sizeof(*entry)); // store the data the engine cares about (address and ping) - strlcpy(serverlist_cache[serverlist_cachecount].info.cname, addressstring, sizeof(serverlist_cache[serverlist_cachecount].info.cname)); - serverlist_cache[serverlist_cachecount].info.ping = 100000; - //serverlist_cache[serverlist_cachecount].querytime = realtime; - serverlist_cache[serverlist_cachecount].querytime = Sys_DoubleTime(); + strlcpy(entry->info.cname, addressstring, sizeof(entry->info.cname)); + entry->info.ping = 100000; + entry->querytime = realtime; // if not in the slist menu we should print the server to console if (serverlist_consoleoutput) Con_Printf("querying %s\n", addressstring); ++serverlist_cachecount; } // if this is the first reply from this server, count it as having replied - if (serverlist_cache[n].info.ping == 100000) - serverreplycount++; - pingtime = (int)((Sys_DoubleTime() - serverlist_cache[n].querytime) * 1000.0 + 0.5); + pingtime = (int)((realtime - entry->querytime) * 1000.0 + 0.5); pingtime = bound(0, pingtime, 9999); - // update the ping - serverlist_cache[n].info.ping = min(serverlist_cache[n].info.ping, pingtime); + if (entry->query == SQS_REFRESHING) { + entry->info.ping = pingtime; + entry->query = SQS_QUERIED; + } else { + // convert to unsigned to catch the -1 + // I still dont like this but its better than the old 10000 magic ping number - as in easier to type and read :( [11/8/2007 Black] + entry->info.ping = min((unsigned) entry->info.ping, (unsigned) pingtime); + serverreplycount++; + } + // other server info is updated by the caller return n; } static void NetConn_ClientParsePacket_ServerList_UpdateCache(int n) { - serverlist_info_t *info = &serverlist_cache[n].info; + serverlist_entry_t *entry = &serverlist_cache[n]; + serverlist_info_t *info = &entry->info; // update description strings for engine menu and console output - dpsnprintf(serverlist_cache[n].line1, sizeof(serverlist_cache[n].line1), "^%c%5d^7 ^%c%3u^7/%3u %-65.65s", info->ping >= 300 ? '1' : (info->ping >= 200 ? '3' : '7'), (int)info->ping, ((info->numplayers > 0 && info->numplayers < info->maxplayers) ? (info->numplayers >= 4 ? '7' : '3') : '1'), info->numplayers, info->maxplayers, info->name); - dpsnprintf(serverlist_cache[n].line2, sizeof(serverlist_cache[n].line2), "^4%-21.21s %-19.19s ^%c%-17.17s^4 %-20.20s", info->cname, info->game, (info->gameversion != gameversion.integer) ? '1' : '4', info->mod, info->map); - if (serverlist_cache[n].query == SQS_QUERIED) - ServerList_ViewList_Remove(&serverlist_cache[n]); + dpsnprintf(entry->line1, sizeof(serverlist_cache[n].line1), "^%c%5d^7 ^%c%3u^7/%3u %-65.65s", info->ping >= 300 ? '1' : (info->ping >= 200 ? '3' : '7'), (int)info->ping, ((info->numhumans > 0 && info->numhumans < info->maxplayers) ? (info->numhumans >= 4 ? '7' : '3') : '1'), info->numplayers, info->maxplayers, info->name); + dpsnprintf(entry->line2, sizeof(serverlist_cache[n].line2), "^4%-21.21s %-19.19s ^%c%-17.17s^4 %-20.20s", info->cname, info->game, (info->gameversion != gameversion.integer) ? '1' : '4', info->mod, info->map); + if (entry->query == SQS_QUERIED) + { + if(!serverlist_paused) + ServerList_ViewList_Remove(entry); + } // if not in the slist menu we should print the server to console (if wanted) else if( serverlist_consoleoutput ) Con_Printf("%s\n%s\n", serverlist_cache[n].line1, serverlist_cache[n].line2); // and finally, update the view set - ServerList_ViewList_Insert( &serverlist_cache[n] ); + if(!serverlist_paused) + ServerList_ViewList_Insert( entry ); + // update the entry's state serverlist_cache[n].query = SQS_QUERIED; } +// returns true, if it's sensible to continue the processing +static qboolean NetConn_ClientParsePacket_ServerList_PrepareQuery( int protocol, const char *ipstring ) { + int n; + serverlist_entry_t *entry; + + // ignore the rest of the message if the serverlist is full + if( serverlist_cachecount == SERVERLIST_TOTALSIZE ) + return false; + // also ignore it if we have already queried it (other master server response) + for( n = 0 ; n < serverlist_cachecount ; n++ ) + if( !strcmp( ipstring, serverlist_cache[ n ].info.cname ) ) + break; + + entry = &serverlist_cache[n]; + + if( n < serverlist_cachecount ) { + // the entry has already been queried once or + return true; + } + + memset(entry, 0, sizeof(entry)); + entry->protocol = protocol; + // store the data the engine cares about (address and ping) + strlcpy (entry->info.cname, ipstring, sizeof(entry->info.cname)); + + // no, then reset the ping right away + entry->info.ping = -1; + // we also want to increase the serverlist_cachecount then + serverlist_cachecount++; + serverquerycount++; + + entry->query = SQS_QUERYING; + + return true; +} + static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *data, int length, lhnetaddress_t *peeraddress) { qboolean fromserver; @@ -1228,6 +1423,58 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat M_Update_Return_Reason(rejectreason); return true; } + if (length >= 15 && !memcmp(string, "statusResponse\x0A", 15)) + { + serverlist_info_t *info; + char *p; + int n; + + string += 15; + // search the cache for this server and update it + n = NetConn_ClientParsePacket_ServerList_ProcessReply(addressstring2); + if (n < 0) + return true; + + info = &serverlist_cache[n].info; + info->game[0] = 0; + info->mod[0] = 0; + info->map[0] = 0; + info->name[0] = 0; + info->qcstatus[0] = 0; + info->players[0] = 0; + info->protocol = -1; + info->numplayers = 0; + info->numbots = -1; + info->maxplayers = 0; + info->gameversion = 0; + + p = strchr(string, '\n'); + if(p) + { + *p = 0; // cut off the string there + ++p; + } + else + Con_Printf("statusResponse without players block?\n"); + + if ((s = SearchInfostring(string, "gamename" )) != NULL) strlcpy(info->game, s, sizeof (info->game)); + if ((s = SearchInfostring(string, "modname" )) != NULL) strlcpy(info->mod , s, sizeof (info->mod )); + if ((s = SearchInfostring(string, "mapname" )) != NULL) strlcpy(info->map , s, sizeof (info->map )); + if ((s = SearchInfostring(string, "hostname" )) != NULL) strlcpy(info->name, s, sizeof (info->name)); + if ((s = SearchInfostring(string, "protocol" )) != NULL) info->protocol = atoi(s); + if ((s = SearchInfostring(string, "clients" )) != NULL) info->numplayers = atoi(s); + if ((s = SearchInfostring(string, "bots" )) != NULL) info->numbots = atoi(s); + if ((s = SearchInfostring(string, "sv_maxclients")) != NULL) info->maxplayers = atoi(s); + if ((s = SearchInfostring(string, "gameversion" )) != NULL) info->gameversion = atoi(s); + if ((s = SearchInfostring(string, "qcstatus" )) != NULL) strlcpy(info->qcstatus, s, sizeof(info->qcstatus)); + if (p != NULL) strlcpy(info->players, p, sizeof(info->players)); + info->numhumans = info->numplayers - max(0, info->numbots); + info->freeslots = info->maxplayers - info->numplayers; + + NetConn_ClientParsePacket_ServerList_UpdateCache(n); + + return true; + } if (length >= 13 && !memcmp(string, "infoResponse\x0A", 13)) { serverlist_info_t *info; @@ -1240,14 +1487,30 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat return true; info = &serverlist_cache[n].info; - if ((s = SearchInfostring(string, "gamename" )) != NULL) strlcpy(info->game, s, sizeof (info->game));else info->game[0] = 0; - if ((s = SearchInfostring(string, "modname" )) != NULL) strlcpy(info->mod , s, sizeof (info->mod ));else info->mod[0] = 0; - if ((s = SearchInfostring(string, "mapname" )) != NULL) strlcpy(info->map , s, sizeof (info->map ));else info->map[0] = 0; - if ((s = SearchInfostring(string, "hostname" )) != NULL) strlcpy(info->name, s, sizeof (info->name));else info->name[0] = 0; - if ((s = SearchInfostring(string, "protocol" )) != NULL) info->protocol = atoi(s);else info->protocol = -1; - if ((s = SearchInfostring(string, "clients" )) != NULL) info->numplayers = atoi(s);else info->numplayers = 0; - if ((s = SearchInfostring(string, "sv_maxclients")) != NULL) info->maxplayers = atoi(s);else info->maxplayers = 0; - if ((s = SearchInfostring(string, "gameversion" )) != NULL) info->gameversion = atoi(s);else info->gameversion = 0; + info->game[0] = 0; + info->mod[0] = 0; + info->map[0] = 0; + info->name[0] = 0; + info->qcstatus[0] = 0; + info->players[0] = 0; + info->protocol = -1; + info->numplayers = 0; + info->numbots = -1; + info->maxplayers = 0; + info->gameversion = 0; + + if ((s = SearchInfostring(string, "gamename" )) != NULL) strlcpy(info->game, s, sizeof (info->game)); + if ((s = SearchInfostring(string, "modname" )) != NULL) strlcpy(info->mod , s, sizeof (info->mod )); + if ((s = SearchInfostring(string, "mapname" )) != NULL) strlcpy(info->map , s, sizeof (info->map )); + if ((s = SearchInfostring(string, "hostname" )) != NULL) strlcpy(info->name, s, sizeof (info->name)); + if ((s = SearchInfostring(string, "protocol" )) != NULL) info->protocol = atoi(s); + if ((s = SearchInfostring(string, "clients" )) != NULL) info->numplayers = atoi(s); + if ((s = SearchInfostring(string, "bots" )) != NULL) info->numbots = atoi(s); + if ((s = SearchInfostring(string, "sv_maxclients")) != NULL) info->maxplayers = atoi(s); + if ((s = SearchInfostring(string, "gameversion" )) != NULL) info->gameversion = atoi(s); + if ((s = SearchInfostring(string, "qcstatus" )) != NULL) strlcpy(info->qcstatus, s, sizeof(info->qcstatus)); + info->numhumans = info->numplayers - max(0, info->numbots); + info->freeslots = info->maxplayers - info->numplayers; NetConn_ClientParsePacket_ServerList_UpdateCache(n); @@ -1263,30 +1526,12 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat Con_Print("received DarkPlaces server list...\n"); while (length >= 7 && data[0] == '\\' && (data[1] != 0xFF || data[2] != 0xFF || data[3] != 0xFF || data[4] != 0xFF) && data[5] * 256 + data[6] != 0) { - int n; - dpsnprintf (ipstring, sizeof (ipstring), "%u.%u.%u.%u:%u", data[1], data[2], data[3], data[4], data[5] * 256 + data[6]); if (serverlist_consoleoutput && developer_networking.integer) Con_Printf("Requesting info from DarkPlaces server %s\n", ipstring); - // ignore the rest of the message if the serverlist is full - if( serverlist_cachecount == SERVERLIST_TOTALSIZE ) + + if( !NetConn_ClientParsePacket_ServerList_PrepareQuery( PROTOCOL_DARKPLACES7, ipstring ) ) { break; - // also ignore it if we have already queried it (other master server response) - for( n = 0 ; n < serverlist_cachecount ; n++ ) - if( !strcmp( ipstring, serverlist_cache[ n ].info.cname ) ) - break; - if( n >= serverlist_cachecount ) - { - serverquerycount++; - - memset(&serverlist_cache[serverlist_cachecount], 0, sizeof(serverlist_cache[serverlist_cachecount])); - serverlist_cache[serverlist_cachecount].protocol = PROTOCOL_DARKPLACES7; - // store the data the engine cares about (address and ping) - strlcpy (serverlist_cache[serverlist_cachecount].info.cname, ipstring, sizeof (serverlist_cache[serverlist_cachecount].info.cname)); - serverlist_cache[serverlist_cachecount].info.ping = 100000; - serverlist_cache[serverlist_cachecount].query = SQS_QUERYING; - - ++serverlist_cachecount; } // move on to next address in packet @@ -1308,30 +1553,12 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat Con_Printf("received QuakeWorld server list from %s...\n", addressstring2); while (length >= 6 && (data[0] != 0xFF || data[1] != 0xFF || data[2] != 0xFF || data[3] != 0xFF) && data[4] * 256 + data[5] != 0) { - int n; - dpsnprintf (ipstring, sizeof (ipstring), "%u.%u.%u.%u:%u", data[0], data[1], data[2], data[3], data[4] * 256 + data[5]); if (serverlist_consoleoutput && developer_networking.integer) Con_Printf("Requesting info from QuakeWorld server %s\n", ipstring); - // ignore the rest of the message if the serverlist is full - if( serverlist_cachecount == SERVERLIST_TOTALSIZE ) + + if( !NetConn_ClientParsePacket_ServerList_PrepareQuery( PROTOCOL_QUAKEWORLD, ipstring ) ) { break; - // also ignore it if we have already queried it (other master server response) - for( n = 0 ; n < serverlist_cachecount ; n++ ) - if( !strcmp( ipstring, serverlist_cache[ n ].info.cname ) ) - break; - if( n >= serverlist_cachecount ) - { - serverquerycount++; - - memset(&serverlist_cache[serverlist_cachecount], 0, sizeof(serverlist_cache[serverlist_cachecount])); - serverlist_cache[serverlist_cachecount].protocol = PROTOCOL_QUAKEWORLD; - // store the data the engine cares about (address and ping) - strlcpy (serverlist_cache[serverlist_cachecount].info.cname, ipstring, sizeof (serverlist_cache[serverlist_cachecount].info.cname)); - serverlist_cache[serverlist_cachecount].info.ping = 100000; - serverlist_cache[serverlist_cachecount].query = SQS_QUERYING; - - ++serverlist_cachecount; } // move on to next address in packet @@ -1343,6 +1570,15 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat serverlist_querywaittime = realtime + 3; return true; } + if (!strncmp(string, "extResponse ", 12)) + { + ++net_extresponse_count; + if(net_extresponse_count > NET_EXTRESPONSE_MAX) + net_extresponse_count = NET_EXTRESPONSE_MAX; + net_extresponse_last = (net_extresponse_last + 1) % NET_EXTRESPONSE_MAX; + dpsnprintf(net_extresponse[net_extresponse_last], sizeof(net_extresponse[net_extresponse_last]), "'%s' %s", addressstring2, string + 12); + return true; + } if (!strncmp(string, "ping", 4)) { if (developer.integer >= 10) @@ -1387,12 +1623,13 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat return true; info = &serverlist_cache[n].info; - strlcpy(info->game, "QuakeWorld", sizeof(info->game));; + strlcpy(info->game, "QuakeWorld", sizeof(info->game)); if ((s = SearchInfostring(string, "*gamedir" )) != NULL) strlcpy(info->mod , s, sizeof (info->mod ));else info->mod[0] = 0; if ((s = SearchInfostring(string, "map" )) != NULL) strlcpy(info->map , s, sizeof (info->map ));else info->map[0] = 0; if ((s = SearchInfostring(string, "hostname" )) != NULL) strlcpy(info->name, s, sizeof (info->name));else info->name[0] = 0; info->protocol = 0; info->numplayers = 0; // updated below + info->numhumans = 0; // updated below if ((s = SearchInfostring(string, "maxclients" )) != NULL) info->maxplayers = atoi(s);else info->maxplayers = 0; if ((s = SearchInfostring(string, "gameversion" )) != NULL) info->gameversion = atoi(s);else info->gameversion = 0; @@ -1409,6 +1646,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat if (s >= string + length) break; info->numplayers++; + info->numhumans++; s++; } } @@ -1439,9 +1677,12 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat int n; serverlist_info_t *info; - c = data[4]; - data += 5; - length -= 5; + data += 4; + length -= 4; + SZ_Clear(&net_message); + SZ_Write(&net_message, data, length); + MSG_BeginReading(); + c = MSG_ReadByte(); switch (c) { case CCREP_ACCEPT: @@ -1451,13 +1692,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat { lhnetaddress_t clientportaddress; clientportaddress = *peeraddress; - if (length >= 4) - { - unsigned int port = (data[0] << 0) | (data[1] << 8) | (data[2] << 16) | (data[3] << 24); - data += 4; - length -= 4; - LHNETADDRESS_SetPort(&clientportaddress, port); - } + LHNETADDRESS_SetPort(&clientportaddress, MSG_ReadLong()); // update the server IP in the userinfo (QW servers expect this, and it is used by the reconnect command) InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "*ip", addressstring2); M_Update_Return_Reason("Accepted"); @@ -1468,7 +1703,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat if (developer.integer >= 10) Con_Printf("Datagram_ParseConnectionless: received CCREP_REJECT from %s.\n", addressstring2); cls.connect_trying = false; - M_Update_Return_Reason((char *)data); + M_Update_Return_Reason((char *)MSG_ReadString()); break; case CCREP_SERVER_INFO: if (developer.integer >= 10) @@ -1506,6 +1741,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat default: break; } + SZ_Clear(&net_message); // we may not have liked the packet, but it was a valid control // packet, so we're done processing this packet now return true; @@ -1524,6 +1760,10 @@ void NetConn_QueryQueueFrame(void) double timeouttime; static double querycounter = 0; + if(!net_slist_pause.integer && serverlist_paused) + ServerList_RebuildViewList(); + serverlist_paused = net_slist_pause.integer; + if (serverlist_querysleep) return; @@ -1542,43 +1782,43 @@ void NetConn_QueryQueueFrame(void) return; } - // scan serverlist and issue queries as needed - serverlist_querysleep = true; + // scan serverlist and issue queries as needed + serverlist_querysleep = true; - timeouttime = realtime - net_slist_timeout.value; - for( index = 0, queries = 0 ; index < serverlist_cachecount && queries < maxqueries ; index++ ) + timeouttime = realtime - net_slist_timeout.value; + for( index = 0, queries = 0 ; index < serverlist_cachecount && queries < maxqueries ; index++ ) { serverlist_entry_t *entry = &serverlist_cache[ index ]; - if( entry->query != SQS_QUERYING ) + if( entry->query != SQS_QUERYING && entry->query != SQS_REFRESHING ) { continue; } - serverlist_querysleep = false; - if( entry->querycounter != 0 && entry->querytime > timeouttime ) + serverlist_querysleep = false; + if( entry->querycounter != 0 && entry->querytime > timeouttime ) { continue; } - if( entry->querycounter != (unsigned) net_slist_maxtries.integer ) + if( entry->querycounter != (unsigned) net_slist_maxtries.integer ) { - lhnetaddress_t address; + lhnetaddress_t address; int socket; LHNETADDRESS_FromString(&address, entry->info.cname, 0); - if (entry->protocol == PROTOCOL_QUAKEWORLD) + if (entry->protocol == PROTOCOL_QUAKEWORLD) { - for (socket = 0; socket < cl_numsockets ; socket++) + for (socket = 0; socket < cl_numsockets ; socket++) NetConn_WriteString(cl_sockets[socket], "\377\377\377\377status\n", &address); } else { - for (socket = 0; socket < cl_numsockets ; socket++) - NetConn_WriteString(cl_sockets[socket], "\377\377\377\377getinfo", &address); + for (socket = 0; socket < cl_numsockets ; socket++) + NetConn_WriteString(cl_sockets[socket], "\377\377\377\377getstatus", &address); } - //entry->querytime = realtime; - entry->querytime = Sys_DoubleTime(); + // update the entry fields + entry->querytime = realtime; entry->querycounter++; // if not in the slist menu we should print the server to console @@ -1589,6 +1829,13 @@ void NetConn_QueryQueueFrame(void) } else { + // have we tried to refresh this server? + if( entry->query == SQS_REFRESHING ) { + // yes, so update the reply count (since its not responding anymore) + serverreplycount--; + if(!serverlist_paused) + ServerList_ViewList_Remove(entry); + } entry->query = SQS_TIMEDOUT; } } @@ -1628,7 +1875,7 @@ void NetConn_ClientFrame(void) while (cl_sockets[i] && (length = NetConn_Read(cl_sockets[i], readbuffer, sizeof(readbuffer), &peeraddress)) > 0) NetConn_ClientParsePacket(cl_sockets[i], readbuffer, length, &peeraddress); NetConn_QueryQueueFrame(); - if (cls.netcon && realtime > cls.netcon->timeout) + if (cls.netcon && realtime > cls.netcon->timeout && !sv.active) { Con_Print("Connection timed out\n"); CL_Disconnect(); @@ -1660,37 +1907,73 @@ static void NetConn_BuildChallengeString(char *buffer, int bufferlength) buffer[i] = 0; } +// (div0) build the full response only if possible; better a getinfo response than no response at all if getstatus won't fit static qboolean NetConn_BuildStatusResponse(const char* challenge, char* out_msg, size_t out_size, qboolean fullstatus) { - unsigned int nb_clients = 0, i; + const char *qcstatus = NULL; + unsigned int nb_clients = 0, nb_bots = 0, i; int length; + SV_VM_Begin(); + // How many clients are there? for (i = 0;i < (unsigned int)svs.maxclients;i++) + { if (svs.clients[i].active) + { nb_clients++; + if (!svs.clients[i].netconnection) + nb_bots++; + } + } + + if(prog->globaloffsets.worldstatus >= 0) + { + const char *str = PRVM_G_STRING(prog->globaloffsets.worldstatus); + if(str && *str) + { + char *p; + const char *q; + qcstatus = p = Mem_Alloc(tempmempool, strlen(str) + 1); + for(q = str; *q; ++q) + if(*q != '\\') + *p++ = *q; + *p = 0; + } + } // TODO: we should add more information for the full status string length = dpsnprintf(out_msg, out_size, "\377\377\377\377%s\x0A" "\\gamename\\%s\\modname\\%s\\gameversion\\%d\\sv_maxclients\\%d" - "\\clients\\%d\\mapname\\%s\\hostname\\%s\\protocol\\%d" + "\\clients\\%d\\bots\\%d\\mapname\\%s\\hostname\\%s\\protocol\\%d" + "%s%s" "%s%s" "%s", fullstatus ? "statusResponse" : "infoResponse", gamename, com_modname, gameversion.integer, svs.maxclients, - nb_clients, sv.name, hostname.string, NET_PROTOCOL_VERSION, + nb_clients, nb_bots, sv.name, hostname.string, NET_PROTOCOL_VERSION, + qcstatus ? "\\qcstatus\\" : "", qcstatus ? qcstatus : "", challenge ? "\\challenge\\" : "", challenge ? challenge : "", fullstatus ? "\n" : ""); + if(qcstatus) + { + Mem_Free((char *)qcstatus); + qcstatus = NULL; + } + // Make sure it fits in the buffer if (length < 0) - return false; + goto bad; if (fullstatus) { char *ptr; int left; + int savelength; + + savelength = length; ptr = out_msg + length; left = (int)out_size - length; @@ -1700,7 +1983,7 @@ static qboolean NetConn_BuildStatusResponse(const char* challenge, char* out_msg client_t *cl = &svs.clients[i]; if (cl->active) { - int nameind, cleanind; + int nameind, cleanind, pingvalue; char curchar; char cleanname [sizeof(cl->name)]; @@ -1718,19 +2001,63 @@ static qboolean NetConn_BuildStatusResponse(const char* challenge, char* out_msg } } while (curchar != '\0'); - length = dpsnprintf(ptr, left, "%d %d \"%s\"\n", - cl->frags, - (int)(cl->ping * 1000.0f), - cleanname); + pingvalue = (int)(cl->ping * 1000.0f); + if(cl->netconnection) + pingvalue = bound(1, pingvalue, 9999); + else + pingvalue = 0; + + if(prog->fieldoffsets.clientstatus >= 0) + { + const char *str = PRVM_E_STRING(PRVM_EDICT_NUM(i + 1), prog->fieldoffsets.clientstatus); + if(str && *str) + { + char *p; + const char *q; + qcstatus = p = Mem_Alloc(tempmempool, strlen(str) + 1); + for(q = str; *q; ++q) + if(*q != '\\' && *q != ' ') + *p++ = *q; + *p = 0; + } + } + + if(qcstatus) + { + length = dpsnprintf(ptr, left, "%s %d \"%s\"\n", + qcstatus, + pingvalue, + cleanname); + Mem_Free((char *)qcstatus); + qcstatus = NULL; + } + else + length = dpsnprintf(ptr, left, "%d %d \"%s\"\n", + cl->frags, + pingvalue, + cleanname); + if(length < 0) - return false; + { + // out of space? + // turn it into an infoResponse! + out_msg[savelength] = 0; + memcpy(out_msg + 4, "infoResponse\x0A", 13); + memmove(out_msg + 17, out_msg + 19, savelength - 19); + break; + } left -= length; ptr += length; } } } + SV_VM_End(); return true; + +bad: + SV_VM_End(); + return false; } static qboolean NetConn_PreventConnectFlood(lhnetaddress_t *peeraddress) @@ -1793,6 +2120,63 @@ void NetConn_ClearConnectFlood(lhnetaddress_t *peeraddress) } } +// returns a string describing the user level, or NULL for auth failure +const char *RCon_Authenticate(const char *password, const char *s, const char *endpos) +{ + const char *text; + qboolean hasquotes; + + if(!strcmp(rcon_password.string, password)) + return "rcon"; + + if(strcmp(rcon_restricted_password.string, password)) + return NULL; + + for(text = s; text != endpos; ++text) + if(*text > 0 && (*text < ' ' || *text == ';')) + return NULL; // block possible exploits against the parser/alias expansion + + while(s != endpos) + { + size_t l = strlen(s); + if(l) + { + hasquotes = (strchr(s, '"') != NULL); + // sorry, we can't allow these substrings in wildcard expressions, + // as they can mess with the argument counts + text = rcon_restricted_commands.string; + while(COM_ParseToken_Console(&text)) + { + // com_token now contains a pattern to check for... + if(strchr(com_token, '*') || strchr(com_token, '?')) // wildcard expression, * can only match a SINGLE argument + { + if(!hasquotes) + if(matchpattern_with_separator(s, com_token, true, " ", true)) // note how we excluded tab, newline etc. above + goto match; + } + else if(strchr(com_token, ' ')) // multi-arg expression? must match in whole + { + if(!strcmp(com_token, s)) + goto match; + } + else // single-arg expression? must match the beginning of the command + { + if(!strcmp(com_token, s)) + goto match; + if(!memcmp(va("%s ", com_token), s, strlen(com_token) + 1)) + goto match; + } + } + // if we got here, nothing matched! + return NULL; + } +match: + s += l + 1; + } + + return "restricted rcon"; +} + extern void SV_SendServerinfo (client_t *client); static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *data, int length, lhnetaddress_t *peeraddress) { @@ -1800,6 +2184,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat double besttime; client_t *client; char *s, *string, response[1400], addressstring2[128], stringbuf[16384]; + qboolean islocal = (LHNETADDRESS_GetAddressType(peeraddress) == LHNETADDRESSTYPE_LOOP); if (!sv.active) return false; @@ -1833,7 +2218,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat Com_HexDumpToConsole(data, length); } - if (length >= 12 && !memcmp(string, "getchallenge", 12)) + if (length >= 12 && !memcmp(string, "getchallenge", 12) && (islocal || sv_public.integer > -2)) { for (i = 0, best = 0, besttime = realtime;i < MAX_CHALLENGES;i++) { @@ -1855,7 +2240,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat NetConn_WriteString(mysocket, va("\377\377\377\377challenge %s", challenge[i].string), peeraddress); return true; } - if (length > 8 && !memcmp(string, "connect\\", 8)) + if (length > 8 && !memcmp(string, "connect\\", 8) && (islocal || sv_public.integer > -2)) { string += 7; length -= 7; @@ -1938,7 +2323,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat return true; } - if (length >= 7 && !memcmp(string, "getinfo", 7)) + if (length >= 7 && !memcmp(string, "getinfo", 7) && (islocal || sv_public.integer > -1)) { const char *challenge = NULL; @@ -1954,7 +2339,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat } return true; } - if (length >= 9 && !memcmp(string, "getstatus", 9)) + if (length >= 9 && !memcmp(string, "getstatus", 9) && (islocal || sv_public.integer > -1)) { const char *challenge = NULL; @@ -1974,38 +2359,69 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat { int i; char *s = string + 5; + char *endpos = string + length + 1; // one behind the NUL, so adding strlen+1 will eventually reach it char password[64]; for (i = 0;*s > ' ';s++) if (i < (int)sizeof(password) - 1) password[i++] = *s; + if(*s <= ' ' && s != endpos) // skip leading ugly space + ++s; password[i] = 0; - if (password[0] > ' ' && !strcmp(rcon_password.string, password)) + if (password[0] > ' ') { - // looks like a legitimate rcon command with the correct password - Con_Printf("server received rcon command from %s:\n%s\n", host_client ? host_client->name : addressstring2, s); - rcon_redirect = true; - rcon_redirect_bufferpos = 0; - Cmd_ExecuteString(s, src_command); - rcon_redirect_buffer[rcon_redirect_bufferpos] = 0; - rcon_redirect = false; - // print resulting text to client - // if client is playing, send a reliable reply instead of - // a command packet - if (host_client) + const char *userlevel = RCon_Authenticate(password, s, endpos); + if(userlevel) { - // if the netconnection is loop, then this is the - // local player on a listen mode server, and it would - // result in duplicate printing to the console - // (not that the local player should be using rcon - // when they have the console) - if (host_client->netconnection && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP) - SV_ClientPrintf("%s", rcon_redirect_buffer); + // looks like a legitimate rcon command with the correct password + char *s_ptr = s; + Con_Printf("server received %s command from %s: ", userlevel, host_client ? host_client->name : addressstring2); + while(s_ptr != endpos) + { + size_t l = strlen(s_ptr); + if(l) + Con_Printf(" %s;", s_ptr); + s_ptr += l + 1; + } + Con_Printf("\n"); + rcon_redirect = true; + rcon_redirect_bufferpos = 0; + while(s != endpos) + { + size_t l = strlen(s); + if(l) + { + client_t *host_client_save = host_client; + Cmd_ExecuteString(s, src_command); + host_client = host_client_save; + // in case it is a command that changes host_client (like restart) + } + s += l + 1; + } + rcon_redirect_buffer[rcon_redirect_bufferpos] = 0; + rcon_redirect = false; + // print resulting text to client + // if client is playing, send a reliable reply instead of + // a command packet + if (host_client) + { + // if the netconnection is loop, then this is the + // local player on a listen mode server, and it would + // result in duplicate printing to the console + // (not that the local player should be using rcon + // when they have the console) + if (host_client->netconnection && LHNETADDRESS_GetAddressType(&host_client->netconnection->peeraddress) != LHNETADDRESSTYPE_LOOP) + SV_ClientPrintf("%s", rcon_redirect_buffer); + } + else + { + // qw print command + dpsnprintf(response, sizeof(response), "\377\377\377\377n%s", rcon_redirect_buffer); + NetConn_WriteString(mysocket, response, peeraddress); + } } else { - // qw print command - dpsnprintf(response, sizeof(response), "\377\377\377\377n%s", rcon_redirect_buffer); - NetConn_WriteString(mysocket, response, peeraddress); + Con_Printf("server denied rcon access to %s\n", host_client ? host_client->name : addressstring2); } } return true; @@ -2028,20 +2444,28 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat // protocol // (this protects more modern protocols against being used for // Quake packet flood Denial Of Service attacks) - if (length >= 5 && (i = BigLong(*((int *)data))) && (i & (~NETFLAG_LENGTH_MASK)) == (int)NETFLAG_CTL && (i & NETFLAG_LENGTH_MASK) == length && (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE || sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3)) + if (length >= 5 && (i = BigLong(*((int *)data))) && (i & (~NETFLAG_LENGTH_MASK)) == (int)NETFLAG_CTL && (i & NETFLAG_LENGTH_MASK) == length && (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE || sv.protocol == PROTOCOL_NEHAHRABJP || sv.protocol == PROTOCOL_NEHAHRABJP2 || sv.protocol == PROTOCOL_NEHAHRABJP3 || sv.protocol == PROTOCOL_DARKPLACES1 || sv.protocol == PROTOCOL_DARKPLACES2 || sv.protocol == PROTOCOL_DARKPLACES3)) { - int c = data[4]; - data += 5; - length -= 5; + int c; + int protocolnumber; + const char *protocolname; + data += 4; + length -= 4; + SZ_Clear(&net_message); + SZ_Write(&net_message, data, length); + MSG_BeginReading(); + c = MSG_ReadByte(); switch (c) { case CCREQ_CONNECT: if (developer.integer >= 10) Con_Printf("Datagram_ParseConnectionless: received CCREQ_CONNECT from %s.\n", addressstring2); - if (length < (int)strlen("QUAKE") + 1 + 1) + if(!islocal && sv_public.integer <= -2) break; - if (memcmp(data, "QUAKE", strlen("QUAKE") + 1) != 0 || (int)data[strlen("QUAKE") + 1] != NET_PROTOCOL_VERSION) + protocolname = MSG_ReadString(); + protocolnumber = MSG_ReadByte(); + if (strcmp(protocolname, "QUAKE") || protocolnumber != NET_PROTOCOL_VERSION) { if (developer.integer >= 10) Con_Printf("Datagram_ParseConnectionless: sending CCREP_REJECT \"Incompatible version.\" to %s.\n", addressstring2); @@ -2137,6 +2561,8 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat case CCREQ_SERVER_INFO: if (developer.integer >= 10) Con_Printf("Datagram_ParseConnectionless: received CCREQ_SERVER_INFO from %s.\n", addressstring2); + if(!islocal && sv_public.integer <= -1) + break; if (sv.active && !strcmp(MSG_ReadString(), "QUAKE")) { int numclients; @@ -2166,6 +2592,8 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat case CCREQ_PLAYER_INFO: if (developer.integer >= 10) Con_Printf("Datagram_ParseConnectionless: received CCREQ_PLAYER_INFO from %s.\n", addressstring2); + if(!islocal && sv_public.integer <= -1) + break; if (sv.active) { int playerNumber, activeNumber, clientNumber; @@ -2185,7 +2613,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat MSG_WriteByte(&net_message, playerNumber); MSG_WriteString(&net_message, client->name); MSG_WriteLong(&net_message, client->colors); - MSG_WriteLong(&net_message, (int)client->edict->fields.server->frags); + MSG_WriteLong(&net_message, client->frags); MSG_WriteLong(&net_message, (int)(realtime - client->connecttime)); MSG_WriteString(&net_message, client->netconnection ? client->netconnection->address : "botclient"); *((int *)net_message.data) = BigLong(NETFLAG_CTL | (net_message.cursize & NETFLAG_LENGTH_MASK)); @@ -2197,6 +2625,8 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat case CCREQ_RULE_INFO: if (developer.integer >= 10) Con_Printf("Datagram_ParseConnectionless: received CCREQ_RULE_INFO from %s.\n", addressstring2); + if(!islocal && sv_public.integer <= -1) + break; if (sv.active) { char *prevCvarName; @@ -2224,6 +2654,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat default: break; } + SZ_Clear(&net_message); // we may not have liked the packet, but it was a valid control // packet, so we're done processing this packet now return true; @@ -2261,6 +2692,11 @@ void NetConn_ServerFrame(void) } } +void NetConn_SleepMicroseconds(int microseconds) +{ + LHNET_SleepUntilPacket_Microseconds(microseconds); +} + void NetConn_QueryMasters(qboolean querydp, qboolean queryqw) { int i; @@ -2295,7 +2731,7 @@ void NetConn_QueryMasters(qboolean querydp, qboolean queryqw) SZ_Clear(&net_message); // search LAN for DarkPlaces servers - NetConn_WriteString(cl_sockets[i], "\377\377\377\377getinfo", &broadcastaddress); + NetConn_WriteString(cl_sockets[i], "\377\377\377\377getstatus", &broadcastaddress); // build the getservers message to send to the dpmaster master servers dpsnprintf(request, sizeof(request), "\377\377\377\377getservers %s %u empty full\x0A", gamename, NET_PROTOCOL_VERSION); @@ -2374,7 +2810,7 @@ void NetConn_Heartbeat(int priority) // make advertising optional and don't advertise singleplayer games, and // only send a heartbeat as often as the admin wants - if (sv.active && sv_public.integer && svs.maxclients >= 2 && (priority > 1 || realtime > nextheartbeattime)) + if (sv.active && sv_public.integer > 0 && svs.maxclients >= 2 && (priority > 1 || realtime > nextheartbeattime)) { nextheartbeattime = realtime + sv_heartbeatperiod.value; for (masternum = 0;sv_masters[masternum].name;masternum++) @@ -2394,7 +2830,7 @@ static void Net_Heartbeat_f(void) void PrintStats(netconn_t *conn) { if ((cls.state == ca_connected && cls.protocol == PROTOCOL_QUAKEWORLD) || (sv.active && sv.protocol == PROTOCOL_QUAKEWORLD)) - Con_Printf("address=%21s canSend=%u sendSeq=%6u recvSeq=%6u\n", conn->address, !conn->sendMessageLength, conn->qw.outgoing_sequence, conn->qw.incoming_sequence); + Con_Printf("address=%21s canSend=%u sendSeq=%6u recvSeq=%6u\n", conn->address, !conn->sendMessageLength, conn->outgoing_unreliable_sequence, conn->qw.incoming_sequence); else Con_Printf("address=%21s canSend=%u sendSeq=%6u recvSeq=%6u\n", conn->address, !conn->sendMessageLength, conn->nq.sendSequence, conn->nq.receiveSequence); } @@ -2416,6 +2852,16 @@ void Net_Stats_f(void) PrintStats(conn); } +void Net_Refresh_f(void) +{ + if (m_state != m_slist) { + Con_Print("Sending new requests to master servers\n"); + ServerList_QueryList(false, true, false, true); + Con_Print("Listening for replies...\n"); + } else + ServerList_QueryList(false, true, false, false); +} + void Net_Slist_f(void) { ServerList_ResetMasks(); @@ -2423,11 +2869,10 @@ void Net_Slist_f(void) serverlist_sortdescending = false; if (m_state != m_slist) { Con_Print("Sending requests to master servers\n"); - ServerList_QueryList(true, false); - serverlist_consoleoutput = true; + ServerList_QueryList(true, true, false, true); Con_Print("Listening for replies...\n"); } else - ServerList_QueryList(true, false); + ServerList_QueryList(true, true, false, false); } void Net_SlistQW_f(void) @@ -2437,11 +2882,11 @@ void Net_SlistQW_f(void) serverlist_sortdescending = false; if (m_state != m_slist) { Con_Print("Sending requests to master servers\n"); - ServerList_QueryList(false, true); + ServerList_QueryList(true, false, true, true); serverlist_consoleoutput = true; Con_Print("Listening for replies...\n"); } else - ServerList_QueryList(false, true); + ServerList_QueryList(true, false, true, false); } void NetConn_Init(void) @@ -2452,16 +2897,21 @@ void NetConn_Init(void) Cmd_AddCommand("net_stats", Net_Stats_f, "print network statistics"); Cmd_AddCommand("net_slist", Net_Slist_f, "query dp master servers and print all server information"); Cmd_AddCommand("net_slistqw", Net_SlistQW_f, "query qw master servers and print all server information"); + Cmd_AddCommand("net_refresh", Net_Refresh_f, "query dp master servers and refresh all server information"); Cmd_AddCommand("heartbeat", Net_Heartbeat_f, "send a heartbeat to the master server (updates your server information)"); + Cvar_RegisterVariable(&rcon_restricted_password); + Cvar_RegisterVariable(&rcon_restricted_commands); Cvar_RegisterVariable(&net_slist_queriespersecond); Cvar_RegisterVariable(&net_slist_queriesperframe); Cvar_RegisterVariable(&net_slist_timeout); Cvar_RegisterVariable(&net_slist_maxtries); + Cvar_RegisterVariable(&net_slist_pause); Cvar_RegisterVariable(&net_messagetimeout); Cvar_RegisterVariable(&net_connecttimeout); Cvar_RegisterVariable(&net_connectfloodblockingtimeout); Cvar_RegisterVariable(&cl_netlocalping); - Cvar_RegisterVariable(&cl_netpacketloss); + Cvar_RegisterVariable(&cl_netpacketloss_send); + Cvar_RegisterVariable(&cl_netpacketloss_receive); Cvar_RegisterVariable(&hostname); Cvar_RegisterVariable(&developer_networking); Cvar_RegisterVariable(&cl_netport); @@ -2478,7 +2928,7 @@ void NetConn_Init(void) { if (LHNETADDRESS_FromString(&tempaddress, com_argv[i + 1], 0) == 1) { - Con_Printf("-ip option used, setting net_address to \"%s\"\n"); + Con_Printf("-ip option used, setting net_address to \"%s\"\n", com_argv[i + 1]); Cvar_SetQuick(&net_address, com_argv[i + 1]); } else