示例#1
0
 public async void Deserialize(IMessageReader reader, bool initialState, IEventManager manager)
 {
     if (initialState)
     {
         for (var i = 0; i < _doors.Count; i++)
         {
             _doors[i] = reader.ReadBoolean();
         }
     }
     else
     {
         var num = reader.ReadPackedUInt32();
         for (var i = 0; i < _doors.Count; i++)
         {
             if ((num & 1 << i) != 0)
             {
                 _doors[i] = reader.ReadBoolean();
                 await manager.CallAsync(new GameDoorStateChangedEvent(_game, num, _doors[i]));
             }
         }
     }
 }
示例#2
0
        public void Deserialize(IMessageReader reader, bool initialState)
        {
            if (initialState)
            {
                for (var i = 0; i < _doors.Count; i++)
                {
                    _doors[i] = reader.ReadBoolean();
                }
            }
            else
            {
                var num = reader.ReadPackedUInt32();

                for (var i = 0; i < _doors.Count; i++)
                {
                    if ((num & 1 << i) != 0)
                    {
                        _doors[i] = reader.ReadBoolean();
                    }
                }
            }
        }
        public override async ValueTask DeserializeAsync(IClientPlayer sender, IClientPlayer?target, IMessageReader reader, bool initialState)
        {
            if (!await ValidateHost(CheatContext.Deserialize, sender))
            {
                return;
            }

            if (initialState)
            {
                IsNew = reader.ReadBoolean();
            }

            PlayerId = reader.ReadByte();
        }
示例#4
0
        public override void Deserialize(IClientPlayer sender, IClientPlayer?target, IMessageReader reader, bool initialState)
        {
            if (!sender.IsHost)
            {
                // throw new ImpostorCheatException($"Client attempted to send data for {nameof(InnerPlayerControl)} as non-host");
            }

            if (initialState)
            {
                IsNew = reader.ReadBoolean();
            }

            PlayerId = reader.ReadByte();
        }
示例#5
0
        public static void Deserialize(IMessageReader reader, out bool hasReason, out DisconnectReason?reason, out string?message)
        {
            hasReason = reader.ReadBoolean();

            if (hasReason)
            {
                var inner = reader.ReadMessage();
                reason  = (DisconnectReason)inner.ReadByte();
                message = reason == DisconnectReason.Custom ? inner.ReadString() : null;
            }
            else
            {
                reason  = null;
                message = null;
            }
        }
        public void Deserialize(IMessageReader reader, bool initialState)
        {
            byte num = reader.ReadByte();

            for (int i = 0; i < num; i++)
            {
                SystemTypes systemType = (SystemTypes)reader.ReadByte();
                float       value      = reader.ReadSingle();

                _timers[systemType] = value;
            }

            for (int j = 0; j < _doors.Count; j++)
            {
                _doors[j] = reader.ReadBoolean();
            }
        }
        public override async ValueTask DeserializeAsync(IClientPlayer sender, IClientPlayer?target, IMessageReader reader, bool initialState)
        {
            if (!sender.IsHost)
            {
                if (await sender.Client.ReportCheatAsync(CheatContext.Deserialize, $"Client attempted to send data for {nameof(InnerPlayerControl)} as non-host"))
                {
                    return;
                }
            }

            if (initialState)
            {
                IsNew = reader.ReadBoolean();
            }

            PlayerId = reader.ReadByte();
        }
示例#8
0
        private static void HandleToClient(string source, IMessageReader packet)
        {
            var tagName = TagMap.ContainsKey(packet.Tag) ? TagMap[packet.Tag] : "Unknown";

            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine($"{source,-15} Client received: {packet.Tag,-2} {tagName}");

            switch (packet.Tag)
            {
            case 14:
            case 13:
                // packet.Position = packet.Length;
                break;

            case 0:
                Console.WriteLine("- GameCode        " + packet.ReadInt32());
                break;

            case 5:
            case 6:
                Console.WriteLine(HexUtils.HexDump(packet.Buffer.ToArray().Take(packet.Length).ToArray()));
                // packet.Position = packet.Length;
                break;

            case 7:
                Console.WriteLine("- GameCode        " + packet.ReadInt32());
                Console.WriteLine("- PlayerId        " + packet.ReadInt32());
                Console.WriteLine("- Host            " + packet.ReadInt32());
                var playerCount = packet.ReadPackedInt32();
                Console.WriteLine("- PlayerCount     " + playerCount);
                for (var i = 0; i < playerCount; i++)
                {
                    Console.WriteLine("-     PlayerId    " + packet.ReadPackedInt32());
                }

                break;

            case 10:
                Console.WriteLine("- GameCode        " + packet.ReadInt32());
                Console.WriteLine("- Flag            " + packet.ReadSByte());
                Console.WriteLine("- Value           " + packet.ReadBoolean());
                break;
            }
        }
