public async Task HandleEventAsync(object emitter, CommandExecutedEvent @event)
        {
            if (@event.CommandContext.Exception is CommandNotFoundException && R.Commands != null)
            {
                var text = @event.CommandContext.GetCommandLine();

                IRocketPlayer rocketPlayer = null;
                if (@event.Actor is UnturnedUser user)
                {
                    var player = user.SteamPlayer;
                    if (UnturnedPermissions.CheckPermissions(player, text))
                    {
                        rocketPlayer = UnturnedPlayer.FromSteamPlayer(player);
                    }
                }
                else if (@event.Actor.Type.Equals(KnownActorTypes.Console, StringComparison.OrdinalIgnoreCase))
                {
                    rocketPlayer = new ConsolePlayer();
                }

                if (rocketPlayer != null)
                {
                    R.Commands.Execute(rocketPlayer, text);
                    @event.CommandContext.Exception = null;
                }
            }
        }
        public Task HandleEventAsync(object emitter, CommandExecutedEvent @event)
        {
            async UniTask Task()
            {
                // RocketMod commands must run on main thread
                await UniTask.SwitchToMainThread();

                if (@event.CommandContext.Exception is CommandNotFoundException && R.Commands != null)
                {
                    var text = @event.CommandContext.GetCommandLine();

                    IRocketPlayer rocketPlayer = null;
                    if (@event.Actor is UnturnedUser user)
                    {
                        var player = user.SteamPlayer;
                        if (UnturnedPermissions.CheckPermissions(player, text))
                        {
                            rocketPlayer = UnturnedPlayer.FromSteamPlayer(player);
                        }
                    }
                    else if (@event.Actor.Type.Equals(KnownActorTypes.Console, StringComparison.OrdinalIgnoreCase))
                    {
                        rocketPlayer = new ConsolePlayer();
                    }

                    if (rocketPlayer != null)
                    {
                        R.Commands.Execute(rocketPlayer, text);
                        @event.CommandContext.Exception = null;
                    }
                }
            }

            return(Task().AsTask());
        }
Example #3
0
 public static bool CheckPermissions(SteamPlayer player, string command)
 {
     if (R.Commands != null && UnturnedPermissions.CheckPermissions(player, command))
     {
         R.Commands.Execute(UnturnedPlayer.FromSteamPlayer(player), command);
     }
     return(false);
 }
Example #4
0
        private void bindDelegates()
        {
            CommandWindow.onCommandWindowInputted += (string text, ref bool shouldExecuteCommand) =>
            {
                if (text.StartsWith("/"))
                {
                    text.Substring(1);
                }
                if (R.Commands != null)
                {
                    R.Commands.Execute(new ConsolePlayer(), text);
                }
                shouldExecuteCommand = false;
            };

            CommandWindow.onCommandWindowOutputted += (object text, ConsoleColor color) =>
            {
                /* Message dupe at logs */

                //Core.Logging.Logger.ExternalLog(text, color);
            };

            /*
             * SteamChannel.onTriggerReceive += (SteamChannel channel, CSteamID steamID, byte[] packet, int offset, int size) =>
             * {
             *   UnturnedPlayerEvents.TriggerReceive(channel, steamID, packet, offset, size);
             * };
             */

            SteamChannel.onTriggerSend += (SteamPlayer player, string name, ESteamCall mode, ESteamPacket type, object[] arguments) =>
            {
                UnturnedPlayerEvents.TriggerSend(player, name, mode, type, arguments);
            };

            ChatManager.onCheckPermissions += (SteamPlayer player, string text, ref bool shouldExecuteCommand, ref bool shouldList) =>
            {
                if (text.StartsWith("/"))
                {
                    text.Substring(1);
                    if (R.Commands != null && UnturnedPermissions.CheckPermissions(player, text))
                    {
                        R.Commands.Execute(UnturnedPlayer.FromSteamPlayer(player), text);
                    }
                    shouldList = false;
                }
                shouldExecuteCommand = false;
            };

            Provider.onCheckValid += (ValidateAuthTicketResponse_t callback, ref bool isValid) =>
            {
                if (isValid)
                {
                    isValid = UnturnedPermissions.CheckValid(callback);
                }
            };
        }
        public Task HandleEventAsync(object emitter, CommandExecutedEvent @event)
        {
            async UniTask Task()
            {
                // RocketMod commands must run on main thread
                await UniTask.SwitchToMainThread();

                if (@event.CommandContext.Exception is CommandNotFoundException && R.Commands != null)
                {
                    IRocketPlayer rocketPlayer;
                    if (@event.Actor is UnturnedUser user)
                    {
                        var steamPlayer = user.SteamPlayer;
                        if (!UnturnedPermissions.CheckPermissions(steamPlayer, $"/{@event.CommandContext.CommandAlias}"))
                        {
                            // command doesnt exist or no permission
                            return;
                        }

                        rocketPlayer = UnturnedPlayer.FromSteamPlayer(steamPlayer);
                    }
                    else if (@event.Actor.Type.Equals(KnownActorTypes.Console, StringComparison.OrdinalIgnoreCase))
                    {
                        rocketPlayer = new ConsolePlayer();

                        var command = R.Commands.GetCommand(@event.CommandContext.CommandAlias.ToLower(CultureInfo.InvariantCulture));
                        if (command == null)
                        {
                            return;
                        }
                    }
                    else
                    {
                        // unsupported user
                        return;
                    }

                    if (string.IsNullOrEmpty(@event.CommandContext.CommandAlias))
                    {
                        Console.WriteLine("command alias is null or empty");
                        return;
                    }

                    var args = new List <string> {
                        @event.CommandContext.CommandAlias
                    };
                    args.AddRange(@event.CommandContext.Parameters);

                    R.Commands.Execute(rocketPlayer, args.ToArray());
                    @event.ExceptionHandled = true;
                }
            }

            return(Task().AsTask());
        }
