UBrowser
Class UBrowserServerList

source: e:\games\UnrealTournament\UBrowser\Classes\UBrowserServerList.uc
Core.Object
   |
   +--UWindow.UWindowBase
      |
      +--UWindow.UWindowList
         |
         +--UBrowser.UBrowserServerList
Direct Known Subclasses:UTBrowserServerList

class UBrowserServerList
extends UWindow.UWindowList

//============================================================================= // UBrowserServerList // Stores a server entry in an Unreal Server List //=============================================================================
Variables
 string Category
           Master server categorization
 string GameMode
           don't overwrite HostName
 string GameName
           Unreal, Unreal Tournament
 int GamePort
           don't overwrite HostName
 string GameType
           don't overwrite HostName
 int GameVer
           don't overwrite HostName
 string HostName
           don't overwrite HostName
 string IP
 string MapDisplayName
           don't overwrite HostName
 string MapName
           don't overwrite HostName
 string MapTitle
           don't overwrite HostName
 int MaxPlayers
           don't overwrite HostName
 int MaxSimBroadbandPing
 int MaxSimultaneousPing
 int MinNetVer
           don't overwrite HostName
 int NumPlayers
           don't overwrite HostName
 float Ping
           don't overwrite HostName
 UBrowserPlayerList PlayerList
           Unreal, Unreal Tournament
 int PlayerListSortColumn
           don't overwrite HostName
 int QueryPort
 UBrowserRulesList RulesList
           Unreal, Unreal Tournament
 UBrowserServerPing ServerPing
           Unreal, Unreal Tournament
 int TotalMaxPlayers
 int TotalPlayers
 int TotalServers
 bool bKeepDescription
           don't overwrite HostName
 bool bLocalServer
           don't overwrite HostName
 bool bNeedUpdateCount
 bool bNoInitalPing
           Unreal, Unreal Tournament
 bool bOldServer
           Unreal, Unreal Tournament
 bool bPingFailed
           Unreal, Unreal Tournament
 bool bPinged
           Unreal, Unreal Tournament
 bool bPinging
           Unreal, Unreal Tournament


Function Summary
 void AppendItem(UWindowList L)
 void CancelPing()
 int Compare(UWindowList T, UWindowList B)
 void ConsiderForSubsets()
 bool DecodeServerProperties(string Data)
 void DestroyListItem()
 UBrowserServerList FindExistingServer(string FindIP, int FindQueryPort)
 PlayerPawn GetPlayerOwner()
 void InvalidatePings()
     
// Functions for sentinel only
 void PingDone(bool bInitial, bool bJustThisServer, bool bSuccess, bool bNoSort)
 void PingNext(bool bInitial, bool bNoSort)
 void PingServer(bool bInitial, bool bJustThisServer, bool bNoSort)
     
// Functions for server list entries only.
 void PingServers(bool bInitial, bool bNoSort)
 void QueryFinished(UBrowserServerListFactory Fact, bool bSuccess, optional string)
 void Remove()
 void ServerStatus()
 void StatusDone(bool bSuccess)
 void UpdateServerCount()
     
// Sentinel only
// FIXME: slow when lots of servers!!



Source Code


