示例#1
0
        public static void Initialize()
        {
            commandHandlers = new Dictionary <string, CommandHandlerInfo>(StringComparer.OrdinalIgnoreCase);
            foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
            {
                foreach (var method in type.GetMethods())
                {
                    foreach (var attribute in method.GetCustomAttributes <CommandHandlerAttribute>())
                    {
                        var commandHandler = new CommandHandlerInfo()
                        {
                            Handler   = (CommandHandler)Delegate.CreateDelegate(typeof(CommandHandler), method),
                            Attribute = attribute
                        };

                        commandHandlers[attribute.Command] = commandHandler;
                    }
                }
            }

            if (Program.IsRunningInContainer)
            {
                return;
            }

            var thread = new Thread(new ThreadStart(CommandThread));

            thread.Name         = "Command Manager";
            thread.IsBackground = true;
            thread.Start();
        }
示例#2
0
        public static void Initialize()
        {
            commandHandlers = new Dictionary <string, CommandHandlerInfo>(StringComparer.OrdinalIgnoreCase);
            foreach (var type in Assembly.GetExecutingAssembly().GetTypes())
            {
                foreach (var method in type.GetMethods())
                {
                    foreach (var attribute in method.GetCustomAttributes <CommandHandlerAttribute>())
                    {
                        var commandHandler = new CommandHandlerInfo()
                        {
                            Handler   = (CommandHandler)Delegate.CreateDelegate(typeof(CommandHandler), method),
                            Attribute = attribute
                        };

                        commandHandlers[attribute.Command] = commandHandler;
                    }
                }
            }

            if (NonInteractiveConsole)
            {
                log.Info("ACEmulator command prompt disabled - Environment.GetEnvironmentVariable(ACE_NONINTERACTIVE_CONSOLE) was true");
                return;
            }

            var thread = new Thread(new ThreadStart(CommandThread));

            thread.Name         = "Command Manager";
            thread.IsBackground = true;
            thread.Start();
        }
示例#3
0
        public static CommandHandlerResponse GetCommandHandler(Session session, string command, string[] parameters, out CommandHandlerInfo commandInfo)
        {
            if (command == null || parameters == null)
            {
                commandInfo = null;
                return(CommandHandlerResponse.InvalidCommand);
            }
            bool isSUDOauthorized = false;

            if (command.ToLower() == "sudo")
            {
                string sudoCommand = "";
                if (parameters.Length > 0)
                {
                    sudoCommand = parameters[0];
                }

                if (!commandHandlers.TryGetValue(sudoCommand, out commandInfo))
                {
                    return(CommandHandlerResponse.InvalidCommand);
                }

                if (session == null)
                {
                    Console.WriteLine("SUDO does not work on the console because you already have full access. Remove SUDO from command and execute again.");
                    return(CommandHandlerResponse.InvalidCommand);
                }

                if (commandInfo.Attribute.Access <= session.AccessLevel)
                {
                    isSUDOauthorized = true;
                }

                if (isSUDOauthorized)
                {
                    command = sudoCommand;
                    var sudoParameters = new string[parameters.Length - 1];
                    for (int i = 1; i < parameters.Length; i++)
                    {
                        sudoParameters[i - 1] = parameters[i];
                    }
                    parameters = sudoParameters;
                }
            }

            if (!commandHandlers.TryGetValue(command, out commandInfo))
            {
                // Provide some feedback for why the console command failed
                if (session == null)
                {
                    Console.WriteLine($"Invalid Command");
                }

                return(CommandHandlerResponse.InvalidCommand);
            }

            if ((commandInfo.Attribute.Flags & CommandHandlerFlag.ConsoleInvoke) != 0 && session != null)
            {
                return(CommandHandlerResponse.NoConsoleInvoke);
            }

            if (session != null)
            {
                bool isAdvocate = session.Player.IsAdvocate;
                bool isSentinel = session.Player.IsSentinel;
                bool isEnvoy    = isSentinel; // TODO: Add more resolution to player levels so we can separate IsEnvoy from IsSentinel
                bool isArch     = session.Player.IsArch;
                bool isAdmin    = session.Player.IsAdmin;

                if (commandInfo.Attribute.Access == AccessLevel.Advocate && !(isAdvocate || isSentinel || isEnvoy || isArch || isAdmin || isSUDOauthorized) ||
                    commandInfo.Attribute.Access == AccessLevel.Sentinel && !(isSentinel || isEnvoy || isArch || isAdmin || isSUDOauthorized) ||
                    commandInfo.Attribute.Access == AccessLevel.Envoy && !(isEnvoy || isArch || isAdmin || isSUDOauthorized) ||
                    commandInfo.Attribute.Access == AccessLevel.Developer && !(isArch || isAdmin || isSUDOauthorized) ||
                    commandInfo.Attribute.Access == AccessLevel.Admin && !(isAdmin || isSUDOauthorized))
                {
                    return(CommandHandlerResponse.NotAuthorized);
                }
            }

            if (commandInfo.Attribute.ParameterCount != -1 && parameters.Length < commandInfo.Attribute.ParameterCount)
            {
                // Provide some feedback for why the console command failed
                if (session == null)
                {
                    Console.WriteLine($"The syntax of the command is incorrect.\nUsage: " + commandInfo.Attribute.Command + " " + commandInfo.Attribute.Usage);
                }
                return(CommandHandlerResponse.InvalidParameterCount);
            }

            if ((commandInfo.Attribute.Flags & CommandHandlerFlag.RequiresWorld) != 0 && (session == null || session.Player == null || session.Player.CurrentLandblock == null))
            {
                return(CommandHandlerResponse.NotInWorld);
            }

            if (isSUDOauthorized)
            {
                return(CommandHandlerResponse.SudoOk);
            }

            return(CommandHandlerResponse.Ok);
        }
