Core.Object | +--Engine.Actor | +--Engine.Info | +--Engine.InternetInfo | +--IpDrv.InternetLink | +--IpDrv.TcpLink | +--UBrowser.UBrowserBufferedTcpLink | +--UBrowser.UBrowserGSpyLink
string
CouldNotConnectError
GameName
MasterServerAddress
IpAddr
MasterServerIpAddr
int
MasterServerTCPPort
MasterServerTimeout
UBrowserGSpyFact
OwnerFactory
Region
ResolveFailedError
TimeOutError
bool
bOpened
void
BeginPlay()
// for WaitFor
DoBufferQueueIO()
GotMatch(int MatchData)
GotMatchTimeout(int MatchData)
HandleServer(string Text)
ResolveFailed()
// Host resolution failue.
Resolved(IpAddr Addr)
Start()
Tick(float DeltaTime)
Tick(float Delta)
00001 class UBrowserGSpyLink extends UBrowserBufferedTcpLink; 00002 00003 // Misc 00004 var UBrowserGSpyFact OwnerFactory; 00005 var IpAddr MasterServerIpAddr; 00006 var bool bOpened; 00007 00008 // Params 00009 var string MasterServerAddress; // Address of the master server 00010 var int MasterServerTCPPort; // Optional port that the master server is listening on 00011 var int Region; // Region of the game server 00012 var int MasterServerTimeout; 00013 var string GameName; 00014 00015 // Error messages 00016 var localized string ResolveFailedError; 00017 var localized string TimeOutError; 00018 var localized string CouldNotConnectError; 00019 00020 // for WaitFor 00021 const FoundSecureRequest = 1; 00022 const FoundSecret = 2; 00023 const NextIP = 3; 00024 const NextAddress = 4; 00025 00026 function BeginPlay() 00027 { 00028 Disable('Tick'); 00029 Super.BeginPlay(); 00030 } 00031 00032 function Start() 00033 { 00034 ResetBuffer(); 00035 00036 MasterServerIpAddr.Port = MasterServerTCPPort; 00037 00038 if( MasterServerAddress=="" ) 00039 MasterServerAddress = "master"$Region$".gamespy.com"; 00040 00041 Resolve( MasterServerAddress ); 00042 } 00043 00044 function DoBufferQueueIO() 00045 { 00046 Super.DoBufferQueueIO(); 00047 } 00048 00049 function Resolved( IpAddr Addr ) 00050 { 00051 // Set the address 00052 MasterServerIpAddr.Addr = Addr.Addr; 00053 00054 // Handle failure. 00055 if( MasterServerIpAddr.Addr == 0 ) 00056 { 00057 Log( "UBrowserGSpyLink: Invalid master server address, aborting." ); 00058 return; 00059 } 00060 00061 // Display success message. 00062 Log( "UBrowserGSpyLink: Master Server is "$MasterServerAddress$":"$MasterServerIpAddr.Port ); 00063 00064 // Bind the local port. 00065 if( BindPort() == 0 ) 00066 { 00067 Log( "UBrowserGSpyLink: Error binding local port, aborting." ); 00068 return; 00069 } 00070 00071 Open( MasterServerIpAddr ); 00072 SetTimer(MasterServerTimeout, False); 00073 } 00074 00075 event Timer() 00076 { 00077 if(!bOpened) 00078 { 00079 Log("UBrowserGSpyLink: Couldn't connect to master server."); 00080 OwnerFactory.QueryFinished(False, CouldNotConnectError$MasterServerAddress); 00081 GotoState('Done'); 00082 } 00083 } 00084 00085 event Closed() 00086 { 00087 } 00088 00089 // Host resolution failue. 00090 function ResolveFailed() 00091 { 00092 Log("UBrowserGSpyLink: Failed to resolve master server address, aborting."); 00093 OwnerFactory.QueryFinished(False, ResolveFailedError$MasterServerAddress); 00094 GotoState('Done'); 00095 } 00096 00097 event Opened() 00098 { 00099 bOpened = True; 00100 Enable('Tick'); 00101 00102 WaitFor("\\basic\\\\secure\\", 5, FoundSecureRequest); 00103 } 00104 00105 00106 function Tick(float DeltaTime) 00107 { 00108 DoBufferQueueIO(); 00109 } 00110 00111 00112 function HandleServer(string Text) 00113 { 00114 local string Address; 00115 local string Port; 00116 00117 Address = ParseDelimited(Text, ":", 1); 00118 Port = ParseDelimited(ParseDelimited(Text, ":", 2), "\\", 1); 00119 00120 OwnerFactory.FoundServer(Address, int(Port), "", GameName); 00121 } 00122 00123 00124 function GotMatch(int MatchData) 00125 { 00126 00127 switch(MatchData) 00128 { 00129 case FoundSecureRequest: 00130 Enable('Tick'); 00131 WaitForCount(6, 5, FoundSecret); 00132 break; 00133 case FoundSecret: 00134 Enable('Tick'); 00135 SendBufferedData("\\gamename\\"$GameName$"\\location\\"$Region$"\\validate\\"$Validate(WaitResult, GameName)$"\\final\\"); 00136 GotoState('FoundSecretState'); 00137 break; 00138 case NextIP: 00139 Enable('Tick'); 00140 if(WaitResult == "final\\") 00141 { 00142 OwnerFactory.QueryFinished(True); 00143 GotoState('Done'); 00144 } 00145 else 00146 WaitFor("\\", 10, NextAddress); 00147 break; 00148 case NextAddress: 00149 Enable('Tick'); 00150 HandleServer(WaitResult); 00151 WaitFor("\\", 5, NextIP); 00152 break; 00153 default: 00154 break; 00155 } 00156 } 00157 00158 function GotMatchTimeout(int MatchData) 00159 { 00160 Log("Timed out in master server protocol. Waiting for "$WaitingFor$" in state "$MatchData); 00161 OwnerFactory.QueryFinished(False, TimeOutError); 00162 GotoState('Done'); 00163 } 00164 00165 // States 00166 state FoundSecretState 00167 { 00168 function Tick(float Delta) 00169 { 00170 Global.Tick(Delta); 00171 00172 // Hack for 0 servers in server list 00173 if(!IsConnected() && WaitResult == "\\final\\") 00174 { 00175 OwnerFactory.QueryFinished(True); 00176 GotoState('Done'); 00177 } 00178 } 00179 00180 Begin: 00181 Enable('Tick'); 00182 SendBufferedData("\\list\\\\gamename\\"$GameName$"\\final\\"); 00183 WaitFor("ip\\", 30, NextIP); 00184 } 00185 00186 state Done 00187 { 00188 Begin: 00189 Disable('Tick'); 00190 } 00191 00192 defaultproperties 00193 { 00194 ResolveFailedError="The master server could not be resolved: " 00195 TimeOutError="Timeout talking to the master server" 00196 CouldNotConnectError="Connecting to the master server timed out: " 00197 }