Core/Movement: ported time synchronization (commits: 975f1e364a6a68be2beca261a64ea8aecc16f6f6 and 50d32fe49386598c7cd876e51cf02478669cc252)

This commit is contained in:
Ovahlord committed 2019-04-26 16:48:09 +02:00
1 parent 433bd5a1bb
commit ee69943717
10 files changed
+212 -127

No files matched your search

+39 -3
View File
@@ -124,7 +124,6 @@ WorldSession::WorldSession(uint32 id, std::string&& name, uint32 battlenetAccoun
m_sessionDbcLocale(sWorld->GetAvailableDbcLocale(locale)),
m_sessionDbLocaleIndex(locale),
m_latency(0),
m_clientTimeDelay(0),
m_TutorialsChanged(TUTORIALS_FLAG_NONE),
_filterAddonMessages(false),
recruiterId(recruiter),
@@ -132,10 +131,16 @@ WorldSession::WorldSession(uint32 id, std::string&& name, uint32 battlenetAccoun
_RBACData(nullptr),
expireTime(60000), // 1 min after socket loss, session is deleted
forceExit(false),
m_currentBankerGUID()
m_currentBankerGUID(),
_timeSyncClockDeltaQueue(6),
_timeSyncClockDelta(0),
_pendingTimeSyncRequests()
{
memset(m_Tutorials, 0, sizeof(m_Tutorials));
_timeSyncNextCounter = 0;
_timeSyncTimer = 0;
if (sock)
{
m_Address = sock->GetRemoteIpAddress().to_string();
@@ -431,11 +436,23 @@ bool WorldSession::Update(uint32 diff, PacketFilter& updater)
if (m_Socket && m_Socket->IsOpen() && _warden)
_warden->Update();
if (!updater.ProcessUnsafe()) // <=> updater is of type MapSessionFilter
{
// Send time sync packet every 10s.
if (_timeSyncTimer > 0)
{
if (diff >= _timeSyncTimer)
SendTimeSync();
else
_timeSyncTimer -= diff;
}
}
ProcessQueryCallbacks();
//check if we are safe to proceed with logout
//logout procedure should happen only in World::UpdateSessions() method!!!
if (updater.ProcessLogout())
if (updater.ProcessUnsafe())
{
time_t currTime = time(nullptr);
///- If necessary, log the player out
@@ -1481,3 +1498,22 @@ uint32 WorldSession::DosProtection::GetMaxPacketCounterAllowed(uint16 opcode) co
WorldSession::DosProtection::DosProtection(WorldSession* s) : Session(s), _policy((Policy)sWorld->getIntConfig(CONFIG_PACKET_SPOOF_POLICY))
{
}
void WorldSession::ResetTimeSync()
{
_timeSyncNextCounter = 0;
_pendingTimeSyncRequests.clear();
}
void WorldSession::SendTimeSync()
{
WorldPacket data(SMSG_TIME_SYNC_REQ, 4);
data << uint32(_timeSyncNextCounter);
SendPacket(&data);
_pendingTimeSyncRequests[_timeSyncNextCounter] = getMSTime();
// Schedule next sync in 10 sec (except for the 2 first packets, which are spaced by only 5s)
_timeSyncTimer = _timeSyncNextCounter == 0 ? 5000 : 10000;
_timeSyncNextCounter++;
}