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

UBrowser.UBrowserServerPing


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
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
//=============================================================================
// UBrowserServerPing: Query an Unreal server for its details
//=============================================================================
class UBrowserServerPing extends UdpLink;

var UBrowserServerList	Server;

var IpAddr				ServerIPAddr;
var float				ElapsedTime;
var name				QueryState;
var bool				bInitial;
var bool				bJustThisServer;
var bool				bNoSort;
var int					PingAttempts;
var int					AttemptNumber;
var int					BindAttempts;

var localized string	AdminEmailText;
var localized string	AdminNameText;
var localized string	ChangeLevelsText;
var localized string	MultiplayerBotsText;
var localized string	FragLimitText;
var localized string	TimeLimitText;
var localized string	GameModeText;
var localized string	GameTypeText;
var localized string	GameVersionText;
var localized string	GameSubVersionText;
var localized string	WorldLogText;
var localized string	TrueString;
var localized string	FalseString;
var localized string	MapFileString,DLLString,DLLVerString,WebURLString,ServerOSString,GameClassString;

// config
var config int			MaxBindAttempts;
var config int			BindRetryTime;
var config int			PingTimeout;

function ValidateServer()
{
	if (Server.ServerPing != Self)
	{
		Log("ORPHANED: "$Self);
		Destroy();
	}
}

function StartQuery(name S, int InPingAttempts)
{
	QueryState = S;
	ValidateServer();
	ServerIPAddr.Port = Server.QueryPort;
	GotoState('Resolving');
	PingAttempts=InPingAttempts;
	AttemptNumber=1;
}

function Resolved( IpAddr Addr )
{
	ServerIPAddr.Addr = Addr.Addr;

	GotoState('Binding');
}

function bool GetNextValue(string In, out string Out, out string Result)
{
	local int i;
	local bool bFoundStart;

	Result = "";
	bFoundStart = False;

	for (i=0; i<Len(In); i++)
	{
		if (bFoundStart)
		{
			if (Mid(In, i, 1) == "\\")
			{
				Out = Right(In, Len(In) - i);
				return True;
			}
			else
			{
				Result = Result $ Mid(In, i, 1);
			}
		}
		else
		{
			if (Mid(In, i, 1) == "\\")
			{
				bFoundStart = True;
			}
		}
	}

	return False;
}

final function string LocalizeBoolValue(string Value)
{
	if (Value ~= "True")
		return TrueString;

	if (Value ~= "False")
		return TrueString;

	return Value;
}

function AddRule(string Rule, string Value)
{
	local UBrowserRulesList  RulesList;

	ValidateServer();

	for (RulesList = UBrowserRulesList(Server.RulesList.Next); RulesList != None; RulesList = UBrowserRulesList(RulesList.Next))
		if (RulesList.Rule == Rule)
			return; // Rule already exists

	// Add the rule
	RulesList = UBrowserRulesList(Server.RulesList.Append(class'UBrowserRulesList'));
	RulesList.Rule = Rule;
	RulesList.Value = Value;
}
function AddRuleX(string Rule, string Value)
{
	local UBrowserRulesList  RulesList;

	ValidateServer();

	// Add the rule
	RulesList = UBrowserRulesList(Server.RulesList.Append(class'UBrowserRulesList'));
	RulesList.Rule = Rule;
	RulesList.Value = Value;
}

state Binding
{
Begin:
	if ( !BindPort(2000, true) )
	{
		Log("UBrowserServerPing: Port failed to bind.  Attempt "$BindAttempts);
		BindAttempts++;

		ValidateServer();
		if (BindAttempts == MaxBindAttempts)
			Server.PingDone(bInitial, bJustThisServer, False, bNoSort);
		else
			GotoState('BindFailed');
	}
	else
	{
		GotoState(QueryState);
	}
}

state BindFailed
{
	event Timer()
	{
		GotoState('Binding');
	}

Begin:
	SetTimer(BindRetryTime, False);
}

