コード例 #1
0
        /// <summary>
        /// Recieves chat commands and attempts to execute them.
        /// </summary>
        private void MessageHandler(string message, ref bool sendToOthers)
        {
            string cmdName;

            string[] matches;
            bool     cmdFound = false;

            message = message.ToLower();

            if (message.StartsWith(prefix))
            {
                sendToOthers = false;

                if (TryParseCommand(message, out matches))
                {
                    cmdName = matches[0];

                    foreach (Command cmd in commands)
                    {
                        if (cmd.cmdName == cmdName)
                        {
                            cmdFound = true;

                            if (cmd.takesArgs)
                            {
                                if (matches.Length > 1)
                                {
                                    cmd.action(Utilities.GetSubarray(matches, 1));
                                }
                                else
                                {
                                    Main.SendChatMessage("Invalid Command. This command requires an argument.");
                                }
                            }
                            else
                            {
                                cmd.action(null);
                            }

                            break;
                        }
                    }
                }

                if (!cmdFound)
                {
                    Main.SendChatMessage("Command not recognised.");
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Instantiates commands and regex
        /// </summary>
        private ChatCommands(string prefix)
        {
            this.prefix = prefix;
            cmdParser   = new Regex(@"((\s*?[\s,;|]\s*?)(\w+))+");

            commands = new Command[]
            {
                new Command("help",
                            () => Main.ShowMissionScreen("Help", GetHelpMessage())),
                new Command("bindHelp",
                            () => Main.ShowMissionScreen("Bind Help", GetBindHelpMessage())),
                new Command("printBinds",
                            () => Main.SendChatMessage(GetPrintBindsMessage())),
                new Command("bind",
                            (string[] args) => Binds.TryUpdateBind(args[0], Utilities.GetSubarray(args, 1))),
                new Command("resetBinds",
                            () => Binds.TryUpdateConfig(BindsConfig.Defaults)),
                new Command("save",
                            () => Main.SaveConfig()),
                new Command("load",
                            () => Main.LoadConfig()),
                new Command("resetConfig",
                            () => Main.ResetConfig()),
                new Command("toggleApi",
                            () => Main.Cfg.forceFallbackHud = !Main.Cfg.forceFallbackHud),
                new Command("toggleAutoclose",
                            () => Main.Cfg.closeIfNotInView = !Main.Cfg.closeIfNotInView),
                new Command("toggleOpenWhileHolding",
                            () => Main.Cfg.canOpenIfHolding = !Main.Cfg.canOpenIfHolding),

                // Debug/Testing
                new Command("open",
                            () => Main.TryOpenMenu()),
                new Command("close",
                            () => Main.TryCloseMenu()),
                new Command("toggleTestPattern",
                            () => Hud.TestPattern.Toggle()),
                new Command("reload",
                            () => Main.Close())
            };

            controlList = Binds.GetControlListString();
            MyAPIGateway.Utilities.MessageEntered += MessageHandler;
        }