From 8b2fa7c8ddfbe5ee7f72fc5eb9203cadf0cc9ca4 Mon Sep 17 00:00:00 2001 From: OkaMoez Date: Sat, 20 Jan 2024 09:59:23 +0000 Subject: [PATCH] Adjust server raid time calculations to match client (!202) This change brings the server in raid time calculation (accelerated time/time you see when choosing a map) to parity with the client. The time returned by `getInRaidTime()` effectively is the same, but the server can stop using `acceleration - 1` and the adjacent comment has an answer. ----- The Tarkov client calculates current raid time via the following formula in `Session.GetCurrentLocationTime()`: `In Raid Time = Today's Date + Connection Time + Time Since Client Connection * Acceleration` The server currently uses the following: `In Raid Time = Current Date and Time + Time Since Client Connection * (Acceleration - 1)` The `Current Time` and `-1` used in the server calculation effectively cancel each other out if `acceleration > 1`. Removing both should have no effect on the calculated time (not date). The client side using `Today's Date + Connection Time` is kinda weird. Using `acceleration = 1`, you'd see the calculated date move 2 days after 24 hours. That said, I don't see the date portion of the raid time being used, so that might not matter. Either way, I've matched the formula to avoid any edge cases causing desync. Co-authored-by: OkaMoez <43766412+OkaMoez@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT-AKI/Server/pulls/202 Co-authored-by: OkaMoez Co-committed-by: OkaMoez (cherry picked from commit afb64c1ebf20505bf3c91143aa4c8e6b65aac21c) --- project/src/generators/WeatherGenerator.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/project/src/generators/WeatherGenerator.ts b/project/src/generators/WeatherGenerator.ts index 19627dda..76a3d5a9 100644 --- a/project/src/generators/WeatherGenerator.ts +++ b/project/src/generators/WeatherGenerator.ts @@ -72,9 +72,16 @@ export class WeatherGenerator .getValue(); // Get delta between now and when client connected to server in milliseconds - const deltaMSFromNow = Date.now() - gameStartTimeStampMS; - const acceleratedMS = deltaMSFromNow * (this.weatherConfig.acceleration - 1); // For some reason nodejs moves faster than client time, reducing acceleration by 1 when client is 7 helps - const clientAcceleratedDate = new Date(currentDate.valueOf() + acceleratedMS); + const deltaMSFromNow = currentDate.getTime() - gameStartTimeStampMS; + const acceleratedMS = deltaMSFromNow * (this.weatherConfig.acceleration); + + // Match client side time calculations which start from the current date + connection time, not current time + const locationTime = new Date(gameStartTimeStampMS); + locationTime.setFullYear(currentDate.getFullYear()); + locationTime.setMonth(currentDate.getMonth()); + locationTime.setDate(currentDate.getDate()); + + const clientAcceleratedDate = new Date(locationTime.getTime() + acceleratedMS); return clientAcceleratedDate; }