state GetStatus
{
	final function string SplitDLLVer( string S )
	{
		local int i;
		local string v;

		i = InStr(S,"/");
		if( i==-1 )
			return S;
		else
		{
			v = Mid(S,i+1);
			S = Left(S,i);
		}
		return ReplaceStr(ReplaceStr(DLLVerString,"%s",S),"%i",v);
	}
	event ReceivedText( IpAddr Addr, string Text )
	{
		local string Value,StrValue;
		local string In;
		local string Out;
		local byte ID;
		local bool bOK,bNoMoreValues;
		local UBrowserPlayerList PlayerEntry;

		ValidateServer();

		In = Text;
		do
		{
			bOK = GetNextValue(In, Out, Value);
			In = Out;
			if (Left(Value, 7) == "player_")
			{
				bNoMoreValues = True;
				ID = Int(Right(Value, Len(Value) - 7));

				PlayerEntry = Server.PlayerList.FindID(ID);
				if (PlayerEntry == None)
					PlayerEntry = UBrowserPlayerList(Server.PlayerList.Append(class'UBrowserPlayerList'));
				PlayerEntry.PlayerID = ID;

				bOK = GetNextValue(In, Out, Value);
				In = Out;
				PlayerEntry.PlayerName = Value;
			}
			else if (Left(Value, 6) == "frags_")
			{
				ID = Int(Right(Value, Len(Value) - 6));

				bOK = GetNextValue(In, Out, Value);
				In = Out;
				PlayerEntry = Server.PlayerList.FindID(ID);
				PlayerEntry.PlayerFrags = Int(Value);
			}
			else if (Left(Value, 5) == "ping_")
			{
				ID = Int(Right(Value, Len(Value) - 5));

				bOK = GetNextValue(In, Out, Value);
				In = Out;
				PlayerEntry = Server.PlayerList.FindID(ID);
				PlayerEntry.PlayerPing = Int(Right(Value, len(Value) - 1));  // leading space
			}
			else if (Left(Value, 5) == "team_")
			{
				ID = Int(Right(Value, Len(Value) - 5));

				bOK = GetNextValue(In, Out, Value);
				In = Out;
				PlayerEntry = Server.PlayerList.FindID(ID);
				PlayerEntry.PlayerTeam = Value;
			}
			else if (Left(Value, 5) == "skin_")
			{
				ID = Int(Right(Value, Len(Value) - 5));

				bOK = GetNextValue(In, Out, Value);
				In = Out;
				PlayerEntry = Server.PlayerList.FindID(ID);
				PlayerEntry.PlayerSkin = GetItemName(Value);
			}
			else if (Left(Value, 5) == "mesh_")
			{
				ID = Int(Right(Value, Len(Value) - 5));

				bOK = GetNextValue(In, Out, Value);
				In = Out;
				PlayerEntry = Server.PlayerList.FindID(ID);
				PlayerEntry.PlayerMesh = GetItemName(Value);
			}
			else if (Value == "final")
			{
				Server.StatusDone(True);
				return;
			}
			else if (Value ~= "gamever")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(GameVersionText, Value);
				In = Out;
			}
			else if (Value ~= "gametype")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(GameTypeText, Value);
				In = Out;
			}
			else if (Value ~= "gameclass")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(GameClassString, Value);
				In = Out;
			}
			else if (Value ~= "gamemode")
			{
				bOK = GetNextValue(In, Out, Value);
				//AddRule(GameModeText, Value); <- No reason for this rule as it's hardcoded to openplaying.
				In = Out;
			}
			else if (Value ~= "timelimit")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(TimeLimitText, Value);
				In = Out;
			}
			else if (Value ~= "fraglimit")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(FragLimitText, Value);
				In = Out;
			}
			else if (Value ~= "MultiplayerBots")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(MultiplayerBotsText, LocalizeBoolValue(Value));
				In = Out;
			}
			else if (Value ~= "ChangeLevels")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(ChangeLevelsText, LocalizeBoolValue(Value));
				In = Out;
			}
			else if (Value ~= "AdminName")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(AdminNameText, Value);
				In = Out;
			}
			else if (Value ~= "AdminEMail")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(AdminEmailText, Value);
				In = Out;
			}
			else if (Value ~= "WorldLog")
			{
				bOK = GetNextValue(In, Out, Value);
				//AddRule(WorldLogText, LocalizeBoolValue(Value)); <- Not really intresting eighter.
				In = Out;
			}
			else if (Value ~= "mapfilename")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(MapFileString,Value);
				In = Out;
			}
			else if (Value == "DLL")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(DLLString,SplitDLLVer(Value));
				In = Out;
			}
			else if (Value == "servurl")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(WebURLString,Value);
				In = Out;
			}
			else if (Value == "OS")
			{
				bOK = GetNextValue(In, Out, Value);
				AddRule(ServerOSString,Value);
				In = Out;
			}
			else if ( bNoMoreValues )
				Continue;
			else if ( Value~="gamename" || Value~="mingamever" || Value~="location" || Value=="liburl"
			 || Value~="hostname" || Value~="shortname" || Value~="hostport" || Value=="gamesubver"
			 || Value~="mapname" || Value~="numplayers" || Value~="maxplayers"
			 || Value~="gamemode" || Value~="queryid" || Value ~= "gamever" ) // Standard values we dont need.
			{
				bOK = GetNextValue(In, Out, Value);
				In = Out;
			}
			else
			{
				StrValue = Caps(Left(Value,1))$Mid(Value,1);
				bOK = GetNextValue(In, Out, Value);
				AddRuleX(StrValue,Value);
				In = Out;
			}
		}
		until(!bOK);
	}

	event Timer()
	{
		if (AttemptNumber < PingAttempts)
		{
			Log("Timed out getting player replies.  Attempt "$AttemptNumber);
			AttemptNumber++;
			GotoState(QueryState);
		}
		else
		{
			Server.StatusDone(False);
			Log("Timed out getting player replies.  Giving Up");
		}
	}
