From 9ab9c617b97a507c188931b4cbec21835ff4e4a2 Mon Sep 17 00:00:00 2001 From: Harest Date: Sun, 24 Nov 2019 22:52:46 +0100 Subject: [PATCH] Little refactor and changed how completion time is calculated - Using the moment the player clicked on "start quest button" for instance could lead to the player letting the window open until being close to a token. (Race)StartTime taken instead. - Refactored the times formatting for the board a bit. - URLEncoding Username. --- GetBoard.php | 14 ++------------ Main.php | 15 +++++---------- UpdateQuest.php | 2 +- includes/functions.php | 10 ++++++++++ 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/GetBoard.php b/GetBoard.php index 1183943..74315d0 100644 --- a/GetBoard.php +++ b/GetBoard.php @@ -47,18 +47,8 @@ $qh = null; // Format the players' times foreach ($players as $key => $player) { - $tmpTime = gameTimeToDateInterval($player["firstTime"]); - if ($tmpTime->h >= 1) { - $players[$key]["firstTime"] = "more than 1 hour"; - } else { - $players[$key]["firstTime"] = $tmpTime->format("%I:%S.").substr($tmpTime->f, 0, 3); - } - $tmpTime = gameTimeToDateInterval($player["bestTime"]); - if ($tmpTime->h >= 1) { - $players[$key]["bestTime"] = "more than 1 hour"; - } else { - $players[$key]["bestTime"] = $tmpTime->format("%I:%S.").substr($tmpTime->f, 0, 3); - } + $players[$key]["firstTime"] = gameTimeFormatted($player["firstTime"]); + $players[$key]["bestTime"] = gameTimeFormatted($player["bestTime"]); } // Return the results $playersList = array("Players" => $players, diff --git a/Main.php b/Main.php index cc6f6a1..0a5197a 100644 --- a/Main.php +++ b/Main.php @@ -179,14 +179,12 @@ declare persistent Text[][Integer] Pe_LocalTokensIds for Map; declare persistent Text[][Integer] Pe_PlayerPos for Map; declare persistent Integer[Integer] P_PlayerRaceStartTime for Map; - declare persistent Integer[Integer] P_PlayerQuestStartTime for Map; declare persistent Text[Integer] P_QuestMapUid for Map; Per_LocalTokensCollected[G_QuestId] = []; Pe_LocalTokensIds[G_QuestId] = []; Pe_PlayerPos[G_QuestId] = []; P_PlayerRaceStartTime[G_QuestId] = 0; - P_PlayerQuestStartTime[G_QuestId] = 0; P_QuestMapUid[G_QuestId] = ""; } @@ -208,9 +206,9 @@ if (nbPlayers >= 1) { declare Text QuestTitleToDisplay = TextLib::Replace(QuestTitleList, "[count]", nbPlayers ^ " " ^ PluralPlayers); Message.SetText(Message.Value ^ QuestTitleToDisplay ^ "\n"); - if (CurPage == 1) Message.SetText(Message.Value ^ "$nNote: This list is cached 10 minutes, ordered by first completion date.$z\n"); + if (CurPage == 1) Message.SetText(Message.Value ^ "$n$fffNote: This list is cached 10 minutes, ordered by first completion date.$z\n"); } else { - Message.SetText(Message.Value ^ QuestTitleEmptyList ^ "\n$nNote: This list is cached 10 minutes.$z"); + Message.SetText(Message.Value ^ QuestTitleEmptyList ^ "\n$n$fffNote: This list is cached 10 minutes.$z"); } for(i, StartPos, MaxLimit) { @@ -265,7 +263,6 @@ declare persistent Text[][Integer] Pe_LocalTokensIds for Map; declare persistent Text[][Integer] Pe_PlayerPos for Map; declare persistent Integer[Integer] P_PlayerRaceStartTime for Map; - declare persistent Integer[Integer] P_PlayerQuestStartTime for Map; declare persistent Text[Integer] P_QuestMapUid for Map; declare persistent Boolean DebugMode for Map; G_QuestId = '.htmlentities($QuestId, ENT_XML1).'; @@ -351,7 +348,6 @@ if (P_QuestMapUid[G_QuestId] == "") P_QuestMapUid[G_QuestId] = "'.htmlentities($QuestInfo["map_uid"], ENT_XML1).'"; if (DebugMode) log("MapUid for quest " ^ TextLib::ToText(G_QuestId) ^ " set to: " ^ P_QuestMapUid[G_QuestId]); P_PlayerRaceStartTime[G_QuestId] = GUIPlayer.'.$startTimeVar.'; - P_PlayerQuestStartTime[G_QuestId] = GameTime; // Check if the MapUid matches if (P_QuestMapUid[G_QuestId] != Map.MapInfo.MapUid) { @@ -388,7 +384,7 @@ } else { - Message.SetText(QuestFullDesc ^ "\n\nHave fun!\n\n$nNote: You need to complete the quest in the same race from where you started it. If you restart (e.g. by pressing del), you\'ll need to start the quest again. Several quests can be done in the same race.$z"); + Message.SetText(QuestFullDesc ^ "\n\n$fffHave fun!\n\n$nNote: You need to complete the quest in the same race from where you started it. If you restart (e.g. by pressing del), you\'ll need to start the quest again. Several quests can be done in the same race.$z"); } // Log all tokens for quest if debug activated @@ -446,7 +442,6 @@ if (P_QuestMapUid[G_QuestId] == "") P_QuestMapUid[G_QuestId] = "'.htmlentities($QuestInfo["map_uid"], ENT_XML1).'"; if (DebugMode) log("MapUid for quest " ^ TextLib::ToText(G_QuestId) ^ " set to: " ^ P_QuestMapUid[G_QuestId]); P_PlayerRaceStartTime[G_QuestId] = GUIPlayer.'.$startTimeVar.'; - P_PlayerQuestStartTime[G_QuestId] = GameTime; // Check if the MapUid matches if (P_QuestMapUid[G_QuestId] != Map.MapInfo.MapUid) { @@ -514,11 +509,11 @@ declare Text Pe_PlayerPosString = LogMissingTokens(); // Get quest completion time - declare Integer QuestCompletionTime = GameTime - P_PlayerQuestStartTime[G_QuestId]; + declare Integer QuestCompletionTime = GameTime - P_PlayerRaceStartTime[G_QuestId]; declare CHttpRequest request; if (DebugMode) log("Quest " ^ TextLib::ToText(G_QuestId) ^ " completed. Processing..."); - request = Http.CreateGet("'.$urlToRequest.'UpdateQuest.php?QuestId=" ^ TextLib::ToText(G_QuestId) ^ "&Login=" ^ LocalUser.Login ^ "&UserName=" ^ LocalUser.Name ^ "&Positions=" ^ TextLib::URLEncode(Pe_PlayerPosString) ^ "&MapUid=" ^ P_QuestMapUid[G_QuestId] ^ "&Time=" ^ TextLib::ToText(QuestCompletionTime) ^ "&" ^ Now); + request = Http.CreateGet("'.$urlToRequest.'UpdateQuest.php?QuestId=" ^ TextLib::ToText(G_QuestId) ^ "&Login=" ^ LocalUser.Login ^ "&UserName=" ^ TextLib::URLEncode(LocalUser.Name) ^ "&Positions=" ^ TextLib::URLEncode(Pe_PlayerPosString) ^ "&MapUid=" ^ P_QuestMapUid[G_QuestId] ^ "&Time=" ^ TextLib::ToText(QuestCompletionTime) ^ "&" ^ Now); clearPersistentData(); wait(request.IsCompleted); if (DebugMode) { diff --git a/UpdateQuest.php b/UpdateQuest.php index 6ff471b..dea39ee 100644 --- a/UpdateQuest.php +++ b/UpdateQuest.php @@ -13,7 +13,7 @@ // Get vars $Login = filter_input(INPUT_GET, 'Login'); $QuestId = intval(filter_input(INPUT_GET, 'QuestId')); - $UserName = filter_input(INPUT_GET, 'UserName'); + $UserName = urldecode(filter_input(INPUT_GET, 'UserName')); $Positions = urldecode(filter_input(INPUT_GET, 'Positions')); $MapUid = filter_input(INPUT_GET, 'MapUid'); $Time = intval(filter_input(INPUT_GET, 'Time')); diff --git a/includes/functions.php b/includes/functions.php index 8baa305..880a15a 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -33,4 +33,14 @@ function gameTimeToDateInterval($time) { $dateInterval->s = floor($seconds % 60); $dateInterval->f = $time - ($seconds * 1000); return $dateInterval; +} + +// Return a GameTime DateInterval formatted as MM:SS.ms +function gameTimeFormatted($time) { + $tmpTime = gameTimeToDateInterval($time); + if ($tmpTime->h >= 1) { + return "more than 1 hour"; + } else { + return $tmpTime->format("%I:%S.").$tmpTime->f; + } } \ No newline at end of file