コード例 #1
0
    private bool ValidateSimInput(SimInput input, INetworkInterfaceConnection instigator)
    {
        PlayerInfo instigatorPlayer = PlayerHelpers.GetPlayerInfo(instigator);

        if (instigatorPlayer == null)
        {
            Log.Info($"[{nameof(SimulationController)}] We refused an input from connection {instigator.Id} " +
                     $"because no player seems associated with that connection.");
            return(false);
        }

        if (input is SimPlayerInput playerInput)
        {
            playerInput.SimPlayerId = instigatorPlayer.SimPlayerId;

            if (playerInput.SimPlayerId == PersistentId.Invalid)
            {
                Log.Info($"[{nameof(SimulationController)}] We refused {instigatorPlayer.PlayerName}'s input " +
                         $"because (s)he doesn't have a valid {nameof(instigatorPlayer.SimPlayerId)} yet.");
                return(false);
            }
        }

        return(true);
    }