MCPcopy Create free account
hub / github.com/GarageGames/Torque2D / pickMasterServer

Function pickMasterServer

engine/source/network/serverQuery.cc:675–714  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

673//-----------------------------------------------------------------------------
674
675bool pickMasterServer()
676{
677 // Reset the master server ping:
678 gMasterServerPing.time = 0;
679 gMasterServerPing.key = 0;
680 gMasterServerPing.tryCount = gMasterServerRetryCount;
681 gMasterServerPing.session = gPingSession;
682
683 char addrString[256];
684 U32 serverCount = gMasterServerList.size();
685 if ( !serverCount )
686 {
687 // There are no more servers left to try...:(
688 return( false );
689 }
690
691 U32 region = Con::getIntVariable( "$pref::Net::RegionMask" );
692 U32 index = Sim::getCurrentTime() % serverCount;
693
694 // First try to find a master server in the same region:
695 for ( U32 i = 0; i < serverCount; i++ )
696 {
697 if ( gMasterServerList[index].region == region )
698 {
699 Net::addressToString( &gMasterServerList[index].address, addrString );
700 Con::printf( "Found master server %s in same region.", addrString );
701 gMasterServerPing.address = gMasterServerList[index].address;
702 return( true );
703 }
704
705 index = index < serverCount - 1 ? index + 1 : 0;
706 }
707
708 // Settle for the one we first picked:
709 Net::addressToString( &gMasterServerList[index].address, addrString );
710 Con::printf( "No master servers found in this region, trying %s.", addrString );
711 gMasterServerPing.address = gMasterServerList[index].address;
712
713 return( true );
714}
715
716//-----------------------------------------------------------------------------
717

Callers 2

queryMasterServerFunction · 0.85
processMasterServerQueryFunction · 0.85

Calls 4

getIntVariableFunction · 0.85
getCurrentTimeFunction · 0.85
printfFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected