Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |
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 |
//============================================================================== // Created on: 09/10/2003 // Choose a difficulty level and gametype, and the player will be automatically // connected to the server with the best ping in that category. // // Written by Ron Prestenback // © 2003, Epic Games, Inc. All Rights Reserved //============================================================================== class UT2K4QuickPlay extends LargeWindow; var automated GUIImage i_Border; var automated GUILabel l_Status, l_ServerCount; var automated moComboBox co_Game, co_Difficulty; var automated GUIButton b_QuickConnect, b_lClose; var MasterServerClient MSC; var localized array<string> DifficultyOptions; // Whether we are currently conducting a search for a good server var bool bPendingSearch; // Number of concurrent ping requests currently active - used to make sure we don't surpass MaxSimultaneousPing var int ThreadCount; var array<int> PingQueue; // Indexes of servers still waiting to be pinged var int QuickConnectSeconds; // Number of seconds since we began pinging for quick connect var config int MaxWaitSeconds; // Maximum number of seconds to wait for pinging to be completed // List of servers received from the Master Server var array<GameInfo.ServerResponseLine> Servers; // Quick Connect properties var localized string PlayText, SearchingText, ReadyText, ConnectText, CancelText, ConnectHint, CancelHint; // Localized status text var localized string BeginningSearchText; var localized string AuthFailedText; var localized string ServerCountText; var localized string SearchCancelledText; var localized string ConnectionFailedText; var localized string TimedOutText; var localized string NoServersReceivedText; var localized string NoValidText; delegate OnOpenConnection(); delegate OnCloseConnection(); function InitComponent(GUIController MyController, GUIComponent MyComponent) { local int i; Super.InitComponent(MyController, MyComponent); for ( i = 0; i < DifficultyOptions.Length; i++ ) co_Difficulty.AddItem(DifficultyOptions[i]); StatusTimer(None); ChangeQuickPlayStatus(False); } event Opened(GUIComponent Sender) { local int i; local array<CacheManager.GameRecord> Records; Super.Opened(Sender); class'CacheManager'.static.GetGameTypeList(Records); for ( i = 0; i < Records.Length; i++ ) co_Game.AddItem(Records[i].GameName,,Records[i].ClassName); } event Closed(GUIComponent Sender, bool bCancelled) { Super.Closed(Sender, bCancelled); CloseMSConnection(); } event Free() { Super.Free(); CloseMSConnection(); } function bool NotifyLevelChange() { CloseMSConnection(); return Super.NotifyLevelChange(); } function CloseMSConnection() { KillTimer(); if ( MSC != None ) { MSC.CancelPings(); MSC.Stop(); } MSC = None; } // Master Server Methods function AddQueryTerm(coerce string Key, coerce string Value, MasterServerClient.EQueryType QueryType) { local MasterServerClient.QueryData QD; local int i; for ( i = 0; i < MSC.Query.Length; i++ ) { QD = MSC.Query[i]; if ( QD.Key ~= Key && QD.Value ~= Value && QD.QueryType == QueryType ) return; } QD.Key = Key; QD.Value = Value; QD.QueryType = QueryType; MSC.Query[i] = QD; } function HandleObject( Object Obj, optional Object OptionalObj_1, optional Object OptionalObj_2 ) { MSC = MasterServerClient(Obj); } event Timer() { if ( Playerowner() != None && PlayerOwner().Level.TimeSeconds - QuickConnectSeconds > MaxWaitSeconds ) { SetStatusCaption( NoValidText ); CancelQuickPlay(); } UpdateQueue(); } function bool InternalOnClick(GUIComponent Sender) { if ( Sender == b_QuickConnect ) { if ( QuickConnectPending() ) { CancelQuickPlay(); SetStatusCaption(SearchCancelledText); } else { SetStatusCaption( BeginningSearchText @ co_Game.GetText() ); CreateQuickPlayQuery( co_Game.GetExtra(), co_Difficulty.GetIndex() ); } return true; } if ( Sender == b_lClose ) { Controller.CloseMenu(false); return true; } return false; } function CreateQuickPlayQuery( string GameType, int Index ) { local int Pos; // Reset any browser query in progress. ResetQueryClient(MSC); // Add all query parameters ChangeQuickPlayStatus(True); // Remove the package name, if it exists Pos = InStr(GameType, "."); if ( Pos != -1 ) GameType = Mid(GameType, Pos + 1); // Desired GameType AddQueryTerm( "gametype", GameType, QT_Equals ); // Desired Difficulty AddQueryTerm( "category", Index, QT_Equals ); // Must be standard server AddQueryTerm( "standard", "true", QT_Equals ); // Must not be passworded AddQueryTerm( "password", "false", QT_Equals ); // Cannot be empty or full AddQueryTerm( "currentplayers", "0", QT_GreaterThan ); AddQueryTerm( "freespace", "0", QT_GreaterThan ); // begin searching for an appropriate server (too bad objects don't support states) QuickConnectSeconds = PlayerOwner().Level.TimeSeconds; MSC.StartQuery( CTM_Query ); } function QueryComplete( MasterServerClient.EResponseInfo ResponseInfo, int Info ) { switch ( ResponseInfo ) { case RI_Success: SetTimer(0.1, True); break; case RI_AuthenticationFailed: SetStatusCaption( AuthFailedText ); CancelQuickPlay(); break; case RI_ConnectionFailed: SetStatusCaption( ConnectionFailedText ); CancelQuickPlay(); break; case RI_ConnectionTimeout: SetStatusCaption( TimedOutText ); CancelQuickPlay(); break; } } function CancelQuickPlay() { // Cancel pings MSC.CancelPings(); ChangeQuickPlayStatus(False); } function ChangeQuickPlayStatus(bool bIsSearching) { bPendingSearch = bIsSearching; if ( QuickConnectPending() ) { // Set the button text SetStatusCaption(SearchingText); b_QuickConnect.Caption = CancelText; b_QuickConnect.SetHint(CancelHint); } else { KillTimer(); l_Status.SetTimer(2.5, False); b_QuickConnect.Caption = ConnectText; b_QuickConnect.SetHint(ConnectHint); } } function ResetQueryClient(ServerQueryClient Client) { if ( Client == None ) return; ThreadCount = 0; if ( PingQueue.Length > 0 ) PingQueue.Remove(0, PingQueue.Length); if ( Servers.Length > 0 ) Servers.Remove(0, Servers.Length); UpdateServerCount(); Client.OnReceivedPingInfo = ReceivedPingInfo; Client.OnPingTimeout = ReceivedPingTimeout; if ( MasterServerClient(Client) == None ) return; MasterServerClient(Client).OnReceivedServer = ReceivedNewServer; MasterServerClient(Client).OnQueryFinished = QueryComplete; MasterServerClient(Client).Query.Length = 0; } function ReceivedNewServer( GameInfo.ServerResponseLine NewServer ) { local int i; // log("ReceivedNewServer:"$NewServer.ServerName@"IP:"$NewServer.IP); // Just add this entry i = Servers.Length; Servers[i] = NewServer; // If the response packet didn't include the ping, set it to the highest value if ( Servers[i].Ping == 0 ) Servers[i].Ping = 9999; AddServerToPingQueue(i); } function AddServerToPingQueue(int ServerIndex) { local int i; // log("AddServerToPingQueue ServerIndex:"$ServerIndex); i = PingQueue.Length; PingQueue[i] = ServerIndex; UpdateServerCount(); if ( ThreadCount < class'UT2K4ServerBrowser'.static.CalculateMaxConnections() ) PingServer(i); } // go through our list of server received from the master server, and ping each one // this search will only ping servers for which we have not received pings from // this allows the ping to be stopped and restarted (such as when switching tabs) function UpdateQueue() { local int maxcount; maxcount = class'UT2K4ServerBrowser'.static.CalculateMaxConnections(); // log("UpdateQueue cnt:"$maxcount@"ThreadCount:"$ThreadCount@"PingQueue.Length:"$PingQueue.Length); while ( ThreadCount < maxcount && PingQueue.Length > 0 ) PingServer(0); UpdateServerCount(); if ( PingQueue.Length == 0 && ThreadCount <= 0 ) PingingComplete(); } function PingServer(int QueueIndex) { local int i; if ( QueueIndex < 0 || QueueIndex >= PingQueue.Length ) return; i = PingQueue[QueueIndex]; PingQueue.Remove(QueueIndex, 1); ThreadCount++; MSC.PingServer( i, PC_AutoPing, Servers[i].IP, Servers[i].QueryPort, QI_Ping, Servers[i] ); OnOpenConnection(); } function ReceivedPingInfo( int ServerIndex, ServerQueryClient.EPingCause PingCause, GameInfo.ServerResponseLine ServerInfo ) { // log("ReceivedPingInfo ServerIndex:"$ServerIndex@"EPingCause:"$GetEnum(enum'EPingCause', PingCause)); // Validation if ( ServerIndex < 0 || ServerIndex >= Servers.Length ) return; // Replace my copy with this copy OnCloseConnection(); ThreadCount--; Servers[ServerIndex] = ServerInfo; UpdateServerCount(); } function ReceivedPingTimeout( int ServerIndex, ServerQueryClient.EPingCause PingCause ) { // log("ReceivedPingTimeout ServerIndex:"$ServerIndex@"Servers.Length:"$Servers.Length); // Validation if ( ServerIndex < 0 || ServerIndex >= Servers.Length ) return; OnCloseConnection(); ThreadCount--; UpdateServerCount(); } function PingingComplete() { local int i, Best; local string URL; local PlayerController PC; // log("PingingComplete Servers.Length:"$Servers.Length); if ( Servers.Length == 0 ) { SetStatusCaption(NoServersReceivedText); ChangeQuickPlayStatus(False); return; } Best = -1; for ( i = 0; i < Servers.Length; i++ ) { if ( Best == -1 ) { if ( Servers[i].Ping < 9999 ) Best = i; } else if ( Servers[i].Ping <= Servers[Best].Ping ) { if ( Servers[i].Ping < Servers[Best].Ping ) { Best = i; continue; } if ( Servers[i].CurrentPlayers > Servers[Best].CurrentPlayers ) { Best = i; continue; } } } // No valid servers found!!!!! if ( Best == -1 ) { SetStatusCaption(NoValidText); ChangeQuickPlayStatus(False); return; } PC = PlayerOwner(); // TODO: Possibly display chosen server, and offer to accept or reject choice URL = PC.GetURLProtocol() $ "://" $ Servers[Best].IP $ ":" $ Servers[Best].Port; log("Performing ClientTravel URL:"$URL); KillTimer(); CloseMSConnection(); Controller.CloseAll(False,True); PC.ClientTravel( URL, TRAVEL_Relative, False ); } function bool QuickConnectPending() { return bPendingSearch; } function StatusTimer(GUIComponent Sender) { SetStatusCaption(ReadyText); } function SetStatusCaption(string StatusMessage) { l_Status.Caption = StatusMessage; } function UpdateServerCount() { local string s; s = Repl(ServerCountText, "%NumReceived%", Servers.Length - PingQueue.Length); s = Repl(s, "%TotalServers%", Servers.Length); l_ServerCount.Caption = s; } DefaultProperties { WinWidth=1.000000 WinHeight=0.370059 WinLeft=0.000000 WinTop=0.250000 Begin Object Class=GUILabel Name=ConnectionStatus WinWidth=0.849415 WinHeight=0.411678 WinLeft=0.073594 WinTop=0.323438 TextAlign=TXTA_Center FontScale=FNS_Medium bBoundToParent=True bScaleToParent=True RenderWeight=0.1 OnTimer=StatusTimer StyleName="TextLabel" End Object Begin Object Class=GUILabel Name=ServerCount WinWidth=0.761916 WinHeight=0.130428 WinLeft=0.120469 WinTop=0.604924 TextAlign=TXTA_Center FontScale=FNS_Small StyleName="TextLabel" bBoundToParent=True bScaleToParent=True RenderWeight=0.1 End Object Begin Object Class=moComboBox Name=GameType WinWidth=0.488417 WinHeight=0.087720 WinLeft=0.059751 WinTop=0.204219 Caption="Game Type" Hint="Select the game type you would like to play." CaptionWidth=0.3 ComponentWidth=-1 TabOrder=0 bAutoSizeCaption=True bReadOnly=True bBoundToParent=True bScaleToParent=True bStandardized=true End Object Begin Object Class=moComboBox Name=DifficultyLevel WinWidth=0.367167 WinHeight=0.087720 WinLeft=0.571664 WinTop=0.200564 Caption="Difficulty" Hint="Select the desired game difficulty level to search for. If you are new to UT2004, it is recommended that you choose the \"Beginner\" setting." CaptionWidth=0.3 ComponentWidth=-1 TabOrder=1 bAutoSizeCaption=True bReadOnly=True bBoundToParent=True bScaleToParent=True bStandardized=true End Object ConnectText="SEARCH" ConnectHint="Once you've selected a gametype and difficulty level, click \"Search\" to begin searching for a server in the category that has the lowest ping" CancelText="CANCEL" CancelHint="Cancel the current \"Quick Join\" search" Begin Object Class=GUIButton Name=QuickPlaySearch WinWidth=0.120347 WinHeight=0.109137 WinLeft=0.307992 WinTop=0.767551 TabOrder=2 OnClick=InternalOnClick bScaleToParent=True bBoundToParent=True // bAutoSize=True bStandardized=true End Object Begin Object Class=GUIButton Name=QuickPlayClose Caption="CLOSE" WinWidth=0.125690 WinHeight=0.109137 WinLeft=0.600883 WinTop=0.767551 TabOrder=4 Hint="Close this window" OnClick=InternalOnClick bScaleToParent=True bBoundToParent=True bStandardized=true End Object Begin Object class=GUIImage name=IBorder WinWidth=0.878815 WinHeight=0.460699 WinLeft=0.060258 WinTop=0.300283 RenderWeight=0.001 ImageStyle=ISTY_Stretched Image=material'2K4Menus.NewControls.Display99' bScaleToParent=True bBoundToParent=True End Object I_Border=iBorder MaxWaitSeconds=20 b_QuickConnect=QuickPlaySearch b_lClose=QuickPlayClose co_Difficulty=DifficultyLevel co_Game=GameType l_ServerCount=ServerCount l_Status=ConnectionStatus DifficultyOptions(0)="Beginner" DifficultyOptions(1)="Experienced" DifficultyOptions(2)="Expert" bCaptureInput=True SearchingText="SEARCHING..." ReadyText="Ready" BeginningSearchText="Please wait...requesting servers for gametype:" AuthFailedText="Authentication failed! Please try again later..." ConnectionFailedText="Connection failed - unable to contact the master server. Please check your network connection and try again!" TimedOutText="Master server took too long to respond to query. Please try again later." SearchCancelledText="Search cancelled!" NoServersReceivedText="Sorry, no valid servers found for this gametype!" NoValidText="Unknown error encountered while pinging servers! Please retry query..." ServerCountText="Received/Total - %NumReceived%/%TotalServers%" WindowName="Quick Play" } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |