Esempio n. 1
0
    public long KeepAlive()
    {
        var keepAliveId = TimeUtilities.GetElapsedMilliseconds();

        _keepAliveIdQueue.Enqueue(keepAliveId);

        using var keepAlivePacket = new KeepAlivePacket(keepAliveId);
        SendPacket(keepAlivePacket);

        return(keepAliveId);
    }
Esempio n. 2
0
    public void CheckKeepAlive(long keepAliveId)
    {
        if (_keepAliveIdQueue.TryDequeue(out long nextKeepAliveId))
        {
            if (nextKeepAliveId != keepAliveId)
            {
                _user.Disconnect("Keep-alive id doesn't match.");
                return;
            }

            Ping = (int)(TimeUtilities.GetElapsedMilliseconds() - nextKeepAliveId);

            using var playerInfoLatencyPacket = new PlayerInfoPacket(PlayerInfoActionType.UpdateLatency, this);
            World.SendToAll(playerInfoLatencyPacket);
        }
    }