Example #6
0
        private void bindDelegates()
        {
            CommandWindow.onCommandWindowInputted += (string text, ref bool shouldExecuteCommand) =>
            {
                if (text.StartsWith("/"))
                {
                    text.Substring(1);
                }
                if (R.Commands != null)
                {
                    R.Commands.Execute(new ConsolePlayer(), text);
                }
                shouldExecuteCommand = false;
            };

            CommandWindow.onCommandWindowOutputted += (object text, ConsoleColor color) =>
            {
                Core.Logging.Logger.ExternalLog(text, color);
            };

            /*
             * SteamChannel.onTriggerReceive += (SteamChannel channel, CSteamID steamID, byte[] packet, int offset, int size) =>
             * {
             *   UnturnedPlayerEvents.TriggerReceive(channel, steamID, packet, offset, size);
             * };
             */

            // Replacements for Rocket usage of onTriggerSend:
            SDG.Unturned.Player.onPlayerStatIncremented += UnturnedPlayerEvents.InternalOnPlayerStatIncremented;
            PlayerClothing.OnShirtChanged_Global        += UnturnedPlayerEvents.InternalOnShirtChanged;
            PlayerClothing.OnPantsChanged_Global        += UnturnedPlayerEvents.InternalOnPantsChanged;
            PlayerClothing.OnHatChanged_Global          += UnturnedPlayerEvents.InternalOnHatChanged;
            PlayerClothing.OnBackpackChanged_Global     += UnturnedPlayerEvents.InternalOnBackpackChanged;
            PlayerClothing.OnVestChanged_Global         += UnturnedPlayerEvents.InternalOnVestChanged;
            PlayerClothing.OnMaskChanged_Global         += UnturnedPlayerEvents.InternalOnMaskChanged;
            PlayerClothing.OnGlassesChanged_Global      += UnturnedPlayerEvents.InternalOnGlassesChanged;
            PlayerAnimator.OnGestureChanged_Global      += UnturnedPlayerEvents.InternalOnGestureChanged;
            PlayerLife.OnTellHealth_Global          += UnturnedPlayerEvents.InternalOnTellHealth;
            PlayerLife.OnTellFood_Global            += UnturnedPlayerEvents.InternalOnTellFood;
            PlayerLife.OnTellWater_Global           += UnturnedPlayerEvents.InternalOnTellWater;
            PlayerLife.OnTellVirus_Global           += UnturnedPlayerEvents.InternalOnTellVirus;
            PlayerLife.OnTellBleeding_Global        += UnturnedPlayerEvents.InternalOnTellBleeding;
            PlayerLife.OnTellBroken_Global          += UnturnedPlayerEvents.InternalOnTellBroken;
            PlayerLife.OnRevived_Global             += UnturnedPlayerEvents.InternalOnRevived;
            PlayerLife.RocketLegacyOnDeath          += UnturnedPlayerEvents.InternalOnPlayerDeath;
            PlayerLife.onPlayerDied                 += UnturnedPlayerEvents.InternalOnPlayerDied;
            PlayerSkills.OnExperienceChanged_Global += UnturnedPlayerEvents.InternalOnExperienceChanged;
            PlayerStance.OnStanceChanged_Global     += UnturnedPlayerEvents.InternalOnStanceChanged;

            ChatManager.onCheckPermissions += (SteamPlayer player, string text, ref bool shouldExecuteCommand, ref bool shouldList) =>
            {
                if (text.StartsWith("/"))
                {
                    text.Substring(1);
                    if (R.Commands != null && UnturnedPermissions.CheckPermissions(player, text))
                    {
                        R.Commands.Execute(UnturnedPlayer.FromSteamPlayer(player), text);
                    }
                    shouldList = false;
                }
                shouldExecuteCommand = false;
            };

            Provider.onCheckValidWithExplanation += (ValidateAuthTicketResponse_t callback, ref bool isValid, ref string explanation) =>
            {
                if (isValid)
                {
                    isValid = UnturnedPermissions.CheckValid(callback);
                }
            };
        }
Example #7
0
 public static bool CheckPermissions(SteamPlayer player, string permission)
 {
     return(UnturnedPermissions.CheckPermissions(player, permission));
 }