コード例 #1
0
ファイル: Player.cs プロジェクト: Eastrall/Redstone
    public long KeepAlive()
    {
        var keepAliveId = TimeUtilities.GetElapsedMilliseconds();

        _keepAliveIdQueue.Enqueue(keepAliveId);

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

        return(keepAliveId);
    }
コード例 #2
0
ファイル: Player.cs プロジェクト: Eastrall/Redstone
    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);
        }
    }