示例#9
0
        public PlayerInfo(IMessageReader reader)
        {
            Name  = reader.ReadString();
            Color = reader.ReadByte();
            Hat   = reader.ReadPackedUInt32();
            Pet   = reader.ReadPackedUInt32();
            Skin  = reader.ReadPackedUInt32();
            var flags = reader.ReadByte();

            Disconnected = (flags & 1) != 0;
            IsImpostor   = (flags & 2) != 0;
            IsDead       = (flags & 4) != 0;
            var capacity = reader.ReadByte();

            for (var i = 0; i < capacity; i++)
            {
                var id = reader.ReadPackedUInt32();
                //var typeId = reader.ReadByte(); // idk if this is written
                var complete = reader.ReadBoolean();
            }
        }
示例#10
0
        public override async ValueTask HandleRpc(ClientPlayer sender, ClientPlayer?target, RpcCalls call, IMessageReader reader)
        {
            switch (call)
            {
            case RpcCalls.Close:
            {
                if (!sender.IsHost)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.Close)} but was not a host");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.Close)} to a specific player instead of broadcast");
                }

                break;
            }

            case RpcCalls.VotingComplete:
            {
                if (!sender.IsHost)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.VotingComplete)} but was not a host");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.VotingComplete)} to a specific player instead of broadcast");
                }

                var states   = reader.ReadBytesAndSize();
                var playerId = reader.ReadByte();
                var tie      = reader.ReadBoolean();

                if (playerId != byte.MaxValue)
                {
                    var player = _game.GameNet.GameData.GetPlayerById(playerId);
                    if (player != null)
                    {
                        player.Controller.Die(DeathReason.Exile);
                        await _eventManager.CallAsync(new PlayerExileEvent(_game, sender, player.Controller));
                    }
                }

                await _eventManager.CallAsync(new MeetingEndedEvent(_game, this));

                break;
            }

            case RpcCalls.CastVote:
            {
                var srcPlayerId = reader.ReadByte();
                if (srcPlayerId != sender.Character.PlayerId)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CastVote)} to an unowned {nameof(InnerPlayerControl)}");
                }

                // Host broadcasts vote to others.
                if (sender.IsHost && target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CastVote)} to a specific player instead of broadcast");
                }

                // Player sends vote to host.
                if (target == null || !target.IsHost)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CastVote)} to wrong destinition, must be host");
                }

                var targetPlayerId = reader.ReadByte();
                break;
            }

            default:
            {
                _logger.LogWarning("{0}: Unknown rpc call {1}", nameof(InnerMeetingHud), call);
                break;
            }
            }
        }
