X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=netconn.c;h=b23d9f4784b878d7503c167f3a02bf3320884831;hb=dfe4cea30617a7a94d3285ed30dc96a45f69e2dd;hp=598199beb15aeeaa0c395de4dee548cb29833ecf;hpb=ce5cb0cd619468dcb9e0740507abd57f74c7c685;p=xonotic%2Fdarkplaces.git diff --git a/netconn.c b/netconn.c index 598199be..b23d9f47 100755 --- a/netconn.c +++ b/netconn.c @@ -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", "excalibur.nvg.ntnu.no", "default master server 3 (admin: tChr)"}, // admin: tChr {0, NULL, NULL, NULL} }; @@ -126,6 +125,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 +184,12 @@ 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_PROTOCOL: result = A->info.protocol - B->info.protocol; break; @@ -282,6 +291,10 @@ 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->protocol, mask->tests[SLIF_PROTOCOL], mask->info.protocol )) return false; if( *mask->info.cname @@ -379,8 +392,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 @@ -401,8 +421,7 @@ static void _ServerList_Test(void) void ServerList_QueryList(qboolean querydp, qboolean queryqw) { - //masterquerytime = realtime; - masterquerytime = Sys_DoubleTime(); + masterquerytime = realtime; masterquerycount = 0; masterreplycount = 0; serverquerycount = 0; @@ -470,8 +489,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) { + 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; @@ -512,16 +554,22 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers 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; } + // 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 +579,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 + 18; } else { @@ -564,11 +609,15 @@ 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 + 18; } // if we have a new reliable message to send, do so @@ -576,7 +625,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers { 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,15 +660,19 @@ 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 + 18; } // if we have an unreliable message to send, do so - if (data->cursize) + //if (data->cursize) { packetLen = NET_HEADERSIZE + data->cursize; @@ -636,13 +689,26 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers conn->nq.unreliableSendSequence++; + conn->outgoing_unreliablesize[conn->outgoing_packetcounter] += packetLen; + NetConn_Write(conn->mysocket, (void *)&sendbuffer, packetLen, &conn->peeraddress); packetsSent++; unreliableMessagesSent++; + + if (data->cursize) + totallen += packetLen + 18; } - 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; } void NetConn_CloseClientPorts(void) @@ -848,6 +914,7 @@ 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; @@ -893,12 +960,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 +1019,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 +1047,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) @@ -1030,6 +1106,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 +1166,9 @@ 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.movesequence = 0; + cls.servermovesequence = 0; if (cls.protocol == PROTOCOL_QUAKEWORLD) Cmd_ForwardStringToServer("new"); if (cls.protocol == PROTOCOL_QUAKE) @@ -1100,7 +1181,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); } } @@ -1132,8 +1213,7 @@ static int NetConn_ClientParsePacket_ServerList_ProcessReply(const char *address // 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(); + serverlist_cache[serverlist_cachecount].querytime = realtime; // if not in the slist menu we should print the server to console if (serverlist_consoleoutput) Con_Printf("querying %s\n", addressstring); @@ -1142,7 +1222,7 @@ static int NetConn_ClientParsePacket_ServerList_ProcessReply(const char *address // 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 - serverlist_cache[n].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); @@ -1154,7 +1234,7 @@ static void NetConn_ClientParsePacket_ServerList_UpdateCache(int n) { serverlist_info_t *info = &serverlist_cache[n].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].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(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]); @@ -1240,14 +1320,25 @@ 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->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); + info->numhumans = info->numplayers - max(0, info->numbots); NetConn_ClientParsePacket_ServerList_UpdateCache(n); @@ -1343,6 +1434,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) @@ -1439,9 +1539,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 +1554,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 +1565,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 +1603,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; @@ -1577,8 +1675,7 @@ void NetConn_QueryQueueFrame(void) NetConn_WriteString(cl_sockets[socket], "\377\377\377\377getinfo", &address); } - //entry->querytime = realtime; - entry->querytime = Sys_DoubleTime(); + entry->querytime = realtime; entry->querycounter++; // if not in the slist menu we should print the server to console @@ -1662,24 +1759,30 @@ static void NetConn_BuildChallengeString(char *buffer, int bufferlength) static qboolean NetConn_BuildStatusResponse(const char* challenge, char* out_msg, size_t out_size, qboolean fullstatus) { - unsigned int nb_clients = 0, i; + unsigned int nb_clients = 0, nb_bots = 0, i; int length; // 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++; + } + } // 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", 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, challenge ? "\\challenge\\" : "", challenge ? challenge : "", fullstatus ? "\n" : ""); @@ -1805,6 +1908,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; @@ -1838,7 +1942,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++) { @@ -1860,7 +1964,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; @@ -1943,7 +2047,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; @@ -1959,7 +2063,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; @@ -2035,20 +2139,26 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat // 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)) { - 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) - break; - if(sv_public.integer <= -2) + 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); @@ -2144,7 +2254,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")) { @@ -2175,7 +2285,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) { @@ -2196,7 +2306,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)); @@ -2208,7 +2318,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) { @@ -2237,6 +2347,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; @@ -2274,6 +2385,11 @@ void NetConn_ServerFrame(void) } } +void NetConn_SleepMicroseconds(int microseconds) +{ + LHNET_SleepUntilPacket_Microseconds(microseconds); +} + void NetConn_QueryMasters(qboolean querydp, qboolean queryqw) { int i; @@ -2491,7 +2607,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