X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=netconn.c;h=3f0796e54e9485027ae685c18c4f981cfc751412;hb=d896dc4570e9eea6e50367f9a1c13a8d2a16b865;hp=595a671452179e7131b7b23a26fef58f292d5714;hpb=f5afebcef735508a40a20fb2a5a1b81e2ac8af8f;p=xonotic%2Fdarkplaces.git diff --git a/netconn.c b/netconn.c index 595a6714..3f0796e5 100755 --- a/netconn.c +++ b/netconn.c @@ -148,15 +148,16 @@ serverlist_infofield_t serverlist_sortbyfield; int serverlist_sortflags; int serverlist_viewcount = 0; -serverlist_entry_t *serverlist_viewlist[SERVERLIST_VIEWLISTSIZE]; +unsigned short serverlist_viewlist[SERVERLIST_VIEWLISTSIZE]; -int serverlist_cachecount; -serverlist_entry_t serverlist_cache[SERVERLIST_TOTALSIZE]; +int serverlist_maxcachecount = 0; +int serverlist_cachecount = 0; +serverlist_entry_t *serverlist_cache = NULL; qboolean serverlist_consoleoutput; static int nFavorites = 0; -static lhnetaddress_t favorites[256]; +static lhnetaddress_t favorites[MAX_FAVORITESERVERS]; void NetConn_UpdateFavorites(void) { @@ -184,7 +185,7 @@ static void _ServerList_ViewList_Helper_InsertBefore( int index, serverlist_entr for( ; i > index ; i-- ) serverlist_viewlist[ i ] = serverlist_viewlist[ i - 1 ]; - serverlist_viewlist[index] = entry; + serverlist_viewlist[index] = (int)(entry - serverlist_cache); } /// we suppose serverlist_viewcount to be valid, ie > 0 @@ -430,11 +431,11 @@ static void ServerList_ViewList_Insert( serverlist_entry_t *entry ) // two special cases // check whether to insert it as new first item - if( _ServerList_Entry_Compare( entry, serverlist_viewlist[0] ) ) { + if( _ServerList_Entry_Compare( entry, ServerList_GetViewEntry(0) ) ) { _ServerList_ViewList_Helper_InsertBefore( 0, entry ); return; } // check whether to insert it as new last item - else if( !_ServerList_Entry_Compare( entry, serverlist_viewlist[serverlist_viewcount - 1] ) ) { + else if( !_ServerList_Entry_Compare( entry, ServerList_GetViewEntry(serverlist_viewcount - 1) ) ) { _ServerList_ViewList_Helper_InsertBefore( serverlist_viewcount, entry ); return; } @@ -444,7 +445,7 @@ static void ServerList_ViewList_Insert( serverlist_entry_t *entry ) { mid = (start + end) / 2; // test the item that lies in the middle between start and end - if( _ServerList_Entry_Compare( entry, serverlist_viewlist[mid] ) ) + if( _ServerList_Entry_Compare( entry, ServerList_GetViewEntry(mid) ) ) // the item has to be in the upper half end = mid; else @@ -459,7 +460,7 @@ static void ServerList_ViewList_Remove( serverlist_entry_t *entry ) int i; for( i = 0; i < serverlist_viewcount; i++ ) { - if (serverlist_viewlist[i] == entry) + if (ServerList_GetViewEntry(i) == entry) { _ServerList_ViewList_Helper_Remove(i); break; @@ -513,6 +514,11 @@ void ServerList_GetPlayerStatistics(int *numplayerspointer, int *maxplayerspoint static void _ServerList_Test(void) { int i; + if (serverlist_maxcachecount <= 1024) + { + serverlist_maxcachecount = 1024; + serverlist_cache = (serverlist_entry_t *)Mem_Realloc(netconn_mempool, (void *)serverlist_cache, sizeof(serverlist_entry_t) * serverlist_maxcachecount); + } for( i = 0 ; i < 1024 ; i++ ) { memset( &serverlist_cache[serverlist_cachecount], 0, sizeof( serverlist_entry_t ) ); serverlist_cache[serverlist_cachecount].info.ping = 1000 + 1024 - i; @@ -535,6 +541,8 @@ void ServerList_QueryList(qboolean resetcache, qboolean querydp, qboolean queryq serverreplycount = 0; serverlist_cachecount = 0; serverlist_viewcount = 0; + serverlist_maxcachecount = 0; + serverlist_cache = (serverlist_entry_t *)Mem_Realloc(netconn_mempool, (void *)serverlist_cache, sizeof(serverlist_entry_t) * serverlist_maxcachecount); } else { // refresh all entries int n; @@ -624,7 +632,6 @@ qboolean NetConn_CanSend(netconn_t *conn) int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolversion_t protocol, int rate, qboolean quakesignon_suppressreliables) { int totallen = 0; - int temp; // if this packet was supposedly choked, but we find ourselves sending one // anyway, make sure the size counting starts at zero @@ -654,11 +661,9 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers sendreliable = true; } // outgoing unreliable packet number, and outgoing reliable packet number (0 or 1) - temp = (unsigned int)conn->outgoing_unreliable_sequence | ((unsigned int)sendreliable<<31); - *((int *)(sendbuffer + 0)) = LittleLong(temp); + StoreLittleLong(sendbuffer, (unsigned int)conn->outgoing_unreliable_sequence | ((unsigned int)sendreliable<<31)); // last received unreliable packet number, and last received reliable packet number (0 or 1) - temp = (unsigned int)conn->qw.incoming_sequence | ((unsigned int)conn->qw.incoming_reliable_sequence<<31); - *((int *)(sendbuffer + 4)) = LittleLong(temp); + StoreLittleLong(sendbuffer + 4, (unsigned int)conn->qw.incoming_sequence | ((unsigned int)conn->qw.incoming_reliable_sequence<<31)); packetLen = 8; conn->outgoing_unreliable_sequence++; // client sends qport in every packet @@ -1089,7 +1094,7 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len int sequence, sequence_ack; int reliable_ack, reliable_message; int count; - int qport; + //int qport; sequence = LittleLong(*((int *)(data + 0))); sequence_ack = LittleLong(*((int *)(data + 4))); @@ -1102,7 +1107,7 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len if (length < 2) return 0; // TODO: use qport to identify that this client really is who they say they are? (and elsewhere in the code to identify the connection without a port match?) - qport = LittleShort(*((int *)(data + 8))); + //qport = LittleShort(*((int *)(data + 8))); data += 2; length -= 2; } @@ -1379,6 +1384,11 @@ static int NetConn_ClientParsePacket_ServerList_ProcessReply(const char *address if (serverlist_cachecount == SERVERLIST_TOTALSIZE) return -1; + if (serverlist_maxcachecount <= serverlist_cachecount) + { + serverlist_maxcachecount += 64; + serverlist_cache = (serverlist_entry_t *)Mem_Realloc(netconn_mempool, (void *)serverlist_cache, sizeof(serverlist_entry_t) * serverlist_maxcachecount); + } entry = &serverlist_cache[n]; memset(entry, 0, sizeof(*entry)); @@ -1454,13 +1464,19 @@ static qboolean NetConn_ClientParsePacket_ServerList_PrepareQuery( int protocol, 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; } + if (serverlist_maxcachecount <= n) + { + serverlist_maxcachecount += 64; + serverlist_cache = (serverlist_entry_t *)Mem_Realloc(netconn_mempool, (void *)serverlist_cache, sizeof(serverlist_entry_t) * serverlist_maxcachecount); + } + + entry = &serverlist_cache[n]; + memset(entry, 0, sizeof(entry)); entry->protocol = protocol; // store the data the engine cares about (address and ping) @@ -1585,9 +1601,10 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat if (length > 10 && !memcmp(string, "challenge ", 10) && cls.rcon_trying) { - int i, j; + int i = 0, j; for (j = 0;j < MAX_RCONS;j++) { + // note: this value from i is used outside the loop too... i = (cls.rcon_ringpos + j) % MAX_RCONS; if(cls.rcon_commands[i][0]) if (!LHNETADDRESS_Compare(peeraddress, &cls.rcon_addresses[i])) @@ -1607,24 +1624,26 @@ static int NetConn_ClientParsePacket(lhnetsocket_t *mysocket, unsigned char *dat if(HMAC_MDFOUR_16BYTES((unsigned char *) (buf + 29), (unsigned char *) argbuf, strlen(argbuf), (unsigned char *) rcon_password.string, n)) { + int k; buf[45] = ' '; strlcpy(buf + 46, argbuf, sizeof(buf) - 46); NetConn_Write(mysocket, buf, 46 + strlen(buf + 46), peeraddress); cls.rcon_commands[i][0] = 0; --cls.rcon_trying; - for (i = 0;i < MAX_RCONS;i++) - if(cls.rcon_commands[i][0]) - if (!LHNETADDRESS_Compare(peeraddress, &cls.rcon_addresses[i])) + for (k = 0;k < MAX_RCONS;k++) + if(cls.rcon_commands[k][0]) + if (!LHNETADDRESS_Compare(peeraddress, &cls.rcon_addresses[k])) break; - if(i < MAX_RCONS) + if(k < MAX_RCONS) { + int l; NetConn_WriteString(mysocket, "\377\377\377\377getchallenge", peeraddress); // extend the timeout on other requests as we asked for a challenge - for (i = 0;i < MAX_RCONS;i++) - if(cls.rcon_commands[i][0]) - if (!LHNETADDRESS_Compare(peeraddress, &cls.rcon_addresses[i])) - cls.rcon_timeout[i] = realtime + rcon_secure_challengetimeout.value; + for (l = 0;l < MAX_RCONS;l++) + if(cls.rcon_commands[l][0]) + if (!LHNETADDRESS_Compare(peeraddress, &cls.rcon_addresses[l])) + cls.rcon_timeout[l] = realtime + rcon_secure_challengetimeout.value; } return true; // we used up the challenge, so we can't use this oen for connecting now anyway @@ -2106,8 +2125,14 @@ void NetConn_ClientFrame(void) SZ_Clear(&net_message); } for (i = 0;i < cl_numsockets;i++) + { while (cl_sockets[i] && (length = NetConn_Read(cl_sockets[i], readbuffer, sizeof(readbuffer), &peeraddress)) > 0) + { +// R_TimeReport("clientreadnetwork"); NetConn_ClientParsePacket(cl_sockets[i], readbuffer, length, &peeraddress); +// R_TimeReport("clientparsepacket"); + } + } NetConn_QueryQueueFrame(); if (cls.netcon && realtime > cls.netcon->timeout && !sv.active) { @@ -2188,7 +2213,7 @@ static qboolean NetConn_BuildStatusResponse(const char* challenge, char* out_msg "%s", fullstatus ? "statusResponse" : "infoResponse", gamename, com_modname, gameversion.integer, svs.maxclients, - nb_clients, nb_bots, sv.name, hostname.string, NET_PROTOCOL_VERSION, + nb_clients, nb_bots, sv.worldbasename, hostname.string, NET_PROTOCOL_VERSION, *qcstatus ? "\\qcstatus\\" : "", qcstatus, challenge ? "\\challenge\\" : "", challenge ? challenge : "", fullstatus ? "\n" : ""); @@ -2425,7 +2450,7 @@ qboolean plaintext_matching(lhnetaddress_t *peeraddress, const char *password, c const char *RCon_Authenticate(lhnetaddress_t *peeraddress, const char *password, const char *s, const char *endpos, rcon_matchfunc_t comparator, const char *cs, int cslen) { const char *text, *userpass_start, *userpass_end, *userpass_startpass; - char buf[MAX_INPUTLINE]; + static char buf[MAX_INPUTLINE]; qboolean hasquotes; qboolean restricted = false; qboolean have_usernames = false; @@ -2515,10 +2540,8 @@ allow: userpass_startpass = strchr(userpass_start, ':'); if(have_usernames && userpass_startpass && userpass_startpass < userpass_end) return va("%srcon (username %.*s)", restricted ? "restricted " : "", (int)(userpass_startpass-userpass_start), userpass_start); - else - return va("%srcon", restricted ? "restricted " : ""); - return "restricted rcon"; + return va("%srcon", restricted ? "restricted " : ""); } void RCon_Execute(lhnetsocket_t *mysocket, lhnetaddress_t *peeraddress, const char *addressstring2, const char *userlevel, const char *s, const char *endpos) @@ -2565,7 +2588,8 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat int i, ret, clientnum, best; double besttime; client_t *client; - char *s, *string, response[1400], addressstring2[128], stringbuf[16384]; + char *s, *string, response[1400], addressstring2[128]; + static char stringbuf[16384]; qboolean islocal = (LHNETADDRESS_GetAddressType(peeraddress) == LHNETADDRESSTYPE_LOOP); if (!sv.active)