示例#11
0
        public override async ValueTask HandleRpc(ClientPlayer sender, ClientPlayer?target, RpcCalls call, IMessageReader reader)
        {
            switch (call)
            {
            // Play an animation.
            case RpcCalls.PlayAnimation:
            {
                if (!sender.IsOwner(this))
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.PlayAnimation)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.PlayAnimation)} to a specific player instead of broadcast");
                }

                var animation = reader.ReadByte();
                break;
            }

            // Complete a task.
            case RpcCalls.CompleteTask:
            {
                if (!sender.IsOwner(this))
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CompleteTask)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CompleteTask)} to a specific player instead of broadcast");
                }

                var taskId = reader.ReadPackedUInt32();
                var task   = PlayerInfo.Tasks[(int)taskId];
                if (task == null)
                {
                    _logger.LogWarning($"Client sent {nameof(RpcCalls.CompleteTask)} with a taskIndex that is not in their {nameof(InnerPlayerInfo)}");
                }
                else
                {
                    task.Complete = true;
                    await _eventManager.CallAsync(new PlayerCompletedTaskEvent(_game, sender, this, task));
                }

                break;
            }

            // Update GameOptions.
            case RpcCalls.SyncSettings:
            {
                if (!sender.IsHost)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SyncSettings)} but was not a host");
                }

                _game.Options.Deserialize(reader.ReadBytesAndSize());
                break;
            }

            // Set Impostors.
            case RpcCalls.SetInfected:
            {
                if (!sender.IsHost)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetInfected)} but was not a host");
                }

                var length = reader.ReadPackedInt32();

                for (var i = 0; i < length; i++)
                {
                    var playerId = reader.ReadByte();
                    var player   = _game.GameNet.GameData.GetPlayerById(playerId);
                    if (player != null)
                    {
                        player.IsImpostor = true;
                    }
                }

                if (_game.GameState == GameStates.Starting)
                {
                    await _game.StartedAsync();
                }

                break;
            }

            // Player was voted out.
            case RpcCalls.Exiled:
            {
                if (!sender.IsHost)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.Exiled)} but was not a host");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.Exiled)} to a specific player instead of broadcast");
                }

                // TODO: Not hit?
                Die(DeathReason.Exile);

                await _eventManager.CallAsync(new PlayerExileEvent(_game, sender, this));

                break;
            }

            // Validates the player name at the host.
            case RpcCalls.CheckName:
            {
                if (target == null || !target.IsHost)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CheckName)} to the wrong player");
                }

                var name = reader.ReadString();
                break;
            }

            // Update the name of a player.
            case RpcCalls.SetName:
            {
                if (!sender.IsHost)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetName)} but was not a host");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetName)} to a specific player instead of broadcast");
                }

                PlayerInfo.PlayerName = reader.ReadString();
                break;
            }

            // Validates the color at the host.
            case RpcCalls.CheckColor:
            {
                if (target == null || !target.IsHost)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CheckColor)} to the wrong player");
                }

                var color = reader.ReadByte();
                break;
            }

            // Update the color of a player.
            case RpcCalls.SetColor:
            {
                if (!sender.IsHost)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetColor)} but was not a host");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetColor)} to a specific player instead of broadcast");
                }

                PlayerInfo.ColorId = reader.ReadByte();
                break;
            }

            // Update the hat of a player.
            case RpcCalls.SetHat:
            {
                if (!sender.IsOwner(this))
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetHat)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetHat)} to a specific player instead of broadcast");
                }

                PlayerInfo.HatId = reader.ReadPackedUInt32();
                break;
            }

            case RpcCalls.SetSkin:
            {
                if (!sender.IsOwner(this))
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetSkin)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetHat)} to a specific player instead of broadcast");
                }

                PlayerInfo.SkinId = reader.ReadPackedUInt32();
                break;
            }

            // TODO: (ANTICHEAT) Location check?
            // only called by a non-host player on to start meeting
            case RpcCalls.ReportDeadBody:
            {
                if (!sender.IsOwner(this))
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.ReportDeadBody)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.ReportDeadBody)} to a specific player instead of broadcast");
                }


                var deadBodyPlayerId = reader.ReadByte();
                // deadBodyPlayerId == byte.MaxValue -- means emergency call by button

                break;
            }

            // TODO: (ANTICHEAT) Cooldown check?
            case RpcCalls.MurderPlayer:
            {
                if (!sender.IsOwner(this))
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.MurderPlayer)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.MurderPlayer)} to a specific player instead of broadcast");
                }

                if (!sender.Character.PlayerInfo.IsImpostor)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.MurderPlayer)} as crewmate");
                }

                if (!sender.Character.PlayerInfo.CanMurder(_game))
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.MurderPlayer)} too fast");
                }

                sender.Character.PlayerInfo.LastMurder = DateTimeOffset.UtcNow;

                var player = reader.ReadNetObject <InnerPlayerControl>(_game);
                if (!player.PlayerInfo.IsDead)
                {
                    player.Die(DeathReason.Kill);
                    await _eventManager.CallAsync(new PlayerMurderEvent(_game, sender, this, player));
                }

                break;
            }

            case RpcCalls.SendChat:
            {
                if (!sender.IsOwner(this))
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SendChat)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SendChat)} to a specific player instead of broadcast");
                }

                var chat = reader.ReadString();

                await _eventManager.CallAsync(new PlayerChatEvent(_game, sender, this, chat));

                break;
            }

            case RpcCalls.StartMeeting:
            {
                if (!sender.IsHost)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.StartMeeting)} but was not a host");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.StartMeeting)} to a specific player instead of broadcast");
                }

                // deadBodyPlayerId == byte.MaxValue -- means emergency call by button
                var deadBodyPlayerId = reader.ReadByte();
                var deadPlayer       = deadBodyPlayerId != byte.MaxValue
                        ? _game.GameNet.GameData.GetPlayerById(deadBodyPlayerId)?.Controller
                        : null;

                await _eventManager.CallAsync(new PlayerStartMeetingEvent(_game, _game.GetClientPlayer(this.OwnerId), this, deadPlayer));

                break;
            }

            case RpcCalls.SetScanner:
            {
                if (!sender.IsOwner(this))
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetScanner)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetScanner)} to a specific player instead of broadcast");
                }

                var on    = reader.ReadBoolean();
                var count = reader.ReadByte();
                break;
            }

            case RpcCalls.SendChatNote:
            {
                if (!sender.IsOwner(this))
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SendChatNote)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SendChatNote)} to a specific player instead of broadcast");
                }

                var playerId = reader.ReadByte();
                var chatNote = (ChatNoteType)reader.ReadByte();
                break;
            }

            case RpcCalls.SetPet:
            {
                if (!sender.IsOwner(this))
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetPet)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetPet)} to a specific player instead of broadcast");
                }

                PlayerInfo.PetId = reader.ReadPackedUInt32();
                break;
            }

            // TODO: Understand this RPC
            case RpcCalls.SetStartCounter:
            {
                if (!sender.IsOwner(this))
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetStartCounter)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetStartCounter)} to a specific player instead of broadcast");
                }

                // Used to compare with LastStartCounter.
                var startCounter = reader.ReadPackedUInt32();

                // Is either start countdown or byte.MaxValue
                var secondsLeft = reader.ReadByte();
                if (secondsLeft < byte.MaxValue)
                {
                    await _eventManager.CallAsync(new PlayerSetStartCounterEvent(_game, sender, this, secondsLeft));
                }

                break;
            }

            default:
            {
                _logger.LogWarning("{0}: Unknown rpc call {1}", nameof(InnerPlayerControl), call);
                break;
            }
            }
        }
