예제 #1
0
파일: Parser.cs 프로젝트: vadian/Novus
        static public void ExecuteCommand(Character.Iactor actor, string command, string message = null)
        {
            User.User player = new User.User(true);
            player.UserID = actor.ID;
            player.Player = actor;
            bool commandFound = false;

            if (CombatCommands.ContainsKey(command.ToUpper()))    //check to see if player provided a combat related command
            {
                CombatCommands[command.ToUpper()](player, new List <string>(new string[] { command, message }));
                commandFound = true;
            }

            if (!commandFound)
            {
                foreach (Dictionary <string, CommandDelegate> AvailableCommands in CommandsList)
                {
                    if (AvailableCommands.ContainsKey(command.ToUpper()))
                    {
                        AvailableCommands[command.ToUpper()](player, new List <string>(new string[] { command + " " + message, command, message }));
                        break;
                    }
                }
            }
        }
예제 #2
0
        /// <inheritdoc />
        public override void ExecuteCommand(ICommonSession?session, string command)
        {
            if (string.IsNullOrWhiteSpace(command))
            {
                return;
            }

            // echo the command locally
            WriteLine(null, "> " + command);

            //Commands are processed locally and then sent to the server to be processed there again.
            var args = new List <string>();

            CommandParsing.ParseArguments(command, args);

            var commandName = args[0];

            if (AvailableCommands.ContainsKey(commandName))
            {
                var command1 = AvailableCommands[commandName];
                args.RemoveAt(0);
                var shell   = new ConsoleShell(this, null);
                var cmdArgs = args.ToArray();

                AnyCommandExecuted?.Invoke(shell, commandName, command, cmdArgs);
                command1.Execute(shell, command, cmdArgs);
            }
            else
            {
                WriteError(null, "Unknown command: " + commandName);
            }
        }
예제 #3
0
파일: Parser.cs 프로젝트: vadian/Novus
        static public void ParseCommands(User.User player)
        {
            List <string> commands     = ParseCommandLine(player.InBufferPeek);
            bool          commandFound = false;

            foreach (Dictionary <string, CommandDelegate> AvailableCommands in CommandsList)
            {
                if (AvailableCommands.ContainsKey(commands[1].ToUpper()))
                {
                    AvailableCommands[commands[1].ToUpper()](player, commands);
                    commandFound = true;
                    break;
                }
            }

            //if all else fails auto-attack
            if (player.Player.InCombat && player.Player.CurrentTarget != null)
            {
                //auto attack! or we could remove this and let a player figure out on their own they're being attacked
                commands.Clear();
                commands.Add("KILL");
                commands.Add("target");
                commands.Insert(0, commands[0] + " " + commands[1]);
            }

            if (!commandFound && CombatCommands.ContainsKey(commands[1].ToUpper()))                //check to see if player provided a combat related command
            {
                CombatCommands[commands[1].ToUpper()](player, commands);
                commandFound = true;
                commands[0]  = player.InBuffer; //just removing the command from the queue now
                commands.Clear();
            }


            if (commands.Count == 0)
            {
                return;
            }

            //maybe this command shouldn't be a character method call...we'll see
            if (commands.Count >= 2 && commands[1].ToLower() == "save")
            {
                player.Player.Save();
                player.MessageHandler("Save succesful!\r\n");

                commandFound = true;
            }

            if (!commandFound && commands[0].Length > 0)
            {
                player.MessageHandler("I don't know what you're trying to do, but that's not going to happen.");
            }

            commands[0] = player.InBuffer;  //remove command from queue
        }
예제 #4
0
        private void HandleConCmdReg(MsgConCmdReg msg)
        {
            foreach (var cmd in msg.Commands)
            {
                string?commandName = cmd.Name;

                // Do not do duplicate commands.
                if (AvailableCommands.ContainsKey(commandName))
                {
                    Logger.DebugS("console", $"Server sent console command {commandName}, but we already have one with the same name. Ignoring.");
                    continue;
                }

                var command = new ServerDummyCommand(commandName, cmd.Help, cmd.Description);
                AvailableCommands[commandName] = command;
            }
        }
예제 #5
0
        /// <inheritdoc />
        public override void ExecuteCommand(ICommonSession?session, string command)
        {
            if (string.IsNullOrWhiteSpace(command))
            {
                return;
            }

            // echo the command locally
            WriteLine(null, "> " + command);

            //Commands are processed locally and then sent to the server to be processed there again.
            var args = new List <string>();

            CommandParsing.ParseArguments(command, args);

            var commandName = args[0];

            if (AvailableCommands.ContainsKey(commandName))
            {
                var playerManager = IoCManager.Resolve <IPlayerManager>();
#if !DEBUG
                if (!_conGroup.CanCommand(commandName) && playerManager.LocalPlayer?.Session.Status > SessionStatus.Connecting)
                {
                    WriteError(null, $"Insufficient perms for command: {commandName}");
                    return;
                }
#endif
                var command1 = AvailableCommands[commandName];
                args.RemoveAt(0);
                var shell   = new ConsoleShell(this, null);
                var cmdArgs = args.ToArray();

                AnyCommandExecuted?.Invoke(shell, commandName, command, cmdArgs);
                command1.Execute(shell, command, cmdArgs);
            }
            else
            {
                WriteError(null, "Unknown command: " + commandName);
            }
        }