From 39a04df7a0477708c11dae6e45e99c6da33e20d7 Mon Sep 17 00:00:00 2001 From: Ben Millwood Date: Sat, 3 Oct 2009 13:15:18 +0000 Subject: * Convert master address resolution to IPv6-compatible API * MOTD parsing should use the whole string rather than just arg1 --- src/client/cl_main.c | 34 ++++++++++++++++++++++++---------- src/server/sv_main.c | 31 ++++++++++++++++--------------- 2 files changed, 40 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/client/cl_main.c b/src/client/cl_main.c index 9e2add18..16ddcffc 100644 --- a/src/client/cl_main.c +++ b/src/client/cl_main.c @@ -1336,15 +1336,22 @@ void CL_RequestMotd( void ) { return; } Com_Printf( "Resolving %s\n", MASTER_SERVER_NAME ); - if ( !NET_StringToAdr( MASTER_SERVER_NAME, &cls.updateServer, NA_IP ) ) { - Com_Printf( "Couldn't resolve address\n" ); - return; + + switch( NET_StringToAdr( MASTER_SERVER_NAME, &cls.updateServer, + NA_UNSPEC ) ) + { + case 0: + Com_Printf( "Couldn't resolve master address\n" ); + return; + + case 2: + cls.updateServer.port = BigShort( PORT_MASTER ); + default: + break; } - cls.updateServer.port = BigShort( PORT_MASTER ); - Com_Printf( "%s resolved to %i.%i.%i.%i:%i\n", MASTER_SERVER_NAME, - cls.updateServer.ip[0], cls.updateServer.ip[1], - cls.updateServer.ip[2], cls.updateServer.ip[3], - BigShort( cls.updateServer.port ) ); + + Com_Printf( "%s resolved to %s\n", MASTER_SERVER_NAME, + NET_AdrToStringwPort( cls.updateServer ) ); info[0] = 0; // NOTE TTimo xoring against Com_Milliseconds, otherwise we may not have a true randomization @@ -2197,16 +2204,23 @@ CL_MotdPacket =================== */ void CL_MotdPacket( netadr_t from, const char *info ) { - char *v; + const char *v; // if not from our server, ignore it if ( !NET_CompareAdr( from, cls.updateServer ) ) { + Com_DPrintf( "MOTD packet from unexpected source\n" ); return; } + Com_DPrintf( "MOTD packet: %s\n", info ); + while( *info != '\\' ) + info++; + // check challenge v = Info_ValueForKey( info, "challenge" ); if ( strcmp( v, cls.updateChallenge ) ) { + Com_DPrintf( "MOTD packet mismatched challenge: " + "'%s' != '%s'\n", v, cls.updateChallenge ); return; } @@ -2438,7 +2452,7 @@ void CL_ConnectionlessPacket( netadr_t from, msg_t *msg ) { // global MOTD from trem master if ( !Q_stricmp(c, "motd") ) { - CL_MotdPacket( from, arg1 ); + CL_MotdPacket( from, s ); return; } diff --git a/src/server/sv_main.c b/src/server/sv_main.c index 01da0f5d..305cf299 100644 --- a/src/server/sv_main.c +++ b/src/server/sv_main.c @@ -299,28 +299,29 @@ SV_MasterGameStat */ void SV_MasterGameStat( const char *data ) { - static netadr_t adr; + netadr_t adr; - if( !com_dedicated || com_dedicated->integer != 2 ) - return; // only dedicated servers send stats + if( !com_dedicated || com_dedicated->integer != 2 ) + return; // only dedicated servers send stats Com_Printf( "Resolving %s\n", MASTER_SERVER_NAME ); - if( !NET_StringToAdr( MASTER_SERVER_NAME, &adr, NA_IP ) ) - { - Com_Printf( "Couldn't resolve address: %s\n", MASTER_SERVER_NAME ); - return; - } - else + + switch( NET_StringToAdr( MASTER_SERVER_NAME, &adr, NA_UNSPEC ) ) { - if( !strstr( ":", MASTER_SERVER_NAME ) ) - adr.port = BigShort( PORT_MASTER ); + case 0: + Com_Printf( "Couldn't resolve master address: %s\n", MASTER_SERVER_NAME ); + return; - Com_Printf( "%s resolved to %i.%i.%i.%i:%i\n", MASTER_SERVER_NAME, - adr.ip[0], adr.ip[1], adr.ip[2], adr.ip[3], - BigShort( adr.port ) ); + case 2: + adr.port = BigShort( PORT_MASTER ); + default: + break; } - Com_Printf ("Sending gamestat to %s\n", MASTER_SERVER_NAME ); + Com_Printf( "%s resolved to %s\n", MASTER_SERVER_NAME, + NET_AdrToStringwPort( adr ) ); + + Com_Printf( "Sending gamestat to %s\n", MASTER_SERVER_NAME ); NET_OutOfBandPrint( NS_SERVER, adr, "gamestat %s", data ); } -- cgit