Begin:
	// Player info

	ValidateServer();
	if (Server.PlayerList != None)
	{
		Server.PlayerList.DestroyList();
	}
	Server.PlayerList = New(None) class'UBrowserPlayerList';
	Server.PlayerList.SetupSentinel();

	if (Server.RulesList != None)
	{
		Server.RulesList.DestroyList();
	}
	Server.RulesList = New(None) class'UBrowserRulesList';
	Server.RulesList.SetupSentinel();

	SendText( ServerIPAddr, "\\status\\" );
	SetTimer(PingTimeout + Rand(200)/100, False);
}

state GetInfo
{
	event ReceivedText(IpAddr Addr, string Text)
	{
		local string Temp;
		local int i;
		local int l,DLLCount;

		Disable('Tick');

		ValidateServer();
		Server.Ping = 1000*ElapsedTime;
		Server.HostName = Server.IP;
		Server.GamePort = 0;
		Server.MapName = "";
		Server.GameType = "";
		Server.GameMode = "";
		Server.NumPlayers = 0;
		Server.MaxPlayers = 0;
		Server.GameVer = 0;
		Server.MinGameVer = 0;
		Server.LibraryWebPage = Server.Default.LibraryWebPage;
		Server.ServerWebPage = "";
		Array_Size(Server.Libaries,0);

		l = Len(Text);

		i=InStr(Text, "\\hostname\\");
		if (i >= 0)
		{
			Temp = Right(Text, l - i - 10);
			Server.HostName = Left(Temp, InStr(Temp, "\\"));
		}
		else
		{
			// Invalid ping response
			Disable('Tick');

			Server.Ping = 9999;
			Server.bNeverPinged = True;
			Server.PingDone(bInitial, bJustThisServer, False, bNoSort);
			return;
		}

		i=InStr(Text, "\\hostport\\");
		if (i >= 0)
		{
			Temp = Right(Text, l - i - 10);
			Server.GamePort = Int(Left(Temp, InStr(Temp, "\\")));
		}

		i=InStr(Text, "\\mapname\\");
		if (i >= 0)
		{
			Temp = Right(Text, l - i - 9);
			Server.MapName = Left(Temp, InStr(Temp, "\\"));
		}

		i=InStr(Text, "\\gametype\\");
		if (i >= 0)
		{
			Temp = Right(Text, l - i - 10);
			Server.GameType = Left(Temp, InStr(Temp, "\\"));
		}

		i=InStr(Text, "\\numplayers\\");
		if (i >= 0)
		{
			Temp = Right(Text, l - i - 12);
			Server.NumPlayers = Int(Left(Temp, InStr(Temp, "\\")));
		}

		i=InStr(Text, "\\maxplayers\\");
		if (i >= 0)
		{
			Temp = Right(Text, l - i - 12);
			Server.MaxPlayers = Int(Left(Temp, InStr(Temp, "\\")));
		}

		i=InStr(Text, "\\gamemode\\");
		if (i >= 0)
		{
			Temp = Right(Text, l - i - 10);
			Server.GameMode = Left(Temp, InStr(Temp, "\\"));
		}

		Temp = Text;
		while( true )
		{
			i=InStr(Temp, "\\DLL\\");
			if( i==-1 )
				break;
			Temp = Mid(Temp, i+5);
			Server.Libaries[DLLCount++] = Left(Temp, InStr(Temp, "\\"));
		}

		i=InStr(Text, "\\gamever\\");
		if (i >= 0)
		{
			Temp = Right(Text, l - i - 9);
			Server.GameVerStr = Left(Temp, InStr(Temp, "\\"));
			Server.GameVer = int(Server.GameVerStr);
		}

		i=InStr(Text, "\\mingamever\\");
		if (i >= 0)
		{
			Temp = Right(Text, l - i - 12);
			Server.MinGameVer = Int(Left(Temp, InStr(Temp, "\\")));
		}

		i=InStr(Text, "\\liburl\\");
		if (i >= 0)
		{
			Temp = Right(Text, l - i - 8);
			Server.LibraryWebPage = Left(Temp, InStr(Temp, "\\"));
		}

		i=InStr(Text, "\\servurl\\");
		if (i >= 0)
		{
			Temp = Right(Text, l - i - 9);
			Server.ServerWebPage = Left(Temp, InStr(Temp, "\\"));
		}

		Server.PingDone(bInitial, bJustThisServer, True, bNoSort);
	}

	event Tick(Float DeltaTime)
	{
		ElapsedTime = ElapsedTime + DeltaTime;
	}

	event Timer()
	{
		ValidateServer();
		if (AttemptNumber < PingAttempts)
		{
			Log("Ping Timeout from "$Server.IP$".  Attempt "$AttemptNumber);
			AttemptNumber++;
			GotoState(QueryState);
		}
		else
		{
			Log("Ping Timeout from "$Server.IP$" Giving Up");

			Server.Ping = 9999;
			Server.GamePort = 0;
			Server.MapName = "";
			Server.GameType = "";
			Server.GameMode = "";
			Server.NumPlayers = 0;
			Server.MaxPlayers = 0;

			Disable('Tick');

			Server.PingDone(bInitial, bJustThisServer, False, bNoSort);
		}
	}

Begin:
	ElapsedTime = 0;
	Enable('Tick');
	SendText( ServerIPAddr, "\\info\\" );
	SetTimer(PingTimeout + Rand(200)/100, False);
}

state Resolving
{
Begin:
	Resolve( Server.IP );
}

defaultproperties
{
				AdminEmailText="Admin Email"
				AdminNameText="Admin Name"
				ChangeLevelsText="Change Levels"
				MultiplayerBotsText="Bots in Multiplayer"
				FragLimitText="Frag Limit"
				TimeLimitText="Time Limit"
				GameModeText="Game Mode"
				GameTypeText="Game Type"
				GameVersionText="Game Version"
				GameSubVersionText="Game SubVersion"
				WorldLogText="ngStats World Stat-Logging"
				TrueString="Enabled"
				FalseString="Disabled"
				MapFileString="Map Filename"
				DLLString="C++ Library"
				DLLVerString="%s (ver %i)"
				WebURLString="Website URL"
				ServerOSString="Server OS"
				GameClassString="Game Class"
				MaxBindAttempts=5
				BindRetryTime=10
				PingTimeout=5
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: zo 11-11-2012 21:10:30.000 - Creation time: zo 11-11-2012 21:14:21.006 - Created with UnCodeX