示例#12
0
 public void Deserialize(IMessageReader reader, bool initialState)
 {
     byte sid      = reader.ReadByte();
     uint targetId = reader.ReadUInt32();
     bool isLeft   = reader.ReadBoolean();
 }
示例#13
0
 public void Deserialize(IMessageReader reader)
 {
     Id       = reader.ReadPackedUInt32();
     Complete = reader.ReadBoolean();
 }
示例#14
0
 public static void Deserialize(IMessageReader reader, out GameOverReason gameOverReason)
 {
     gameOverReason = (GameOverReason)reader.ReadByte();
     reader.ReadBoolean(); // showAd
 }
 public void Deserialize(IMessageReader reader, bool initialState)
 {
     var sid      = reader.ReadByte();
     var targetId = reader.ReadUInt32();
     var isLeft   = reader.ReadBoolean();
 }
示例#16
0
 public static void Deserialize(IMessageReader reader, out ReadOnlyMemory <byte> states, out byte playerId, out bool tie)
 {
     states   = reader.ReadBytesAndSize();
     playerId = reader.ReadByte();
     tie      = reader.ReadBoolean();
 }
示例#17
0
 public static void Deserialize(IMessageReader reader, out bool on, out byte scannerCount)
 {
     on           = reader.ReadBoolean();
     scannerCount = reader.ReadByte();
 }
示例#18
0
 public void Deserialize(IMessageReader reader, bool initialState, IEventManager eventManager)
 {
     IsActive = reader.ReadBoolean();
 }
 public void Deserialize(IMessageReader reader, bool initialState)
 {
     IsActive = reader.ReadBoolean();
 }
 public static void Deserialize(IMessageReader reader, out int playerId, out bool isBan)
 {
     playerId = reader.ReadPackedInt32();
     isBan    = reader.ReadBoolean();
 }
