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 |
// ============================================================================ // JBWebApplicationScoreboard // Copyright 2003 by Mychaeel <mychaeel@planetjailbreak.com> // $Id: JBWebApplicationScoreboard.uc,v 1.5 2006-09-01 19:45:06 jrubzjeknf Exp $ // // Serves the Jailbreak Web Scoreboard to web browsers. // ============================================================================ class JBWebApplicationScoreboard extends WebApplication; // ============================================================================ // Types // ============================================================================ struct TInfoPlayer { var string Name; // player name var int Score; // total score var string Info; // partial scores }; struct TInfoTeam { var string Name; // team name var int Score; // team score var array<TInfoPlayer> ListInfoPlayer; // players on this team var string VarTemplateName; // template var for team name var string VarTemplateScore; // template var for team score var string VarTemplateHeaderLines; // template var for header rowspan var string VarTemplateEntry; // template var for entry in row var string FileTemplateEntry; // template inc file for entry var string FileTemplateEntryNone; // template inc file for no entry }; // ============================================================================ // Configuration // ============================================================================ var string PathSourceImages; // source path for images var string PathSourceTemplates; // source path for template files var string PathSourceStyles; // source path for style sheets var string FileTemplateScoreboard; // main template for scoreboard var string FileTemplateRow; // template inc file for one row var string FileTemplateMutators; // template inc file for mutator list var string FileTemplateMutatorsNone; // template inc file for no mutators // ============================================================================ // Variables // ============================================================================ var private TInfoTeam InfoTeam[2]; // info for red and blue team // ============================================================================ // Query // // If a file in the virtual image or styles directory was requested, delivers // it. Otherwise redirects the browser to the canonical scoreboard address if // applicable, or serves the Jailbreak Web Scoreboard. // ============================================================================ function Query(WebRequest WebRequest, WebResponse WebResponse) { if (Left(WebRequest.URI, 8) == "/images/") QueryImage(WebRequest, WebResponse); else if (Left(WebRequest.URI, 8) == "/styles/") QueryStyle(WebRequest, WebResponse); else if (WebRequest.URI != "/") WebResponse.Redirect(WebServer.ServerName $ Path $ "/"); else QueryScoreboard(WebRequest, WebResponse); } // ============================================================================ // QueryImage // // Delivers an image that is cached by the browser. // ============================================================================ function QueryImage(WebRequest WebRequest, WebResponse WebResponse) { local string FileImage; local string MIMEType; FileImage = WebRequest.URI; while (InStr(FileImage, "/") >= 0) FileImage = Mid(FileImage, InStr(FileImage, "/") + 1); if (Right(FileImage, 4) ~= ".gif") MIMEType = "image/gif"; else if (Right(FileImage, 4) ~= ".jpe") MIMEType = "image/jpeg"; else if (Right(FileImage, 4) ~= ".jpg") MIMEType = "image/jpeg"; else if (Right(FileImage, 5) ~= ".jpeg") MIMEType = "image/jpeg"; else if (Right(FileImage, 4) ~= ".png") MIMEType = "image/png"; if (MIMEType == "") WebResponse.HTTPError(404); else { WebResponse.SendStandardHeaders(MIMEType, True); WebResponse.IncludeBinaryFile(PathSourceImages $ "/" $ FileImage); } } // ============================================================================ // QueryStyle // // Delivers a style sheet that is cached by the browser. // ============================================================================ function QueryStyle(WebRequest WebRequest, WebResponse WebResponse) { local string FileStyle; local string MIMEType; FileStyle = WebRequest.URI; while (InStr(FileStyle, "/") >= 0) FileStyle = Mid(FileStyle, InStr(FileStyle, "/") + 1); if (Right(FileStyle, 4) ~= ".css") MIMEType = "text/css"; if (MIMEType == "") WebResponse.HTTPError(404); else { WebResponse.SendStandardHeaders(MIMEType, True); WebResponse.IncludeBinaryFile(PathSourceStyles $ "/" $ FileStyle); } } // ============================================================================ // QueryScoreboard // // Creates the Jailbreak Web Scoreboard from templates and serves it. // ============================================================================ function QueryScoreboard(WebRequest WebRequest, WebResponse WebResponse) { local int iInfoPlayer; local int iInfoTeam; local int iRow; local int nHeaderLines; local int nInfoPlayerMax; local string ResultEntry; local string ResultEntries; local string ResultMutators; ReadListInfoPlayer(); nInfoPlayerMax = 1; for (iInfoTeam = 0; iInfoTeam < ArrayCount(InfoTeam); iInfoTeam++) { nInfoPlayerMax = Max(nInfoPlayerMax, InfoTeam[iInfoTeam].ListInfoPlayer.Length); InfoTeam[iInfoTeam].Name = Level.Game.GameReplicationInfo.Teams[iInfoTeam].TeamName; InfoTeam[iInfoTeam].Score = Level.Game.GameReplicationInfo.Teams[iInfoTeam].Score; } for (iRow = 0; iRow < nInfoPlayerMax; iRow++) { for (iInfoTeam = 0; iInfoTeam < ArrayCount(InfoTeam); iInfoTeam++) { ResultEntry = ""; iInfoPlayer = InfoTeam[iInfoTeam].ListInfoPlayer.Length - nInfoPlayerMax + iRow; if (iInfoPlayer == -1 && InfoTeam[iInfoTeam].ListInfoPlayer.Length == 0) ResultEntry = WebResponse.LoadParsedUHTM(GetFileTemplate(InfoTeam[iInfoTeam].FileTemplateEntryNone)); else if (iInfoPlayer >= 0) { WebResponse.Subst("Name", EscapeHTML(InfoTeam[iInfoTeam].ListInfoPlayer[iInfoPlayer].Name)); WebResponse.Subst("Score", EscapeHTML(InfoTeam[iInfoTeam].ListInfoPlayer[iInfoPlayer].Score)); WebResponse.Subst("Info", EscapeHTML(InfoTeam[iInfoTeam].ListInfoPlayer[iInfoPlayer].Info)); ResultEntry = WebResponse.LoadParsedUHTM(GetFileTemplate(InfoTeam[iInfoTeam].FileTemplateEntry)); } WebResponse.Subst(InfoTeam[iInfoTeam].VarTemplateEntry, ResultEntry); } ResultEntries = ResultEntries $ WebResponse.LoadParsedUHTM(GetFileTemplate(FileTemplateRow)); } ResultMutators = GetMutators(); if (ResultMutators == "") ResultMutators = "" $ WebResponse.LoadParsedUHTM(GetFileTemplate(FileTemplateMutatorsNone)); else { WebResponse.Subst("Mutators", EscapeHTML(ResultMutators)); ResultMutators = "" $ WebResponse.LoadParsedUHTM(GetFileTemplate(FileTemplateMutators)) $ ""; } for (iInfoTeam = 0; iInfoTeam < ArrayCount(InfoTeam); iInfoTeam++) { nHeaderLines = nInfoPlayerMax - Max(1, InfoTeam[iInfoTeam].ListInfoPlayer.Length) + 1; WebResponse.Subst(InfoTeam[iInfoTeam].VarTemplateName, EscapeHTML(InfoTeam[iInfoTeam].Name)); WebResponse.Subst(InfoTeam[iInfoTeam].VarTemplateScore, EscapeHTML(InfoTeam[iInfoTeam].Score)); WebResponse.Subst(InfoTeam[iInfoTeam].VarTemplateHeaderLines, EscapeHTML(nHeaderLines)); } WebResponse.Subst("URL", WebServer.ServerURL $ Path $ "/"); WebResponse.Subst("Entries", ResultEntries); WebResponse.Subst("Mutators", ResultMutators); WebResponse.Subst("ServerName", EscapeHTML(Level.Game.GameReplicationInfo.ServerName)); WebResponse.Subst("AdminName", EscapeHTML(Level.Game.GameReplicationInfo.AdminName)); WebResponse.Subst("AdminEmail", EscapeHTML(Level.Game.GameReplicationInfo.AdminEmail)); WebResponse.Subst("GameURL", GetGameURL()); WebResponse.Subst("GameTitle", EscapeHTML(Class'JBInterfaceScores'.Static.GetGameTitle (Level))); WebResponse.Subst("GameDescription", EscapeHTML(Class'JBInterfaceScores'.Static.GetGameDescription(Level)) @ EscapeHTML(Class'JBInterfaceScores'.Static.GetGameLimits (Level))); WebResponse.Subst("GameTime", GetTime()); WebResponse.IncludeUHTM(GetFileTemplate(FileTemplateScoreboard)); } // ============================================================================ // GetFileTemplate // // Returns the full relative path for the given template file name. // ============================================================================ function string GetFileTemplate(string FileTemplate) { return PathSourceTemplates $ "/" $ FileTemplate; } // ============================================================================ // GetGameURL // // Returns the server's address that can be used to join the game. // ============================================================================ function string GetGameURL() { local string GameURL; GameURL = Mid(WebServer.ServerURL, 7); // strip protocol GameURL = Left(GameURL, InStr(GameURL $ ":", ":")); GameURL = "ut2004://" $ GameURL $ ":" $ Level.Game.GetServerPort(); return GameURL; } // ============================================================================ // GetMutators // // Returns a list of mutators currently running on this server. // ============================================================================ function string GetMutators() { local string Mutators; local Mutator thisMutator; for (thisMutator = Level.Game.BaseMutator; thisMutator != None; thisMutator = thisMutator.NextMutator) if (thisMutator.bUserAdded && thisMutator.FriendlyName != Class'Mutator'.Default.FriendlyName) { if (Mutators != "") Mutators = Mutators $ ", "; Mutators = Mutators $ thisMutator.FriendlyName; } return Mutators; } // ============================================================================ // GetTime // // Returns the ingame time. // ============================================================================ function string GetTime() { local int TotalTime, Minutes, Seconds; local string Head, MinutesText, SecondsText, Tail; if (!Level.Game.GameReplicationInfo.bMatchHasBegun) // Match hasnt started yet return "The game hasn't started yet"; TotalTime = Level.Game.GameReplicationInfo.ElapsedTime; if (Level.Game.bGameEnded) { // Match has ended Head = "After"; Tail = "the game has ended"; } else { if (Level.Game.TimeLimit > 0) { // There's a time limit, count down instead Tail = "to go"; TotalTime = Level.Game.TimeLimit*60 - TotalTime; if (TotalTime < 0) { // Overtime Tail = "in overtime"; TotalTime = -TotalTime; } } else Tail = "passed"; } Minutes = TotalTime / 60; Seconds = TotalTime % 60; if (Minutes == 1) MinutesText = "minute and"; else MinutesText = "minutes and"; if (Seconds == 1) SecondsText = "second"; else SecondsText = "seconds"; return Head @ Minutes @ MinutesText @ Seconds @ SecondsText @ Tail; } // ============================================================================ // ReadListInfoPlayer // // For both teams, fills the ListInfoPlayer array with a list of players and // their corresponding information and sorts that list. // ============================================================================ function ReadListInfoPlayer() { local int iInfoTeam; local int iInfoPlayer; local JBTagPlayer firstTagPlayer; local JBTagPlayer thisTagPlayer; local PlayerReplicationInfo PlayerReplicationInfo; for (iInfoTeam = 0; iInfoTeam < ArrayCount(InfoTeam); iInfoTeam++) InfoTeam[iInfoTeam].ListInfoPlayer.Length = 0; firstTagPlayer = JBGameReplicationInfo(Level.Game.GameReplicationInfo).firstTagPlayer; for (thisTagPlayer = firstTagPlayer; thisTagPlayer != None; thisTagPlayer = thisTagPlayer.nextTag) { iInfoTeam = thisTagPlayer.GetTeam().TeamIndex; iInfoPlayer = InfoTeam[iInfoTeam].ListInfoPlayer.Length; InfoTeam[iInfoTeam].ListInfoPlayer.Length = InfoTeam[iInfoTeam].ListInfoPlayer.Length + 1; PlayerReplicationInfo = thisTagPlayer.GetPlayerReplicationInfo(); InfoTeam[iInfoTeam].ListInfoPlayer[iInfoPlayer].Name = PlayerReplicationInfo.PlayerName; InfoTeam[iInfoTeam].ListInfoPlayer[iInfoPlayer].Score = PlayerReplicationInfo.Score; InfoTeam[iInfoTeam].ListInfoPlayer[iInfoPlayer].Info = Class'JBInterfaceScores'.Static.GetInfoScores(thisTagPlayer); } for (iInfoTeam = 0; iInfoTeam < ArrayCount(InfoTeam); iInfoTeam++) SortListInfoPlayer(InfoTeam[iInfoTeam].ListInfoPlayer, 0, InfoTeam[iInfoTeam].ListInfoPlayer.Length - 1); } // ============================================================================ // SortListInfoPlayer // // Sorts the given array of player infos, using a QuickSort implementation. // ============================================================================ function SortListInfoPlayer(out array<TInfoPlayer> ListInfoPlayer, int iInfoPlayerStart, int iInfoPlayerEnd) { local int iInfoPlayerLeft; local int iInfoPlayerRight; local TInfoPlayer InfoPlayerMiddle; local TInfoPlayer InfoPlayerSwapped; if (iInfoPlayerStart >= iInfoPlayerEnd) return; iInfoPlayerLeft = iInfoPlayerStart; iInfoPlayerRight = iInfoPlayerEnd; InfoPlayerMiddle = ListInfoPlayer[(iInfoPlayerStart + iInfoPlayerEnd) / 2]; while (iInfoPlayerLeft < iInfoPlayerRight) { while (iInfoPlayerLeft < iInfoPlayerEnd && IsInfoPlayerInOrder(ListInfoPlayer[iInfoPlayerLeft], InfoPlayerMiddle)) iInfoPlayerLeft += 1; while (iInfoPlayerStart < iInfoPlayerRight && IsInfoPlayerInOrder(InfoPlayerMiddle, ListInfoPlayer[iInfoPlayerRight])) iInfoPlayerRight -= 1; if (iInfoPlayerLeft < iInfoPlayerRight) { InfoPlayerSwapped = ListInfoPlayer[iInfoPlayerLeft]; ListInfoPlayer[iInfoPlayerLeft] = ListInfoPlayer[iInfoPlayerRight]; ListInfoPlayer[iInfoPlayerRight] = InfoPlayerSwapped; } iInfoPlayerLeft += 1; iInfoPlayerRight -= 1; } SortListInfoPlayer(ListInfoPlayer, iInfoPlayerStart, iInfoPlayerRight); SortListInfoPlayer(ListInfoPlayer, iInfoPlayerLeft, iInfoPlayerEnd); } // ============================================================================ // IsInfoPlayerInOrder // // Checks whether the two given player info variables are in the correct order // for the scoreboard. If both match, they are considered not to be in the // right order for the sake of the sorting algorithm. // ============================================================================ function bool IsInfoPlayerInOrder(TInfoPlayer InfoPlayer1, TInfoPlayer InfoPlayer2) { return (InfoPlayer1.Score > InfoPlayer2.Score || (InfoPlayer1.Score == InfoPlayer2.Score && InfoPlayer1.Name < InfoPlayer2.Name)); } // ============================================================================ // EscapeHTML // // Escapes characters with a special meaning in HTML. // ============================================================================ function string EscapeHTML(coerce string Text) { Level.ReplaceText(Text, "<", "<"); Level.ReplaceText(Text, ">", ">"); Level.ReplaceText(Text, "&", "&"); Level.ReplaceText(Text, "\"", """); return Text; } // ============================================================================ // Defaults // ============================================================================ defaultproperties { PathSourceImages = "JailbreakWebScoreboard"; PathSourceTemplates = "JailbreakWebScoreboard"; PathSourceStyles = "JailbreakWebScoreboard"; FileTemplateScoreboard = "scoreboard.htm"; FileTemplateRow = "scoreboard_row.inc"; FileTemplateMutators = "scoreboard_mutators.inc"; FileTemplateMutatorsNone = "scoreboard_mutators_none.inc"; InfoTeam[0] = (VarTemplateName="TeamNameRed",VarTemplateScore="TeamScoreRed",VarTemplateHeaderLines="HeaderLinesRed",VarTemplateEntry="EntryRed",FileTemplateEntry="scoreboard_entry_red.inc",FileTemplateEntryNone="scoreboard_entry_none_red.inc"); InfoTeam[1] = (VarTemplateName="TeamNameBlue",VarTemplateScore="TeamScoreBlue",VarTemplateHeaderLines="HeaderLinesBlue",VarTemplateEntry="EntryBlue",FileTemplateEntry="scoreboard_entry_blue.inc",FileTemplateEntryNone="scoreboard_entry_none_blue.inc"); } |
Overview | Package | Class | Source | Class tree | Glossary | UnrealScript Documentation |
previous class next class | frames no frames |