Browse Source

engine: client: only accept server list from master servers (thanks @tyabus for idea)

pull/2/head
Alibek Omarov 2 years ago
parent
commit
01a3321d63
  1. 6
      engine/client/cl_main.c
  2. 1
      engine/common/common.h
  3. 33
      engine/common/masterlist.c

6
engine/client/cl_main.c

@ -2095,6 +2095,12 @@ void CL_ConnectionlessPacket( netadr_t from, sizebuf_t *msg )
} }
else if( !Q_strcmp( c, "f" )) else if( !Q_strcmp( c, "f" ))
{ {
if( !NET_IsMasterAdr( from ))
{
Con_Printf( S_WARN "unexpected server list packet from %s\n", NET_AdrToString( from ));
return;
}
// serverlist got from masterserver // serverlist got from masterserver
while( MSG_GetNumBitsLeft( msg ) > 8 ) while( MSG_GetNumBitsLeft( msg ) > 8 )
{ {

1
engine/common/common.h

@ -868,6 +868,7 @@ void GAME_EXPORT ID_SetCustomClientID( const char *id );
void NET_InitMasters( void ); void NET_InitMasters( void );
void NET_SaveMasters( void ); void NET_SaveMasters( void );
qboolean NET_SendToMasters( netsrc_t sock, size_t len, const void *data ); qboolean NET_SendToMasters( netsrc_t sock, size_t len, const void *data );
qboolean NET_IsMasterAdr( netadr_t adr );
#ifdef REF_DLL #ifdef REF_DLL
#error "common.h in ref_dll" #error "common.h in ref_dll"

33
engine/common/masterlist.c

@ -21,6 +21,7 @@ typedef struct master_s
qboolean sent; qboolean sent;
qboolean save; qboolean save;
string address; string address;
netadr_t adr; // temporary, rewritten after each send
} master_t; } master_t;
struct masterlist_s struct masterlist_s
@ -44,31 +45,32 @@ qboolean NET_SendToMasters( netsrc_t sock, size_t len, const void *data )
for( list = ml.list; list; list = list->next ) for( list = ml.list; list; list = list->next )
{ {
netadr_t adr;
int res; int res;
if( list->sent ) if( list->sent )
continue; continue;
res = NET_StringToAdrNB( list->address, &adr ); res = NET_StringToAdrNB( list->address, &list->adr );
if( !res ) if( !res )
{ {
Con_Reportf( "Can't resolve adr: %s\n", list->address ); Con_Reportf( "Can't resolve adr: %s\n", list->address );
list->sent = true; list->sent = true;
list->adr.type = NA_UNUSED;
continue; continue;
} }
if( res == 2 ) if( res == 2 )
{ {
list->sent = false; list->sent = false;
list->adr.type = NA_UNUSED;
wait = true; wait = true;
continue; continue;
} }
list->sent = true; list->sent = true;
NET_SendPacket( sock, len, data, adr ); NET_SendPacket( sock, len, data, list->adr );
} }
if( !wait ) if( !wait )
@ -85,6 +87,25 @@ qboolean NET_SendToMasters( netsrc_t sock, size_t len, const void *data )
return wait; return wait;
} }
/*
========================
NET_IsMasterAdr
========================
*/
qboolean NET_IsMasterAdr( netadr_t adr )
{
master_t *master;
for( master = ml.list; master; master = master->next )
{
if( NET_CompareAdr( adr, master->adr ))
return true;
}
return false;
}
/* /*
======================== ========================
NET_AddMaster NET_AddMaster
@ -107,6 +128,7 @@ static void NET_AddMaster( const char *addr, qboolean save )
master->sent = false; master->sent = false;
master->save = save; master->save = save;
master->next = NULL; master->next = NULL;
master->adr.type = NA_UNUSED;
// link in // link in
if( last ) if( last )
@ -161,7 +183,10 @@ static void NET_ListMasters_f( void )
for( i = 1, list = ml.list; list; i++, list = list->next ) for( i = 1, list = ml.list; list; i++, list = list->next )
{ {
Msg( "%d\t%s\n", i, list->address ); Msg( "%d\t%s", i, list->address );
if( list->adr.type != NA_UNUSED )
Msg( "\t%s\n", NET_AdrToString( list->adr ));
else Msg( "\n" );
} }
} }

Loading…
Cancel
Save