00001	//=============================================================================
00002	// UBrowserServerList
00003	//		Stores a server entry in an Unreal Server List
00004	//=============================================================================
00005	
00006	class UBrowserServerList extends UWindowList;
00007	
00008	// Valid for sentinel only
00009	var	UBrowserServerListWindow	Owner;
00010	var int					TotalServers;
00011	var int					TotalPlayers;
00012	var int					TotalMaxPlayers;
00013	var bool				bNeedUpdateCount;
00014	
00015	// Config
00016	var config int			MaxSimultaneousPing;
00017	var config int			MaxSimBroadbandPing;
00018	
00019	// Master server variables
00020	var string				IP;
00021	var int					QueryPort;
00022	var string				Category;		// Master server categorization
00023	var string				GameName;		// Unreal, Unreal Tournament
00024	
00025	// State of the ping
00026	var UBrowserServerPing	ServerPing;
00027	var bool				bPinging;
00028	var bool				bPingFailed;
00029	var bool				bPinged;
00030	var bool				bNoInitalPing;
00031	var bool				bOldServer;
00032	
00033	// Rules and Lists
00034	var UBrowserRulesList	RulesList;
00035	var UBrowserPlayerList  PlayerList;
00036	var bool				bKeepDescription;	// don't overwrite HostName
00037	var int					PlayerListSortColumn;
00038	
00039	// Unreal server variables
00040	var bool				bLocalServer;
00041	var float				Ping;
00042	var string				HostName;
00043	var int					GamePort;
00044	var string				MapName;
00045	var string				MapTitle;
00046	var string				MapDisplayName;
00047	var string				GameType;
00048	var string				GameMode;
00049	var int					NumPlayers;
00050	var int					MaxPlayers;
00051	var int					GameVer;
00052	var int					MinNetVer;
00053	
00054	function DestroyListItem() 
00055	{
00056		Owner = None;
00057	
00058		if(ServerPing != None)
00059		{
00060			ServerPing.Destroy();
00061			ServerPing = None;
00062		}
00063		Super.DestroyListItem();
00064	}
00065	
00066	function QueryFinished(UBrowserServerListFactory Fact, bool bSuccess, optional string ErrorMsg)
00067	{
00068		Owner.QueryFinished(Fact, bSuccess, ErrorMsg);
00069	}
00070	
00071	// Functions for server list entries only.
00072	function PingServer(bool bInitial, bool bJustThisServer, bool bNoSort)
00073	{
00074		// Create the UdpLink to ping the server
00075		ServerPing = GetPlayerOwner().GetEntryLevel().Spawn(class'UBrowserServerPing');
00076		ServerPing.Server = Self;
00077		ServerPing.StartQuery('GetInfo', 2);
00078		ServerPing.bInitial = bInitial;
00079		ServerPing.bJustThisServer = bJustThisServer;
00080		ServerPing.bNoSort = bNoSort;
00081		bPinging = True;
00082	}
00083	
00084	function ServerStatus()
00085	{
00086		// Create the UdpLink to ping the server
00087		ServerPing = GetPlayerOwner().GetEntryLevel().Spawn(class'UBrowserServerPing');
00088		ServerPing.Server = Self;
00089		ServerPing.StartQuery('GetStatus', 2);
00090		bPinging = True;
00091	}
00092	
00093	function StatusDone(bool bSuccess)
00094	{
00095		// Destroy the UdpLink
00096		ServerPing.Destroy();
00097		ServerPing = None;
00098	
00099		bPinging = False;
00100	
00101		RulesList.Sort();
00102		PlayerList.Sort();
00103	}
00104	
00105	function CancelPing()
00106	{
00107		if(bPinging && ServerPing != None && ServerPing.bJustThisServer)
00108			PingDone(False, True, False, True);
00109	}
00110	
00111	function PingDone(bool bInitial, bool bJustThisServer, bool bSuccess, bool bNoSort)
00112	{
00113		local UBrowserServerListWindow W;
00114		local UBrowserServerList OldSentinel;
00115	
00116		// Destroy the UdpLink
00117		if(ServerPing != None)
00118			ServerPing.Destroy();
00119		
00120		ServerPing = None;
00121	
00122		bPinging = False;
00123		bPingFailed = !bSuccess;
00124		bPinged = True;
00125	
00126		OldSentinel = UBrowserServerList(Sentinel);
00127		if(!bNoSort)
00128		{
00129			Remove();
00130	
00131			// Move to the ping list
00132			if(!bPingFailed || (OldSentinel != None && OldSentinel.Owner != None && OldSentinel.Owner.bShowFailedServers))
00133			{
00134				if(OldSentinel.Owner.PingedList != None)
00135					OldSentinel.Owner.PingedList.AppendItem(Self);
00136			}
00137		}
00138		else
00139		{
00140			if(OldSentinel != None && OldSentinel.Owner != None && OldSentinel != OldSentinel.Owner.PingedList)
00141				Log("Unsorted PingDone lost as it's not in ping list!");
00142		}
00143	
00144		if(Sentinel != None)
00145		{
00146			UBrowserServerList(Sentinel).bNeedUpdateCount = True;
00147	
00148			if(bInitial)
00149				ConsiderForSubsets();
00150		}
00151	
00152		if(!bJustThisServer)
00153			if(OldSentinel != None)
00154			{
00155				W = OldSentinel.Owner;
00156	
00157				if(W.bPingSuspend)
00158				{
00159					W.bPingResume = True;
00160					W.bPingResumeIntial = bInitial;
00161				}
00162				else
00163					OldSentinel.PingNext(bInitial, bNoSort);
00164			}
00165	}
00166	
00167	function ConsiderForSubsets()
00168	{
00169		local UBrowserSubsetList l;
00170	
00171		for(l = UBrowserSubsetList(UBrowserServerList(Sentinel).Owner.SubsetList.Next); l != None; l = UBrowserSubsetList(l.Next))
00172		{
00173			l.SubsetFactory.ConsiderItem(Self);
00174		}
00175	}
00176	
00177	// Functions for sentinel only
00178	
00179	function InvalidatePings()
00180	{
00181		local UBrowserServerList l;
00182	
00183		for(l = UBrowserServerList(Next);l != None;l = UBrowserServerList(l.Next)) 
00184			l.Ping = 9999;
00185	}
00186	
00187	function PingServers(bool bInitial, bool bNoSort)
00188	{
00189		local UBrowserServerList l;
00190		
00191		bPinging = False;
00192	
00193		for(l = UBrowserServerList(Next);l != None;l = UBrowserServerList(l.Next)) 
00194		{
00195			l.bPinging = False;
00196			l.bPingFailed = False;
00197			l.bPinged = False;
00198		}
00199	
00200		PingNext(bInitial, bNoSort);
00201	}
00202	
00203	function PingNext(bool bInitial, bool bNoSort)
00204	{
00205		local int TotalPinging;
00206		local UBrowserServerList l;
00207		local bool bDone;
00208		local int MaxPing;
00209	
00210		MaxPing = MaxSimultaneousPing;
00211		if( Owner != None && Owner.GetPlayerOwner().Player.CurrentNetSpeed > 5000 )
00212			MaxPing = MaxSimBroadbandPing;
00213	
00214		TotalPinging = 0;
00215		
00216		bDone = True;
00217		for(l = UBrowserServerList(Next);l != None;l = UBrowserServerList(l.Next)) 
00218		{
00219			if(!l.bPinged)
00220				bDone = False;
00221			if(l.bPinging)
00222				TotalPinging ++;
00223		}
00224		
00225		if(bDone && Owner != None)
00226		{
00227			bPinging = False;
00228			Owner.PingFinished();
00229		}
00230		else
00231		if(TotalPinging < MaxPing)
00232		{
00233			for(l = UBrowserServerList(Next);l != None;l = UBrowserServerList(l.Next))
00234			{
00235				if(		!l.bPinging 
00236					&&	!l.bPinged 
00237					&&	(!bInitial || !l.bNoInitalPing)
00238					&&	TotalPinging < MaxPing
00239				)
00240				{
00241					TotalPinging ++;		
00242					l.PingServer(bInitial, False, bNoSort);
00243				}
00244	
00245				if(TotalPinging >= MaxPing)
00246					break;
00247			}
00248		}
00249	}
00250	
00251	function UBrowserServerList FindExistingServer(string FindIP, int FindQueryPort)
00252	{
00253		local UWindowList l;
00254	
00255		for(l = Next;l != None;l = l.Next)
00256		{
00257			if(UBrowserServerList(l).IP == FindIP && UBrowserServerList(l).QueryPort == FindQueryPort)
00258				return UBrowserServerList(l);
00259		}
00260		return None;
00261	}
00262	
00263	function PlayerPawn GetPlayerOwner()
00264	{
00265		return UBrowserServerList(Sentinel).Owner.GetPlayerOwner();
00266	}
00267	
00268	function UWindowList CopyExistingListItem(Class<UWindowList> ItemClass, UWindowList SourceItem)
00269	{
00270		local UBrowserServerList L;
00271	
00272		L = UBrowserServerList(Super.CopyExistingListItem(ItemClass, SourceItem));
00273	
00274		L.bLocalServer	= UBrowserServerList(SourceItem).bLocalServer;
00275		L.IP			= UBrowserServerList(SourceItem).IP;
00276		L.QueryPort		= UBrowserServerList(SourceItem).QueryPort;
00277		L.Ping			= UBrowserServerList(SourceItem).Ping;
00278		L.HostName		= UBrowserServerList(SourceItem).HostName;
00279		L.GamePort		= UBrowserServerList(SourceItem).GamePort;
00280		L.MapName		= UBrowserServerList(SourceItem).MapName;
00281		L.MapTitle		= UBrowserServerList(SourceItem).MapTitle;
00282		L.MapDisplayName= UBrowserServerList(SourceItem).MapDisplayName;
00283		L.MapName		= UBrowserServerList(SourceItem).MapName;
00284		L.GameType		= UBrowserServerList(SourceItem).GameType;
00285		L.GameMode		= UBrowserServerList(SourceItem).GameMode;
00286		L.NumPlayers	= UBrowserServerList(SourceItem).NumPlayers;
00287		L.MaxPlayers	= UBrowserServerList(SourceItem).MaxPlayers;
00288		L.GameVer		= UBrowserServerList(SourceItem).GameVer;
00289		L.MinNetVer		= UBrowserServerList(SourceItem).MinNetVer;
00290		L.bKeepDescription = UBrowserServerList(SourceItem).bKeepDescription;
00291	
00292		return L;
00293	}
00294	
00295	function int Compare(UWindowList T, UWindowList B)
00296	{
00297		CompareCount++;
00298		return UBrowserServerList(Sentinel).Owner.Grid.Compare(UBrowserServerList(T), UBrowserServerList(B));
00299	}
00300	
00301	function AppendItem(UWindowList L)
00302	{
00303		Super.AppendItem(L);
00304		UBrowserServerList(Sentinel).bNeedUpdateCount = True;
00305	}
00306	
00307	function Remove()
00308	{
00309		local UBrowserServerList S;
00310	
00311		S = UBrowserServerList(Sentinel);
00312		Super.Remove();
00313	
00314		if(S != None)
00315			S.bNeedUpdateCount = True;
00316	}
00317	
00318	// Sentinel only
00319	// FIXME: slow when lots of servers!!
00320	function UpdateServerCount()
00321	{
00322		local UBrowserServerList l;
00323	
00324		TotalServers = 0;
00325		TotalPlayers = 0;
00326		TotalMaxPlayers = 0;
00327	
00328		for(l = UBrowserServerList(Next);l != None;l = UBrowserServerList(l.Next))
00329		{
00330			TotalServers++;
00331			TotalPlayers += l.NumPlayers;
00332			TotalMaxPlayers += l.MaxPlayers;
00333		}
00334	}
00335	
00336	function bool DecodeServerProperties(string Data)
00337	{
00338		return True;
00339	}
00340	
00341	defaultproperties
00342	{
00343	     MaxSimultaneousPing=10
00344	     MaxSimBroadbandPing=20
00345	     PlayerListSortColumn=1
00346	}

End Source Code