示例#4
0
        public static CommandHandlerResponse GetCommandHandler(Session session, string command, string[] parameters, out CommandHandlerInfo commandInfo)
        {
            bool isSUDOauthorized = false;

            if (command.ToLower() == "sudo")
            {
                string sudoCommand = "";
                if (parameters.Length > 0)
                {
                    sudoCommand = parameters[0];
                }

                if (!commandHandlers.TryGetValue(sudoCommand, out commandInfo))
                {
                    return(CommandHandlerResponse.InvalidCommand);
                }

                if (session == null)
                {
                    Console.WriteLine("SUDO does not work on the console because you already have full access. Remove SUDO from command and execute again.");
                    return(CommandHandlerResponse.InvalidCommand);
                }

                if (commandInfo.Attribute.Access <= session.AccessLevel)
                {
                    isSUDOauthorized = true;
                }

                if (isSUDOauthorized)
                {
                    command = sudoCommand;
                    var sudoParameters = new string[parameters.Length - 1];
                    for (int i = 1; i < parameters.Length; i++)
                    {
                        sudoParameters[i - 1] = parameters[i];
                    }
                    parameters = sudoParameters;
                }
            }

            if (!commandHandlers.TryGetValue(command, out commandInfo))
            {
                return(CommandHandlerResponse.InvalidCommand);
            }

            if ((commandInfo.Attribute.Flags & CommandHandlerFlag.ConsoleInvoke) != 0 && session != null)
            {
                return(CommandHandlerResponse.NoConsoleInvoke);
            }

            if (session != null)
            {
                bool isAdvocate = session.Player.IsAdvocate;
                bool isSentinel = session.Player.IsEnvoy; // we map this to envoy
                bool isEnvoy    = isSentinel;
                bool isArch     = session.Player.IsArch;
                bool isAdmin    = session.Player.IsAdmin;

                if (commandInfo.Attribute.Access == AccessLevel.Advocate && !(isAdvocate || isSentinel || isEnvoy || isArch || isAdmin || isSUDOauthorized) ||
                    commandInfo.Attribute.Access == AccessLevel.Sentinel && !(isSentinel || isEnvoy || isArch || isAdmin || isSUDOauthorized) ||
                    commandInfo.Attribute.Access == AccessLevel.Envoy && !(isEnvoy || isArch || isAdmin || isSUDOauthorized) ||
                    commandInfo.Attribute.Access == AccessLevel.Developer && !(isArch || isAdmin || isSUDOauthorized) ||
                    commandInfo.Attribute.Access == AccessLevel.Admin && !(isAdmin || isSUDOauthorized))
                {
                    return(CommandHandlerResponse.NotAuthorized);
                }
            }

            if (commandInfo.Attribute.ParameterCount != -1 && parameters.Length < commandInfo.Attribute.ParameterCount)
            {
                return(CommandHandlerResponse.InvalidParameterCount);
            }

            if ((commandInfo.Attribute.Flags & CommandHandlerFlag.RequiresWorld) != 0 && (session == null || session.Player == null || !session.Player.InWorld))
            {
                return(CommandHandlerResponse.NotInWorld);
            }

            if (isSUDOauthorized)
            {
                return(CommandHandlerResponse.SudoOk);
            }

            return(CommandHandlerResponse.Ok);
        }