Browse Source

Improve server time sync

Prevents cheating with time based puzzles (pellets) and ensures the KI time
stays somewhat correct. The server time will be reset on the plNetMessage
received after the user changes their system clock. That might take a bit,
but it's better than nothing.
Adam Johnson 13 years ago
parent
commit
638259e749
  1. 8
      Sources/Plasma/Apps/plClient/winmain.cpp
  2. 3
      Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp
  3. 2
      Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h

8
Sources/Plasma/Apps/plClient/winmain.cpp

@ -367,6 +367,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
// Handle messages
switch (message) {
case WM_TIMECHANGE:
// To prevent cheating and keep things better synchronized,
// we will completely re-eval the offsets on the next NetMsg we
// get from the server
if (plNetClientMgr* nc = plNetClientMgr::GetInstance())
nc->ResetServerTimeOffset(true);
break;
case WM_KEYDOWN :
case WM_LBUTTONDOWN :
case WM_RBUTTONDOWN :

3
Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp

@ -506,8 +506,9 @@ void plNetClientMgr::UpdateServerTimeOffset(plNetMessage* msg)
}
}
void plNetClientMgr::ResetServerTimeOffset()
void plNetClientMgr::ResetServerTimeOffset(bool delayed)
{
if (!delayed)
fServerTimeOffset = 0;
fTimeSamples = 0;
fLastTimeUpdate = 0;

2
Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h

@ -383,7 +383,7 @@ public:
void StoreSDLState(const plStateDataRecord* sdRec, const plUoid& uoid, uint32_t sendFlags, uint32_t writeOptions);
void UpdateServerTimeOffset(plNetMessage* msg);
void ResetServerTimeOffset();
void ResetServerTimeOffset(bool delayed=false);
private:
plNetClientComm fNetClientComm;

Loading…
Cancel
Save