Beispiel #1
0
        static void populateAdminCommands()
        {
            _adminCommands = new Dictionary <string, AdminCommand>();
            Type[] types = System.Reflection.Assembly.GetExecutingAssembly().GetTypes();
            foreach (Type type in types)
            {
                AdminCommandAttribute adminCommandAttribute = (AdminCommandAttribute)Attribute.GetCustomAttribute(type, typeof(AdminCommandAttribute));
                if (adminCommandAttribute == null)
                {
                    continue;
                }

                _adminCommands.Add(adminCommandAttribute.CommandKey.ToLower(), (AdminCommand)Activator.CreateInstance(type));
            }
        }
Beispiel #2
0
        public static void Init()
        {
            foreach (string path in Directory.GetFiles(".\\Scripts\\Chat", "*.cs"))
            {
                Type t = Loader.LoadScript(path);
                if (t == null)
                {
                    continue;
                }
                object[] objs = t.GetCustomAttributes(typeof(AdminCommandAttribute), false);
                if (objs.Length < 1)
                {
                    continue;
                }
                AdminCommandAttribute cmdAttr = (AdminCommandAttribute)objs[0];
                Log.Debug("Loaded custom command {0}", cmdAttr.Command);
                Commands.Add(cmdAttr, t);
            }

            ChatHandler.OnSendMessage += ProccesActionCommand;
        }
Beispiel #3
0
        //public override bool ExecuteBeforeCommand(CommandMethodInfo methodInfo, string rawParameters, params CommandParameter[] parameters)
        //{
        //    AdminCommandAttribute adminCommandAttribute = methodInfo.Attribute as AdminCommandAttribute;
        //    if (adminCommandAttribute?.MinLevel > Level)
        //    {
        //        Send($"You're a not allowed to use '{adminCommandAttribute.Name}'.");
        //        Log.Default.WriteLine(LogLevels.Info, $"{DisplayName} [Level:{Level}] tried to use {adminCommandAttribute.Name} [Level:{adminCommandAttribute.MinLevel}]");
        //        return false;
        //    }
        //    return base.ExecuteBeforeCommand(methodInfo, rawParameters, parameters);
        //}

        protected override bool IsCommandAvailable(CommandAttribute attribute)
        {
            AdminCommandAttribute adminCommandAttribute = attribute as AdminCommandAttribute;

            return(adminCommandAttribute == null || Level >= adminCommandAttribute?.MinLevel);
        }