From 638259e749b543d61e9be137d4869d52af90990a Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 4 Mar 2012 21:10:34 -0500 Subject: [PATCH 1/2] 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. --- Sources/Plasma/Apps/plClient/winmain.cpp | 10 +++++++++- .../Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp | 5 +++-- Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Sources/Plasma/Apps/plClient/winmain.cpp b/Sources/Plasma/Apps/plClient/winmain.cpp index e003f674..94bcdd5b 100644 --- a/Sources/Plasma/Apps/plClient/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/winmain.cpp @@ -366,7 +366,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) static uint32_t keyState=0; // Handle messages - switch (message) { + 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 : diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp index b3a9c693..f563a2c6 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp +++ b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp @@ -506,9 +506,10 @@ void plNetClientMgr::UpdateServerTimeOffset(plNetMessage* msg) } } -void plNetClientMgr::ResetServerTimeOffset() +void plNetClientMgr::ResetServerTimeOffset(bool delayed) { - fServerTimeOffset = 0; + if (!delayed) + fServerTimeOffset = 0; fTimeSamples = 0; fLastTimeUpdate = 0; } diff --git a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h b/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h index b2ac3af3..5d435364 100644 --- a/Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.h +++ b/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; From 69970aba43feb54325738a965528827f71331f8c Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 4 Mar 2012 21:13:17 -0500 Subject: [PATCH 2/2] Fix the George W. Bush bug Fix the DST hack to use the correct dates in post-2006 US and Canada. I unfortunately could not find a decent cross-platform way to do this. --- Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp index 057733b7..257a52d6 100644 --- a/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp +++ b/Sources/Plasma/FeatureLib/pfPython/cyMisc.cpp @@ -648,19 +648,19 @@ time_t cyMisc::ConvertGMTtoDni(time_t gtime) plUnifiedTime utime = plUnifiedTime(); utime.SetSecs(dtime); // check for daylight savings time in New Mexico and adjust - if ( utime.GetMonth() >= 4 && utime.GetMonth() < 11 ) + if ( utime.GetMonth() >= 3 && utime.GetMonth() < 11 ) { plUnifiedTime dstStart = plUnifiedTime(); - dstStart.SetGMTime(utime.GetYear(),4,1,2,0,0); - // find first Sunday after 4/1 (first sunday of April) + dstStart.SetGMTime(utime.GetYear(),3,7,2,0,0); + // find first Sunday after 3/7 (second Sunday of March) int days_to_go = 7 - dstStart.GetDayOfWeek(); if (days_to_go == 7) days_to_go = 0; time_t dstStartSecs = dstStart.GetSecs() + days_to_go * kOneDay; plUnifiedTime dstEnd = plUnifiedTime(); - dstEnd.SetGMTime(utime.GetYear(),10,25,1,0,0); - // find first sunday after 10/25 (last sunday of Oct.) + dstEnd.SetGMTime(utime.GetYear(),11,1,1,0,0); + // find first sunday after 11/1 (first Sunday of November) days_to_go = 7 - dstEnd.GetDayOfWeek(); if (days_to_go == 7) days_to_go = 0;