From b62540e5b47b5c7289892ce8d2b34518fdf2cb52 Mon Sep 17 00:00:00 2001 From: timiimit Date: Wed, 15 Mar 2023 13:59:40 +0100 Subject: [PATCH] Show accurate elapsed time only when useful --- .../src/pages/Servers/hooks/use-match.hook.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/UT4MasterServer.Web/src/pages/Servers/hooks/use-match.hook.ts b/UT4MasterServer.Web/src/pages/Servers/hooks/use-match.hook.ts index 0e3badf1..ab6458a7 100644 --- a/UT4MasterServer.Web/src/pages/Servers/hooks/use-match.hook.ts +++ b/UT4MasterServer.Web/src/pages/Servers/hooks/use-match.hook.ts @@ -42,6 +42,14 @@ export function useMatch() { ServerAttribute.uuForcedMutators ] as string; const forcedMutators = forcedMutatorsString?.split(',') ?? []; + const elapsedTimeRaw = response.attributes[ + ServerAttribute.elapsedTime + ] as number; + const elapsedTimeAccurate = Math.round( + (Date.now() - + (new Date(response.lastUpdated).getTime() - elapsedTimeRaw * 1000)) / + 1000 + ); return { id, name: @@ -49,20 +57,14 @@ export function useMatch() { (response.attributes[ServerAttribute.serverName] as string), gameType: response.attributes[ServerAttribute.gameType] as string, map: response.attributes[ServerAttribute.mapName] as string, - matchState, + matchState: matchState, matchStateDisplay: matchStateMap[matchState] ?? matchState, maxPlayers: response.attributes[ServerAttribute.maxPlayers] as number, playersOnline: response.attributes[ ServerAttribute.playersOnline ] as number, duration: response.attributes[ServerAttribute.matchDuration] as number, - elapsedTime: Math.round( - (Date.now() - - (new Date(response.lastUpdated).getTime() - - (response.attributes[ServerAttribute.elapsedTime] as number) * - 1000)) / - 1000 - ), + elapsedTime: elapsedTimeRaw > 0 ? elapsedTimeAccurate : elapsedTimeRaw, publicPlayers: response.publicPlayers, mutators, gameMode,