Skip to content

Commit e10f298

Browse files
committed
engine(masterserver): fix servers duplication
1 parent c3417ca commit e10f298

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

engine/master.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class IMaster
4646
// Master sent back a challenge value, read it and send the actual heartbeat
4747
virtual void RespondToHeartbeatChallenge( netadr_t &from, bf_read &msg ) = 0;
4848
// Console command to set/remove master server
49-
virtual void SetMaster_f( const CCommand &args ) = 0;
49+
virtual void AddMaster_f( const CCommand &args ) = 0;
5050
// Force a heartbeat to be issued right away
5151
virtual void Heartbeat_f( void ) = 0;
5252

engine/masterserver.cpp

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class CMaster : public IMaster, public IServersInfo
7676

7777
void ProcessConnectionlessPacket( netpacket_t *packet );
7878

79-
void SetMaster_f( const CCommand &args );
79+
void AddMaster_f( const CCommand &args );
8080
void Heartbeat_f( void );
8181

8282
void RunFrame();
@@ -89,15 +89,15 @@ class CMaster : public IMaster, public IServersInfo
8989
void RequestInternetServerList( const char *gamedir, IServerListResponse *response );
9090
void RequestLANServerList( const char *gamedir, IServerListResponse *response );
9191
void AddServerAddresses( netadr_t **adr, int count );
92-
void StopRefresh();
9392
void RequestServerInfo( const netadr_t &adr );
93+
void StopRefresh();
9494

9595
private:
9696
// List of known master servers
9797
adrlist_t *m_pMasterAddresses;
9898

9999
bool m_bInitialized;
100-
bool m_bWaitingForReplys;
100+
bool m_bRefreshing;
101101

102102
int m_iServersResponded;
103103

@@ -139,7 +139,7 @@ CMaster::CMaster( void )
139139
m_serverListResponse = NULL;
140140
SetDefLessFunc( m_serverAddresses );
141141
SetDefLessFunc( m_serversRequestTime );
142-
m_bWaitingForReplys = false;
142+
m_bRefreshing = false;
143143
m_iInfoSequence = 1;
144144

145145
Init();
@@ -153,14 +153,14 @@ void CMaster::RunFrame()
153153
{
154154
CheckHeartbeat();
155155

156-
if( !m_bWaitingForReplys )
156+
if( !m_bRefreshing )
157157
return;
158158

159159
if( m_serverListResponse &&
160-
m_flStartRequestTime < Plat_FloatTime()-INFO_REQUEST_TIMEOUT )
160+
m_flStartRequestTime < Plat_FloatTime()-INFO_REQUEST_TIMEOUT )
161161
{
162-
m_serverListResponse->RefreshComplete( NServerResponse::nServerFailedToRespond );
163162
StopRefresh();
163+
m_serverListResponse->RefreshComplete( NServerResponse::nServerFailedToRespond );
164164
return;
165165
}
166166

@@ -190,11 +190,11 @@ void CMaster::RunFrame()
190190

191191
void CMaster::StopRefresh()
192192
{
193-
if( !m_bWaitingForReplys )
193+
if( !m_bRefreshing )
194194
return;
195195

196196
m_iServersResponded = 0;
197-
m_bWaitingForReplys = false;
197+
m_bRefreshing = false;
198198
m_serverAddresses.RemoveAll();
199199
m_serversRequestTime.RemoveAll();
200200
}
@@ -235,9 +235,7 @@ void CMaster::ReplyInfo( const netadr_t &adr, uint sequence )
235235
buf.PutUnsignedInt( nFlags );
236236

237237
if ( nFlags & S2A_EXTRA_DATA_HAS_GAMETAG_DATA )
238-
{
239238
buf.PutString( pchTags );
240-
}
241239

242240
NET_SendPacket( NULL, NS_SERVER, adr, (unsigned char *)buf.Base(), buf.TellPut() );
243241
}
@@ -293,6 +291,9 @@ void CMaster::ProcessConnectionlessPacket( netpacket_t *packet )
293291
}
294292
case M2C_QUERY:
295293
{
294+
if( !m_bRefreshing )
295+
break;
296+
296297
ip = msg.ReadLong();
297298
port = msg.ReadShort();
298299

@@ -323,6 +324,9 @@ void CMaster::ProcessConnectionlessPacket( netpacket_t *packet )
323324
}
324325
case S2C_INFOREPLY:
325326
{
327+
if( !m_bRefreshing )
328+
break;
329+
326330
uint sequence = msg.ReadLong();
327331
newgameserver_t &s = ProcessInfo( msg );
328332

@@ -584,7 +588,7 @@ void CMaster::RespondToHeartbeatChallenge( netadr_t &from, bf_read &msg )
584588
//-----------------------------------------------------------------------------
585589
// Purpose: Add/remove master servers
586590
//-----------------------------------------------------------------------------
587-
void CMaster::SetMaster_f ( const CCommand &args )
591+
void CMaster::AddMaster_f ( const CCommand &args )
588592
{
589593
CUtlString cmd( ( args.ArgC() > 1 ) ? args[ 1 ] : "" );
590594

@@ -620,9 +624,9 @@ void CMaster::Heartbeat_f (void)
620624
//-----------------------------------------------------------------------------
621625
// Purpose:
622626
//-----------------------------------------------------------------------------
623-
void SetMaster_f( const CCommand &args )
627+
void AddMaster_f( const CCommand &args )
624628
{
625-
master->SetMaster_f( args );
629+
master->AddMaster_f( args );
626630
}
627631

628632
//-----------------------------------------------------------------------------
@@ -633,7 +637,7 @@ void Heartbeat1_f( void )
633637
master->Heartbeat_f();
634638
}
635639

636-
static ConCommand setmaster("setmaster", SetMaster_f );
640+
static ConCommand setmaster("addmaster", AddMaster_f );
637641
static ConCommand heartbeat("heartbeat", Heartbeat1_f, "Force heartbeat of master servers" );
638642

639643
//-----------------------------------------------------------------------------
@@ -679,7 +683,7 @@ void CMaster::RequestInternetServerList(const char *gamedir, IServerListResponse
679683
if( response )
680684
{
681685
StopRefresh();
682-
m_bWaitingForReplys = true;
686+
m_bRefreshing = true;
683687
m_serverListResponse = response;
684688
m_flRetryRequestTime = m_flStartRequestTime = m_flMasterRequestTime = Plat_FloatTime();
685689
}

0 commit comments

Comments
 (0)