X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=netconn.c;h=916dc6885ea85bd2e9834db53823bc06692b4a35;hb=f991f593b4e0aadd992f25c9ae5649532204dabc;hp=778046ac1c055d4105cbcef6e18b63aaee7c8fbb;hpb=2e11c41508ae51b8a84bab8bfdcb09dac6a33fe0;p=xonotic%2Fdarkplaces.git diff --git a/netconn.c b/netconn.c index 778046ac..916dc688 100755 --- a/netconn.c +++ b/netconn.c @@ -76,7 +76,8 @@ 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"}; @@ -291,9 +292,9 @@ 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->numplayers, mask->tests[SLIF_NUMBOTS], mask->info.numbots ) ) + if( !_ServerList_CompareInt( info->numbots, mask->tests[SLIF_NUMBOTS], mask->info.numbots ) ) return false; - if( !_ServerList_CompareInt( info->numplayers, mask->tests[SLIF_NUMHUMANS], mask->info.numhumans ) ) + if( !_ServerList_CompareInt( info->numhumans, mask->tests[SLIF_NUMHUMANS], mask->info.numhumans ) ) return false; if( !_ServerList_CompareInt( info->protocol, mask->tests[SLIF_PROTOCOL], mask->info.protocol )) return false; @@ -392,8 +393,15 @@ void ServerList_RebuildViewList(void) 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; } #if 0 @@ -436,9 +444,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) { @@ -460,9 +468,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) @@ -572,7 +580,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers packetsSent++; unreliableMessagesSent++; - totallen += packetLen + 18; + totallen += packetLen + 28; } else { @@ -610,7 +618,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers packetsReSent++; } - totallen += packetLen + 18; + totallen += packetLen + 28; } // if we have a new reliable message to send, do so @@ -661,7 +669,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers packetsSent++; reliableMessagesSent++; - totallen += packetLen + 18; + totallen += packetLen + 28; } // if we have an unreliable message to send, do so @@ -689,8 +697,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers packetsSent++; unreliableMessagesSent++; - if (data->cursize) - totallen += packetLen + 18; + totallen += packetLen + 28; } } @@ -911,8 +918,6 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len if (length < 8) return 0; - // TODO: add netgraph stuff rather than just packetloss counting... - if (protocol == PROTOCOL_QUAKEWORLD) { int sequence, sequence_ack; @@ -1160,7 +1165,7 @@ void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_t *peer cls.signon = 0; // need all the signon messages before playing cls.protocol = initialprotocol; // reset move sequence numbering on this new connection - cls.movesequence = 0; + cls.movesequence = 1; cls.servermovesequence = 0; if (cls.protocol == PROTOCOL_QUAKEWORLD) Cmd_ForwardStringToServer("new"); @@ -1319,7 +1324,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat info->name[0] = 0; info->protocol = -1; info->numplayers = 0; - info->numbots = 0; + info->numbots = -1; info->maxplayers = 0; info->gameversion = 0; if ((s = SearchInfostring(string, "gamename" )) != NULL) strlcpy(info->game, s, sizeof (info->game)); @@ -1331,7 +1336,7 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat 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); - info->numhumans = info->numplayers - info->numbots; + info->numhumans = info->numplayers - max(0, info->numbots); NetConn_ClientParsePacket_ServerList_UpdateCache(n); @@ -1901,6 +1906,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; @@ -1934,7 +1940,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat Com_HexDumpToConsole(data, length); } - if (length >= 12 && !memcmp(string, "getchallenge", 12) && sv_public.integer > -2) + if (length >= 12 && !memcmp(string, "getchallenge", 12) && (islocal || sv_public.integer > -2)) { for (i = 0, best = 0, besttime = realtime;i < MAX_CHALLENGES;i++) { @@ -1956,7 +1962,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) && sv_public.integer > -2) + if (length > 8 && !memcmp(string, "connect\\", 8) && (islocal || sv_public.integer > -2)) { string += 7; length -= 7; @@ -2039,7 +2045,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat return true; } - if (length >= 7 && !memcmp(string, "getinfo", 7) && sv_public.integer > -1) + if (length >= 7 && !memcmp(string, "getinfo", 7) && (islocal || sv_public.integer > -1)) { const char *challenge = NULL; @@ -2055,7 +2061,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat } return true; } - if (length >= 9 && !memcmp(string, "getstatus", 9) && sv_public.integer > -1) + if (length >= 9 && !memcmp(string, "getstatus", 9) && (islocal || sv_public.integer > -1)) { const char *challenge = NULL; @@ -2145,7 +2151,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat case CCREQ_CONNECT: if (developer.integer >= 10) Con_Printf("Datagram_ParseConnectionless: received CCREQ_CONNECT from %s.\n", addressstring2); - if(sv_public.integer <= -2) + if(!islocal && sv_public.integer <= -2) break; protocolname = MSG_ReadString(); @@ -2246,7 +2252,7 @@ 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(sv_public.integer <= -1) + if(!islocal && sv_public.integer <= -1) break; if (sv.active && !strcmp(MSG_ReadString(), "QUAKE")) { @@ -2277,7 +2283,7 @@ 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(sv_public.integer <= -1) + if(!islocal && sv_public.integer <= -1) break; if (sv.active) { @@ -2310,7 +2316,7 @@ 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(sv_public.integer <= -1) + if(!islocal && sv_public.integer <= -1) break; if (sv.active) { @@ -2582,7 +2588,8 @@ void NetConn_Init(void) 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);