Ejemplo n.º 1
0
        private void LoadPlugin(string name)
        {
            Logger.LogDebug(string.Format("{0} Loading plugin {1}.", brktname, name));

            if (plugins.ContainsKey(name))
            {
                Logger.LogError(string.Format("{0} {1} plugin is already loaded.", brktname, name));
                throw new InvalidOperationException(string.Format("{0} {1} plugin is already loaded.", brktname, name));
            }

            try {
                string        text   = GetPluginScriptText(name);
                DirectoryInfo dir    = new DirectoryInfo(Path.Combine(pluginDirectory.FullName, name));
                Plugin        plugin = new Plugin(dir, name, text);
                plugin.InstallHooks();
                plugins[name] = plugin;

                Logger.Log(string.Format("{0} {1} plugin was loaded successfuly.", brktname, name));
            } catch (Exception ex) {
                Logger.LogError(string.Format("{0} {1} plugin could not be loaded.", brktname, name));
                Logger.LogException(ex);
            }
        }
Ejemplo n.º 2
0
        private void LoadPlugin(string name)
        {
            Logger.LogDebug(string.Format("{0} Loading plugin {1}.", brktname, name));

            if (plugins.ContainsKey(name)) {
                Logger.LogError(string.Format("{0} {1} plugin is already loaded.", brktname, name));
                throw new InvalidOperationException(string.Format("{0} {1} plugin is already loaded.", brktname, name));
            }

            try {
                string text = GetPluginScriptText(name);
                DirectoryInfo dir = new DirectoryInfo(Path.Combine(pluginDirectory.FullName, name));
                Plugin plugin = new Plugin(dir, name, text);
                plugin.InstallHooks();
                plugins[name] = plugin;

                Logger.Log(string.Format("{0} {1} plugin was loaded successfuly.", brktname, name));
            } catch (Exception ex) {
                Logger.LogError(string.Format("{0} {1} plugin could not be loaded.", brktname, name));
                Logger.LogException(ex);
            }
        }
Ejemplo n.º 3
0
        private void LoadPlugin(string name)
        {
            Logger.LogDebug(string.Format("{0} Loading plugin {1}.", brktname, name));

            if (plugins.ContainsKey(name))
            {
                Logger.LogError(string.Format("{0} {1} plugin is already loaded.", brktname, name));
                throw new InvalidOperationException(string.Format("{0} {1} plugin is already loaded.", brktname, name));
            }

            try {
                string        text   = GetPluginScriptText(name);
                string[]      lines  = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                DirectoryInfo dir    = new DirectoryInfo(Path.Combine(pluginDirectory.FullName, name));
                Plugin        plugin = new Plugin(dir, name, text);
                plugin.InstallHooks();
                string cmdname = null;
                bool   b = false, d = false, f = false;
                foreach (string line in lines)
                {
                    if (line.Contains("On_Command"))
                    {
                        string[] spl = line.Split(Convert.ToChar(","));
                        cmdname = spl[1].Trim();
                        b       = true;
                        if (plugin.CommandList.Count == 0)
                        {
                            f = true;
                        }
                        continue;
                    }
                    if (cmdname != null)
                    {
                        if (!b)
                        {
                            break;
                        }
                        if (line.Contains("function"))
                        {
                            b = false;
                            continue;
                        }
                        string n = line.Trim();
                        string l = n.ToLower();
                        if ((n.Contains(cmdname) && n.Contains("==")) || n.Contains("case"))
                        {
                            if (l.Contains("getsetting") || l.Contains("datastore"))
                            {
                                if (!d && f)
                                {
                                    Logger.LogWarning("I detected the usage of custom commands in " + plugin.Name);
                                    Logger.LogWarning("Make sure you add the commands manually to: Plugin.CommandList");
                                    Logger.LogWarning("Example: Plugin.CommandList.Add(ini.GetSetting(...))");
                                    Logger.LogWarning("If you have questions go to www.fougerite.com !");
                                    d = true;
                                }
                                continue;
                            }
                            IEnumerable <string> s  = null;
                            IEnumerable <string> s2 = null;
                            if (n.Contains("'"))
                            {
                                s = getBetween(l, "'", "'");
                            }
                            else if (n.Contains('"'.ToString()))
                            {
                                s2 = getBetween(l, '"'.ToString(), '"'.ToString());
                            }
                            else
                            {
                                if (!d && f)
                                {
                                    Logger.LogWarning("I detected the usage of custom commands in: " + plugin.Name);
                                    Logger.LogWarning("Make sure you add the commands manually to: Plugin.CommandList");
                                    Logger.LogWarning("Example: Plugin.CommandList.Add(ini.GetSetting(...))");
                                    Logger.LogWarning("If you have questions go to www.fougerite.com !");
                                    d = true;
                                }
                                continue;
                            }
                            if (s != null)
                            {
                                foreach (var cmd in s)
                                {
                                    plugin.CommandList.Add(cmd);
                                }
                            }
                            if (s2 != null)
                            {
                                foreach (var cmd in s2)
                                {
                                    plugin.CommandList.Add(cmd);
                                }
                            }
                        }
                    }
                }
                if (d)
                {
                    plugin.CommandList.Clear();
                }
                plugins[name] = plugin;

                Logger.Log(string.Format("{0} {1} plugin was loaded successfuly.", brktname, name));
            } catch (Exception ex) {
                Logger.LogError(string.Format("{0} {1} plugin could not be loaded.", brktname, name));
                Logger.LogException(ex);
            }
        }