UBrowser
Class UBrowserServerList

source: c:\runehov\UBrowser\Classes\UBrowserServerList.uc
Core.Object
   |
   +--UWindow.UWindowBase
      |
      +--UWindow.UWindowList
         |
         +--UBrowser.UBrowserServerList
Direct Known Subclasses:RBrowserServerList

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

End Source Code