mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-18 19:29:09 +00:00
Don't trust the local machine's system time.
Co-authored-by: Adam Johnson <AdamJohnso@gmail.com>
This commit is contained in:
@ -211,7 +211,7 @@ void plNCAgeJoiner::Start () {
|
|||||||
|
|
||||||
plNetClientMgr * nc = plNetClientMgr::GetInstance();
|
plNetClientMgr * nc = plNetClientMgr::GetInstance();
|
||||||
nc->SetFlagsBit(plNetClientMgr::kPlayingGame, false);
|
nc->SetFlagsBit(plNetClientMgr::kPlayingGame, false);
|
||||||
nc->fServerTimeOffset = 0; // reset since we're connecting to a new server
|
nc->ResetServerTimeOffset();
|
||||||
nc->fRequiredNumInitialSDLStates = 0;
|
nc->fRequiredNumInitialSDLStates = 0;
|
||||||
nc->fNumInitialSDLStates = 0;
|
nc->fNumInitialSDLStates = 0;
|
||||||
nc->SetFlagsBit(plNetClientApp::kNeedInitialAgeStateCount);
|
nc->SetFlagsBit(plNetClientApp::kNeedInitialAgeStateCount);
|
||||||
|
@ -133,9 +133,7 @@ plNetClientMgr::plNetClientMgr() :
|
|||||||
// fProgressBar( nil ),
|
// fProgressBar( nil ),
|
||||||
fTaskProgBar( nil ),
|
fTaskProgBar( nil ),
|
||||||
fMsgRecorder(nil),
|
fMsgRecorder(nil),
|
||||||
fServerTimeOffset(0),
|
fLastLocalTime(),
|
||||||
fTimeSamples(0),
|
|
||||||
fLastTimeUpdate(0),
|
|
||||||
fListenListMode(kListenList_Distance),
|
fListenListMode(kListenList_Distance),
|
||||||
fAgeSDLObjectKey(nil),
|
fAgeSDLObjectKey(nil),
|
||||||
fExperimentalLevel(0),
|
fExperimentalLevel(0),
|
||||||
@ -480,34 +478,23 @@ void plNetClientMgr::StartLinkInFX()
|
|||||||
//
|
//
|
||||||
void plNetClientMgr::UpdateServerTimeOffset(plNetMessage* msg)
|
void plNetClientMgr::UpdateServerTimeOffset(plNetMessage* msg)
|
||||||
{
|
{
|
||||||
if ((hsTimer::GetSysSeconds() - fLastTimeUpdate) > 5)
|
if (!msg->GetHasTimeSent())
|
||||||
{
|
return;
|
||||||
fLastTimeUpdate = hsTimer::GetSysSeconds();
|
if (msg->GetTimeSent().AtEpoch())
|
||||||
|
return;
|
||||||
|
|
||||||
const plUnifiedTime& msgSentUT = msg->GetTimeSent();
|
double localTime = hsTimer::GetSeconds();
|
||||||
if (!msgSentUT.AtEpoch())
|
if (localTime - fLastLocalTime < 1.0)
|
||||||
{
|
return;
|
||||||
double diff = plUnifiedTime::GetTimeDifference(msgSentUT, plClientUnifiedTime::GetCurrentTime());
|
|
||||||
|
|
||||||
if (fServerTimeOffset == 0)
|
fLastServerTime = msg->GetTimeSent();
|
||||||
{
|
fLastLocalTime = localTime;
|
||||||
fServerTimeOffset = diff;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
fServerTimeOffset = fServerTimeOffset + ((diff - fServerTimeOffset) / ++fTimeSamples);
|
|
||||||
}
|
|
||||||
|
|
||||||
DebugMsg("Setting server time offset to %f", fServerTimeOffset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void plNetClientMgr::ResetServerTimeOffset()
|
void plNetClientMgr::ResetServerTimeOffset()
|
||||||
{
|
{
|
||||||
fServerTimeOffset = 0;
|
fLastServerTime.ToEpoch();
|
||||||
fTimeSamples = 0;
|
fLastLocalTime = 0.0;
|
||||||
fLastTimeUpdate = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -515,14 +502,12 @@ void plNetClientMgr::ResetServerTimeOffset()
|
|||||||
//
|
//
|
||||||
plUnifiedTime plNetClientMgr::GetServerTime() const
|
plUnifiedTime plNetClientMgr::GetServerTime() const
|
||||||
{
|
{
|
||||||
if ( fServerTimeOffset==0 ) // offline mode or before connecting/calibrating to a server
|
if (fLastServerTime.AtEpoch()) {
|
||||||
|
WarningMsg("Someone asked for the server time, but we don't know it yet!");
|
||||||
return plUnifiedTime::GetCurrentTime();
|
return plUnifiedTime::GetCurrentTime();
|
||||||
|
}
|
||||||
plUnifiedTime serverUT;
|
|
||||||
if (fServerTimeOffset<0)
|
return fLastServerTime + plUnifiedTime(hsTimer::GetSeconds() - fLastLocalTime);
|
||||||
return plUnifiedTime::GetCurrentTime() - plUnifiedTime(fabs(fServerTimeOffset));
|
|
||||||
else
|
|
||||||
return plUnifiedTime::GetCurrentTime() + plUnifiedTime(fServerTimeOffset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -166,9 +166,8 @@ private:
|
|||||||
std::string fSPDesiredPlayerName; // SP: the player we want to load from vault.
|
std::string fSPDesiredPlayerName; // SP: the player we want to load from vault.
|
||||||
|
|
||||||
// server info
|
// server info
|
||||||
double fServerTimeOffset; // diff between our unified time and server's unified time
|
plUnifiedTime fLastServerTime; // Last received time update from the server
|
||||||
UInt32 fTimeSamples;
|
double fLastLocalTime; // Last monotonic time (in seconds) when the above update was received
|
||||||
double fLastTimeUpdate;
|
|
||||||
|
|
||||||
UInt8 fJoinOrder; // returned by the server
|
UInt8 fJoinOrder; // returned by the server
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user