UBrowser
Class UBrowserServerListWindow

source: e:\games\UnrealTournament\UBrowser\Classes\UBrowserServerListWindow.uc
Core.Object
   |
   +--UWindow.UWindowBase
      |
      +--UWindow.UWindowWindow
         |
         +--UWindow.UWindowClientWindow
            |
            +--UWindow.UWindowDialogClientWindow
               |
               +--UWindow.UWindowPageWindow
                  |
                  +--UBrowser.UBrowserServerListWindow
Direct Known Subclasses:UBrowserFavoriteServers, UTBrowserServerListWindow

class UBrowserServerListWindow
extends UWindow.UWindowPageWindow


Variables
 int AutoRefreshTime
           Non-localized page title
 string ErrorString
           Non-localized page title
 UBrowserServerListFactory Factories[10]
           Non-localized page title
 int FallbackFactory
           Non-localized page title
 UBrowserServerGrid Grid
           Non-localized page title
 string GridClass
           Non-localized page title
 UBrowserInfoClientWindow InfoClient
           Non-localized page title
 UBrowserServerList InfoItem
           Non-localized page title
 string InfoName
           Non-localized page title
 UBrowserInfoWindow InfoWindow
           Non-localized page title
 string ListFactories[10]
           Non-localized page title
 EPingState PingState
           Non-localized page title
 UBrowserServerList PingedList
           Non-localized page title
 string PlayerCountLeader
           Non-localized page title
 string PlayerCountName
           Non-localized page title
 int QueryDone[10]
           Non-localized page title
 class RightClickMenuClass
           Non-localized page title
 string ServerCountLeader
           Non-localized page title
 string ServerCountName
           Non-localized page title
 class ServerListClass
           Non-localized page title
 string ServerListClassName
           Non-localized page title
 string ServerListTitle
           Non-localized page title
 UBrowserSubsetList SubsetList
           Non-localized page title
 UBrowserSupersetList SupersetList
           Non-localized page title
 float TimeElapsed
           Non-localized page title
 string URLAppend
           Non-localized page title
 UBrowserServerList UnpingedList
           Non-localized page title
 UWindowVSplitter VSplitter
           Non-localized page title
 bool bFallbackFactories
           Non-localized page title
 bool bHadInitialRefresh
           Non-localized page title
 bool bHidden
           Non-localized page title
 bool bNoAutoSort
           Non-localized page title
 bool bNoSort
           Non-localized page title
 bool bPingResume
           Non-localized page title
 bool bPingResumeIntial
           Non-localized page title
 bool bPingSuspend
           Non-localized page title
 bool bShowFailedServers
           Non-localized page title
 bool bSuspendPingOnClose
           Non-localized page title

States
P

Function Summary
 UBrowserServerList AddFavorite(UBrowserServerList Server)
 void AddSubset(UBrowserSubsetFact Subset)
 void AddSuperSet(UBrowserServerListWindow Superset)
 void AutoInfo(UBrowserServerList I)
 void BeforePaint(Canvas C, float X, float Y)
 void CreateFactories(bool bUsePingedList)
 void Created()
 void Paint(Canvas C, float X, float Y)
 void PingFinished()
 void Query(optional bool, optional bool, optional bool)
 void QueryFinished(UBrowserServerListFactory Fact, bool bSuccess, optional string)
 void RePing()
 void Refresh(optional bool, optional bool, optional bool, optional bool)
 void RefreshSubsets()
 void RemoveOldServers()
 void RemoveSubset(UBrowserSubsetFact Subset)
 void RemoveSuperset(UBrowserServerListWindow Superset)
 void Resized()
 void ResolutionChanged(float W, float H)
 void ResumePinging()
 void ShowInfo(UBrowserServerList I, optional bool)
 void ShowInfoArea(bool bShow, optional bool, optional bool)
 void ShutdownFactories(optional bool)
 void SuspendPinging()
 void TagServersAsOld()
 void Tick(float Delta)
 void WindowHidden()
 void WindowShown()


State P Function Summary



Source Code


