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

Function pickMasterServer

Engine/source/app/net/serverQuery.cpp:818–857  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

816//-----------------------------------------------------------------------------
817
818bool pickMasterServer()
819{
820 // Reset the master server ping:
821 gMasterServerPing.time = 0;
822 gMasterServerPing.key = 0;
823 gMasterServerPing.tryCount = gMasterServerRetryCount;
824 gMasterServerPing.session = gPingSession;
825
826 char addrString[256];
827 U32 serverCount = gMasterServerList.size();
828 if ( !serverCount )
829 {
830 // There are no more servers left to try...:(
831 return( false );
832 }
833
834 U32 region = Con::getIntVariable( "$pref::Net::RegionMask" );
835 U32 index = Sim::getCurrentTime() % serverCount;
836
837 // First try to find a master server in the same region:
838 for ( U32 i = 0; i < serverCount; i++ )
839 {
840 if ( gMasterServerList[index].region == region )
841 {
842 Net::addressToString( &gMasterServerList[index].address, addrString );
843 Con::printf( "Found master server %s in same region.", addrString );
844 gMasterServerPing.address = gMasterServerList[index].address;
845 return( true );
846 }
847
848 index = index < serverCount - 1 ? index + 1 : 0;
849 }
850
851 // Settle for the one we first picked:
852 Net::addressToString( &gMasterServerList[index].address, addrString );
853 Con::printf( "No master servers found in this region, trying %s.", addrString );
854 gMasterServerPing.address = gMasterServerList[index].address;
855
856 return( true );
857}
858
859//-----------------------------------------------------------------------------
860

Callers 2

queryMasterServerFunction · 0.85
processMasterServerQueryFunction · 0.85

Calls 4

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

Tested by

no test coverage detected