Skip to content

Commit c7fdec2

Browse files
committed
Server: Use GetTickCount() to track time passed, instead of a timestamp
1 parent f7e6450 commit c7fdec2

File tree

7 files changed

+14
-14
lines changed

7 files changed

+14
-14
lines changed

InternetGamesServer/Util.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,31 +212,31 @@ class ChangeTimeTracker final
212212
public:
213213
ChangeTimeTracker() :
214214
val(),
215-
timeLastChange(std::time(nullptr))
215+
timeLastChange(GetTickCount())
216216
{}
217217
ChangeTimeTracker(T defaultVal) :
218218
val(std::move(defaultVal)),
219-
timeLastChange(std::time(nullptr))
219+
timeLastChange(GetTickCount())
220220
{}
221221

222222
inline const T& Get() const { return val; }
223223
inline operator const T&() const { return val; }
224224

225-
inline std::time_t GetTimeLastChange() const { return timeLastChange; }
226-
inline std::time_t GetSecondsSinceLastChange() const { return std::time(nullptr) - timeLastChange; }
225+
inline DWORD GetTimeLastChange() const { return timeLastChange; }
226+
inline DWORD GetTimePassedMS() const { return GetTickCount() - timeLastChange; }
227227

228228
void operator=(const T& otherVal)
229229
{
230230
if (val == otherVal)
231231
return;
232232

233233
val = otherVal;
234-
timeLastChange = std::time(nullptr);
234+
timeLastChange = GetTickCount();
235235
}
236236

237237
private:
238238
T val;
239-
std::time_t timeLastChange;
239+
DWORD timeLastChange;
240240
};
241241

242242
/** Struct padding */

InternetGamesServer/Win7/Match.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ Match::Update()
232232
if (m_endTime == 0)
233233
{
234234
SessionLog() << "[MATCH] " << m_guid << ": Game over, match will automatically close in 60 seconds!" << std::endl;
235-
m_endTime = std::time(nullptr);
235+
m_endTime = GetTickCount();
236236
}
237-
else if (std::time(nullptr) - m_endTime >= 60) // A minute has passed since the match ended
237+
else if (GetTickCount() - m_endTime >= 60000) // A minute has passed since the match ended
238238
{
239239
SessionLog() << "[MATCH] " << m_guid << ": Match ended a minute ago, closing!" << std::endl;
240240
m_state = STATE_ENDED;

InternetGamesServer/Win7/Match.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class Match : public ::Match<PlayerSocket>
101101
// Mutex to prevent simultaneous match processes, like adding/removing players and processing events and removal of the match
102102
HANDLE m_mutex;
103103

104-
std::time_t m_endTime;
104+
DWORD m_endTime;
105105

106106
private:
107107
Match(const Match&) = delete;

InternetGamesServer/Win7/PlayerSocket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ PlayerSocket::ProcessMessages()
7272
// Time out the client in states not involving participation in a match
7373
if (m_state != STATE_WAITINGFOROPPONENTS &&
7474
m_state != STATE_PLAYING &&
75-
m_state.GetSecondsSinceLastChange() >= 60)
75+
m_state.GetTimePassedMS() >= 60000)
7676
{
7777
throw std::runtime_error("Win7::PlayerSocket::ProcessMessages(): Timeout: Client has not switched from state "
7878
+ std::to_string(m_state) + " for 60 seconds or more!");

InternetGamesServer/WinXP/Match.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ Match::Update()
261261
if (m_endTime == 0)
262262
{
263263
SessionLog() << "[MATCH] " << m_guid << ": Game over, match will automatically close in 60 seconds!" << std::endl;
264-
m_endTime = std::time(nullptr);
264+
m_endTime = GetTickCount();
265265
}
266-
else if (std::time(nullptr) - m_endTime >= 60) // A minute has passed since the match ended
266+
else if (GetTickCount() - m_endTime >= 60000) // A minute has passed since the match ended
267267
{
268268
SessionLog() << "[MATCH] " << m_guid << ": Match ended a minute ago, closing!" << std::endl;
269269
m_state = STATE_ENDED;

InternetGamesServer/WinXP/Match.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class Match : public ::Match<PlayerSocket>
114114

115115
std::array<uint32, MATCH_MAX_PLAYERS> m_playerComputerIDs; // IDs of computer players by seat.
116116

117-
std::time_t m_endTime;
117+
DWORD m_endTime;
118118

119119
private:
120120
Match(const Match&) = delete;

InternetGamesServer/WinXP/PlayerSocket.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ PlayerSocket::ProcessMessages()
175175
// Time out the client in states not involving participation in a match
176176
if (m_state != STATE_WAITINGFOROPPONENTS &&
177177
m_state != STATE_PLAYING &&
178-
m_state.GetSecondsSinceLastChange() >= 60)
178+
m_state.GetTimePassedMS() >= 60000)
179179
{
180180
throw std::runtime_error("WinXP::PlayerSocket::ProcessMessages(): Timeout: Client has not switched from state \""
181181
+ StateToString(m_state) + "\" for 60 seconds or more!");

0 commit comments

Comments
 (0)