00001	class UBrowserServerListWindow extends UWindowPageWindow
00002		PerObjectConfig;
00003	
00004	var config string				ServerListTitle;	// Non-localized page title
00005	var config string				ListFactories[10];
00006	var config string				URLAppend;
00007	var config int					AutoRefreshTime;
00008	var config bool					bNoAutoSort;
00009	var config bool					bHidden;
00010	var config bool					bFallbackFactories;
00011	
00012	var string						ServerListClassName;
00013	var class<UBrowserServerList>	ServerListClass;
00014	
00015	var UBrowserServerList			PingedList;
00016	var UBrowserServerList			UnpingedList;
00017	
00018	var UBrowserServerListFactory	Factories[10];
00019	var int							QueryDone[10];
00020	var UBrowserServerGrid			Grid;
00021	var string						GridClass;
00022	var float						TimeElapsed;
00023	var bool						bPingSuspend;
00024	var bool						bPingResume;
00025	var bool						bPingResumeIntial;
00026	var bool						bNoSort;
00027	var bool						bSuspendPingOnClose;
00028	var UBrowserSubsetList			SubsetList;
00029	var UBrowserSupersetList		SupersetList;
00030	var class<UBrowserRightClickMenu>	RightClickMenuClass;
00031	var bool						bShowFailedServers;
00032	var bool						bHadInitialRefresh;
00033	var int							FallbackFactory;
00034	
00035	var UWindowVSplitter			VSplitter;
00036	var UBrowserInfoWindow			InfoWindow;
00037	var UBrowserInfoClientWindow	InfoClient;
00038	var UBrowserServerList			InfoItem;
00039	var localized string			InfoName;
00040	
00041	const MinHeightForSplitter = 384;
00042	
00043	var localized string			PlayerCountLeader;
00044	var localized string			ServerCountLeader;
00045	
00046	
00047	// Status info
00048	enum EPingState
00049	{
00050		PS_QueryServer,
00051		PS_QueryFailed,
00052		PS_Pinging,
00053		PS_RePinging,
00054		PS_Done
00055	};
00056	
00057	var localized string			PlayerCountName;
00058	var localized string			ServerCountName;
00059	var	localized string			QueryServerText;
00060	var	localized string			QueryFailedText;
00061	var	localized string			PingingText;
00062	var	localized string			CompleteText;
00063	
00064	var string						ErrorString;
00065	var EPingState					PingState;
00066	
00067	function WindowShown()
00068	{
00069		local UBrowserSupersetList l;
00070	
00071		Super.WindowShown();
00072		if(VSplitter.bWindowVisible)
00073		{
00074			if(UWindowVSplitter(InfoClient.ParentWindow) != None)
00075				VSplitter.SplitPos = UWindowVSplitter(InfoClient.ParentWindow).SplitPos;
00076	
00077			InfoClient.SetParent(VSplitter);
00078		}
00079	
00080		InfoClient.Server = InfoItem;
00081		if(InfoItem != None)
00082			InfoWindow.WindowTitle = InfoName$" - "$InfoItem.HostName;
00083		else
00084			InfoWindow.WindowTitle = InfoName;
00085	
00086		ResumePinging();
00087	
00088		for(l = UBrowserSupersetList(SupersetList.Next); l != None; l = UBrowserSupersetList(l.Next))
00089			l.SuperSetWindow.ResumePinging();
00090	}
00091	
00092	function WindowHidden()
00093	{
00094		local UBrowserSupersetList l;
00095	
00096		Super.WindowHidden();
00097		SuspendPinging();
00098	
00099		for(l = UBrowserSupersetList(SupersetList.Next); l != None; l = UBrowserSupersetList(l.Next))
00100			l.SuperSetWindow.SuspendPinging();
00101	}
00102	
00103	function SuspendPinging()
00104	{
00105		if(bSuspendPingOnClose)
00106			bPingSuspend = True;
00107	}
00108	
00109	function ResumePinging()
00110	{
00111		if(!bHadInitialRefresh)
00112			Refresh(False, True);	
00113	
00114		bPingSuspend = False;
00115		if(bPingResume)
00116		{
00117			bPingResume = False;
00118			UnpingedList.PingNext(bPingResumeIntial, bNoSort);
00119		}
00120	}
00121	
00122	function Created()
00123	{
00124		local Class<UBrowserServerGrid> C;
00125		
00126		ServerListClass = class<UBrowserServerList>(DynamicLoadObject(ServerListClassName, class'Class'));
00127		C = class<UBrowserServerGrid>(DynamicLoadObject(GridClass, class'Class'));
00128		Grid = UBrowserServerGrid(CreateWindow(C, 0, 0, WinWidth, WinHeight));
00129		Grid.SetAcceptsFocus();
00130	
00131		SubsetList = new class'UBrowserSubsetList';
00132		SubsetList.SetupSentinel();
00133	
00134		SupersetList = new class'UBrowserSupersetList';
00135		SupersetList.SetupSentinel();
00136	
00137		VSplitter = UWindowVSplitter(CreateWindow(class'UWindowVSplitter', 0, 0, WinWidth, WinHeight));
00138		VSplitter.SetAcceptsFocus();
00139		VSplitter.MinWinHeight = 60;
00140		VSplitter.HideWindow();
00141		InfoWindow = UBrowserMainClientWindow(GetParent(class'UBrowserMainClientWindow')).InfoWindow;
00142		InfoClient = UBrowserInfoClientWindow(InfoWindow.ClientArea);
00143	
00144		if(Root.WinHeight >= MinHeightForSplitter)
00145			ShowInfoArea(True, False);
00146	}
00147	
00148	function ShowInfoArea(bool bShow, optional bool bFloating, optional bool bNoActivate)
00149	{
00150		if(bShow)
00151		{
00152			if(bFloating)
00153			{
00154				VSplitter.HideWindow();
00155				VSplitter.TopClientWindow = None;
00156				VSplitter.BottomClientWindow = None;
00157				InfoClient.SetParent(InfoWindow);
00158				Grid.SetParent(Self);
00159				Grid.SetSize(WinWidth, WinHeight);
00160				if(!InfoWindow.bWindowVisible)
00161					InfoWindow.ShowWindow();
00162				if(!bNoActivate)
00163					InfoWindow.BringToFront();
00164			}
00165			else
00166			{
00167				InfoWindow.HideWindow();
00168				VSplitter.ShowWindow();
00169				VSplitter.SetSize(WinWidth, WinHeight);
00170				Grid.SetParent(VSplitter);
00171				InfoClient.SetParent(VSplitter);
00172				VSplitter.TopClientWindow = Grid;
00173				VSplitter.BottomClientWindow = InfoClient;
00174			}
00175		}
00176		else
00177		{
00178			InfoWindow.HideWindow();
00179			VSplitter.HideWindow();
00180			VSplitter.TopClientWindow = None;
00181			VSplitter.BottomClientWindow = None;
00182			InfoClient.SetParent(InfoWindow);
00183			Grid.SetParent(Self);
00184			Grid.SetSize(WinWidth, WinHeight);
00185		}
00186	}
00187	
00188	function AutoInfo(UBrowserServerList I)
00189	{
00190		if(Root.WinHeight >= MinHeightForSplitter || InfoWindow.bWindowVisible)
00191			ShowInfo(I, True);
00192	}
00193	
00194	function ShowInfo(UBrowserServerList I, optional bool bAutoInfo)
00195	{
00196		if(I == None) return;
00197		ShowInfoArea(True, Root.WinHeight < MinHeightForSplitter, bAutoInfo);
00198	
00199		InfoItem = I;
00200		InfoClient.Server = InfoItem;
00201		InfoWindow.WindowTitle = InfoName$" - "$InfoItem.HostName;
00202		I.ServerStatus();
00203	}
00204	
00205	function ResolutionChanged(float W, float H)
00206	{
00207		if(Root.WinHeight >= MinHeightForSplitter)
00208			ShowInfoArea(True, False);
00209		else
00210			ShowInfoArea(False, True);
00211		
00212		if(InfoWindow != None)
00213			InfoWindow.ResolutionChanged(W, H);
00214	
00215		Super.ResolutionChanged(W, H);
00216	}
00217	
00218	function Resized()
00219	{
00220		Super.Resized();
00221		if(VSplitter.bWindowVisible)
00222		{
00223			VSplitter.SetSize(WinWidth, WinHeight);
00224			VSplitter.OldWinHeight = VSplitter.WinHeight;
00225			VSplitter.SplitPos = VSplitter.WinHeight - Min(VSplitter.WinHeight / 2, 250);
00226		}
00227		else
00228			Grid.SetSize(WinWidth, WinHeight);
00229	}
00230	
00231	function AddSubset(UBrowserSubsetFact Subset)
00232	{
00233		local UBrowserSubsetList l;
00234	
00235		for(l = UBrowserSubsetList(SubsetList.Next); l != None; l = UBrowserSubsetList(l.Next))
00236			if(l.SubsetFactory == Subset)
00237				return;
00238		
00239		l = UBrowserSubsetList(SubsetList.Append(class'UBrowserSubsetList'));
00240		l.SubsetFactory = Subset;
00241	}
00242	
00243	function AddSuperSet(UBrowserServerListWindow Superset)
00244	{
00245		local UBrowserSupersetList l;
00246	
00247		for(l = UBrowserSupersetList(SupersetList.Next); l != None; l = UBrowserSupersetList(l.Next))
00248			if(l.SupersetWindow == Superset)
00249				return;
00250		
00251		l = UBrowserSupersetList(SupersetList.Append(class'UBrowserSupersetList'));
00252		l.SupersetWindow = Superset;
00253	}
00254	
00255	function RemoveSubset(UBrowserSubsetFact Subset)
00256	{
00257		local UBrowserSubsetList l;
00258	
00259		for(l = UBrowserSubsetList(SubsetList.Next); l != None; l = UBrowserSubsetList(l.Next))
00260			if(l.SubsetFactory == Subset)
00261				l.Remove();
00262	}
00263	
00264	function RemoveSuperset(UBrowserServerListWindow Superset)
00265	{
00266		local UBrowserSupersetList l;
00267	
00268		for(l = UBrowserSupersetList(SupersetList.Next); l != None; l = UBrowserSupersetList(l.Next))
00269			if(l.SupersetWindow == Superset)
00270				l.Remove();
00271	}
00272	
00273	function UBrowserServerList AddFavorite(UBrowserServerList Server)
00274	{
00275		return UBrowserServerListWindow(UBrowserMainClientWindow(GetParent(class'UBrowserMainClientWindow')).Favorites.Page).AddFavorite(Server);
00276	}
00277	
00278	function Refresh(optional bool bBySuperset, optional bool bInitial, optional bool bSaveExistingList, optional bool bInNoSort)
00279	{
00280		bHadInitialRefresh = True;
00281	
00282		if(!bSaveExistingList)
00283		{
00284			InfoItem = None;
00285			InfoClient.Server = None;
00286		}
00287	
00288		if(!bSaveExistingList && PingedList != None)
00289		{
00290			PingedList.DestroyList();
00291			PingedList = None;
00292			Grid.SelectedServer = None;
00293		}
00294	
00295		if(PingedList == None)
00296		{
00297			PingedList=New ServerListClass;
00298			PingedList.Owner = Self;
00299			PingedList.SetupSentinel(True);
00300			PingedList.bSuspendableSort = True;
00301		}
00302		else
00303		{
00304			TagServersAsOld();
00305		}
00306	
00307		if(UnpingedList != None)
00308			UnpingedList.DestroyList();
00309		
00310		if(!bSaveExistingList)
00311		{
00312			UnpingedList = New ServerListClass;
00313			UnpingedList.Owner = Self;
00314			UnpingedList.SetupSentinel(False);
00315		}
00316	
00317		PingState = PS_QueryServer;
00318		ShutdownFactories(bBySuperset);
00319		CreateFactories(bSaveExistingList);
00320		Query(bBySuperset, bInitial, bInNoSort);
00321	
00322		if(!bInitial)
00323			RefreshSubsets();
00324	}
00325	
00326	function TagServersAsOld()
00327	{
00328		local UBrowserServerList l;
00329	
00330		for(l = UBrowserServerList(PingedList.Next);l != None;l = UBrowserServerList(l.Next)) 
00331			l.bOldServer = True;
00332	}
00333	
00334	function RemoveOldServers()
00335	{
00336		local UBrowserServerList l, n;
00337	
00338		l = UBrowserServerList(PingedList.Next);
00339		while(l != None) 
00340		{
00341			n = UBrowserServerList(l.Next);
00342	
00343			if(l.bOldServer)
00344			{
00345				if(Grid.SelectedServer == l)
00346					Grid.SelectedServer = n;
00347	
00348				l.Remove();
00349			}
00350			l = n;
00351		}
00352	}
00353	
00354	function RefreshSubsets()
00355	{
00356		local UBrowserSubsetList l, NextSubset;
00357	
00358		for(l = UBrowserSubsetList(SubsetList.Next); l != None; l = UBrowserSubsetList(l.Next))
00359			l.bOldElement = True;
00360	
00361		l = UBrowserSubsetList(SubsetList.Next);
00362		while(l != None && l.bOldElement)
00363		{
00364			NextSubset = UBrowserSubsetList(l.Next);
00365			l.SubsetFactory.Owner.Owner.Refresh(True);
00366			l = NextSubset;
00367		}
00368	}
00369	
00370	function RePing()
00371	{
00372		PingState = PS_RePinging;
00373		PingedList.InvalidatePings();
00374		PingedList.PingServers(True, False);
00375	}
00376	
00377	function QueryFinished(UBrowserServerListFactory Fact, bool bSuccess, optional string ErrorMsg)
00378	{
00379		local int i;
00380		local bool bDone;
00381	
00382		bDone = True;
00383		for(i=0;i<10;i++)
00384		{
00385			if(Factories[i] != None)
00386			{
00387				if(Factories[i] == Fact)
00388					QueryDone[i] = 1;
00389				if(QueryDone[i] == 0)
00390					bDone = False;
00391			}
00392		}
00393	
00394		if(!bSuccess)
00395		{
00396			PingState = PS_QueryFailed;
00397			ErrorString = ErrorMsg;
00398	
00399			// don't ping and report success if we have no servers.
00400			if(bDone && UnpingedList.Count() == 0)
00401			{
00402				if( bFallbackFactories )
00403				{
00404					FallbackFactory++;
00405					if( ListFactories[FallbackFactory] != "" )
00406						Refresh();	// try the next fallback master server
00407					else
00408						FallbackFactory = 0;
00409				}
00410				return;
00411			}
00412		}
00413		else
00414			ErrorString = "";
00415	
00416		if(bDone)
00417		{
00418			RemoveOldServers();
00419	
00420			PingState = PS_Pinging;
00421			if(!bNoSort && !Fact.bIncrementalPing)
00422				PingedList.Sort();
00423			UnpingedList.PingServers(True, bNoSort || Fact.bIncrementalPing);
00424		}
00425	}
00426	
00427	function PingFinished()
00428	{
00429		PingState = PS_Done;
00430	}
00431	
00432	function CreateFactories(bool bUsePingedList)
00433	{
00434		local int i;
00435	
00436		for(i=0;i<10;i++)
00437		{
00438			if(ListFactories[i] == "")
00439				break;
00440			if(!bFallbackFactories || FallbackFactory == i)
00441			{
00442				Factories[i] = UBrowserServerListFactory(BuildObjectWithProperties(ListFactories[i]));
00443				
00444				Factories[i].PingedList = PingedList;
00445				Factories[i].UnpingedList = UnpingedList;
00446			
00447				if(bUsePingedList)
00448					Factories[i].Owner = PingedList;
00449				else
00450					Factories[i].Owner = UnpingedList;
00451			}
00452			QueryDone[i] = 0;
00453		}	
00454	}
00455	
00456	function ShutdownFactories(optional bool bBySuperset)
00457	{
00458		local int i;
00459	
00460		for(i=0;i<10;i++)
00461		{
00462			if(Factories[i] != None) 
00463			{
00464				Factories[i].Shutdown(bBySuperset);
00465				Factories[i] = None;
00466			}
00467		}	
00468	}
00469	
00470	function Query(optional bool bBySuperset, optional bool bInitial, optional bool bInNoSort)
00471	{
00472		local int i;
00473	
00474		bNoSort = bInNoSort;
00475	
00476		// Query all our factories
00477		for(i=0;i<10;i++)
00478		{
00479			if(Factories[i] != None)
00480				Factories[i].Query(bBySuperset, bInitial);
00481		}
00482	}
00483	
00484	function Paint(Canvas C, float X, float Y)
00485	{
00486		DrawStretchedTexture(C, 0, 0, WinWidth, WinHeight, Texture'BlackTexture');
00487	}
00488	
00489	function Tick(float Delta)
00490	{
00491		PingedList.Tick(Delta);
00492	
00493		if(PingedList.bNeedUpdateCount)
00494		{
00495			PingedList.UpdateServerCount();
00496			PingedList.bNeedUpdateCount = False;
00497		}
00498	
00499		// AutoRefresh local servers
00500		if(AutoRefreshTime > 0)
00501		{
00502			TimeElapsed += Delta;
00503			
00504			if(TimeElapsed > AutoRefreshTime)
00505			{
00506				TimeElapsed = 0;
00507				Refresh(,,True, bNoAutoSort);
00508			}
00509		}	
00510	}
00511	
00512	function BeforePaint(Canvas C, float X, float Y)
00513	{
00514		local UBrowserMainWindow W;
00515		local UBrowserSupersetList l;
00516		local EPingState P;
00517		local int PercentComplete;
00518		local int TotalReturnedServers;
00519		local string E;
00520		local int TotalServers;
00521		local int PingedServers;
00522		local int MyServers;
00523	
00524		Super.BeforePaint(C, X, Y);
00525	
00526		W = UBrowserMainWindow(GetParent(class'UBrowserMainWindow'));
00527		l = UBrowserSupersetList(SupersetList.Next);
00528	
00529		if(l != None && PingState != PS_RePinging)
00530		{
00531			P = l.SupersetWindow.PingState;
00532			PingState = P;
00533	
00534			if(P == PS_QueryServer)
00535				TotalReturnedServers = l.SupersetWindow.UnpingedList.Count();
00536	
00537			PingedServers = l.SupersetWindow.PingedList.Count();
00538			TotalServers = l.SupersetWindow.UnpingedList.Count() + PingedServers;
00539			MyServers = PingedList.Count();
00540		
00541			E = l.SupersetWindow.ErrorString;
00542		}
00543		else
00544		{
00545			P = PingState;
00546			if(P == PS_QueryServer)
00547				TotalReturnedServers = UnpingedList.Count();
00548	
00549			PingedServers = PingedList.Count();
00550			TotalServers = UnpingedList.Count() + PingedServers;
00551			MyServers = PingedList.Count();
00552	
00553			E = ErrorString;
00554		}
00555	
00556		if(TotalServers > 0)
00557			PercentComplete = PingedServers*100.0/TotalServers;
00558	
00559		switch(P)
00560		{
00561		case PS_QueryServer:
00562			if(TotalReturnedServers > 0)
00563				W.DefaultStatusBarText(QueryServerText$" ("$ServerCountLeader$TotalReturnedServers$" "$ServerCountName$")");
00564			else
00565				W.DefaultStatusBarText(QueryServerText);
00566			break;
00567		case PS_QueryFailed:
00568			W.DefaultStatusBarText(QueryFailedText$E);
00569			break;
00570		case PS_Pinging:
00571		case PS_RePinging:
00572			W.DefaultStatusBarText(PingingText$" "$PercentComplete$"% "$CompleteText$". "$ServerCountLeader$MyServers$" "$ServerCountName$", "$PlayerCountLeader$PingedList.TotalPlayers$" "$PlayerCountName);
00573			break;
00574		case PS_Done:
00575			W.DefaultStatusBarText(ServerCountLeader$MyServers$" "$ServerCountName$", "$PlayerCountLeader$PingedList.TotalPlayers$" "$PlayerCountName);
00576			break;
00577		}
00578	}
00579	
00580	defaultproperties
00581	{
00582	     ServerListClassName="UBrowser.UBrowserServerList"
00583	     GridClass="UBrowser.UBrowserServerGrid"
00584	     bSuspendPingOnClose=True
00585	     RightClickMenuClass=Class'UBrowser.UBrowserRightClickMenu'
00586	     InfoName="Info"
00587	     PlayerCountName="Players"
00588	     ServerCountName="Servers"
00589	     QueryServerText="Querying master server (hit F5 if nothing happens)"
00590	     QueryFailedText="Master Server Failed: "
00591	     PingingText="Pinging Servers"
00592	     CompleteText="Complete"
00593	}

End Source Code