Exemplo n.º 1
0
        /// <summary>
        /// Handles the selection of a specific modifier
        /// </summary>
        private static void OnModifierMenu(object sender, EventArgs e)
        {
            if (m_cmModifiers.SourceControl.Tag != null)
            {
                CommandCallback callback = m_cmModifiers.SourceControl.Tag as CommandCallback;

                if (callback != null)
                {
                    MenuItem mi = sender as MenuItem;

                    int index = m_cmModifiers.MenuItems.IndexOf(mi);

                    if (Pandora.Profile.General.ModifiersWarnings[index])
                    {
                        if (MessageBox.Show(Pandora.BoxForm as Form,
                                            string.Format(Pandora.Localization.TextProvider["Errors.ModifierWarn"], mi.Text),
                                            "",
                                            MessageBoxButtons.YesNo) == DialogResult.No)
                        {
                            return;
                        }
                    }

                    // Do
                    callback.DynamicInvoke(new object[] { mi.Text });
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Registers the specified command
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="type"></param>
        /// <param name="callback"></param>
        public void RegisterCommand(string cmd, CommandType type, CommandCallback callback)
        {
            // Is it a console command?
            if (type == CommandType.Console) return;

            // Convert to lowercase
            var command_name = cmd.ToLowerInvariant();

            // Check if it already exists
            if (CommandManager.RegisteredCommands.ContainsKey(command_name))
            {
                throw new CommandAlreadyExistsException(command_name);
            }

            // Register it
            var commandAttribute = new CommandAttribute("/" + command_name, string.Empty)
            {
                Method = info =>
                {
                    var player = HurtworldCovalenceProvider.Instance.PlayerManager.GetPlayer(info.PlayerId.ToString());
                    callback(info.Label, CommandType.Chat, player, info.Args);
                }
            };
            CommandManager.RegisteredCommands[command_name] = commandAttribute;
        }
Exemplo n.º 3
0
        protected void AddCovalenceCommand(string[] commands, string[] perms, CommandCallback callback)
        {
            foreach (var cmdName in commands)
            {
                if (commandInfos.ContainsKey(cmdName))
                {
                    Interface.Oxide.LogWarning("Plugin.AddCovalenceCommand command alias already exists: {0}", cmdName);
                    continue;
                }
                commandInfos.Add(cmdName, new CommandInfo(commands, perms, callback));
            }

            if (perms == null)
            {
                return;
            }

            foreach (var perm in perms)
            {
                if (permission.PermissionExists(perm))
                {
                    continue;
                }
                permission.RegisterPermission(perm, this);
            }
        }
Exemplo n.º 4
0
        ///////////////////////////////////////////////////////////////////////

        #region Public Static Methods
        public static object StaticFireDynamicInvokeCallback(
            object firstArgument,
            object[] args
            )
        {
            ICallback callback;

            lock (syncRoot)
            {
                if ((firstArgument == null) || (callbacks == null) ||
                    !callbacks.TryGetValue(firstArgument, out callback))
                {
                    throw new ScriptException(String.Format(
                        "{0} for object {1} with hash code {2} not found",
                        typeof(ICallback), FormatOps.WrapOrNull(
                        firstArgument), RuntimeHelpers.GetHashCode(
                        firstArgument)));
                }
            }

            //
            // NOTE: The "callback" variable could be null at this point.
            //
            return CommandCallback.StaticFireDynamicInvokeCallback(
                callback, args);
        }
Exemplo n.º 5
0
 public ConsoleCommand(string command, string[] aliases, string description, CommandCallback callback)
 {
     _command     = command;
     _aliases     = aliases;
     _description = description;
     _callback    = callback;
 }
Exemplo n.º 6
0
 public CommandObj(string name, string displayName, CommandCallback callback, string key = null)
 {
     this.name        = name;
     this.displayName = displayName;
     this.callback    = callback;
     this.key         = key;
 }
Exemplo n.º 7
0
        public void RegisterCommand(string command, Plugin plugin, CommandCallback callback)
        {
            object name;

            if (this.cmdSystem == null)
            {
                return;
            }
            try
            {
                this.cmdSystem.RegisterCommand(command, plugin, callback);
            }
            catch (CommandAlreadyExistsException commandAlreadyExistsException)
            {
                if (plugin != null)
                {
                    name = plugin.Name;
                }
                else
                {
                    name = null;
                }
                if (name == null)
                {
                    name = "An unknown plugin";
                }
                string str = (string)name;
                this.logger.Write(LogType.Error, "{0} tried to register command '{1}', this command already exists and cannot be overridden!", new object[] { str, command });
            }
        }
 public RegisteredCommand(string prefix, DiscordPermissionLevel level, CommandCallback callback, string info)
 {
     this.prefix        = prefix;
     this.requiredLevel = level;
     this.callback      = callback;
     this.info          = info;
 }
Exemplo n.º 9
0
        /// <summary>
        /// Registers the specified command
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="callback"></param>
        public void RegisterCommand(string cmd, CommandCallback callback)
        {
            // Initialize if needed
            if (rustCommands == null)
            {
                Initialize();
            }

            // Convert to lowercase
            var commandName = cmd.ToLowerInvariant();

            // Register the command as a console command
            // Check if it already exists
            if (rustCommands != null && rustCommands.ContainsKey(commandName))
            {
                throw new CommandAlreadyExistsException(commandName);
            }

            // Register it
            var splitName = commandName.Split('.');

            rustCommands?.Add(commandName, new ConsoleSystem.Command
            {
                name      = splitName.Length >= 2 ? splitName[1] : splitName[0],
                parent    = splitName.Length >= 2 ? splitName[0] : "global",
                namefull  = commandName,
                isCommand = true,
                isUser    = true,
                isAdmin   = true,
                GetString = () => string.Empty,
                SetString = s => { },
                Call      = arg =>
                {
                    if (arg == null)
                    {
                        return;
                    }

                    if (arg.connection != null)
                    {
                        if (arg.Player())
                        {
                            var livePlayer = rustCovalence.PlayerManager.GetOnlinePlayer(arg.connection.userid.ToString()) as RustLivePlayer;
                            if (livePlayer == null)
                            {
                                return;
                            }
                            livePlayer.LastCommand = CommandType.Console;
                            livePlayer.LastArg     = arg;
                            callback(livePlayer?.BasePlayer, commandName, ExtractArgs(arg));
                            return;
                        }
                    }
                    callback(consolePlayer, commandName, ExtractArgs(arg));
                }
            });

            // Register the command as a chat command
            registeredChatCommands.Add(commandName, callback);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Button pressed
        /// </summary>
        private void OnButtonDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            Button b = sender as Button;

            if (m_SelectingDecoLight)
            {
                int index = 0;

                for (int i = 0; i < 10; i++)
                {
                    if (m_Buttons[i] == b)
                    {
                        index = i;
                        break;
                    }
                }

                Pandora.Profile.Deco.Light = Pandora.Lights.Names[index];
                lnkDecoLight.Text          = Pandora.Lights.Names[index];
            }
            else
            {
                CommandCallback callback = b.Tag as CommandCallback;

                callback.DynamicInvoke(new object[] { null });
            }
        }
Exemplo n.º 11
0
 public CommandQueueItem(UIScreenNames name, UICommand command, UIScreen screen, CommandCallback callback)
 {
     this.name     = name;
     this.command  = command;
     this.screen   = screen;
     this.callback = callback;
 }
        internal Option <uint> SendQueryInternal(EntityQuery query, CommandCallback <EntityQueryResult> callback, TimeSpan?timeout = null)
        {
            Func <uint, uint> sendRequestWithTimeoutMs =
                timeoutMs => communicator.SendEntityQueryRequest(query, timeoutMs).Id;

            return(SendGenericCommand(callback, sendRequestWithTimeoutMs, timeout));
        }
Exemplo n.º 13
0
 public void addEndCommandCallback(CommandCallback cmdCallback)
 {
     if (cmdCallback != null)
     {
         mEndCallback.Add(cmdCallback);
     }
 }
        /// <summary>
        /// Registers the specified command
        /// </summary>
        /// <param name="command"></param>
        /// <param name="plugin"></param>
        /// <param name="callback"></param>
        public void RegisterCommand(string command, Plugin plugin, CommandCallback callback)
        {
            // Convert command to lowercase and remove whitespace
            command = command.ToLowerInvariant().Trim();

            // Setup a new Covalence command
            RegisteredCommand newCommand = new RegisteredCommand(plugin, command, callback);

            // Check if the command can be overridden
            if (!CanOverrideCommand(command))
            {
                throw new CommandAlreadyExistsException(command);
            }

            // Check if command already exists in another Covalence plugin
            if (registeredCommands.TryGetValue(command, out RegisteredCommand cmd))
            {
                string previousPluginName = cmd.Source?.Name ?? "an unknown plugin";
                string newPluginName      = plugin?.Name ?? "An unknown plugin";
                string message            = $"{newPluginName} has replaced the '{command}' command previously registered by {previousPluginName}";
                Interface.Oxide.LogWarning(message);
            }

            // Register the command
            registeredCommands[command] = newCommand;
        }
        internal Option <uint> DeleteEntityInternal(EntityId entityId, CommandCallback <DeleteEntityResult> callback, TimeSpan?timeout = null)
        {
            Func <uint, uint> sendRequestWithTimeoutMs =
                timeoutMs => communicator.SendDeleteEntityRequest(entityId, timeoutMs).Id;

            return(SendGenericCommand(callback, sendRequestWithTimeoutMs, timeout));
        }
        public Option <uint> ReserveEntityIdsInternal(CommandCallback <ReserveEntityIdsResult> callback, uint numberOfEntityIds, TimeSpan?timeout = null)
        {
            Func <uint, uint> sendRequestWithTimeoutMs =
                timeoutMs => communicator.SendReserveEntityIdsRequest(numberOfEntityIds, timeoutMs).Id;

            return(SendGenericCommand(callback, sendRequestWithTimeoutMs, timeout));
        }
Exemplo n.º 17
0
        /// <summary>
        /// Registers the specified command
        /// </summary>
        /// <param name="command"></param>
        /// <param name="callback"></param>
        public void RegisterCommand(string command, Plugin plugin, CommandCallback callback)
        {
            // Initialize if needed
            if (registeredCommands == null)
            {
                Initialize();
            }

            // Convert to lowercase
            var commandName = command.ToLowerInvariant();

            // Setup console command name
            var split    = commandName.Split('.');
            var parent   = split.Length >= 2 ? split[0].Trim() : "global";
            var name     = split.Length >= 2 ? string.Join(".", split.Skip(1).ToArray()) : split[0].Trim();
            var fullname = $"{parent}.{name}";

            // Check if it already exists
            if (registeredCommands.ContainsKey(commandName) || Command.ChatCommands.ContainsKey(commandName) || Command.ConsoleCommands.ContainsKey(fullname))
            {
                throw new CommandAlreadyExistsException(commandName);
            }

            // Register it
            registeredCommands.Add(commandName, callback);
        }
Exemplo n.º 18
0
 public void addStartCommandCallback(CommandCallback cmdCallback)
 {
     if (cmdCallback != null)
     {
         mStartCallback.Add(cmdCallback);
     }
 }
Exemplo n.º 19
0
 /// <summary>
 /// remove callback registration from a command type
 /// </summary>
 /// <param name="type">command type</param>
 /// <param name="execute">delegate to remove from callback</param>
 public static void Unregister(Type type, CommandCallback execute)
 {
     if (execute != null)
     {
         _executeCallbacks[type] -= execute;
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Registers the specified command
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="type"></param>
        /// <param name="callback"></param>
        public void RegisterCommand(string cmd, CommandType type, CommandCallback callback)
        {
            // Is it a console command?
            if (type == CommandType.Console)
            {
                return;
            }

            // Convert to lowercase
            var command_name = cmd.ToLowerInvariant();

            // Check if it already exists
            if (CommandManager.RegisteredCommands.ContainsKey(command_name))
            {
                throw new CommandAlreadyExistsException(command_name);
            }

            // Register it
            var commandAttribute = new CommandAttribute("/" + command_name, string.Empty)
            {
                Method = info =>
                {
                    var player = ReignOfKingsCovalenceProvider.Instance.PlayerManager.GetPlayer(info.PlayerId.ToString());
                    callback(info.Label, CommandType.Chat, player, info.Args);
                }
            };

            CommandManager.RegisteredCommands[command_name] = commandAttribute;
        }
Exemplo n.º 21
0
        protected void AddCovalenceCommand(string[] commands, string[] perms, CommandCallback callback)
        {
            int i;

            string[] strArrays = commands;
            for (i = 0; i < (int)strArrays.Length; i++)
            {
                string str = strArrays[i];
                if (!this.commandInfos.ContainsKey(str.ToLowerInvariant()))
                {
                    this.commandInfos.Add(str.ToLowerInvariant(), new Plugin.CommandInfo(commands, perms, callback));
                }
                else
                {
                    Interface.Oxide.LogWarning("Covalence command alias already exists: {0}", new object[] { str });
                }
            }
            if (perms == null)
            {
                return;
            }
            strArrays = perms;
            for (i = 0; i < (int)strArrays.Length; i++)
            {
                string str1 = strArrays[i];
                if (!this.permission.PermissionExists(str1, null))
                {
                    this.permission.RegisterPermission(str1, this);
                }
            }
        }
Exemplo n.º 22
0
 internal static void Register(string cmd, CommandCallback callback)
 {
     if (!m_List.ContainsKey(cmd))
     {
         m_List.Add(cmd, callback);
     }
 }
Exemplo n.º 23
0
 public void SendCommand <TCommand, TRequest, TResponse>(
     ICommandDescriptor <TCommand, TRequest, TResponse> commandDescriptor, TRequest request,
     EntityId entityId, CommandCallback <TResponse> callback, TimeSpan?timeout = null, CommandDelivery commandDelivery = CommandDelivery.RoundTrip)
     where TCommand : ICommandMetaclass, new()
 {
     SendCommandInternal(null, SkipAuthorityCheck, commandDescriptor, request, entityId, callback, timeout, commandDelivery);
 }
        private Option <uint> SendGenericCommand <TResponse>(CommandCallback <TResponse> callback,
                                                             Func <uint, uint> sendRequestWithTimeoutMs, TimeSpan?timeout = null)
        {
            var callbackWrapper = new CommandCallbackWrapper <TResponse>(callback);

            if (component != null && component.Authority != Authority.Authoritative && component.Authority != Authority.AuthorityLossImminent)
            {
                // This needs to be deferred, so that all callbacks are registered
                // before they are actually called.
                communicator.Defer(() => callbackWrapper.TriggerWithError(StatusCode.AuthorityLost, string.Format(
                                                                              "Tried to send a command from (entity ID: {0}, component: {1}) without " +
                                                                              "authority on that pair.",
                                                                              component.EntityId,
                                                                              component.GetType()
                                                                              )));

                return(new Option <uint>());
            }

            var timeoutMs = timeout.HasValue ? (uint)timeout.Value.Milliseconds : DefaultCommandTimeoutMs;
            var requestId = sendRequestWithTimeoutMs(timeoutMs);

            requestIdToCallback.Add(requestId, callbackWrapper);
            return(requestId);
        }
        internal Option <uint> CreateEntityInternal(Worker.Entity template,
                                                    CommandCallback <CreateEntityResult> callback, TimeSpan?timeout = null)
        {
            Func <uint, uint> sendRequestWithTimeoutMs =
                timeoutMs => communicator.SendCreateEntityRequest(template, null, timeoutMs).Id;

            return(SendGenericCommand(callback, sendRequestWithTimeoutMs, timeout));
        }
Exemplo n.º 26
0
        /// <summary>
        /// Add a command, passes info down.
        /// </summary>
        /// <param name="commandName">taken in user input mode, single string including separators</param>
        /// <param name="helpText"></param>
        /// <param name="callback"></param>
        public static void RegisterCommand(string commandName, string helpText, CommandCallback callback)
        {
            Assert.IsFalse(string.IsNullOrEmpty(commandName));

            InputStringToCommandAndParams(commandName, out string[] names, out string param);

            Instance.commandRoot.Add(names, callback, helpText);
        }
Exemplo n.º 27
0
 public void addEndCommandCallback(CommandCallback cmdCallback, object userdata)
 {
     if (cmdCallback != null)
     {
         mEndCallback.Add(cmdCallback);
         mEndUserData.Add(userdata);
     }
 }
Exemplo n.º 28
0
 protected bool mInited;                                          // 是否已经初始化,子节点在初始化时需要先确保父节点已经初始化
 public SceneProcedure()
 {
     mDelayCmdList       = new HashSet <ulong>();
     mChildProcedureList = new Dictionary <Type, SceneProcedure>();
     mPrepareTimer       = new MyTimer();
     mPrepareIntent      = null;
     mCmdStartCallback   = onCmdStarted;
 }
Exemplo n.º 29
0
 public void addStartCommandCallback(CommandCallback cmdCallback, object userdata)
 {
     if (cmdCallback != null)
     {
         mStartCallback.Add(cmdCallback);
         mStartUserData.Add(userdata);
     }
 }
Exemplo n.º 30
0
 public CommandTable(CommandCallback callback, string command, string description, bool requiresAuthorization)
 {
     this.command               = command;
     this.description           = description;
     this.callback              = callback;
     this.requiresAuthorization = requiresAuthorization;
     Rollback = null;
 }
Exemplo n.º 31
0
        ///////////////////////////////////////////////////////////////////////

        #region Callback Methods
        private ReturnCode InterruptCallback(
            Interpreter interpreter, /* NOTE: Parent interpreter. */
            InterruptType interruptType,
            IClientData clientData,
            ref Result error
            ) /* throw */
        {
            //
            // NOTE: If the are no callback arguments configured, just skip it
            //       and return success.
            //
            StringList arguments = CallbackArguments;

            if (arguments == null) /* NOTE: Disabled? */
            {
                return(ReturnCode.Ok);
            }

            Interpreter debugInterpreter = this.interpreter;

            if (debugInterpreter == null)
            {
                error = "debugger interpreter not available";
                return(ReturnCode.Error);
            }

            //
            // NOTE: *WARNING* This is a cross-interpreter call, do NOT dispose
            //       the parent interpreter because we do not own it.  This is
            //       guaranteed by using the NoDispose object flag (indirectly)
            //       here.
            //
            ICallback callback = CommandCallback.Create(
                MarshalFlags.Default, CallbackFlags.Default,
                ObjectFlags.Callback, ByRefArgumentFlags.None,
                debugInterpreter, clientData, null, new StringList(
                    arguments), ref error);

            if (callback == null)
            {
                return(ReturnCode.Error);
            }

            try
            {
                callback.FireEventHandler(this,
                                          RuntimeOps.GetInterruptEventArgs(interpreter,
                                                                           interruptType, clientData) as EventArgs);

                return(ReturnCode.Ok);
            }
            catch (Exception e)
            {
                error = e;
            }

            return(ReturnCode.Error);
        }
Exemplo n.º 32
0
 public static PluginCommand Create(string name, string descrption, CommandCallback cb, ParamiterType Parameters, params UserInput[] inp)
 {
     PluginCommand pt = new PluginCommand(name);
     pt.Description = descrption;
     pt.OnExecute += cb;
     pt.Paramiter = Parameters;
     pt.AddUserInput(inp);
     return pt;
 }
        public RustCommandSystem()
        {
            this.registeredCommands = new Dictionary <string, RustCommandSystem.RegisteredCommand>();
            CommandCallback commandCallback = new CommandCallback(this.CommandCallback);
            IDictionary <string, RustCommandSystem.RegisteredCommand> strs = this.registeredCommands;

            this.commandHandler = new CommandHandler(commandCallback, new Func <string, bool>(strs.ContainsKey));
            this.consolePlayer  = new RustConsolePlayer();
        }
Exemplo n.º 34
0
        /// <summary>
        /// Registers the specified command
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="callback"></param>
        public void RegisterCommand(string cmd, CommandCallback callback)
        {
            // Convert to lowercase
            var commandName = cmd.ToLowerInvariant();

            // Check if it already exists
            if (registeredCommands.ContainsKey(commandName))
                throw new CommandAlreadyExistsException(commandName);

            registeredCommands.Add(commandName, callback);
        }
Exemplo n.º 35
0
 /// <summary>
 /// registration of a command type to a callback
 /// </summary>
 /// <param name="type">command type</param>
 /// <param name="execute">delegate for callback</param>
 public static void Register(Type type, CommandCallback execute)
 {
     if (!_executeCallbacks.ContainsKey(type))
     {
         SelfRegister(type);
     }
     if (execute != null)
     {
         _executeCallbacks[type] += execute;
     }
     //Debug.Log("Registering: " + type.ToString());
 }
Exemplo n.º 36
0
        /// <summary>
        /// Registers the specified command
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="callback"></param>
        public void RegisterCommand(string cmd, CommandCallback callback)
        {
            // No console command support so no need to register the command as console command
            // Register the command as a chat command
            // Convert to lowercase
            var commandName = cmd.ToLowerInvariant();

            // Check if it already exists
            if (CommandManager.RegisteredCommands.ContainsKey(commandName) || registeredCommands.ContainsKey(commandName))
                throw new CommandAlreadyExistsException(commandName);

            registeredCommands.Add(commandName, callback);
        }
Exemplo n.º 37
0
        public Player()
        {
            CurrentSongCallback = new CommandCallback(UpdateCurrentSong);
            ListAllCallback = new CommandCallback(UpdateFiles);
            PlaylistCallback = new CommandCallback(UpdatePlaylist);
            StatusCallback = new CommandCallback(UpdateStatus);
            ArtistsAndAlbumsCallback = new CommandCallback(UpdateAlbums);
            BookmarksCallback = new CommandCallback(UpdateBookmarks);
            IsConnected = false;

            updateTimer = new System.Timers.Timer(1000);
            updateTimer.Elapsed+=updateTimer_Elapsed;
            updateTimer.Start();
        }
Exemplo n.º 38
0
        /// <summary>
        /// Registers the specified command
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="callback"></param>
        public void RegisterCommand(string cmd, CommandCallback callback)
        {
            // Initialize if needed
            if (rustCommands == null) Initialize();

            // Convert to lowercase
            var commandName = cmd.ToLowerInvariant();

            // Register the command as a console command
            // Check if it already exists
            if (rustCommands != null && rustCommands.ContainsKey(commandName))
                throw new CommandAlreadyExistsException(commandName);

            // Register it
            var splitName = commandName.Split('.');
            rustCommands?.Add(commandName, new ConsoleSystem.Command
            {
                name = splitName.Length >= 2 ? splitName[1] : splitName[0],
                parent = splitName.Length >= 2 ? splitName[0] : "global",
                namefull = commandName,
                isCommand = true,
                isUser = true,
                isAdmin = true,
                GetString = () => string.Empty,
                SetString = s => { },
                Call = arg =>
                {
                    if (arg == null) return;

                    if (arg.connection != null)
                    {
                        if (arg.Player())
                        {
                            var livePlayer = rustCovalence.PlayerManager.GetOnlinePlayer(arg.connection.userid.ToString()) as RustLivePlayer;
                            if (livePlayer == null) return;
                            livePlayer.LastCommand = CommandType.Console;
                            livePlayer.LastArg = arg;
                            callback(livePlayer?.BasePlayer, commandName, ExtractArgs(arg));
                            return;
                        }
                    }
                    callback(consolePlayer, commandName, ExtractArgs(arg));
                }
            });

            // Register the command as a chat command
            registeredChatCommands.Add(commandName, callback);
        }
Exemplo n.º 39
0
 public void RegisterCommand(string cmd, CommandType type, CommandCallback callback)
 {
     if (type == CommandType.Console) return;
     var command_name = cmd.ToLowerInvariant();
     if (CommandManager.RegisteredCommands.ContainsKey(command_name))
     {
         throw new CommandAlreadyExistsException(command_name);
     }
     var commandAttribute = new CommandAttribute("/" + command_name, string.Empty)
     {
         Method = info =>
         {
             var player = ReignOfKingsCovalenceProvider.Instance.PlayerManager.GetPlayer(info.PlayerId.ToString());
             callback(info.Label, CommandType.Chat, player, info.Args);
         }
     };
     CommandManager.RegisteredCommands[command_name] = commandAttribute;
 }
Exemplo n.º 40
0
        /// <summary>
        /// Registers the specified command
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="type"></param>
        /// <param name="callback"></param>
        public void RegisterCommand(string cmd, CommandType type, CommandCallback callback)
        {
            // Initialize if needed
            if (rustCommands == null) Initialize();

            // Convert to lowercase
            var command_name = cmd.ToLowerInvariant();

            // Is it a console command?
            if (type == CommandType.Console)
            {
                // Check if it already exists
                if (rustCommands != null && rustCommands.ContainsKey(command_name))
                {
                    throw new CommandAlreadyExistsException(command_name);
                }

                // Register it
                var splitName = command_name.Split('.');
                rustCommands?.Add(command_name, new ConsoleSystem.Command
                {
                    name = splitName.Length >= 2 ? splitName[1] : splitName[0],
                    parent = splitName.Length >= 2 ? splitName[0] : string.Empty,
                    namefull = command_name,
                    isCommand = true,
                    isUser = true,
                    isAdmin = true,
                    GetString = () => string.Empty,
                    SetString = (s) => { },
                    Call = (arg) =>
                    {
                        if (arg == null) return;
                        callback(command_name, CommandType.Console, consolePlayer, ExtractArgs(arg));
                    }
                });
            }
            else if (type == CommandType.Chat)
            {
                registeredChatCommands.Add(command_name, callback);
            }
        }
Exemplo n.º 41
0
 /// <summary>
 /// Register a console command. The passed callback will be called when the user enters the command in the console.
 /// </summary>
 /// <param name="command">The command to register</param>
 /// <param name="callback">The callback to be called when the command is entered</param>
 /// <param name="helpText">Help text for this command. Used for <c><![CDATA[help <mod> <command>]]></c></param>
 /// <returns>True if registration succeeded, false otherwise</returns>
 public static bool RegisterCommand(string command, CommandCallback callback, string helpText = "")
 {
     Command com = new Command();
     com.callback = callback;
     com.helpMessage = helpText;
     var callingAssembly = Assembly.GetCallingAssembly();
     com.mod = ModLoader.LoadedMods.Find(mod => mod.assembly.Equals(callingAssembly));
     if (com.mod == null)
     {
         Debug.LogError("Could not identify mod trying to register command " + command + "!");
         return false;
     }
     if (commands.ContainsKey(command))
     {
         commands[command].Add(com);
     }
     else
     {
         List<Command> newList = new List<Command>();
         newList.Add(com);
         commands.Add(command.ToLower(), newList);
     }
     return true;
 }
Exemplo n.º 42
0
 /// <summary>
 /// Initializes a new instance of the ChatCommandHandler class
 /// </summary>
 /// <param name="callback"></param>
 public ChatCommandHandler(CommandCallback callback, Func<string, bool> commandFilter)
 {
     this.callback = callback;
     this.commandFilter = commandFilter;
 }
Exemplo n.º 43
0
 public Command(String name, int arguments, CommandCallback callback)
 {
     m_Name = name;
     m_ArgumentCount = arguments;
     m_Callback = callback;
 }
Exemplo n.º 44
0
 /// <summary>
 /// Register a console command. The passed callback will be called when the user enters the command in the console.
 /// </summary>
 /// <param name="command">The command to register</param>
 /// <param name="callback">The callback to be called when the command is entered</param>
 /// <param name="helpText">Help text for this command. Used for <c><![CDATA[help <mod> <command>]]></c></param>
 /// <returns>True if registration succeeded, false otherwise</returns>
 public static bool RegisterCommand(string command, CommandCallback callback, string helpText = "")
 {
     return spaar.ModLoader.Commands.RegisterCommand(command, (a, n) => { return callback(a, n); }, helpText);
 }
Exemplo n.º 45
0
 // Lists all files in database (MusicCollection)
 public void ListAll(CommandCallback callback)
 {
     SendCommand("listallinfo",
         callbacks.MusicCollectionPerFileCallback, callback);
 }
Exemplo n.º 46
0
 // Lists all files within a directory (MusicCollection)
 public void ListAll(string directory, CommandCallback callback)
 {
     SendCommand("listallinfo" + Functions.EscapeStr(directory),
         callbacks.MusicCollectionPerFileCallback, callback);
 }
Exemplo n.º 47
0
 // Gets current status (StatusInfo)
 public void Status(CommandCallback callback)
 {
     SendCommand("status", callbacks.StatusInfoCallback, callback);
 }
Exemplo n.º 48
0
 public void RegisterCommand(string command, CommandCallback callback, bool admin, string description)
 {
     commandCallbacks.Add(command, new JKACommand(callback, admin, description));
 }
Exemplo n.º 49
0
 // Lists all current saved playlists (string[])
 public void ListPlaylists(CommandCallback clback)
 {
     SendCommand("lsinfo", callbacks.StartsWithPlaylistCallback, clback);
 }
Exemplo n.º 50
0
 // Returns the current playlist (MusicCollection).
 public void Playlist(CommandCallback callback)
 {
     SendCommand("playlistid", callbacks.MusicCollectionPerPosCallback,
         callback);
 }
Exemplo n.º 51
0
 // Returns the changes the playlist suffered since the specified version
 // (MusicCollection)
 public void PlaylistChanges(int oldversion, CommandCallback callback)
 {
     SendCommand("plchanges " + Convert.ToString(oldversion),
         callbacks.MusicCollectionPerPosCallback, callback);
 }
Exemplo n.º 52
0
 // Returns info about a specific music in the playlist (MusicInfo)
 public void PlaylistSongInfo(int id, CommandCallback callback)
 {
     SendCommand("playlistid " + Convert.ToString(id),
         callbacks.MusicInfoCallback, callback);
 }
Exemplo n.º 53
0
        // Search for something in the database (MusicCollection)
        public void Search(string type, string what, bool exactmatch, 
						   CommandCallback callback)
        {
            string Command = "";
            if (exactmatch) Command = "find "; else Command = "search ";
            SendCommand(Command + type + Functions.EscapeStr(what),
                callbacks.MusicCollectionPerFileCallback, callback);
        }
Exemplo n.º 54
0
 public void Search(SearchType type, string what, bool exactmatch,
                CommandCallback callback)
 {
     Search(Enum.GetName(typeof(SearchType), type).ToLower(), what, exactmatch, callback);
 }
Exemplo n.º 55
0
        protected void SendCommand(string cmdline, InternalCallback callback,
								   CommandCallback lastCallback)
        {
            blockCommands.Add(new Command(cmdline, callback, lastCallback));
            if (nextReadResultType == ReadResultType.Ignore && lastCallback != null)
                nextReadResultType = ReadResultType.Block;
        }
Exemplo n.º 56
0
 public static void Register( string cmd, CommandCallback callback )
 {
     m_List[cmd] = callback;
 }
Exemplo n.º 57
0
 public Command_AntiBotOnOff(CommandCallback cc)
 {
     callback = cc;
     InitializeComponent();
 }
Exemplo n.º 58
0
        public void RegisterCommand(string command, CommandCallback action)
        {
            command = command.ToLower();

            if (action == null)
            {
                if (commands.ContainsKey(command))
                {
                    commands.Remove(command);
                    sorted.Remove(command);
                }
            }
            else
            {
                commands[command] = action;
                if (!sorted.Contains(command))
                {
                    int i;
                    for (i = 0; i < sorted.Count; i++)
                        if (sorted[i].CompareTo(command) > 0)
                            break;
                    sorted.Insert(i, command);
                }
            }
        }
Exemplo n.º 59
0
 public JKACommand(CommandCallback callback, bool admin, string description)
 {
     this.callback = callback;
     this.admin = admin;
     this.description = description;
 }
Exemplo n.º 60
0
 // Gets the current statistics (StatsInfo)
 public void Statistics(CommandCallback callback)
 {
     SendCommand("stats", callbacks.StatsInfoCallback, callback);
 }