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

Function pickMasterServer

Engine/source/app/net/serverQuery.cpp:819–858  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

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