Skip to content

Commit

Permalink
fix: Created thresholdfor time update
Browse files Browse the repository at this point in the history
  • Loading branch information
andsfonseca committed Apr 24, 2022
1 parent 6121e27 commit 2466c29
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/services/DotaService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class DotaService
{
static DotaService *instance;

int64_t currentMatchTime = 0;

DotaService()
{
}
Expand Down Expand Up @@ -453,6 +455,15 @@ class DotaService
return LocalizedStrings::Get("DOTA_2:CUSTOM_MAP:hero_demo");
}

void FixGameTimeIfNecessary(int64_t &matchTime)
{
const int64_t TOL = 2;
if ((matchTime - TOL) <= currentMatchTime && currentMatchTime <= (matchTime + TOL))
matchTime = currentMatchTime;
else
currentMatchTime = matchTime;
}

public:
static DotaService *getInstance()
{
Expand All @@ -473,6 +484,7 @@ class DotaService
if (playerStatus == PlayerStatus::STAND_BY)
{
discordService->CleanActivity();
currentMatchTime = 0;
return;
}

Expand Down Expand Up @@ -551,6 +563,7 @@ class DotaService
// Time Section
now += std::chrono::seconds(-gameTime);
int64_t time0InMatch = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
FixGameTimeIfNecessary(time0InMatch);
if (gameState == GameState::PRE_GAME)
activity.GetTimestamps().SetEnd(DiscordTimestamp(time0InMatch));
else
Expand Down Expand Up @@ -650,6 +663,7 @@ class DotaService
// Time Section
now += std::chrono::seconds(-gameTime);
int64_t time0InMatch = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
FixGameTimeIfNecessary(time0InMatch);
if (gameState == GameState::PRE_GAME)
activity.GetTimestamps().SetEnd(DiscordTimestamp(time0InMatch));
else
Expand Down

0 comments on commit 2466c29

Please sign in to comment.