Пример #1
0
 /// <summary>
 ///     Prints the man page for a specified command to the console
 /// </summary>
 /// <param name="cmd">The command to print info for</param>
 public void PrintCommandInfo(CommandDispatcher.Command cmd)
 {
     PrintLine("Command: " + cmd.Name);
     PrintLine("Description: " + cmd.Description);
     foreach (var x in cmd.ExpectedArgs)
     {
         var s = cmd.Name + " ";
         foreach (var ca in x)
         {
             s += "<" + ca.Type + " " + ca.Name + "> ";
         }
         PrintLine(s);
     }
 }
        private void RegisterDefaultCommands()
        {
            #region Register help

            _commandDispatcher.RegisterCommand(
                new CommandDispatcher.Command("help", "Displays a list of all commands.", DefaultCommandEventHandler),
                true);

            #endregion

            #region Register clear

            _commandDispatcher.RegisterCommand(
                new CommandDispatcher.Command("clear", "Clears the console window.", DefaultCommandEventHandler), true);

            #endregion

            #region Register man

            var man = new CommandDispatcher.Command("man", "Prints out info for the provided command.",
                DefaultCommandEventHandler);

            man.AddArgumentSet(
                new CommandDispatcher.CommandArgument("cmd", "The command to get info for", typeof (string))
                );

            _commandDispatcher.RegisterCommand(man, true);

            #endregion

            #region Register cs

            var cs = new CommandDispatcher.Command("cs",
                "Executes a block of code and returns the .ToString() of the object.", DefaultCommandEventHandler);

            cs.AddArgumentSet(
                new CommandDispatcher.CommandArgument("code", "The code to execute", typeof (object))
                );

            _commandDispatcher.RegisterCommand(cs, true);

            #endregion

            #region Register god

            var god = new CommandDispatcher.Command("god", "Toggles godmode (invincibility).",
                DefaultCommandEventHandler);

            god.AddArgumentSet(
                new CommandDispatcher.CommandArgument("active", "Whether or not godmode should be active", typeof (bool))
                );

            _commandDispatcher.RegisterCommand(god, true);

            #endregion

            #region Register forcefield

            var forcefield = new CommandDispatcher.Command("forcefield", "Toggles forcefield.",
                DefaultCommandEventHandler);

            forcefield.AddArgumentSet(
                new CommandDispatcher.CommandArgument("active", "Whether or not forcefield should be active", typeof(bool))
                );

            if(ConsoleSettings.IsDevBuild) _commandDispatcher.RegisterCommand(forcefield, true);

            #endregion

            #region Register noclip

            var noclip = new CommandDispatcher.Command("noclip", "Toggles noclip.",
                DefaultCommandEventHandler);

            noclip.AddArgumentSet(
                new CommandDispatcher.CommandArgument("active", "Whether or not noclip should be active", typeof (bool))
                );

            _commandDispatcher.RegisterCommand(noclip, true);

            #endregion

            #region Register tp

            var tp = new CommandDispatcher.Command("tp", "Teleports you to a given location, player or blip.",
                DefaultCommandEventHandler);

            tp.AddArgumentSet();

            tp.AddArgumentSet(
                new CommandDispatcher.CommandArgument("player", "The name of the player to teleport to", typeof (string))
                );

            tp.AddArgumentSet(
                new CommandDispatcher.CommandArgument("x", "The x coordinate to teleport to", typeof (double)),
                new CommandDispatcher.CommandArgument("y", "The y coordinate to teleport to", typeof (double)),
                new CommandDispatcher.CommandArgument("z", "The z coordinate to teleport to", typeof (double))
                );

            tp.AddArgumentSet(
                new CommandDispatcher.CommandArgument("x", "The x coordinate to teleport to", typeof(int)),
                new CommandDispatcher.CommandArgument("y", "The y coordinate to teleport to", typeof(int)),
                new CommandDispatcher.CommandArgument("z", "The z coordinate to teleport to", typeof(int))
            );

            tp.AddArgumentSet(
                new CommandDispatcher.CommandArgument("playerId", "The player ID", typeof (int))
                );

            _commandDispatcher.RegisterCommand(tp, true);

            #endregion

            #region Register players

            _commandDispatcher.RegisterCommand(
                new CommandDispatcher.Command("players", "Displays a list of all players.", DefaultCommandEventHandler),
                true);

            #endregion

            #region Register drop

            var drop = new CommandDispatcher.Command("drop", "Drops an item with the specified hash key and value.",
                DefaultCommandEventHandler);

            drop.AddArgumentSet(
                new CommandDispatcher.CommandArgument("hashKey", "The hash key to drop", typeof (string)),
                new CommandDispatcher.CommandArgument("value", "The dropped items value", typeof (string))
                );

            _commandDispatcher.RegisterCommand(drop, true);

            #endregion

            #region Register vehicle

            var vehicle = new CommandDispatcher.Command("vehicle", "Spawns a vehicle of the speicifed hash key.",
                DefaultCommandEventHandler);

            vehicle.AddArgumentSet(
                new CommandDispatcher.CommandArgument("hashKey", "The hash key of the vehicle", typeof (string))
                );

            _commandDispatcher.RegisterCommand(vehicle, true);

            #endregion

            #region Register dump

            var dump = new CommandDispatcher.Command("dump", "Dumps the properties and methods of a specified object.",
                DefaultCommandEventHandler);

            dump.AddArgumentSet(
                new CommandDispatcher.CommandArgument("object", "The object to dump", typeof (object))
                );

            _commandDispatcher.RegisterCommand(dump, true);

            #endregion

            #region Register money

            _commandDispatcher.RegisterCommand(
                new CommandDispatcher.Command("money", "Drops money.", DefaultCommandEventHandler), true);

            #endregion

            #region Register weapons

            var weapons = new CommandDispatcher.Command("weapons", "Gives player a weapon of the speicifed hash key.",
                DefaultCommandEventHandler);

            _commandDispatcher.RegisterCommand(weapons, true);

            #endregion

            #region Register gtfo

            var gtfo = new CommandDispatcher.Command("gtfo", "Gets you out of a sticky situation.",
                DefaultCommandEventHandler);

            _commandDispatcher.RegisterCommand(gtfo, true);

            #endregion

            #region Register up

            var up = new CommandDispatcher.Command("up", "Teleport entity up.",
                DefaultCommandEventHandler);

            up.AddArgumentSet(
                new CommandDispatcher.CommandArgument("distance", "The distance to be teleported up", typeof(int))
                );

            up.AddArgumentSet(
                new CommandDispatcher.CommandArgument("entity", "The entity to teleport", typeof(Entity)),
                new CommandDispatcher.CommandArgument("distance", "The distance to be teleported up", typeof(int))
                );

            up.AddArgumentSet(
                new CommandDispatcher.CommandArgument("player", "The player to teleport", typeof(Player)),
                new CommandDispatcher.CommandArgument("distance", "The distance to be teleported up", typeof(int))
                );

            _commandDispatcher.RegisterCommand(up, true);

            #endregion

            #region Register launch

            var launch = new CommandDispatcher.Command("launch", "Launch entity up.",
                DefaultCommandEventHandler);

            launch.AddArgumentSet(
                new CommandDispatcher.CommandArgument("velocity", "The distance to be launched up", typeof(int))
                );

            launch.AddArgumentSet(
                new CommandDispatcher.CommandArgument("entity", "The entity to teleport", typeof(Entity)),
                new CommandDispatcher.CommandArgument("velocity", "The distance to be launched up", typeof(int))
                );

            launch.AddArgumentSet(
                new CommandDispatcher.CommandArgument("player", "The player to teleport", typeof(Player)),
                new CommandDispatcher.CommandArgument("velocity", "The distance to be launched up", typeof(int))
                );

            _commandDispatcher.RegisterCommand(launch, true);

            #endregion

            #region Register upright

            var upright = new CommandDispatcher.Command("upright", "Set an entity upright.",
                DefaultCommandEventHandler);

            upright.AddArgumentSet();

            upright.AddArgumentSet(new CommandDispatcher.CommandArgument("entity", "The entity to set upright", typeof(Entity)));

            upright.AddArgumentSet(new CommandDispatcher.CommandArgument("player", "The player to set upright", typeof(Player)));

            _commandDispatcher.RegisterCommand(upright, true);

            #endregion

            #region Register heal

            var heal = new CommandDispatcher.Command("heal", "Heal an entity",
                DefaultCommandEventHandler);

            heal.AddArgumentSet();

            heal.AddArgumentSet(new CommandDispatcher.CommandArgument("entity", "The entity to heal", typeof(Entity)));

            heal.AddArgumentSet(new CommandDispatcher.CommandArgument("player", "The player to heal", typeof(Player)));

            _commandDispatcher.RegisterCommand(heal, true);

            #endregion

            #region Register devshirt

            var devshirt = new CommandDispatcher.Command("devshirt", "Get a dev shirt",
                DefaultCommandEventHandler);

            devshirt.AddArgumentSet(new CommandDispatcher.CommandArgument("color", "The desired shirt color (white, gray/grey or black)", typeof(String)));

            if (ConsoleSettings.IsDevBuild) _commandDispatcher.RegisterCommand(devshirt, true);

            #endregion

            #region Register spectator
            var spectator = new CommandDispatcher.Command("spectator", "Set yourself or another player as a spectator.",
                DefaultCommandEventHandler);

            spectator.AddArgumentSet(
                new CommandDispatcher.CommandArgument("active", "Whether or not the player should be spectating", typeof(bool))
                );

            spectator.AddArgumentSet(
                new CommandDispatcher.CommandArgument("player", "The name of the player that should be spectating", typeof(Player)),
                new CommandDispatcher.CommandArgument("active", "Whether or not the player should be spectating", typeof(bool))
                );

            _commandDispatcher.RegisterCommand(spectator, true);
            #endregion
        }
        private void RegisterDefaultCommands()
        {
            #region Register help

            _commandDispatcher.RegisterCommand(
                new CommandDispatcher.Command("help", "Displays a list of all commands.", DefaultCommandEventHandler),
                true);

            #endregion

            #region Register clear

            _commandDispatcher.RegisterCommand(
                new CommandDispatcher.Command("clear", "Clears the console window.", DefaultCommandEventHandler), true);

            #endregion

            #region Register man

            var man = new CommandDispatcher.Command("man", "Prints out info for the provided command.",
                DefaultCommandEventHandler);

            man.AddArgumentSet(
                new CommandDispatcher.CommandArgument("cmd", "The command to get info for", typeof (string))
                );

            _commandDispatcher.RegisterCommand(man, true);

            #endregion

            #region Register cs

            var cs = new CommandDispatcher.Command("cs",
                "Executes a block of code and returns the .ToString() of the object.", DefaultCommandEventHandler);

            cs.AddArgumentSet(
                new CommandDispatcher.CommandArgument("code", "The code to execute", typeof (object))
                );

            _commandDispatcher.RegisterCommand(cs, true);

            #endregion

            #region Register god

            var god = new CommandDispatcher.Command("god", "Toggles godmode (invincibility).",
                DefaultCommandEventHandler);

            god.AddArgumentSet(
                new CommandDispatcher.CommandArgument("active", "Whether or not godmode should be active", typeof (bool))
                );

            _commandDispatcher.RegisterCommand(god, true);

            #endregion

            #region Register noclip

            var noclip = new CommandDispatcher.Command("noclip", "Toggles noclip.",
                DefaultCommandEventHandler);

            noclip.AddArgumentSet(
                new CommandDispatcher.CommandArgument("active", "Whether or not noclip should be active", typeof (bool))
                );

            _commandDispatcher.RegisterCommand(noclip, true);

            #endregion

            #region Register tp

            var tp = new CommandDispatcher.Command("tp", "Teleports you to a given location, player or blip.",
                DefaultCommandEventHandler);

            tp.AddArgumentSet();

            tp.AddArgumentSet(
                new CommandDispatcher.CommandArgument("player", "The name of the player to teleport to", typeof (string))
                );

            tp.AddArgumentSet(
                new CommandDispatcher.CommandArgument("x", "The x coordinate to teleport to", typeof (double)),
                new CommandDispatcher.CommandArgument("y", "The y coordinate to teleport to", typeof (double)),
                new CommandDispatcher.CommandArgument("z", "The z coordinate to teleport to", typeof (double))
                );

            tp.AddArgumentSet(
                new CommandDispatcher.CommandArgument("playerId", "The player ID", typeof (double))
                );

            _commandDispatcher.RegisterCommand(tp, true);

            #endregion

            #region Register players

            _commandDispatcher.RegisterCommand(
                new CommandDispatcher.Command("players", "Displays a list of all players.", DefaultCommandEventHandler),
                true);

            #endregion

            #region Register drop

            var drop = new CommandDispatcher.Command("drop", "Drops an item with the specified hash key and value.",
                DefaultCommandEventHandler);

            drop.AddArgumentSet(
                new CommandDispatcher.CommandArgument("hashKey", "The hash key to drop", typeof (string)),
                new CommandDispatcher.CommandArgument("value", "The dropped items value", typeof (string))
                );

            _commandDispatcher.RegisterCommand(drop, true);

            #endregion

            #region Register vehicle

            var vehicle = new CommandDispatcher.Command("vehicle", "Spawns a vehicle of the speicifed hash key.",
                DefaultCommandEventHandler);

            vehicle.AddArgumentSet(
                new CommandDispatcher.CommandArgument("hashKey", "The hash key of the vehicle", typeof (string))
                );

            _commandDispatcher.RegisterCommand(vehicle, true);

            #endregion

            #region Register dump

            var dump = new CommandDispatcher.Command("dump", "Dumps the properties and methods of a specified object.",
                DefaultCommandEventHandler);

            dump.AddArgumentSet(
                new CommandDispatcher.CommandArgument("object", "The object to dump", typeof (object))
                );

            _commandDispatcher.RegisterCommand(dump, true);

            #endregion

            #region Register money

            _commandDispatcher.RegisterCommand(
                new CommandDispatcher.Command("money", "Drops money.", DefaultCommandEventHandler), true);

            #endregion

            #region Register weapons

            var weapons = new CommandDispatcher.Command("weapons", "Gives player a weapon of the speicifed hash key.",
                DefaultCommandEventHandler);

            _commandDispatcher.RegisterCommand(weapons, true);

            #endregion

            #region Register gtfo

            var gtfo = new CommandDispatcher.Command("gtfo", "Gets you out of a sticky situation.",
                DefaultCommandEventHandler);

            _commandDispatcher.RegisterCommand(gtfo, true);

            #endregion
        }
        private void RegisterDefaultCommands()
        {
            #region Register help

            _commandDispatcher.RegisterCommand(
                new CommandDispatcher.Command("help", "Displays a list of all commands.", DefaultCommandEventHandler),
                true);

            #endregion

            #region Register clear

            _commandDispatcher.RegisterCommand(
                new CommandDispatcher.Command("clear", "Clears the console window.", DefaultCommandEventHandler), true);

            #endregion

            #region Register man

            var man = new CommandDispatcher.Command("man", "Prints out info for the provided command.",
                                                    DefaultCommandEventHandler);

            man.AddArgumentSet(
                new CommandDispatcher.CommandArgument("cmd", "The command to get info for", typeof(string))
                );

            _commandDispatcher.RegisterCommand(man, true);

            #endregion

            #region Register cs

            var cs = new CommandDispatcher.Command("cs",
                                                   "Executes a block of code and returns the .ToString() of the object.", DefaultCommandEventHandler);

            cs.AddArgumentSet(
                new CommandDispatcher.CommandArgument("code", "The code to execute", typeof(object))
                );

            _commandDispatcher.RegisterCommand(cs, true);

            #endregion

            #region Register god

            var god = new CommandDispatcher.Command("god", "Toggles godmode (invincibility).",
                                                    DefaultCommandEventHandler);

            god.AddArgumentSet(
                new CommandDispatcher.CommandArgument("active", "Whether or not godmode should be active", typeof(bool))
                );

            _commandDispatcher.RegisterCommand(god, true);

            #endregion

            #region Register forcefield

            var forcefield = new CommandDispatcher.Command("forcefield", "Toggles forcefield.",
                                                           DefaultCommandEventHandler);

            forcefield.AddArgumentSet(
                new CommandDispatcher.CommandArgument("active", "Whether or not forcefield should be active", typeof(bool))
                );

            if (ConsoleSettings.IsDevBuild)
            {
                _commandDispatcher.RegisterCommand(forcefield, true);
            }

            #endregion

            #region Register noclip

            var noclip = new CommandDispatcher.Command("noclip", "Toggles noclip.",
                                                       DefaultCommandEventHandler);

            noclip.AddArgumentSet(
                new CommandDispatcher.CommandArgument("active", "Whether or not noclip should be active", typeof(bool))
                );

            _commandDispatcher.RegisterCommand(noclip, true);

            #endregion

            #region Register tp

            var tp = new CommandDispatcher.Command("tp", "Teleports you to a given location, player or blip.",
                                                   DefaultCommandEventHandler);

            tp.AddArgumentSet();

            tp.AddArgumentSet(
                new CommandDispatcher.CommandArgument("player", "The name of the player to teleport to", typeof(string))
                );

            tp.AddArgumentSet(
                new CommandDispatcher.CommandArgument("x", "The x coordinate to teleport to", typeof(double)),
                new CommandDispatcher.CommandArgument("y", "The y coordinate to teleport to", typeof(double)),
                new CommandDispatcher.CommandArgument("z", "The z coordinate to teleport to", typeof(double))
                );

            tp.AddArgumentSet(
                new CommandDispatcher.CommandArgument("x", "The x coordinate to teleport to", typeof(int)),
                new CommandDispatcher.CommandArgument("y", "The y coordinate to teleport to", typeof(int)),
                new CommandDispatcher.CommandArgument("z", "The z coordinate to teleport to", typeof(int))
                );

            tp.AddArgumentSet(
                new CommandDispatcher.CommandArgument("playerId", "The player ID", typeof(int))
                );

            _commandDispatcher.RegisterCommand(tp, true);

            #endregion

            #region Register players

            _commandDispatcher.RegisterCommand(
                new CommandDispatcher.Command("players", "Displays a list of all players.", DefaultCommandEventHandler),
                true);

            #endregion

            #region Register drop

            var drop = new CommandDispatcher.Command("drop", "Drops an item with the specified hash key and value.",
                                                     DefaultCommandEventHandler);

            drop.AddArgumentSet(
                new CommandDispatcher.CommandArgument("hashKey", "The hash key to drop", typeof(string)),
                new CommandDispatcher.CommandArgument("value", "The dropped items value", typeof(string))
                );

            _commandDispatcher.RegisterCommand(drop, true);

            #endregion

            #region Register vehicle

            var vehicle = new CommandDispatcher.Command("vehicle", "Spawns a vehicle of the speicifed hash key.",
                                                        DefaultCommandEventHandler);

            vehicle.AddArgumentSet(
                new CommandDispatcher.CommandArgument("hashKey", "The hash key of the vehicle", typeof(string))
                );

            _commandDispatcher.RegisterCommand(vehicle, true);

            #endregion

            #region Register dump

            var dump = new CommandDispatcher.Command("dump", "Dumps the properties and methods of a specified object.",
                                                     DefaultCommandEventHandler);

            dump.AddArgumentSet(
                new CommandDispatcher.CommandArgument("object", "The object to dump", typeof(object))
                );

            _commandDispatcher.RegisterCommand(dump, true);

            #endregion

            #region Register money

            _commandDispatcher.RegisterCommand(
                new CommandDispatcher.Command("money", "Drops money.", DefaultCommandEventHandler), true);

            #endregion

            #region Register weapons

            var weapons = new CommandDispatcher.Command("weapons", "Gives player a weapon of the speicifed hash key.",
                                                        DefaultCommandEventHandler);

            _commandDispatcher.RegisterCommand(weapons, true);

            #endregion

            #region Register gtfo

            var gtfo = new CommandDispatcher.Command("gtfo", "Gets you out of a sticky situation.",
                                                     DefaultCommandEventHandler);

            _commandDispatcher.RegisterCommand(gtfo, true);

            #endregion

            #region Register up

            var up = new CommandDispatcher.Command("up", "Teleport entity up.",
                                                   DefaultCommandEventHandler);

            up.AddArgumentSet(
                new CommandDispatcher.CommandArgument("distance", "The distance to be teleported up", typeof(int))
                );

            up.AddArgumentSet(
                new CommandDispatcher.CommandArgument("entity", "The entity to teleport", typeof(Entity)),
                new CommandDispatcher.CommandArgument("distance", "The distance to be teleported up", typeof(int))
                );

            up.AddArgumentSet(
                new CommandDispatcher.CommandArgument("player", "The player to teleport", typeof(Player)),
                new CommandDispatcher.CommandArgument("distance", "The distance to be teleported up", typeof(int))
                );

            _commandDispatcher.RegisterCommand(up, true);

            #endregion

            #region Register launch

            var launch = new CommandDispatcher.Command("launch", "Launch entity up.",
                                                       DefaultCommandEventHandler);

            launch.AddArgumentSet(
                new CommandDispatcher.CommandArgument("velocity", "The distance to be launched up", typeof(int))
                );

            launch.AddArgumentSet(
                new CommandDispatcher.CommandArgument("entity", "The entity to teleport", typeof(Entity)),
                new CommandDispatcher.CommandArgument("velocity", "The distance to be launched up", typeof(int))
                );

            launch.AddArgumentSet(
                new CommandDispatcher.CommandArgument("player", "The player to teleport", typeof(Player)),
                new CommandDispatcher.CommandArgument("velocity", "The distance to be launched up", typeof(int))
                );

            _commandDispatcher.RegisterCommand(launch, true);

            #endregion

            #region Register upright

            var upright = new CommandDispatcher.Command("upright", "Set an entity upright.",
                                                        DefaultCommandEventHandler);

            upright.AddArgumentSet();

            upright.AddArgumentSet(new CommandDispatcher.CommandArgument("entity", "The entity to set upright", typeof(Entity)));

            upright.AddArgumentSet(new CommandDispatcher.CommandArgument("player", "The player to set upright", typeof(Player)));

            _commandDispatcher.RegisterCommand(upright, true);

            #endregion

            #region Register heal

            var heal = new CommandDispatcher.Command("heal", "Heal an entity",
                                                     DefaultCommandEventHandler);

            heal.AddArgumentSet();

            heal.AddArgumentSet(new CommandDispatcher.CommandArgument("entity", "The entity to heal", typeof(Entity)));

            heal.AddArgumentSet(new CommandDispatcher.CommandArgument("player", "The player to heal", typeof(Player)));

            _commandDispatcher.RegisterCommand(heal, true);

            #endregion

            #region Register devshirt

            var devshirt = new CommandDispatcher.Command("devshirt", "Get a dev shirt",
                                                         DefaultCommandEventHandler);

            devshirt.AddArgumentSet(new CommandDispatcher.CommandArgument("color", "The desired shirt color (white, gray/grey or black)", typeof(String)));

            if (ConsoleSettings.IsDevBuild)
            {
                _commandDispatcher.RegisterCommand(devshirt, true);
            }

            #endregion

            #region Register spectator
            var spectator = new CommandDispatcher.Command("spectator", "Set yourself or another player as a spectator.",
                                                          DefaultCommandEventHandler);

            spectator.AddArgumentSet(
                new CommandDispatcher.CommandArgument("active", "Whether or not the player should be spectating", typeof(bool))
                );

            spectator.AddArgumentSet(
                new CommandDispatcher.CommandArgument("player", "The name of the player that should be spectating", typeof(Player)),
                new CommandDispatcher.CommandArgument("active", "Whether or not the player should be spectating", typeof(bool))
                );

            _commandDispatcher.RegisterCommand(spectator, true);
            #endregion
        }