/// <summary>
        /// Check the args that were passed on program startup
        /// </summary>
        /// <param name="args">The args</param>
        /// <returns>If returns false, run normal setup. If returns true, cancel normal setup. In this case something has already started the server.</returns>
        static bool CheckArgs(string[] args)
        {
            if (args.Length == 0)
            {
                return(false);
            }
            string name = args[0];

            switch (name)
            {
            case "load-plugin":
                if (args.Length == 1)
                {
                    return(false);
                }
                string   plugin = args[1];
                string[] pargs  = new string[] { "-force" };
                for (int i = 1; i < args.Length; i++)
                {
                    pargs[i] = args[i];
                }
                LoadAllDlls.LoadDLL(plugin, pargs);
                break;

            case "debug":
                Server.DebugMode = true;
                return(false);

            case "abort-setup":
                return(true);
            }
            return(args[args.Length - 1] == "abort-setup");
        }
Exemple #2
0
        /// <summary>
        /// Reload one or all unloaded plugins.
        /// </summary>
        /// <param name="name">The name of the plugin to load, or an empty string to load all plugins</param>
        /// <param name="ignoreCase">Whether the case of the name gets ignored or not</param>
        /// <returns></returns>
        public static int reload(string name = "", bool ignoreCase = true)
        {
            foreach (IPlugin p in Plugins.ToArray())
            {
                if (name != "")
                {
                    if (ignoreCase)
                    {
                        if (p.Name.ToLower() == name.ToLower())
                        {
                            unload(name);
                            break;
                        }
                    }
                    else
                    if (p.Name == name)
                    {
                        unload(name);
                        break;
                    }
                }
                else
                {
                    unload(p.Name);
                    Logger.Log("[Plugin] Unloaded " + p.Name);
                }
            }

            int    ret  = 0;
            string path = Directory.GetCurrentDirectory();

            string[] DLLFiles = Directory.GetFiles(path, "*.dll");
            foreach (string s in DLLFiles)
            {
                ret++;
                if (name == "")
                {
                    LoadAllDlls.LoadDLL(s, new string[] { "-normal" }, typeof(IPlugin));
                }
                else if (ignoreCase)
                {
                    if (s.ToLower() == name.ToLower())
                    {
                        LoadAllDlls.LoadDLL(s, new string[] { "-normal" }, typeof(IPlugin));
                    }
                }
                else
                if (s == name)
                {
                    LoadAllDlls.LoadDLL(s, new string[] { "-normal" }, typeof(IPlugin));
                }
            }
            if (ServerSettings.HasKey("PluginsPath"))
            {
                string pluginspath = ServerSettings.GetSetting("PluginsPath");
                if (Directory.Exists(pluginspath))
                {
                    DLLFiles = Directory.GetFiles(pluginspath, "*.dll");
                    foreach (string s in DLLFiles)
                    {
                        if (name == "")
                        {
                            LoadAllDlls.LoadDLL(s, new string[] { "-normal" }, typeof(IPlugin));
                        }
                        else if (ignoreCase)
                        {
                            if (s.ToLower() == name.ToLower())
                            {
                                LoadAllDlls.LoadDLL(s, new string[] { "-normal" }, typeof(IPlugin));
                            }
                        }
                        else
                        if (s == name)
                        {
                            LoadAllDlls.LoadDLL(s, new string[] { "-normal" }, typeof(IPlugin));
                        }
                        ret++;
                    }
                }
            }
            return(ret);
        }