Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

UBrowser.UBrowserGSpyLink


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
class UBrowserGSpyLink extends UBrowserBufferedTcpLink;

// Misc
var UBrowserGSpyFact        OwnerFactory;
var IpAddr                  MasterServerIpAddr;
var bool                    bOpened;

// Params
var string                  MasterServerAddress;    // Address of the master server
var int                     MasterServerTCPPort;    // Optional port that the master server is listening on
var int                     Region;                 // Region of the game server
var int                     MasterServerTimeout;
var string                  GameName;

// Error messages
var localized string        ResolveFailedError;
var localized string        TimeOutError;
var localized string        CouldNotConnectError;

// for WaitFor
const FoundSecureRequest = 1;
const FoundSecret        = 2;
const NextIP             = 3;
const NextAddress        = 4;

function BeginPlay()
{
    Disable('Tick');
    Super.BeginPlay();
}

function Start()
{
    ResetBuffer();
    
    MasterServerIpAddr.Port = MasterServerTCPPort;

    if( MasterServerAddress=="" )
        MasterServerAddress = "master"$Region$".gamespy.com";

    Resolve( MasterServerAddress );
}

function DoBufferQueueIO()
{
    Super.DoBufferQueueIO();
}

function Resolved( IpAddr Addr )
{
    // Set the address
    MasterServerIpAddr.Addr = Addr.Addr;

    // Handle failure.
    if( MasterServerIpAddr.Addr == 0 )
    {
        Log( "UBrowserGSpyLink: Invalid master server address, aborting." );
        return;
    }

    // Display success message.
    Log( "UBrowserGSpyLink: Master Server is "$MasterServerAddress$":"$MasterServerIpAddr.Port );

    // Bind the local port.
    if( !BindPort() )
    {
        Log( "UBrowserGSpyLink: Error binding local port, aborting." );
        return;
    }

    Open( MasterServerIpAddr );
    SetTimer(MasterServerTimeout, False);
}

event Timer()
{
    if(!bOpened)
    {
        Log("UBrowserGSpyLink: Couldn't connect to master server.");
        OwnerFactory.QueryFinished(False, CouldNotConnectError$MasterServerAddress);
        GotoState('Done');  
    }   
}

event Closed()
{
//	Log( "Connection to Master server closed" );
}

// Host resolution failue.
function ResolveFailed()
{
    Log("UBrowserGSpyLink: Failed to resolve master server address, aborting.");
    OwnerFactory.QueryFinished(False, ResolveFailedError$MasterServerAddress);
    GotoState('Done');
}

event Opened()
{
    bOpened = True;
    Enable('Tick');
//	Log( "Successfully connected to Master server" );

    WaitFor("\\basic\\\\secure\\", 5, FoundSecureRequest);
}


function Tick(float DeltaTime)
{
    DoBufferQueueIO();
}


function HandleServer(string Text)
{
    local string    Address;
    local string    Port;

    Address = ParseDelimited(Text, ":", 1);
    Port = ParseDelimited(ParseDelimited(Text, ":", 2), "\\", 1);

    OwnerFactory.FoundServer(Address, int(Port), "", GameName);
}


function GotMatch(int MatchData)
{

    switch(MatchData)
    {
    case FoundSecureRequest:
        Enable('Tick');
        //Log("FoundSecureRequest >>"$WaitResult$"<<");
        WaitForCount(6, 5, FoundSecret);
        break;
    case FoundSecret:
        Enable('Tick');
        //Log("FoundSecret >>"$WaitResult$"<<");
        SendBufferedData("\\gamename\\"$GameName$"\\location\\"$Region$"\\validate\\"$Validate(WaitResult, GameName)$"\\final\\");
        GotoState('FoundSecretState');
        break;
    case NextIP:
        Enable('Tick');
        if(WaitResult == "final\\")
        {
            OwnerFactory.QueryFinished(True);
            GotoState('Done');
        }
        else
            WaitFor("\\", 10, NextAddress);
        break;
    case NextAddress:
        Enable('Tick');
        HandleServer(WaitResult);
        WaitFor("\\", 5, NextIP);
        break;
    default:
        break;
    }
}

function GotMatchTimeout(int MatchData)
{
    // when a match times out

    OwnerFactory.QueryFinished(False, TimeOutError);
    GotoState('Done');
}

// States
state FoundSecretState 
{
    function Tick(float Delta)
    {
        Global.Tick(Delta);

        // Hack for 0 servers in server list
        if(!IsConnected() && WaitResult == "\\final\\")
        {
            OwnerFactory.QueryFinished(True);
            GotoState('Done');
        }
    }

Begin:
    Enable('Tick');
    Sleep(2);
    SendBufferedData("\\list\\\\gamename\\"$GameName$"\\final\\");
    WaitFor("ip\\", 30, NextIP);
}

state Done
{
Begin:
    Disable('Tick');
//	Log("Done");
}

defaultproperties
{
     ResolveFailedError="The master server could not be resolved: "
     TimeOutError="Timeout talking to the master server"
     CouldNotConnectError="Connecting to the master server timed out: "
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: za 22-4-2006 13:06:32.000 - Creation time: za 22-4-2006 13:07:28.265 - Created with UnCodeX