示例#21
0
        public override async ValueTask HandleRpc(ClientPlayer sender, ClientPlayer?target, RpcCalls call, IMessageReader reader)
        {
            switch (call)
            {
            // Play an animation.
            case RpcCalls.PlayAnimation:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.PlayAnimation)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.PlayAnimation)} to a specific player instead of broadcast");
                }

                var animation = reader.ReadByte();
                break;
            }

            // Complete a task.
            case RpcCalls.CompleteTask:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CompleteTask)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CompleteTask)} to a specific player instead of broadcast");
                }

                var taskId = reader.ReadPackedUInt32();
                var task   = PlayerInfo.Tasks[(int)taskId];
                if (task == null)
                {
                    // _logger.LogWarning($"Client sent {nameof(RpcCalls.CompleteTask)} with a taskIndex that is not in their {nameof(InnerPlayerInfo)}");
                }
                else
                {
                    task.Complete = true;
                    await _eventManager.CallAsync(new PlayerCompletedTaskEvent(_game, sender, this, task));
                }

                break;
            }

            // Update GameOptions.
            case RpcCalls.SyncSettings:
            {
                if (!sender.IsHost)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SyncSettings)} but was not a host");
                }

                _game.Options.Deserialize(reader.ReadBytesAndSize());
                break;
            }

            // Set Impostors.
            case RpcCalls.SetInfected:
            {
                if (!sender.IsHost)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetInfected)} but was not a host");
                }

                var length = reader.ReadPackedInt32();

                for (var i = 0; i < length; i++)
                {
                    var playerId = reader.ReadByte();
                    var player   = _game.GameNet.GameData.GetPlayerById(playerId);
                    if (player != null)
                    {
                        player.IsImpostor = true;
                    }
                }

                if (_game.GameState == GameStates.Starting)
                {
                    await _game.StartedAsync();
                }

                break;
            }

            // Player was voted out.
            case RpcCalls.Exiled:
            {
                if (!sender.IsHost)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.Exiled)} but was not a host");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.Exiled)} to a specific player instead of broadcast");
                }

                // TODO: Not hit?
                Die(DeathReason.Exile);

                await _eventManager.CallAsync(new PlayerExileEvent(_game, sender, this));

                break;
            }

            // Validates the player name at the host.
            case RpcCalls.CheckName:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CheckName)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target == null || !target.IsHost)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CheckName)} to the wrong player");
                }

                var name = reader.ReadString();

                if (name.Length > 10)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CheckName)} with name exceeding 10 characters");
                }

                if (string.IsNullOrWhiteSpace(name) || !name.All(TextBox.IsCharAllowed))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CheckName)} with name containing illegal characters");
                }

                if (sender.Client.Name != name)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetName)} with name not matching his name from handshake");
                }

                PlayerInfo.RequestedPlayerName = name;
                break;
            }

            // Update the name of a player.
            case RpcCalls.SetName:
            {
                if (!sender.IsHost)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetName)} but was not a host");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetName)} to a specific player instead of broadcast");
                }

                var name = reader.ReadString();

                if (sender.IsOwner(this))
                {
                    if (_game.Players.Any(x => x.Character != null && x.Character != this && x.Character.PlayerInfo.PlayerName == name))
                    {
                        // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetName)} with a name that is already used");
                    }

                    if (sender.Client.Name != name)
                    {
                        // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetName)} with name not matching his name from handshake");
                    }
                }
                else
                {
                    if (PlayerInfo.RequestedPlayerName == null)
                    {
                        // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetName)} for a player that didn't request it");
                    }

                    var expected = PlayerInfo.RequestedPlayerName !;

                    if (_game.Players.Any(x => x.Character != null && x.Character != this && x.Character.PlayerInfo.PlayerName == expected))
                    {
                        var i = 1;
                        while (true)
                        {
                            string text = expected + " " + i;

                            if (_game.Players.All(x => x.Character == null || x.Character == this || x.Character.PlayerInfo.PlayerName != text))
                            {
                                expected = text;
                                break;
                            }

                            i++;
                        }
                    }

                    if (name != expected)
                    {
                        // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetName)} with incorrect name");
                    }
                }

                PlayerInfo.PlayerName          = name;
                PlayerInfo.RequestedPlayerName = null;
                break;
            }

            // Validates the color at the host.
            case RpcCalls.CheckColor:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CheckColor)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target == null || !target.IsHost)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CheckColor)} to the wrong player");
                }

                var color = reader.ReadByte();

                if (color > Enum.GetValues <ColorType>().Length)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.CheckColor)} with invalid color");
                }

                PlayerInfo.RequestedColorId = color;
                break;
            }

            // Update the color of a player.
            case RpcCalls.SetColor:
            {
                if (!sender.IsHost)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetColor)} but was not a host");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetColor)} to a specific player instead of broadcast");
                }

                var color = reader.ReadByte();

                if (sender.IsOwner(this))
                {
                    if (_game.Players.Any(x => x.Character != null && x.Character != this && x.Character.PlayerInfo.ColorId == color))
                    {
                        // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetColor)} with a color that is already used");
                    }
                }
                else
                {
                    if (PlayerInfo.RequestedColorId == null)
                    {
                        // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetColor)} for a player that didn't request it");
                        break;
                    }

                    var expected = PlayerInfo.RequestedColorId !.Value;

                    while (_game.Players.Any(x => x.Character != null && x.Character != this && x.Character.PlayerInfo.ColorId == expected))
                    {
                        expected = (byte)((expected + 1) % Enum.GetValues <ColorType>().Length);
                    }

                    if (color != expected)
                    {
                        // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetColor)} with incorrect color");
                    }
                }

                PlayerInfo.ColorId          = color;
                PlayerInfo.RequestedColorId = null;
                break;
            }

            // Update the hat of a player.
            case RpcCalls.SetHat:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetHat)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetHat)} to a specific player instead of broadcast");
                }

                PlayerInfo.HatId = reader.ReadPackedUInt32();
                break;
            }

            case RpcCalls.SetSkin:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetSkin)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetHat)} to a specific player instead of broadcast");
                }

                PlayerInfo.SkinId = reader.ReadPackedUInt32();
                break;
            }

            // TODO: (ANTICHEAT) Location check?
            // only called by a non-host player on to start meeting
            case RpcCalls.ReportDeadBody:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.ReportDeadBody)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.ReportDeadBody)} to a specific player instead of broadcast");
                }


                var deadBodyPlayerId = reader.ReadByte();
                // deadBodyPlayerId == byte.MaxValue -- means emergency call by button

                break;
            }

            // TODO: (ANTICHEAT) Cooldown check?
            case RpcCalls.MurderPlayer:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.MurderPlayer)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.MurderPlayer)} to a specific player instead of broadcast");
                }

                if (!sender.Character.PlayerInfo.IsImpostor)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.MurderPlayer)} as crewmate");
                }

                if (!sender.Character.PlayerInfo.CanMurder(_game))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.MurderPlayer)} too fast");
                }

                sender.Character.PlayerInfo.LastMurder = DateTimeOffset.UtcNow;

                var player = reader.ReadNetObject <InnerPlayerControl>(_game);
                if (!player.PlayerInfo.IsDead)
                {
                    player.Die(DeathReason.Kill);
                    await _eventManager.CallAsync(new PlayerMurderEvent(_game, sender, this, player));
                }

                break;
            }

            case RpcCalls.SendChat:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SendChat)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SendChat)} to a specific player instead of broadcast");
                }

                var chat = reader.ReadString();

                await _eventManager.CallAsync(new PlayerChatEvent(_game, sender, this, chat));

                break;
            }

            case RpcCalls.StartMeeting:
            {
                if (!sender.IsHost)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.StartMeeting)} but was not a host");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.StartMeeting)} to a specific player instead of broadcast");
                }

                // deadBodyPlayerId == byte.MaxValue -- means emergency call by button
                var deadBodyPlayerId = reader.ReadByte();
                var deadPlayer       = deadBodyPlayerId != byte.MaxValue
                        ? _game.GameNet.GameData.GetPlayerById(deadBodyPlayerId)?.Controller
                        : null;

                await _eventManager.CallAsync(new PlayerStartMeetingEvent(_game, _game.GetClientPlayer(this.OwnerId), this, deadPlayer));

                break;
            }

            case RpcCalls.SetScanner:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetScanner)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetScanner)} to a specific player instead of broadcast");
                }

                var on    = reader.ReadBoolean();
                var count = reader.ReadByte();
                break;
            }

            case RpcCalls.SendChatNote:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SendChatNote)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SendChatNote)} to a specific player instead of broadcast");
                }

                var playerId = reader.ReadByte();
                var chatNote = (ChatNoteType)reader.ReadByte();
                break;
            }

            case RpcCalls.SetPet:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetPet)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetPet)} to a specific player instead of broadcast");
                }

                PlayerInfo.PetId = reader.ReadPackedUInt32();
                break;
            }

            // TODO: Understand this RPC
            case RpcCalls.SetStartCounter:
            {
                if (!sender.IsOwner(this))
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetStartCounter)} to an unowned {nameof(InnerPlayerControl)}");
                }

                if (target != null)
                {
                    // throw new ImpostorCheatException($"Client sent {nameof(RpcCalls.SetStartCounter)} to a specific player instead of broadcast");
                }

                // Used to compare with LastStartCounter.
                var startCounter = reader.ReadPackedUInt32();

                // Is either start countdown or byte.MaxValue
                var secondsLeft = reader.ReadByte();
                if (secondsLeft < byte.MaxValue)
                {
                    await _eventManager.CallAsync(new PlayerSetStartCounterEvent(_game, sender, this, secondsLeft));
                }

                break;
            }

            default:
            {
                // _logger.LogWarning("{0}: Unknown rpc call {1}", nameof(InnerPlayerControl), call);
                break;
            }
            }
        }