コード例 #1
0
        /// <summary>
        /// Displays all the chat commands available to a user
        /// </summary>
        /// <param name="user"></param>
        /// <param name="target"></param>
        /// <param name="targetLocation"></param>
        /// <param name="args"></param>
        public void DoAction(NWGameObject user, NWGameObject target, Location targetLocation, params string[] args)
        {
            var authorization = AuthorizationRegistry.GetAuthorizationLevel(user);

            Console.WriteLine("Running: auth = " + authorization);

            if (authorization == AuthorizationLevel.DM)
            {
                SendMessageToPC(user, ChatCommandRegistry.HelpTextDM);
            }
            else if (authorization == AuthorizationLevel.Admin)
            {
                SendMessageToPC(user, ChatCommandRegistry.HelpTextAdmin);
            }
            else
            {
                SendMessageToPC(user, ChatCommandRegistry.HelpTextPlayer);
            }
        }
コード例 #2
0
        private static void ProcessChatCommand(IChatCommand command, NWGameObject sender, NWGameObject target, Location targetLocation, string args)
        {
            if (target == null)
            {
                target = new NWGameObject();
            }

            if (targetLocation == null)
            {
                targetLocation = new Location();
            }

            CommandDetailsAttribute attribute = command.GetType().GetCustomAttribute <CommandDetailsAttribute>();
            var authorization = AuthorizationRegistry.GetAuthorizationLevel(sender);

            if (attribute != null &&
                (attribute.Permissions.HasFlag(CommandPermissionType.Player) && authorization == AuthorizationLevel.Player ||
                 attribute.Permissions.HasFlag(CommandPermissionType.DM) && authorization == AuthorizationLevel.DM ||
                 attribute.Permissions.HasFlag(CommandPermissionType.Admin) && authorization == AuthorizationLevel.Admin))
            {
                string[] argsArr = string.IsNullOrWhiteSpace(args) ? new string[0] : args.Split(' ').ToArray();
                string   error   = command.ValidateArguments(sender, argsArr);

                if (!string.IsNullOrWhiteSpace(error))
                {
                    SendMessageToPC(sender, error);
                }
                else
                {
                    command.DoAction(sender, target, targetLocation, argsArr);
                }
            }
            else
            {
                SendMessageToPC(sender, ColorToken.Red("Invalid chat command. Use '/help' to get a list of available commands."));
            }
        }