예제 #1
0
        public override async ValueTask <bool> HandleRpcAsync(ClientPlayer sender, ClientPlayer?target, RpcCalls call, IMessageReader reader)
        {
            if (!await ValidateHost(call, sender))
            {
                return(false);
            }

            switch (call)
            {
            case RpcCalls.SetTasks:
            {
                Rpc29SetTasks.Deserialize(reader, out var playerId, out var taskTypeIds);
                SetTasks(playerId, taskTypeIds);
                break;
            }

            case RpcCalls.UpdateGameData:
            {
                while (reader.Position < reader.Length)
                {
                    using var message = reader.ReadMessage();
                    var player = GetPlayerById(message.Tag);
                    if (player != null)
                    {
                        player.Deserialize(message);
                    }
                    else
                    {
                        var playerInfo = new InnerPlayerInfo(message.Tag);

                        playerInfo.Deserialize(reader);

                        if (!_allPlayers.TryAdd(playerInfo.PlayerId, playerInfo))
                        {
                            throw new ImpostorException("Failed to add player to InnerGameData.");
                        }
                    }
                }

                break;
            }

            case RpcCalls.CustomRpc:
                return(await HandleCustomRpc(reader, _game));

            default:
                return(await UnregisteredCall(call, sender));
            }

            return(true);
        }
예제 #2
0
        public override async ValueTask <bool> HandleRpcAsync(ClientPlayer sender, ClientPlayer?target, RpcCalls call, IMessageReader reader)
        {
            if (!await ValidateHost(call, sender))
            {
                return(false);
            }

            switch (call)
            {
            case RpcCalls.SetTasks:
            {
                Rpc29SetTasks.Deserialize(reader, out var playerId, out var taskTypeIds);
                SetTasks(playerId, taskTypeIds);
                break;
            }

            default:
                return(await UnregisteredCall(call, sender));
            }

            return(true);
        }
예제 #3
0
        public override async ValueTask <bool> HandleRpcAsync(ClientPlayer sender, ClientPlayer?target, RpcCalls call, IMessageReader reader)
        {
            if (!await ValidateHost(call, sender))
            {
                return(false);
            }

            switch (call)
            {
            case RpcCalls.SetTasks:
            {
                Rpc29SetTasks.Deserialize(reader, out byte playerId, out ReadOnlyMemory <byte> taskTypeIds);
                SetTasks(playerId, taskTypeIds);
                break;
            }

            default:
                return(await base.HandleRpcAsync(sender, target, call, reader));
            }

            return(true);
        }