From 414ebc59e0aa79cd43fe5ee983204dc18d8115ec Mon Sep 17 00:00:00 2001 From: Ensiform Date: Thu, 20 Jun 2024 09:18:20 -0500 Subject: [PATCH] Check netadr by const pointer instead of by value Not as beneficial with only ipv4 but once the netadr struct expands for ipv6 it will be more beneficial performance. --- codemp/client/cl_input.cpp | 2 +- codemp/client/cl_lan.cpp | 14 ++--- codemp/client/cl_main.cpp | 110 ++++++++++++++++----------------- codemp/client/client.h | 2 +- codemp/qcommon/common.cpp | 6 +- codemp/qcommon/net_chan.cpp | 87 +++++++++++++------------- codemp/qcommon/net_ip.cpp | 36 +++++------ codemp/qcommon/qcommon.h | 30 ++++----- codemp/server/server.h | 12 ++-- codemp/server/sv_ccmds.cpp | 34 +++++----- codemp/server/sv_challenge.cpp | 6 +- codemp/server/sv_client.cpp | 26 ++++---- codemp/server/sv_main.cpp | 52 ++++++++-------- codemp/server/sv_snapshot.cpp | 2 +- shared/sys/sys_public.h | 4 +- 15 files changed, 210 insertions(+), 213 deletions(-) diff --git a/codemp/client/cl_input.cpp b/codemp/client/cl_input.cpp index 647efee0f8..5fbb500d0f 100644 --- a/codemp/client/cl_input.cpp +++ b/codemp/client/cl_input.cpp @@ -1451,7 +1451,7 @@ qboolean CL_ReadyToSendPacket( void ) { } // send every frame for LAN - if ( cl_lanForcePackets->integer && Sys_IsLANAddress( clc.netchan.remoteAddress ) ) { + if ( cl_lanForcePackets->integer && Sys_IsLANAddress( &clc.netchan.remoteAddress ) ) { return qtrue; } diff --git a/codemp/client/cl_lan.cpp b/codemp/client/cl_lan.cpp index b530cb1991..fd574b360b 100644 --- a/codemp/client/cl_lan.cpp +++ b/codemp/client/cl_lan.cpp @@ -137,7 +137,7 @@ int LAN_AddServer(int source, const char *name, const char *address) { if (servers && *count < max) { NET_StringToAdr( address, &adr ); for ( i = 0; i < *count; i++ ) { - if (NET_CompareAdr(servers[i].adr, adr)) { + if (NET_CompareAdr(&servers[i].adr, &adr)) { break; } } @@ -164,7 +164,7 @@ int LAN_AddFavAddr( const char *address ) { } for ( int i = 0; i < cls.numfavoriteservers; i++ ) { - if ( NET_CompareAdr( cls.favoriteServers[i].adr, adr ) ) { + if ( NET_CompareAdr( &cls.favoriteServers[i].adr, &adr ) ) { return 0; } } @@ -207,7 +207,7 @@ void LAN_RemoveServer(int source, const char *addr) { netadr_t comp; NET_StringToAdr( addr, &comp ); for (i = 0; i < *count; i++) { - if (NET_CompareAdr( comp, servers[i].adr)) { + if (NET_CompareAdr( &comp, &servers[i].adr)) { int j = i; while (j < *count - 1) { Com_Memcpy(&servers[j], &servers[j+1], sizeof(servers[j])); @@ -251,20 +251,20 @@ void LAN_GetServerAddressString( int source, int n, char *buf, int buflen ) { switch (source) { case AS_LOCAL : if (n >= 0 && n < MAX_OTHER_SERVERS) { - Q_strncpyz(buf, NET_AdrToString( cls.localServers[n].adr) , buflen ); + Q_strncpyz(buf, NET_AdrToString( &cls.localServers[n].adr) , buflen ); return; } break; case AS_MPLAYER: case AS_GLOBAL : if (n >= 0 && n < MAX_GLOBAL_SERVERS) { - Q_strncpyz(buf, NET_AdrToString( cls.globalServers[n].adr) , buflen ); + Q_strncpyz(buf, NET_AdrToString( &cls.globalServers[n].adr) , buflen ); return; } break; case AS_FAVORITES : if (n >= 0 && n < MAX_OTHER_SERVERS) { - Q_strncpyz(buf, NET_AdrToString( cls.favoriteServers[n].adr) , buflen ); + Q_strncpyz(buf, NET_AdrToString( &cls.favoriteServers[n].adr) , buflen ); return; } break; @@ -315,7 +315,7 @@ void LAN_GetServerInfo( int source, int n, char *buf, int buflen ) { Info_SetValueForKey( info, "fdisable", va("%i", server->forceDisable ) ); Info_SetValueForKey( info, "game", server->game); Info_SetValueForKey( info, "gametype", va("%i",server->gameType)); - Info_SetValueForKey( info, "addr", NET_AdrToString(server->adr)); + Info_SetValueForKey( info, "addr", NET_AdrToString(&server->adr)); Info_SetValueForKey( info, "g_humanplayers", va( "%i", server->humans ) ); Info_SetValueForKey( info, "bots", va( "%i", server->bots ) ); // Info_SetValueForKey( info, "sv_allowAnonymous", va("%i", server->allowAnonymous)); diff --git a/codemp/client/cl_main.cpp b/codemp/client/cl_main.cpp index 0a3ac54269..0eff37d9bf 100644 --- a/codemp/client/cl_main.cpp +++ b/codemp/client/cl_main.cpp @@ -148,7 +148,7 @@ extern void SV_BotFrame( int time ); void CL_CheckForResend( void ); void CL_ShowIP_f(void); void CL_ServerStatus_f(void); -void CL_ServerStatusResponse( netadr_t from, msg_t *msg ); +void CL_ServerStatusResponse( const netadr_t *from, msg_t *msg ); static void CL_ShutdownRef( qboolean restarting ); /* @@ -297,7 +297,7 @@ void CL_Record_f( void ) { } // sync 0 doesn't prevent recording, so not forcing it off .. everyone does g_sync 1 ; record ; g_sync 0 .. - if ( NET_IsLocalAddress( clc.serverAddress ) && !Cvar_VariableValue( "g_synchronousClients" ) ) { + if ( NET_IsLocalAddress( &clc.serverAddress ) && !Cvar_VariableValue( "g_synchronousClients" ) ) { Com_Printf (S_COLOR_YELLOW "WARNING: You should set 'g_synchronousClients 1' for smoother demo recording\n"); } @@ -914,7 +914,7 @@ void CL_RequestMotd( void ) { to.type = NA_IP; to.port = BigShort( PORT_UPDATE ); - Com_Printf( "Requesting motd from update %s (%s)...\n", motdaddress, NET_AdrToString( to ) ); + Com_Printf( "Requesting motd from update %s (%s)...\n", motdaddress, NET_AdrToString( &to ) ); cls.updateServer = to; @@ -940,7 +940,7 @@ void CL_RequestMotd( void ) { Info_SetValueForKey( info, "joystick", Cvar_VariableString("in_joystick") ); Info_SetValueForKey( info, "colorbits", va("%d",cls.glconfig.colorBits) ); - NET_OutOfBandPrint( NS_CLIENT, cls.updateServer, "getmotd \"%s\"\n", info ); + NET_OutOfBandPrint( NS_CLIENT, &cls.updateServer, "getmotd \"%s\"\n", info ); } @@ -1049,7 +1049,7 @@ void CL_Connect_f( void ) { clc.serverAddress.port = BigShort( PORT_SERVER ); } - serverString = NET_AdrToString(clc.serverAddress); + serverString = NET_AdrToString(&clc.serverAddress); Com_Printf( "%s resolved to %s\n", cls.servername, serverString ); @@ -1059,7 +1059,7 @@ void CL_Connect_f( void ) { CL_UpdateGUID( NULL, 0 ); // if we aren't playing on a lan, we need to authenticate - if ( NET_IsLocalAddress( clc.serverAddress ) ) { + if ( NET_IsLocalAddress( &clc.serverAddress ) ) { cls.state = CA_CHALLENGING; } else { cls.state = CA_CONNECTING; @@ -1142,7 +1142,7 @@ void CL_Rcon_f( void ) { } } - NET_SendPacket (NS_CLIENT, strlen(message)+1, message, rcon_address); + NET_SendPacket (NS_CLIENT, strlen(message)+1, message, &rcon_address); } /* @@ -1600,7 +1600,7 @@ void CL_CheckForResend( void ) { // The challenge request shall be followed by a client challenge so no malicious server can hijack this connection. Com_sprintf(data, sizeof(data), "getchallenge %d", clc.challenge); - NET_OutOfBandPrint(NS_CLIENT, clc.serverAddress, data); + NET_OutOfBandPrint(NS_CLIENT, &clc.serverAddress, data); break; case CA_CHALLENGING: @@ -1613,7 +1613,7 @@ void CL_CheckForResend( void ) { Info_SetValueForKey( info, "challenge", va("%i", clc.challenge ) ); Com_sprintf(data, sizeof(data), "connect \"%s\"", info ); - NET_OutOfBandData( NS_CLIENT, clc.serverAddress, (byte *)data, strlen(data) ); + NET_OutOfBandData( NS_CLIENT, &clc.serverAddress, (byte *)data, strlen(data) ); // the most current userinfo has been sent, so watch for any // newer changes to userinfo variables @@ -1636,13 +1636,13 @@ to the server, the server will send out of band disconnect packets to the client so it doesn't have to wait for the full timeout period. =================== */ -void CL_DisconnectPacket( netadr_t from ) { +void CL_DisconnectPacket( const netadr_t *from ) { if ( cls.state < CA_AUTHORIZING ) { return; } // if not from our server, ignore it - if ( !NET_CompareAdr( from, clc.netchan.remoteAddress ) ) { + if ( !NET_CompareAdr( from, &clc.netchan.remoteAddress ) ) { return; } @@ -1665,12 +1665,12 @@ CL_MotdPacket =================== */ -void CL_MotdPacket( netadr_t from ) { +void CL_MotdPacket( const netadr_t *from ) { char *challenge; char *info; // if not from our server, ignore it - if ( !NET_CompareAdr( from, cls.updateServer ) ) { + if ( !NET_CompareAdr( from, &cls.updateServer ) ) { return; } @@ -1693,7 +1693,7 @@ void CL_MotdPacket( netadr_t from ) { CL_InitServerInfo =================== */ -void CL_InitServerInfo( serverInfo_t *server, netadr_t *address ) { +void CL_InitServerInfo( serverInfo_t *server, const netadr_t *address ) { server->adr = *address; server->clients = 0; server->hostName[0] = '\0'; @@ -1726,7 +1726,7 @@ void CL_ServersResponsePacket( const netadr_t *from, msg_t *msg ) { byte* buffptr; byte* buffend; - Com_Printf("CL_ServersResponsePacket from %s\n", NET_AdrToString( *from ) ); + Com_Printf("CL_ServersResponsePacket from %s\n", NET_AdrToString( from ) ); if (cls.numglobalservers == -1) { // state to detect lack of servers or lack of response @@ -1792,7 +1792,7 @@ void CL_ServersResponsePacket( const netadr_t *from, msg_t *msg ) { // We just avoid to add a server if it is still in the global servers list. for (j = 0; j < count; j++) { - if (NET_CompareAdr(cls.globalServers[j].adr, addresses[i])) + if (NET_CompareAdr(&cls.globalServers[j].adr, &addresses[i])) break; } @@ -1901,7 +1901,7 @@ CL_ConnectionlessPacket Responses to broadcasts, etc ================= */ -void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { +void CL_ConnectionlessPacket( const netadr_t *from, msg_t *msg ) { char *s; char *c; int challenge = 0; @@ -1932,7 +1932,7 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { if(*c) challenge = atoi(c); - if(!NET_CompareAdr(from, clc.serverAddress)) + if(!NET_CompareAdr(from, &clc.serverAddress)) { // This challenge response is not coming from the expected address. // Check whether we have a matching client challenge to prevent @@ -1953,7 +1953,7 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { // take this address as the new server address. This allows // a server proxy to hand off connections to multiple servers - clc.serverAddress = from; + clc.serverAddress = *from; Com_DPrintf ("challengeResponse: %d\n", clc.challenge); return; } @@ -1968,7 +1968,7 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { Com_Printf ("connectResponse packet while not connecting. Ignored.\n"); return; } - if ( !NET_CompareAdr( from, clc.serverAddress ) ) { + if ( !NET_CompareAdr( from, &clc.serverAddress ) ) { Com_Printf( "connectResponse from wrong address. Ignored.\n" ); return; } @@ -2019,7 +2019,7 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { if ( !Q_stricmp(c, "print") ) { // NOTE: we may have to add exceptions for auth and update servers - if (NET_CompareAdr(from, clc.serverAddress) || NET_CompareAdr(from, rcon_address)) + if (NET_CompareAdr(from, &clc.serverAddress) || NET_CompareAdr(from, &rcon_address)) { char sTemp[MAX_STRINGED_SV_STRING]; @@ -2033,7 +2033,7 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { // list of servers sent back by a master server (classic) if ( !Q_strncmp(c, "getserversResponse", 18) ) { - CL_ServersResponsePacket( &from, msg ); + CL_ServersResponsePacket( from, msg ); return; } @@ -2048,7 +2048,7 @@ CL_PacketEvent A packet has arrived from the main event loop ================= */ -void CL_PacketEvent( netadr_t from, msg_t *msg ) { +void CL_PacketEvent( const netadr_t *from, msg_t *msg ) { int headerBytes; clc.lastPacketTime = cls.realtime; @@ -2070,7 +2070,7 @@ void CL_PacketEvent( netadr_t from, msg_t *msg ) { // // packet from server // - if ( !NET_CompareAdr( from, clc.netchan.remoteAddress ) ) { + if ( !NET_CompareAdr( from, &clc.netchan.remoteAddress ) ) { if ( com_developer->integer ) { Com_Printf( "%s:sequenced packet without connection\n", NET_AdrToString( from ) ); @@ -2652,7 +2652,7 @@ static void CL_AddFavorite_f( void ) { return; } - const char *server = (argc == 2) ? Cmd_Argv( 1 ) : NET_AdrToString( clc.serverAddress ); + const char *server = (argc == 2) ? Cmd_Argv( 1 ) : NET_AdrToString( &clc.serverAddress ); const int status = LAN_AddFavAddr( server ); switch ( status ) { case -1: @@ -3007,23 +3007,23 @@ static void CL_SetServerInfo(serverInfo_t *server, const char *info, int ping) { } } -static void CL_SetServerInfoByAddress(netadr_t from, const char *info, int ping) { +static void CL_SetServerInfoByAddress(const netadr_t *from, const char *info, int ping) { int i; for (i = 0; i < MAX_OTHER_SERVERS; i++) { - if (NET_CompareAdr(from, cls.localServers[i].adr)) { + if (NET_CompareAdr(from, &cls.localServers[i].adr)) { CL_SetServerInfo(&cls.localServers[i], info, ping); } } for (i = 0; i < MAX_GLOBAL_SERVERS; i++) { - if (NET_CompareAdr(from, cls.globalServers[i].adr)) { + if (NET_CompareAdr(from, &cls.globalServers[i].adr)) { CL_SetServerInfo(&cls.globalServers[i], info, ping); } } for (i = 0; i < MAX_OTHER_SERVERS; i++) { - if (NET_CompareAdr(from, cls.favoriteServers[i].adr)) { + if (NET_CompareAdr(from, &cls.favoriteServers[i].adr)) { CL_SetServerInfo(&cls.favoriteServers[i], info, ping); } } @@ -3034,7 +3034,7 @@ static void CL_SetServerInfoByAddress(netadr_t from, const char *info, int ping) CL_ServerInfoPacket =================== */ -void CL_ServerInfoPacket( netadr_t from, msg_t *msg ) { +void CL_ServerInfoPacket( const netadr_t *from, msg_t *msg ) { int i, type; char info[MAX_INFO_STRING]; char *infoString; @@ -3069,7 +3069,7 @@ void CL_ServerInfoPacket( netadr_t from, msg_t *msg ) { // iterate servers waiting for ping response for (i=0; itype) { case NA_BROADCAST: case NA_IP: @@ -3112,7 +3112,7 @@ void CL_ServerInfoPacket( netadr_t from, msg_t *msg ) { } // avoid duplicate - if ( NET_CompareAdr( from, cls.localServers[i].adr ) ) { + if ( NET_CompareAdr( from, &cls.localServers[i].adr ) ) { return; } } @@ -3124,7 +3124,7 @@ void CL_ServerInfoPacket( netadr_t from, msg_t *msg ) { // add this to the list cls.numlocalservers = i+1; - CL_InitServerInfo( &cls.localServers[i], &from ); + CL_InitServerInfo( &cls.localServers[i], from ); Q_strncpyz( info, MSG_ReadString( msg ), MAX_INFO_STRING ); if (strlen(info)) { @@ -3140,11 +3140,11 @@ void CL_ServerInfoPacket( netadr_t from, msg_t *msg ) { CL_GetServerStatus =================== */ -serverStatus_t *CL_GetServerStatus( netadr_t from ) { +serverStatus_t *CL_GetServerStatus( const netadr_t *from ) { int i, oldest, oldestTime; for (i = 0; i < MAX_SERVERSTATUSREQUESTS; i++) { - if ( NET_CompareAdr( from, cl_serverStatusList[i].address ) ) { + if ( NET_CompareAdr( from, &cl_serverStatusList[i].address ) ) { return &cl_serverStatusList[i]; } } @@ -3190,7 +3190,7 @@ int CL_ServerStatus( const char *serverAddress, char *serverStatusString, int ma if ( !NET_StringToAdr( serverAddress, &to ) ) { return qfalse; } - serverStatus = CL_GetServerStatus( to ); + serverStatus = CL_GetServerStatus( &to ); // if no server status string then reset the server status request for this address if ( !serverStatusString ) { serverStatus->retrieved = qtrue; @@ -3198,7 +3198,7 @@ int CL_ServerStatus( const char *serverAddress, char *serverStatusString, int ma } // if this server status request has the same address - if ( NET_CompareAdr( to, serverStatus->address) ) { + if ( NET_CompareAdr( &to, &serverStatus->address) ) { // if we received a response for this server status request if (!serverStatus->pending) { Q_strncpyz(serverStatusString, serverStatus->string, maxLen); @@ -3213,7 +3213,7 @@ int CL_ServerStatus( const char *serverAddress, char *serverStatusString, int ma serverStatus->retrieved = qfalse; serverStatus->time = 0; serverStatus->startTime = Com_Milliseconds(); - NET_OutOfBandPrint( NS_CLIENT, to, "getstatus" ); + NET_OutOfBandPrint( NS_CLIENT, &to, "getstatus" ); return qfalse; } } @@ -3225,7 +3225,7 @@ int CL_ServerStatus( const char *serverAddress, char *serverStatusString, int ma serverStatus->retrieved = qfalse; serverStatus->startTime = Com_Milliseconds(); serverStatus->time = 0; - NET_OutOfBandPrint( NS_CLIENT, to, "getstatus" ); + NET_OutOfBandPrint( NS_CLIENT, &to, "getstatus" ); return qfalse; } return qfalse; @@ -3236,7 +3236,7 @@ int CL_ServerStatus( const char *serverAddress, char *serverStatusString, int ma CL_ServerStatusResponse =================== */ -void CL_ServerStatusResponse( netadr_t from, msg_t *msg ) { +void CL_ServerStatusResponse( const netadr_t *from, msg_t *msg ) { char *s; char info[MAX_INFO_STRING]; int i, l, score, ping; @@ -3245,7 +3245,7 @@ void CL_ServerStatusResponse( netadr_t from, msg_t *msg ) { serverStatus = NULL; for (i = 0; i < MAX_SERVERSTATUSREQUESTS; i++) { - if ( NET_CompareAdr( from, cl_serverStatusList[i].address ) ) { + if ( NET_CompareAdr( from, &cl_serverStatusList[i].address ) ) { serverStatus = &cl_serverStatusList[i]; break; } @@ -3262,7 +3262,7 @@ void CL_ServerStatusResponse( netadr_t from, msg_t *msg ) { if (serverStatus->print) { Com_Printf( "Server (%s)\n", - NET_AdrToString( serverStatus->address ) ); + NET_AdrToString( &serverStatus->address ) ); Com_Printf("Server settings:\n"); // print cvars while (*s) { @@ -3319,7 +3319,7 @@ void CL_ServerStatusResponse( netadr_t from, msg_t *msg ) { Com_sprintf(&serverStatus->string[len], sizeof(serverStatus->string)-len, "\\"); serverStatus->time = Com_Milliseconds(); - serverStatus->address = from; + serverStatus->address = *from; serverStatus->pending = qfalse; if (serverStatus->print) { serverStatus->retrieved = qtrue; @@ -3363,7 +3363,7 @@ void CL_LocalServers_f( void ) { to.port = BigShort( (short)(PORT_SERVER + j) ); to.type = NA_BROADCAST; - NET_SendPacket( NS_CLIENT, strlen( message ), message, to ); + NET_SendPacket( NS_CLIENT, strlen( message ), message, &to ); } } } @@ -3436,7 +3436,7 @@ void CL_GlobalServers_f( void ) { to.type = NA_IP; to.port = BigShort(PORT_MASTER); - Com_Printf( "Requesting servers from the master %s (%s)...\n", masteraddress, NET_AdrToString( to ) ); + Com_Printf( "Requesting servers from the master %s (%s)...\n", masteraddress, NET_AdrToString( &to ) ); cls.numglobalservers = -1; cls.pingUpdateSource = AS_GLOBAL; @@ -3450,7 +3450,7 @@ void CL_GlobalServers_f( void ) { Q_strcat(command, sizeof(command), Cmd_Argv(i)); } - NET_OutOfBandPrint( NS_SERVER, to, "%s", command ); + NET_OutOfBandPrint( NS_SERVER, &to, "%s", command ); } /* @@ -3472,7 +3472,7 @@ void CL_GetPing( int n, char *buf, int buflen, int *pingtime ) return; } - str = NET_AdrToString( cl_pinglist[n].adr ); + str = NET_AdrToString( &cl_pinglist[n].adr ); Q_strncpyz( buf, str, buflen ); time = cl_pinglist[n].time; @@ -3491,7 +3491,7 @@ void CL_GetPing( int n, char *buf, int buflen, int *pingtime ) } } - CL_SetServerInfoByAddress(cl_pinglist[n].adr, cl_pinglist[n].info, cl_pinglist[n].time); + CL_SetServerInfoByAddress(&cl_pinglist[n].adr, cl_pinglist[n].info, cl_pinglist[n].time); *pingtime = time; } @@ -3636,9 +3636,9 @@ void CL_Ping_f( void ) { pingptr->start = Sys_Milliseconds(); pingptr->time = 0; - CL_SetServerInfoByAddress(pingptr->adr, NULL, 0); + CL_SetServerInfoByAddress(&pingptr->adr, NULL, 0); - NET_OutOfBandPrint( NS_CLIENT, to, "getinfo xxx" ); + NET_OutOfBandPrint( NS_CLIENT, &to, "getinfo xxx" ); } /* @@ -3691,7 +3691,7 @@ qboolean CL_UpdateVisiblePings_f(int source) { if (!cl_pinglist[j].adr.port) { continue; } - if (NET_CompareAdr( cl_pinglist[j].adr, server[i].adr)) { + if (NET_CompareAdr( &cl_pinglist[j].adr, &server[i].adr)) { // already on the list break; } @@ -3706,7 +3706,7 @@ qboolean CL_UpdateVisiblePings_f(int source) { memcpy(&cl_pinglist[j].adr, &server[i].adr, sizeof(netadr_t)); cl_pinglist[j].start = Sys_Milliseconds(); cl_pinglist[j].time = 0; - NET_OutOfBandPrint( NS_CLIENT, cl_pinglist[j].adr, "getinfo xxx" ); + NET_OutOfBandPrint( NS_CLIENT, &cl_pinglist[j].adr, "getinfo xxx" ); slots++; } } @@ -3776,9 +3776,9 @@ void CL_ServerStatus_f(void) { return; } - NET_OutOfBandPrint( NS_CLIENT, *toptr, "getstatus" ); + NET_OutOfBandPrint( NS_CLIENT, toptr, "getstatus" ); - serverStatus = CL_GetServerStatus( *toptr ); + serverStatus = CL_GetServerStatus( toptr ); serverStatus->address = *toptr; serverStatus->print = qtrue; serverStatus->pending = qtrue; diff --git a/codemp/client/client.h b/codemp/client/client.h index ced59fcf44..4f2cf54097 100644 --- a/codemp/client/client.h +++ b/codemp/client/client.h @@ -519,7 +519,7 @@ void CL_ParseServerMessage( msg_t *msg ); //==================================================================== -void CL_ServerInfoPacket( netadr_t from, msg_t *msg ); +void CL_ServerInfoPacket( const netadr_t *from, msg_t *msg ); void CL_LocalServers_f( void ); void CL_GlobalServers_f( void ); void CL_FavoriteServers_f( void ); diff --git a/codemp/qcommon/common.cpp b/codemp/qcommon/common.cpp index 4b84c4d141..d4609a1fdd 100644 --- a/codemp/qcommon/common.cpp +++ b/codemp/qcommon/common.cpp @@ -868,7 +868,7 @@ sysEvent_t Com_GetEvent( void ) { Com_RunAndTimeServerPacket ================= */ -void Com_RunAndTimeServerPacket( netadr_t *evFrom, msg_t *buf ) { +void Com_RunAndTimeServerPacket( const netadr_t *evFrom, msg_t *buf ) { int t1, t2, msec; t1 = 0; @@ -877,7 +877,7 @@ void Com_RunAndTimeServerPacket( netadr_t *evFrom, msg_t *buf ) { t1 = Sys_Milliseconds (); } - SV_PacketEvent( *evFrom, buf ); + SV_PacketEvent( evFrom, buf ); if ( com_speeds->integer ) { t2 = Sys_Milliseconds (); @@ -910,7 +910,7 @@ int Com_EventLoop( void ) { if ( ev.evType == SE_NONE ) { // manually send packet events for the loopback channel while ( NET_GetLoopPacket( NS_CLIENT, &evFrom, &buf ) ) { - CL_PacketEvent( evFrom, &buf ); + CL_PacketEvent( &evFrom, &buf ); } while ( NET_GetLoopPacket( NS_SERVER, &evFrom, &buf ) ) { diff --git a/codemp/qcommon/net_chan.cpp b/codemp/qcommon/net_chan.cpp index 69ee3ed5cf..0741c81833 100644 --- a/codemp/qcommon/net_chan.cpp +++ b/codemp/qcommon/net_chan.cpp @@ -82,11 +82,11 @@ Netchan_Setup called to open a channel to a remote system ============== */ -void Netchan_Setup( netsrc_t sock, netchan_t *chan, netadr_t adr, int qport ) { +void Netchan_Setup( netsrc_t sock, netchan_t *chan, const netadr_t *adr, int qport ) { Com_Memset (chan, 0, sizeof(*chan)); chan->sock = sock; - chan->remoteAddress = adr; + chan->remoteAddress = *adr; chan->qport = qport; chan->incomingSequence = 0; chan->outgoingSequence = 1; @@ -125,7 +125,7 @@ void Netchan_TransmitNextFragment( netchan_t *chan ) { MSG_WriteData( &send, chan->unsentBuffer + chan->unsentFragmentStart, fragmentLength ); // send the datagram - NET_SendPacket( chan->sock, send.cursize, send.data, chan->remoteAddress ); + NET_SendPacket( chan->sock, send.cursize, send.data, &chan->remoteAddress ); if ( showpackets->integer ) { Com_Printf ("%s send %4i : s=%i fragment=%i,%i\n" @@ -196,7 +196,7 @@ void Netchan_Transmit( netchan_t *chan, int length, const byte *data ) { MSG_WriteData( &send, data, length ); // send the datagram - NET_SendPacket( chan->sock, send.cursize, send.data, chan->remoteAddress ); + NET_SendPacket( chan->sock, send.cursize, send.data, &chan->remoteAddress ); if ( showpackets->integer ) { Com_Printf( "%s send %4i : s=%i ack=%i\n" @@ -272,7 +272,7 @@ qboolean Netchan_Process( netchan_t *chan, msg_t *msg ) { if ( sequence <= chan->incomingSequence ) { if ( showdrop->integer || showpackets->integer ) { Com_Printf( "%s:Out of order packet %i at %i\n" - , NET_AdrToString( chan->remoteAddress ) + , NET_AdrToString( &chan->remoteAddress ) , sequence , chan->incomingSequence ); } @@ -286,7 +286,7 @@ qboolean Netchan_Process( netchan_t *chan, msg_t *msg ) { if ( chan->dropped > 0 ) { if ( showdrop->integer || showpackets->integer ) { Com_Printf( "%s:Dropped %i packets at %i\n" - , NET_AdrToString( chan->remoteAddress ) + , NET_AdrToString( &chan->remoteAddress ) , chan->dropped , sequence ); } @@ -308,7 +308,7 @@ qboolean Netchan_Process( netchan_t *chan, msg_t *msg ) { if ( fragmentStart != chan->fragmentLength ) { if ( showdrop->integer || showpackets->integer ) { Com_Printf( "%s:Dropped a message fragment\n" - , NET_AdrToString( chan->remoteAddress ) + , NET_AdrToString( &chan->remoteAddress ) , sequence); } // we can still keep the part that we have so far, @@ -333,7 +333,7 @@ qboolean Netchan_Process( netchan_t *chan, msg_t *msg ) { chan->fragmentLength + fragmentLength > (int)sizeof( chan->fragmentBuffer ) ) { if ( showdrop->integer || showpackets->integer ) { Com_Printf ("%s:illegal fragment length\n" - , NET_AdrToString (chan->remoteAddress ) ); + , NET_AdrToString (&chan->remoteAddress ) ); } return qfalse; } @@ -350,7 +350,7 @@ qboolean Netchan_Process( netchan_t *chan, msg_t *msg ) { if ( chan->fragmentLength+4 > msg->maxsize ) { Com_Printf( "%s:fragmentLength %i > msg->maxsize\n" - , NET_AdrToString (chan->remoteAddress ), + , NET_AdrToString (&chan->remoteAddress ), chan->fragmentLength+4 ); return qfalse; } @@ -389,28 +389,28 @@ NET_CompareBaseAdrMask Compare without port, and up to the bit number given in netmask. =================== */ -qboolean NET_CompareBaseAdrMask( netadr_t a, netadr_t b, int netmask ) +qboolean NET_CompareBaseAdrMask( const netadr_t *a, const netadr_t *b, unsigned int netmask ) { byte cmpmask, *addra, *addrb; int curbyte; - if ( a.type != b.type ) + if ( a->type != b->type ) return qfalse; - if ( a.type == NA_LOOPBACK ) + if ( a->type == NA_LOOPBACK ) return qtrue; - if ( a.type == NA_IP ) + if ( a->type == NA_IP ) { - addra = (byte *)&a.ip; - addrb = (byte *)&b.ip; + addra = (byte *)&a->ip; + addrb = (byte *)&b->ip; - if ( netmask < 0 || netmask > 32 ) + if ( netmask > 32 ) netmask = 32; } else { - Com_Printf( "NET_CompareBaseAdr: bad address type\n" ); + Com_Printf( "%s: bad address type\n", __func__ ); return qfalse; } @@ -441,23 +441,23 @@ NET_CompareBaseAdr Compares without the port =================== */ -qboolean NET_CompareBaseAdr( netadr_t a, netadr_t b ) +qboolean NET_CompareBaseAdr( const netadr_t *a, const netadr_t *b ) { - return NET_CompareBaseAdrMask( a, b, -1 ); + return NET_CompareBaseAdrMask( a, b, ~0U ); } -const char *NET_AdrToString (netadr_t a) +const char *NET_AdrToString (const netadr_t *a) { - static char s[64]; + static char s[NET_ADDRSTRMAXLEN]; - if (a.type == NA_LOOPBACK) { + if (a->type == NA_LOOPBACK) { Com_sprintf (s, sizeof(s), "loopback"); - } else if (a.type == NA_BOT) { + } else if (a->type == NA_BOT) { Com_sprintf (s, sizeof(s), "bot"); - } else if (a.type == NA_IP) { + } else if (a->type == NA_IP) { Com_sprintf (s, sizeof(s), "%i.%i.%i.%i:%hu", - a.ip[0], a.ip[1], a.ip[2], a.ip[3], BigShort(a.port)); - } else if (a.type == NA_BAD) { + a->ip[0], a->ip[1], a->ip[2], a->ip[3], BigShort(a->port)); + } else if (a->type == NA_BAD) { Com_sprintf (s, sizeof(s), "BAD"); } @@ -465,28 +465,25 @@ const char *NET_AdrToString (netadr_t a) } -qboolean NET_CompareAdr (netadr_t a, netadr_t b) +qboolean NET_CompareAdr (const netadr_t *a, const netadr_t *b) { - if (a.type != b.type) + if (!NET_CompareBaseAdr(a, b)) return qfalse; - if (a.type == NA_LOOPBACK) - return qtrue; - - if (a.type == NA_IP) + if (a->type == NA_IP) { - if ((memcmp(a.ip, b.ip, 4) == 0) && a.port == b.port) + if (a->port == b->port) return qtrue; - return qfalse; } + else + return qtrue; - Com_Printf ("NET_CompareAdr: bad address type\n"); return qfalse; } -qboolean NET_IsLocalAddress( netadr_t adr ) { - return (qboolean)(adr.type == NA_LOOPBACK); +qboolean NET_IsLocalAddress( const netadr_t *adr ) { + return adr->type == NA_LOOPBACK ? qtrue : qfalse; } @@ -541,7 +538,7 @@ qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_messag } -void NET_SendLoopPacket (netsrc_t sock, int length, const void *data, netadr_t to) +void NET_SendLoopPacket (netsrc_t sock, int length, const void *data) { int i; loopback_t *loop; @@ -558,21 +555,21 @@ void NET_SendLoopPacket (netsrc_t sock, int length, const void *data, netadr_t t //============================================================================= -void NET_SendPacket( netsrc_t sock, int length, const void *data, netadr_t to ) { +void NET_SendPacket( netsrc_t sock, int length, const void *data, const netadr_t *to ) { // sequenced packets are shown in netchan, so just show oob if ( showpackets->integer && *(int *)data == -1 ) { Com_Printf ("send packet %4i\n", length); } - if ( to.type == NA_LOOPBACK ) { - NET_SendLoopPacket (sock, length, data, to); + if ( to->type == NA_LOOPBACK ) { + NET_SendLoopPacket (sock, length, data); return; } - if ( to.type == NA_BOT ) { + if ( to->type == NA_BOT ) { return; } - if ( to.type == NA_BAD ) { + if ( to->type == NA_BAD ) { return; } @@ -586,7 +583,7 @@ NET_OutOfBandPrint Sends a text message in an out-of-band datagram ================ */ -void QDECL NET_OutOfBandPrint( netsrc_t sock, netadr_t adr, const char *format, ... ) { +void QDECL NET_OutOfBandPrint( netsrc_t sock, const netadr_t *adr, const char *format, ... ) { va_list argptr; char string[MAX_MSGLEN]; @@ -612,7 +609,7 @@ NET_OutOfBandPrint Sends a data message in an out-of-band datagram (only used for "connect") ================ */ -void QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len ) { +void QDECL NET_OutOfBandData( netsrc_t sock, const netadr_t *adr, byte *format, int len ) { byte string[MAX_MSGLEN*2]; int i; msg_t mbuf; diff --git a/codemp/qcommon/net_ip.cpp b/codemp/qcommon/net_ip.cpp index bf72ebcc9e..889969a9b0 100644 --- a/codemp/qcommon/net_ip.cpp +++ b/codemp/qcommon/net_ip.cpp @@ -168,7 +168,7 @@ char *NET_ErrorString( void ) { #endif } -static void NetadrToSockadr( netadr_t *a, struct sockaddr_in *s ) { +static void NetadrToSockadr( const netadr_t *a, struct sockaddr_in *s ) { memset( s, 0, sizeof(*s) ); if( a->type == NA_BROADCAST ) { @@ -292,7 +292,7 @@ qboolean NET_GetPacket( netadr_t *net_from, msg_t *net_message, fd_set *fdr ) { } if( ret >= net_message->maxsize ) { - Com_Printf( "Oversize packet from %s\n", NET_AdrToString (*net_from) ); + Com_Printf( "Oversize packet from %s\n", NET_AdrToString (net_from) ); return qfalse; } @@ -309,11 +309,11 @@ static char socksBuf[4096]; Sys_SendPacket ================== */ -void Sys_SendPacket( int length, const void *data, netadr_t to ) { +void Sys_SendPacket( int length, const void *data, const netadr_t *to ) { int ret; struct sockaddr_in addr; - if ( to.type != NA_BROADCAST && to.type != NA_IP ) { + if ( to->type != NA_BROADCAST && to->type != NA_IP ) { Com_Error( ERR_FATAL, "Sys_SendPacket: bad address type" ); return; } @@ -322,9 +322,9 @@ void Sys_SendPacket( int length, const void *data, netadr_t to ) { return; } - NetadrToSockadr( &to, &addr ); + NetadrToSockadr( to, &addr ); - if( usingSocks && to.type == NA_IP ) { + if( usingSocks && to->type == NA_IP ) { socksBuf[0] = 0; // reserved socksBuf[1] = 0; socksBuf[2] = 0; // fragment (not fragmented) @@ -346,7 +346,7 @@ void Sys_SendPacket( int length, const void *data, netadr_t to ) { } // some PPP links do not allow broadcasts and return an error - if( err == EADDRNOTAVAIL && to.type == NA_BROADCAST ) { + if( err == EADDRNOTAVAIL && to->type == NA_BROADCAST ) { return; } @@ -363,31 +363,31 @@ Sys_IsLANAddress LAN clients will have their rate var ignored ================== */ -qboolean Sys_IsLANAddress( netadr_t adr ) { +qboolean Sys_IsLANAddress( const netadr_t *adr ) { if ( !net_forcenonlocal ) net_forcenonlocal = Cvar_Get( "net_forcenonlocal", "0", 0 ); if ( net_forcenonlocal && net_forcenonlocal->integer ) return qfalse; - if( adr.type == NA_LOOPBACK ) + if( adr->type == NA_LOOPBACK ) return qtrue; - if( adr.type != NA_IP ) + if( adr->type != NA_IP ) return qfalse; // RFC1918: // 10.0.0.0 - 10.255.255.255 (10/8 prefix) // 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) // 192.168.0.0 - 192.168.255.255 (192.168/16 prefix) - if ( adr.ip[0] == 10 ) + if ( adr->ip[0] == 10 ) return qtrue; - if ( adr.ip[0] == 172 && (adr.ip[1]&0xf0) == 16 ) + if ( adr->ip[0] == 172 && (adr->ip[1]&0xf0) == 16 ) return qtrue; - if ( adr.ip[0] == 192 && adr.ip[1] == 168 ) + if ( adr->ip[0] == 192 && adr->ip[1] == 168 ) return qtrue; - if ( adr.ip[0] == 127 ) + if ( adr->ip[0] == 127 ) return qtrue; // choose which comparison to use based on the class of the address being tested @@ -395,7 +395,7 @@ qboolean Sys_IsLANAddress( netadr_t adr ) { // Class C for ( int i=0; iip, localIP[i], 3 ) == 0 ) return qtrue; } return qfalse; @@ -418,7 +418,7 @@ void Sys_ShowIP(void) { NET_IPSocket ==================== */ -SOCKET NET_IPSocket( char *net_interface, int port, int *err ) { +static SOCKET NET_IPSocket( const char *net_interface, int port, int *err ) { SOCKET newsocket; struct sockaddr_in address; u_long _true = 1; @@ -468,7 +468,7 @@ SOCKET NET_IPSocket( char *net_interface, int port, int *err ) { address.sin_port = 0; } else { - address.sin_port = htons( port ); + address.sin_port = htons( (short)port ); } if( bind( newsocket, (const struct sockaddr *)&address, sizeof(address) ) == SOCKET_ERROR ) { @@ -1025,7 +1025,7 @@ void NET_Event(fd_set *fdr) if(com_sv_running->integer) Com_RunAndTimeServerPacket(&from, &netmsg); else - CL_PacketEvent(from, &netmsg); + CL_PacketEvent(&from, &netmsg); } else break; diff --git a/codemp/qcommon/qcommon.h b/codemp/qcommon/qcommon.h index 1b5c0324c9..92d6724f35 100644 --- a/codemp/qcommon/qcommon.h +++ b/codemp/qcommon/qcommon.h @@ -136,23 +136,23 @@ void NET_Shutdown( void ); void NET_Restart_f( void ); void NET_Config( qboolean enableNetworking ); -void NET_SendPacket (netsrc_t sock, int length, const void *data, netadr_t to); -void NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...); -void NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len ); - -qboolean NET_CompareAdr (netadr_t a, netadr_t b); -qboolean NET_CompareBaseAdrMask( netadr_t a, netadr_t b, int netmask ); -qboolean NET_CompareBaseAdr (netadr_t a, netadr_t b); -qboolean NET_IsLocalAddress (netadr_t adr); -const char *NET_AdrToString (netadr_t a); +void NET_SendPacket (netsrc_t sock, int length, const void *data, const netadr_t *to); +void NET_OutOfBandPrint( netsrc_t net_socket, const netadr_t *adr, const char *format, ...); +void NET_OutOfBandData( netsrc_t sock, const netadr_t *adr, byte *format, int len ); + +qboolean NET_CompareAdr (const netadr_t *a, const netadr_t *b); +qboolean NET_CompareBaseAdrMask( const netadr_t *a, const netadr_t *b, unsigned int netmask ); +qboolean NET_CompareBaseAdr (const netadr_t *a, const netadr_t *b); +qboolean NET_IsLocalAddress (const netadr_t *adr); +const char *NET_AdrToString (const netadr_t *a); qboolean NET_StringToAdr ( const char *s, netadr_t *a); qboolean NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message); void NET_Sleep(int msec); -void Sys_SendPacket( int length, const void *data, netadr_t to ); +void Sys_SendPacket( int length, const void *data, const netadr_t *to ); //Does NOT parse port numbers, only base addresses. qboolean Sys_StringToAdr( const char *s, netadr_t *a ); -qboolean Sys_IsLANAddress (netadr_t adr); +qboolean Sys_IsLANAddress (const netadr_t *adr); void Sys_ShowIP(void); @@ -195,7 +195,7 @@ typedef struct netchan_s { } netchan_t; void Netchan_Init( int qport ); -void Netchan_Setup( netsrc_t sock, netchan_t *chan, netadr_t adr, int qport ); +void Netchan_Setup( netsrc_t sock, netchan_t *chan, const netadr_t *adr, int qport ); void Netchan_Transmit( netchan_t *chan, int length, const byte *data ); void Netchan_TransmitNextFragment( netchan_t *chan ); @@ -764,7 +764,7 @@ int Com_Filter(char *filter, char *name, int casesensitive); int Com_FilterPath(char *filter, char *name, int casesensitive); int Com_RealTime(qtime_t *qtime); qboolean Com_SafeMode( void ); -void Com_RunAndTimeServerPacket(netadr_t *evFrom, msg_t *buf); +void Com_RunAndTimeServerPacket(const netadr_t *evFrom, msg_t *buf); void Com_StartupVariable( const char *match ); // checks for and removes command line "+set var arg" constructs @@ -936,7 +936,7 @@ void CL_MouseEvent( int dx, int dy, int time ); void CL_JoystickEvent( int axis, int value, int time ); -void CL_PacketEvent( netadr_t from, msg_t *msg ); +void CL_PacketEvent( const netadr_t *from, msg_t *msg ); void CL_ConsolePrint( const char *text ); @@ -984,7 +984,7 @@ void SCR_DebugGraph (float value, int color); // FIXME: move logging to common? void SV_Init( void ); void SV_Shutdown( char *finalmsg ); void SV_Frame( int msec ); -void SV_PacketEvent( netadr_t from, msg_t *msg ); +void SV_PacketEvent( const netadr_t *from, msg_t *msg ); int SV_FrameMsec( void ); qboolean SV_GameCommand( void ); diff --git a/codemp/server/server.h b/codemp/server/server.h index 6a14f7d78d..6a049f92c7 100644 --- a/codemp/server/server.h +++ b/codemp/server/server.h @@ -294,9 +294,9 @@ struct leakyBucket_s { extern leakyBucket_t outboundLeakyBucket; qboolean SVC_RateLimit( leakyBucket_t *bucket, int burst, int period, int now ); -qboolean SVC_RateLimitAddress( netadr_t from, int burst, int period, int now ); +qboolean SVC_RateLimitAddress( const netadr_t *from, int burst, int period, int now ); void SVC_LoadWhitelist( void ); -void SVC_WhitelistAdr( netadr_t adr ); +void SVC_WhitelistAdr( const netadr_t *adr ); void SV_FinalMessage (char *message); void QDECL SV_SendServerCommand( client_t *cl, const char *fmt, ...); @@ -331,15 +331,15 @@ void SV_SpawnServer( char *server, qboolean killBots, ForceReload_e eForceReload // void SV_ChallengeInit(); void SV_ChallengeShutdown(); -int SV_CreateChallenge(netadr_t from); -qboolean SV_VerifyChallenge(int receivedChallenge, netadr_t from); +int SV_CreateChallenge(const netadr_t *from); +qboolean SV_VerifyChallenge(int receivedChallenge, const netadr_t *from); // // sv_client.c // -void SV_GetChallenge( netadr_t from ); +void SV_GetChallenge( const netadr_t *from ); -void SV_DirectConnect( netadr_t from ); +void SV_DirectConnect( const netadr_t *from ); void SV_SendClientMapChange( client_t *client ); void SV_ExecuteClientMessage( client_t *cl, msg_t *msg ); diff --git a/codemp/server/sv_ccmds.cpp b/codemp/server/sv_ccmds.cpp index 47c2deb879..466ba98177 100644 --- a/codemp/server/sv_ccmds.cpp +++ b/codemp/server/sv_ccmds.cpp @@ -682,7 +682,7 @@ static void SV_WriteBans( void ) curban = &serverBans[index]; Com_sprintf( writebuf, sizeof( writebuf ), "%d %s %d\n", - curban->isexception, NET_AdrToString( curban->ip ), curban->subnet ); + curban->isexception, NET_AdrToString( &curban->ip ), curban->subnet ); FS_Write( writebuf, strlen( writebuf ), writeto ); } @@ -847,24 +847,24 @@ static void SV_AddBanToList( qboolean isexception ) if ( curban->subnet <= mask ) { - if ( (curban->isexception || !isexception) && NET_CompareBaseAdrMask( curban->ip, ip, curban->subnet ) ) + if ( (curban->isexception || !isexception) && NET_CompareBaseAdrMask( &curban->ip, &ip, curban->subnet ) ) { - Q_strncpyz( addy2, NET_AdrToString( ip ), sizeof( addy2 ) ); + Q_strncpyz( addy2, NET_AdrToString( &ip ), sizeof( addy2 ) ); Com_Printf( "Error: %s %s/%d supersedes %s %s/%d\n", curban->isexception ? "Exception" : "Ban", - NET_AdrToString( curban->ip ), curban->subnet, + NET_AdrToString( &curban->ip ), curban->subnet, isexception ? "exception" : "ban", addy2, mask ); return; } } if ( curban->subnet >= mask ) { - if ( !curban->isexception && isexception && NET_CompareBaseAdrMask( curban->ip, ip, mask ) ) + if ( !curban->isexception && isexception && NET_CompareBaseAdrMask( &curban->ip, &ip, mask ) ) { - Q_strncpyz( addy2, NET_AdrToString( curban->ip ), sizeof( addy2 ) ); + Q_strncpyz( addy2, NET_AdrToString( &curban->ip ), sizeof( addy2 ) ); Com_Printf( "Error: %s %s/%d supersedes already existing %s %s/%d\n", isexception ? "Exception" : "Ban", - NET_AdrToString( ip ), mask, + NET_AdrToString( &ip ), mask, curban->isexception ? "exception" : "ban", addy2, curban->subnet ); return; } @@ -877,7 +877,7 @@ static void SV_AddBanToList( qboolean isexception ) { curban = &serverBans[index]; - if ( curban->subnet > mask && (!curban->isexception || isexception) && NET_CompareBaseAdrMask( curban->ip, ip, mask ) ) + if ( curban->subnet > mask && (!curban->isexception || isexception) && NET_CompareBaseAdrMask( &curban->ip, &ip, mask ) ) SV_DelBanEntryFromList( index ); else index++; @@ -892,7 +892,7 @@ static void SV_AddBanToList( qboolean isexception ) SV_WriteBans(); Com_Printf( "Added %s: %s/%d\n", isexception ? "ban exception" : "ban", - NET_AdrToString( ip ), mask ); + NET_AdrToString( &ip ), mask ); } /* @@ -941,11 +941,11 @@ static void SV_DelBanFromList( qboolean isexception ) if ( curban->isexception == isexception && curban->subnet >= mask && - NET_CompareBaseAdrMask( curban->ip, ip, mask ) ) + NET_CompareBaseAdrMask( &curban->ip, &ip, mask ) ) { Com_Printf( "Deleting %s %s/%d\n", isexception ? "exception" : "ban", - NET_AdrToString( curban->ip ), curban->subnet ); + NET_AdrToString( &curban->ip ), curban->subnet ); SV_DelBanEntryFromList( index ); } @@ -973,7 +973,7 @@ static void SV_DelBanFromList( qboolean isexception ) { Com_Printf( "Deleting %s %s/%d\n", isexception ? "exception" : "ban", - NET_AdrToString( serverBans[index].ip ), serverBans[index].subnet ); + NET_AdrToString( &serverBans[index].ip ), serverBans[index].subnet ); SV_DelBanEntryFromList( index ); @@ -1015,7 +1015,7 @@ static void SV_ListBans_f( void ) count++; Com_Printf( "Ban #%d: %s/%d\n", count, - NET_AdrToString( ban->ip ), ban->subnet ); + NET_AdrToString( &ban->ip ), ban->subnet ); } } // List all exceptions @@ -1027,7 +1027,7 @@ static void SV_ListBans_f( void ) count++; Com_Printf( "Except #%d: %s/%d\n", count, - NET_AdrToString( ban->ip ), ban->subnet ); + NET_AdrToString( &ban->ip ), ban->subnet ); } } } @@ -1194,7 +1194,7 @@ static void SV_Status_f( void ) } ps = SV_GameClientNum( i ); - s = NET_AdrToString( cl->netchan.remoteAddress ); + s = NET_AdrToString( &cl->netchan.remoteAddress ); if (!avoidTruncation) { @@ -1921,8 +1921,8 @@ static void SV_WhitelistIP_f( void ) { netadr_t adr; if ( NET_StringToAdr( Cmd_Argv(i), &adr ) ) { - SVC_WhitelistAdr( adr ); - Com_Printf("Added %s to the IP whitelist\n", NET_AdrToString(adr)); + SVC_WhitelistAdr( &adr ); + Com_Printf("Added %s to the IP whitelist\n", NET_AdrToString(&adr)); } else { Com_Printf("Incorrect IP address: %s\n", Cmd_Argv(i)); } diff --git a/codemp/server/sv_challenge.cpp b/codemp/server/sv_challenge.cpp index 147c48da58..4586b78ce3 100644 --- a/codemp/server/sv_challenge.cpp +++ b/codemp/server/sv_challenge.cpp @@ -105,7 +105,7 @@ SV_CreateChallenge (internal) Create a challenge for the given client address and timestamp. ==================== */ -static int SV_CreateChallenge(int timestamp, netadr_t from) +static int SV_CreateChallenge(int timestamp, const netadr_t *from) { const char *clientParams = NET_AdrToString(from); size_t clientParamsLen = strlen(clientParams); @@ -141,7 +141,7 @@ SV_CreateChallenge Create an unforgeable, temporal challenge for the given client address. ==================== */ -int SV_CreateChallenge(netadr_t from) +int SV_CreateChallenge(const netadr_t *from) { if (!challengerInitialized) { Com_Error(ERR_FATAL, "SV_CreateChallenge: The challenge subsystem has not been initialized"); @@ -160,7 +160,7 @@ SV_VerifyChallenge Verify a challenge received by the client matches the expected challenge. ==================== */ -qboolean SV_VerifyChallenge(int receivedChallenge, netadr_t from) +qboolean SV_VerifyChallenge(int receivedChallenge, const netadr_t *from) { if (!challengerInitialized) { Com_Error(ERR_FATAL, "SV_VerifyChallenge: The challenge subsystem has not been initialized"); diff --git a/codemp/server/sv_client.cpp b/codemp/server/sv_client.cpp index fb2d4418ca..b19ff6f935 100644 --- a/codemp/server/sv_client.cpp +++ b/codemp/server/sv_client.cpp @@ -59,7 +59,7 @@ to their packets, to make it more difficult for malicious servers to hi-jack client connections. ================= */ -void SV_GetChallenge( netadr_t from ) { +void SV_GetChallenge( const netadr_t *from ) { int challenge; int clientChallenge; @@ -91,7 +91,7 @@ Check whether a certain address is banned ================== */ -static qboolean SV_IsBanned( netadr_t *from, qboolean isexception ) +static qboolean SV_IsBanned( const netadr_t *from, qboolean isexception ) { int index; serverBan_t *curban; @@ -113,7 +113,7 @@ static qboolean SV_IsBanned( netadr_t *from, qboolean isexception ) if ( curban->isexception == isexception ) { - if ( NET_CompareBaseAdrMask( curban->ip, *from, curban->subnet ) ) + if ( NET_CompareBaseAdrMask( &curban->ip, from, curban->subnet ) ) return qtrue; } } @@ -128,7 +128,7 @@ SV_DirectConnect A "connect" OOB command has been received ================== */ -void SV_DirectConnect( netadr_t from ) { +void SV_DirectConnect( const netadr_t *from ) { char userinfo[MAX_INFO_STRING]; int i; client_t *cl, *newcl; @@ -147,7 +147,7 @@ void SV_DirectConnect( netadr_t from ) { Com_DPrintf ("SVC_DirectConnect ()\n"); // Check whether this client is banned. - if ( SV_IsBanned( &from, qfalse ) ) + if ( SV_IsBanned( from, qfalse ) ) { NET_OutOfBandPrint( NS_SERVER, from, "print\nYou are banned from this server.\n" ); Com_DPrintf( " rejected connect from %s (banned)\n", NET_AdrToString(from) ); @@ -178,9 +178,9 @@ void SV_DirectConnect( netadr_t from ) { } */ - if ( NET_CompareBaseAdr( from, cl->netchan.remoteAddress ) + if ( NET_CompareBaseAdr( from, &cl->netchan.remoteAddress ) && ( cl->netchan.qport == qport - || from.port == cl->netchan.remoteAddress.port ) ) { + || from->port == cl->netchan.remoteAddress.port ) ) { if (( svs.time - cl->lastConnectTime) < (sv_reconnectlimit->integer * 1000)) { NET_OutOfBandPrint( NS_SERVER, from, "print\nReconnect rejected : too soon\n" ); @@ -223,9 +223,9 @@ void SV_DirectConnect( netadr_t from ) { if ( cl->state == CS_FREE ) { continue; } - if ( NET_CompareBaseAdr( from, cl->netchan.remoteAddress ) + if ( NET_CompareBaseAdr( from, &cl->netchan.remoteAddress ) && ( cl->netchan.qport == qport - || from.port == cl->netchan.remoteAddress.port ) ) { + || from->port == cl->netchan.remoteAddress.port ) ) { Com_Printf ("%s:reconnect\n", NET_AdrToString (from)); newcl = cl; // VVFIXME - both SOF2 and Wolf remove this call, claiming it blows away the user's info @@ -553,7 +553,7 @@ void SV_ClientEnterWorld( client_t *client, usercmd_t *cmd ) { client->state = CS_ACTIVE; if (sv_autoWhitelist->integer) { - SVC_WhitelistAdr( client->netchan.remoteAddress ); + SVC_WhitelistAdr( &client->netchan.remoteAddress ); } // resend all configstrings using the cs commands since these are @@ -1071,7 +1071,7 @@ void SV_UserinfoChanged( client_t *cl ) { // if the client is on the same subnet as the server and we aren't running an // internet public server, assume they don't need a rate choke - if ( Sys_IsLANAddress( cl->netchan.remoteAddress ) && com_dedicated->integer != 2 && sv_lanForceRate->integer == 1 ) { + if ( Sys_IsLANAddress( &cl->netchan.remoteAddress ) && com_dedicated->integer != 2 && sv_lanForceRate->integer == 1 ) { cl->rate = 100000; // lans should not rate limit } else { val = Info_ValueForKey (cl->userinfo, "rate"); @@ -1125,10 +1125,10 @@ void SV_UserinfoChanged( client_t *cl ) { // TTimo // maintain the IP information // the banning code relies on this being consistently present - if( NET_IsLocalAddress(cl->netchan.remoteAddress) ) + if( NET_IsLocalAddress(&cl->netchan.remoteAddress) ) ip = "localhost"; else - ip = (char*)NET_AdrToString( cl->netchan.remoteAddress ); + ip = (char*)NET_AdrToString( &cl->netchan.remoteAddress ); val = Info_ValueForKey( cl->userinfo, "ip" ); if( val[0] ) diff --git a/codemp/server/sv_main.cpp b/codemp/server/sv_main.cpp index 1bb2f7daf6..3b29b4ca1d 100644 --- a/codemp/server/sv_main.cpp +++ b/codemp/server/sv_main.cpp @@ -273,15 +273,15 @@ void SV_MasterHeartbeat( void ) { if ( !strstr( ":", sv_master[i]->string ) ) { adr[i].port = BigShort( PORT_MASTER ); } - Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToString(adr[i]) ); + Com_Printf( "%s resolved to %s\n", sv_master[i]->string, NET_AdrToString(&adr[i]) ); - SVC_WhitelistAdr( adr[i] ); + SVC_WhitelistAdr( &adr[i] ); } Com_Printf ("Sending heartbeat to %s\n", sv_master[i]->string ); // this command should be changed if the server info / status format // ever incompatably changes - NET_OutOfBandPrint( NS_SERVER, adr[i], "heartbeat %s\n", HEARTBEAT_GAME ); + NET_OutOfBandPrint( NS_SERVER, &adr[i], "heartbeat %s\n", HEARTBEAT_GAME ); } } @@ -323,11 +323,11 @@ Find or allocate a bucket for an address */ #include -static leakyBucket_t *SVC_BucketForAddress( netadr_t address, int burst, int period, int now ) { +static leakyBucket_t *SVC_BucketForAddress( const netadr_t *address, int burst, int period, int now ) { static std::map bucketMap; static int lastGC = 0; - if (address.type != NA_IP) { + if (address->type != NA_IP) { return NULL; } @@ -361,7 +361,7 @@ static leakyBucket_t *SVC_BucketForAddress( netadr_t address, int burst, int per } } - return &bucketMap[address.ipi]; + return &bucketMap[address->ipi]; } /* @@ -402,7 +402,7 @@ SVC_RateLimitAddress Rate limit for a particular address ================ */ -qboolean SVC_RateLimitAddress( netadr_t from, int burst, int period, int now ) { +qboolean SVC_RateLimitAddress( const netadr_t *from, int burst, int period, int now ) { leakyBucket_t *bucket = SVC_BucketForAddress( from, burst, period, now ); return SVC_RateLimit( bucket, burst, period, now ); @@ -417,7 +417,7 @@ and all connected players. Used for getting detailed information after the simple info query. ================ */ -void SVC_Status( netadr_t from ) { +void SVC_Status( const netadr_t *from ) { char player[1024]; char status[MAX_MSGLEN]; int i; @@ -473,7 +473,7 @@ Responds with a short info message that should be enough to determine if a user is interested in a server to do a full status ================ */ -void SVC_Info( netadr_t from ) { +void SVC_Info( const netadr_t *from ) { int i, count, humans, wDisable; char *gamedir; char infostring[MAX_INFO_STRING]; @@ -560,7 +560,7 @@ SVC_FlushRedirect ================ */ void SV_FlushRedirect( char *outputbuf ) { - NET_OutOfBandPrint( NS_SERVER, svs.redirectAddress, "print\n%s", outputbuf ); + NET_OutOfBandPrint( NS_SERVER, &svs.redirectAddress, "print\n%s", outputbuf ); } /* @@ -572,7 +572,7 @@ Shift down the remaining args Redirect all printfs =============== */ -void SVC_RemoteCommand( netadr_t from, msg_t *msg ) { +void SVC_RemoteCommand( const netadr_t *from, msg_t *msg ) { qboolean valid; char remaining[1024]; // TTimo - scaled down to accumulate, but not overflow anything network wise, print wise etc. @@ -591,7 +591,7 @@ void SVC_RemoteCommand( netadr_t from, msg_t *msg ) { } // start redirecting all print outputs to the packet - svs.redirectAddress = from; + svs.redirectAddress = *from; Com_BeginRedirect (sv_outputbuf, SV_OUTPUTBUF_LENGTH, SV_FlushRedirect); if ( !strlen( sv_rconPassword->string ) ) { @@ -654,14 +654,14 @@ void SVC_LoadWhitelist( void ) { data = NULL; } -void SVC_WhitelistAdr( netadr_t adr ) { +void SVC_WhitelistAdr( const netadr_t *adr ) { fileHandle_t f; - if (adr.type != NA_IP) { + if (adr->type != NA_IP) { return; } - if (!svc_whitelist.insert(adr.ipi).second) { + if (!svc_whitelist.insert(adr->ipi).second) { return; } @@ -673,13 +673,13 @@ void SVC_WhitelistAdr( netadr_t adr ) { return; } - FS_Write(adr.ip, sizeof(adr.ip), f); + FS_Write(adr->ip, sizeof(adr->ip), f); FS_FCloseFile(f); } -static qboolean SVC_IsWhitelisted( netadr_t adr ) { - if (adr.type == NA_IP) { - return (qboolean)(svc_whitelist.find(adr.ipi) != svc_whitelist.end()); +static qboolean SVC_IsWhitelisted( const netadr_t *adr ) { + if (adr->type == NA_IP) { + return (qboolean)(svc_whitelist.find(adr->ipi) != svc_whitelist.end()); } else { return qtrue; } @@ -695,7 +695,7 @@ Clients that are in the game can still send connectionless packets. ================= */ -void SV_ConnectionlessPacket( netadr_t from, msg_t *msg ) { +void SV_ConnectionlessPacket( const netadr_t *from, msg_t *msg ) { static leakyBucket_t bucket; static int dropped = 0; static int lastMsg = 0; @@ -783,7 +783,7 @@ void SV_ConnectionlessPacket( netadr_t from, msg_t *msg ) { SV_ReadPackets ================= */ -void SV_PacketEvent( netadr_t from, msg_t *msg ) { +void SV_PacketEvent( const netadr_t *from, msg_t *msg ) { int i; client_t *cl; int qport; @@ -805,7 +805,7 @@ void SV_PacketEvent( netadr_t from, msg_t *msg ) { if (cl->state == CS_FREE) { continue; } - if ( !NET_CompareBaseAdr( from, cl->netchan.remoteAddress ) ) { + if ( !NET_CompareBaseAdr( from, &cl->netchan.remoteAddress ) ) { continue; } // it is possible to have multiple clients from a single IP @@ -817,9 +817,9 @@ void SV_PacketEvent( netadr_t from, msg_t *msg ) { // the IP port can't be used to differentiate them, because // some address translating routers periodically change UDP // port assignments - if (cl->netchan.remoteAddress.port != from.port) { + if (cl->netchan.remoteAddress.port != from->port) { Com_Printf( "SV_ReadPackets: fixing up a translated port\n" ); - cl->netchan.remoteAddress.port = from.port; + cl->netchan.remoteAddress.port = from->port; } // make sure it is a valid, in sequence packet @@ -1029,7 +1029,7 @@ void SV_CheckCvars( void ) { for (i = 0, cl = svs.clients; i < sv_maxclients->integer; i++, cl++) { // if the client is on the same subnet as the server and we aren't running an // internet public server, assume they don't need a rate choke - if (Sys_IsLANAddress(cl->netchan.remoteAddress) && com_dedicated->integer != 2 && sv_lanForceRate->integer == 1) { + if (Sys_IsLANAddress(&cl->netchan.remoteAddress) && com_dedicated->integer != 2 && sv_lanForceRate->integer == 1) { cl->rate = 100000; // lans should not rate limit } else { @@ -1049,7 +1049,7 @@ void SV_CheckCvars( void ) { for (i = 0, cl = svs.clients; i < sv_maxclients->integer; i++, cl++) { // if the client is on the same subnet as the server and we aren't running an // internet public server, assume they don't need a rate choke - if (Sys_IsLANAddress(cl->netchan.remoteAddress) && com_dedicated->integer != 2 && sv_lanForceRate->integer == 1) { + if (Sys_IsLANAddress(&cl->netchan.remoteAddress) && com_dedicated->integer != 2 && sv_lanForceRate->integer == 1) { cl->rate = 100000; // lans should not rate limit } else { diff --git a/codemp/server/sv_snapshot.cpp b/codemp/server/sv_snapshot.cpp index b8515bf376..5f844a9bf0 100644 --- a/codemp/server/sv_snapshot.cpp +++ b/codemp/server/sv_snapshot.cpp @@ -730,7 +730,7 @@ void SV_SendMessageToClient( msg_t *msg, client_t *client ) { // local clients get snapshots every server frame // TTimo - https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=491 // added sv_lanForceRate check - if ( client->netchan.remoteAddress.type == NA_LOOPBACK || (sv_lanForceRate->integer && Sys_IsLANAddress (client->netchan.remoteAddress)) ) { + if ( client->netchan.remoteAddress.type == NA_LOOPBACK || (sv_lanForceRate->integer && Sys_IsLANAddress (&client->netchan.remoteAddress)) ) { client->nextSnapshotTime = svs.time + ((int) (1000.0 / sv_fps->integer * com_timescale->value)); return; } diff --git a/shared/sys/sys_public.h b/shared/sys/sys_public.h index c93006a698..62e2244508 100644 --- a/shared/sys/sys_public.h +++ b/shared/sys/sys_public.h @@ -123,12 +123,12 @@ bool Sys_RandomBytes( byte *string, int len ); void Sys_SetErrorText( const char *text ); -void Sys_SendPacket( int length, const void *data, netadr_t to ); +void Sys_SendPacket( int length, const void *data, const netadr_t *to ); qboolean Sys_StringToAdr( const char *s, netadr_t *a ); //Does NOT parse port numbers, only base addresses. -qboolean Sys_IsLANAddress (netadr_t adr); +qboolean Sys_IsLANAddress (const netadr_t *adr); void Sys_ShowIP(void); qboolean Sys_Mkdir( const char *path );