d40c2938a3
Port From (https://github.com/TrinityCore/TrinityCore/commit/f922c6e7a46a7c712daaaef9b1a72ca865fbe94b)
55 lines
2.3 KiB
C#
55 lines
2.3 KiB
C#
/*
|
|
* Copyright (C) 2012-2020 CypherCore <http://github.com/CypherCore>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
using Framework.Constants;
|
|
using Game.Networking;
|
|
using Game.Networking.Packets;
|
|
using System.Linq;
|
|
|
|
namespace Game
|
|
{
|
|
public partial class WorldSession
|
|
{
|
|
[WorldPacketHandler(ClientOpcodes.ServerTimeOffsetRequest, Status = SessionStatus.Authed, Processing = PacketProcessing.Inplace)]
|
|
void HandleServerTimeOffsetRequest(ServerTimeOffsetRequest packet)
|
|
{
|
|
ServerTimeOffset response = new ServerTimeOffset();
|
|
response.Time = (uint)Time.UnixTime;
|
|
SendPacket(response);
|
|
}
|
|
|
|
[WorldPacketHandler(ClientOpcodes.TimeSyncResponse, Processing = PacketProcessing.Inplace)]
|
|
void HandleTimeSyncResponse(TimeSyncResponse packet)
|
|
{
|
|
Log.outDebug(LogFilter.Network, "CMSG_TIME_SYNC_RESP");
|
|
|
|
if (packet.SequenceIndex != _player.m_timeSyncQueue.FirstOrDefault())
|
|
Log.outError(LogFilter.Network, "Wrong time sync counter from player {0} (cheater?)", _player.GetName());
|
|
|
|
Log.outDebug(LogFilter.Network, "Time sync received: counter {0}, client ticks {1}, time since last sync {2}", packet.SequenceIndex, packet.ClientTime, packet.ClientTime - _player.m_timeSyncClient);
|
|
|
|
uint ourTicks = packet.ClientTime + (GameTime.GetGameTimeMS() - _player.m_timeSyncServer);
|
|
|
|
// diff should be small
|
|
Log.outDebug(LogFilter.Network, "Our ticks: {0}, diff {1}, latency {2}", ourTicks, ourTicks - packet.ClientTime, GetLatency());
|
|
|
|
_player.m_timeSyncClient = packet.ClientTime;
|
|
_player.m_timeSyncQueue.Pop();
|
|
}
|
|
}
|
|
}
|