diff --git a/codemp/client/cl_input.cpp b/codemp/client/cl_input.cpp index 10b6fddaa4..1a4019ecf8 100644 --- a/codemp/client/cl_input.cpp +++ b/codemp/client/cl_input.cpp @@ -1510,7 +1510,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 ad2fd5acd8..aba09ba0ef 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; @@ -316,7 +316,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 2eb0da9e54..70b86b3ee1 100644 --- a/codemp/client/cl_main.cpp +++ b/codemp/client/cl_main.cpp @@ -176,7 +176,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 ); /* @@ -325,10 +325,9 @@ 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 .. - //^kill yourself - /*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"); - }*/ + } if (protocolswitch->integer != 2) Com_sprintf(extension, sizeof(extension), "dm_%d", PROTOCOL_VERSION); @@ -1042,7 +1041,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; @@ -1068,7 +1067,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 ); } @@ -1177,7 +1176,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 ); @@ -1187,7 +1186,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; @@ -1271,7 +1270,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); } /* @@ -1768,13 +1767,13 @@ void CL_CheckForResend( void ) { if (!localserver) { Cvar_Set("protocolswitch", "0"); //reset this here, just to be safe? - NET_OutOfBandPrint(NS_CLIENT, clc.serverAddress, "getinfo"); //request serverinfo so we know what protocol to use + NET_OutOfBandPrint(NS_CLIENT, &clc.serverAddress, "getinfo"); //request serverinfo so we know what protocol to use } // 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: @@ -1800,7 +1799,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 @@ -1823,13 +1822,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; } @@ -1852,12 +1851,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; } @@ -1880,7 +1879,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->filterBots = 0; @@ -1914,7 +1913,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 @@ -1980,7 +1979,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; } @@ -2089,7 +2088,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; @@ -2120,7 +2119,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 @@ -2141,7 +2140,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; } @@ -2156,7 +2155,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; } @@ -2207,7 +2206,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]; @@ -2221,7 +2220,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; } @@ -2236,7 +2235,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; @@ -2258,7 +2257,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 ) ); @@ -2977,7 +2976,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: @@ -3639,23 +3638,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); } } @@ -3665,7 +3664,7 @@ void CL_SetServerFakeInfoByAddress(netadr_t from, int clients, int bots) { 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)) { if (clients != -1) { cls.localServers[i].clients = clients; cls.localServers[i].filterBots = bots; @@ -3674,7 +3673,7 @@ void CL_SetServerFakeInfoByAddress(netadr_t from, int clients, int bots) { } for (i = 0; i < MAX_GLOBAL_SERVERS; i++) { - if (NET_CompareAdr(from, cls.globalServers[i].adr)) { + if (NET_CompareAdr(&from, &cls.globalServers[i].adr)) { if (clients != -1) { cls.globalServers[i].clients = clients; cls.globalServers[i].filterBots = bots; @@ -3683,7 +3682,7 @@ void CL_SetServerFakeInfoByAddress(netadr_t from, int clients, int bots) { } for (i = 0; i < MAX_OTHER_SERVERS; i++) { - if (NET_CompareAdr(from, cls.favoriteServers[i].adr)) { + if (NET_CompareAdr(&from, &cls.favoriteServers[i].adr)) { if (clients != -1) { cls.favoriteServers[i].clients = clients; cls.favoriteServers[i].filterBots = bots; @@ -3697,7 +3696,7 @@ void CL_SetServerFakeInfoByAddress(netadr_t from, int clients, int bots) { 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; @@ -3713,7 +3712,7 @@ void CL_ServerInfoPacket( netadr_t from, msg_t *msg ) { } //multiprotocol "support" - if ((cls.state == CA_CONNECTING || cls.state == CA_CHALLENGING) && NET_CompareAdr(from, clc.serverAddress) && !Cvar_VariableIntegerValue("sv_running")) + if ((cls.state == CA_CONNECTING || cls.state == CA_CHALLENGING) && NET_CompareAdr(from, &clc.serverAddress) && !Cvar_VariableIntegerValue("sv_running")) { if (prot == PROTOCOL_VERSION) { Cvar_Set("protocolswitch", "1"); @@ -3763,7 +3762,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: @@ -3806,7 +3805,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; } } @@ -3818,7 +3817,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)) { @@ -3834,11 +3833,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]; } } @@ -3884,7 +3883,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; @@ -3892,7 +3891,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); @@ -3907,8 +3906,8 @@ 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, "getinfo"); - NET_OutOfBandPrint( NS_CLIENT, to, "getstatus" ); + NET_OutOfBandPrint(NS_CLIENT, &to, "getinfo"); + NET_OutOfBandPrint( NS_CLIENT, &to, "getstatus" ); return qfalse; } } @@ -3920,8 +3919,8 @@ 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, "getinfo"); - NET_OutOfBandPrint( NS_CLIENT, to, "getstatus" ); + NET_OutOfBandPrint(NS_CLIENT, &to, "getinfo"); + NET_OutOfBandPrint( NS_CLIENT, &to, "getstatus" ); return qfalse; } return qfalse; @@ -3932,7 +3931,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; @@ -3940,11 +3939,11 @@ void CL_ServerStatusResponse( netadr_t from, msg_t *msg ) { int bots; serverStatus_t *serverStatus; - CL_SetServerFakeInfoByAddress(from, -1, -1); + CL_SetServerFakeInfoByAddress(*from, -1, -1); 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; } @@ -3961,7 +3960,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) { @@ -4022,13 +4021,13 @@ void CL_ServerStatusResponse( netadr_t from, msg_t *msg ) { } } - CL_SetServerFakeInfoByAddress(from, i, bots); + CL_SetServerFakeInfoByAddress(*from, i, bots); len = strlen(serverStatus->string); 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; @@ -4072,7 +4071,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 ); } } } @@ -4145,7 +4144,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; @@ -4159,7 +4158,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 ); } /* @@ -4181,7 +4180,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; @@ -4200,7 +4199,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; } @@ -4345,9 +4344,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" ); } /* @@ -4400,7 +4399,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; } @@ -4415,16 +4414,16 @@ 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" ); - serverStatus_t *serverStatus = CL_GetServerStatus(cl_pinglist[j].adr); + serverStatus_t *serverStatus = CL_GetServerStatus(&cl_pinglist[j].adr); serverStatus->address = cl_pinglist[j].adr; serverStatus->print = qfalse; serverStatus->pending = qtrue; serverStatus->retrieved = qfalse; serverStatus->startTime = Com_Milliseconds(); serverStatus->time = 0; - NET_OutOfBandPrint(NS_CLIENT, cl_pinglist[j].adr, "getstatus"); + NET_OutOfBandPrint(NS_CLIENT, &cl_pinglist[j].adr, "getstatus"); slots++; } @@ -4495,9 +4494,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 f4e029b276..4d2b1f232b 100644 --- a/codemp/client/client.h +++ b/codemp/client/client.h @@ -593,7 +593,7 @@ void CL_KillDownload(); //==================================================================== -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/null/null_client.cpp b/codemp/null/null_client.cpp index a0bafab5fa..fff73ff1c0 100644 --- a/codemp/null/null_client.cpp +++ b/codemp/null/null_client.cpp @@ -41,7 +41,7 @@ void Key_WriteBindings( fileHandle_t f ) { void CL_Frame ( int msec ) { } -void CL_PacketEvent( netadr_t from, msg_t *msg ) { +void CL_PacketEvent( const netadr_t *from, msg_t *msg ) { } void CL_CharEvent( int key ) { diff --git a/codemp/qcommon/common.cpp b/codemp/qcommon/common.cpp index 3e9c403c03..09ffe7208c 100755 --- a/codemp/qcommon/common.cpp +++ b/codemp/qcommon/common.cpp @@ -1057,7 +1057,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; @@ -1066,7 +1066,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 (); @@ -1099,7 +1099,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 595ef8d0dd..4daeac0b3e 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; @@ -484,7 +484,7 @@ static SOCKET NET_IPSocket( const 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 ) { @@ -1042,7 +1042,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 175cfe270c..0c30e1de8f 100755 --- a/codemp/qcommon/qcommon.h +++ b/codemp/qcommon/qcommon.h @@ -156,23 +156,23 @@ void NET_HTTP_StopServer(); dlHandle_t NET_HTTP_StartDownload(const char *url, const char *toPath, dl_ended_callback ended_callback, dl_status_callback status_callback); void NET_HTTP_StopDownload(dlHandle_t handle); -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); @@ -199,7 +199,7 @@ typedef struct bufferedMsg_s { int readcount; int bit; // for bitwise reads and writes public: - bufferedMsg_s(msg_t* src) { + bufferedMsg_s(msg_t* src) { allowoverflow = src->allowoverflow; overflowed = src->overflowed; oob = src->oob; @@ -268,7 +268,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 ); @@ -852,7 +852,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 @@ -1026,7 +1026,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 ); @@ -1074,7 +1074,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 565a99d467..ae68f33d02 100644 --- a/codemp/server/server.h +++ b/codemp/server/server.h @@ -372,9 +372,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, ...); @@ -409,15 +409,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 24fe107ddf..0cacc273eb 100755 --- a/codemp/server/sv_ccmds.cpp +++ b/codemp/server/sv_ccmds.cpp @@ -714,7 +714,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 ); } @@ -879,24 +879,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; } @@ -909,7 +909,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++; @@ -924,7 +924,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 ); } /* @@ -973,11 +973,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 ); } @@ -1005,7 +1005,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 ); @@ -1047,7 +1047,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 @@ -1059,7 +1059,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 ); } } } @@ -1210,7 +1210,7 @@ static void SV_Status_f( void ) } ps = SV_GameClientNum( i ); - s = NET_AdrToString( cl->netchan.remoteAddress ); + s = NET_AdrToString( &cl->netchan.remoteAddress ); Com_Printf("%2i %5i %s %5i %22s %s^7\n", i, ps->persistant[PERS_SCORE], state, cl->rate, s, cl->name);//No need for truncation "feature" if we move name to end } @@ -2280,8 +2280,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 86dda1587d..eff30e37e5 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 @@ -311,7 +311,7 @@ void SV_DirectConnect( netadr_t from ) { // save the address Netchan_Setup (NS_SERVER, &newcl->netchan , from, qport); - NET_HTTP_AllowClient( clientNum, from ); + NET_HTTP_AllowClient( clientNum, *from ); // save the userinfo Q_strncpyz( newcl->userinfo, userinfo, sizeof(newcl->userinfo) ); @@ -584,7 +584,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 @@ -1199,7 +1199,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"); @@ -1253,10 +1253,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_init.cpp b/codemp/server/sv_init.cpp index f9cf579d08..2c2d8b7824 100644 --- a/codemp/server/sv_init.cpp +++ b/codemp/server/sv_init.cpp @@ -572,7 +572,7 @@ Ghoul2 Insert End for (i=0 ; iinteger ; i++) { // save when the server started for each client already connected if (svs.clients[i].state >= CS_CONNECTED) { - svs.clients[i].oldServerTime = svs.time; + svs.clients[i].oldServerTime = sv.time; } } diff --git a/codemp/server/sv_main.cpp b/codemp/server/sv_main.cpp index c1310532e2..41a7b7d18a 100644 --- a/codemp/server/sv_main.cpp +++ b/codemp/server/sv_main.cpp @@ -295,16 +295,16 @@ 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] ); } if (com_developer->integer) 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 ); } } @@ -346,11 +346,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; } @@ -384,7 +384,7 @@ static leakyBucket_t *SVC_BucketForAddress( netadr_t address, int burst, int per } } - return &bucketMap[address.ipi]; + return &bucketMap[address->ipi]; } /* @@ -425,7 +425,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 ); @@ -440,7 +440,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; @@ -496,7 +496,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]; @@ -594,7 +594,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 ); } /* @@ -606,7 +606,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. @@ -625,7 +625,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 ) ) { @@ -688,14 +688,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; } @@ -707,13 +707,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; } @@ -729,7 +729,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; @@ -817,7 +817,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; @@ -839,7 +839,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 @@ -851,9 +851,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 @@ -1067,7 +1067,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 { @@ -1087,7 +1087,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 7ca30d3378..8bbc86db45 100644 --- a/codemp/server/sv_snapshot.cpp +++ b/codemp/server/sv_snapshot.cpp @@ -927,7 +927,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 0e5fe1d200..a281c62add 100644 --- a/shared/sys/sys_public.h +++ b/shared/sys/sys_public.h @@ -125,12 +125,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 );