Пример #1
0
 public LuaPlugin(string name, string code, DirectoryInfo path)
 {
     //MoonSharp.Interpreter.Script.DefaultOptions.ScriptLoader = new MoonSharp.Interpreter.Loaders.EmbeddedResourcesScriptLoader();
     Globals        = new List <string>();
     Timers         = new Dictionary <string, MoonSharpTE>();
     ParallelTimers = new List <MoonSharpTE>();
     Name           = name;
     Code           = code;
     RootDir        = path;
     UserData.RegistrationPolicy = InteropRegistrationPolicy.Automatic;
     script = new Script();
     script.DoString(code);
     script.Globals.Set("Util", UserData.Create(Fougerite.Util.GetUtil()));
     script.Globals.Set("Plugin", UserData.Create(this));
     script.Globals.Set("Server", UserData.Create(Fougerite.Server.GetServer()));
     script.Globals.Set("DataStore", UserData.Create(Fougerite.DataStore.GetInstance()));
     script.Globals.Set("Data", UserData.Create(Fougerite.Data.GetData()));
     script.Globals.Set("Web", UserData.Create(new Fougerite.Web()));
     script.Globals.Set("World", UserData.Create(Fougerite.World.GetWorld()));
     script.Globals.Set("PluginCollector", UserData.Create(GlobalPluginCollector.GetPluginCollector()));
     script.Globals.Set("Loom", UserData.Create(Loom.Current));
     script.Globals.Set("JSON", UserData.Create(JsonAPI.GetInstance));
     script.Globals.Set("MySQL", UserData.Create(MySQLConnector.GetInstance));
     script.Globals.Set("SQLite", UserData.Create(Fougerite.SQLiteConnector.GetInstance));
     foreach (DynValue v in script.Globals.Keys)
     {
         Globals.Add(v.ToString().Replace('"'.ToString(), ""));
     }
     Author  = string.IsNullOrEmpty(script.Globals.Get("Author").String) ? "Unknown" : script.Globals.Get("Author").String;
     Version = string.IsNullOrEmpty(script.Globals.Get("Version").String) ? "1.0" : script.Globals.Get("Version").String;
     About   = script.Globals.Get("About").String;
     Tables  = script.Globals;
 }
Пример #2
0
        public void LoadPlugin(string name)
        {
            Logger.LogDebug("[MoonSharp] Loading plugin " + name + ".");

            if (plugins.ContainsKey(name))
            {
                Logger.LogError("[MoonSharp] " + name + " plugin is already loaded.");
                throw new InvalidOperationException("[MoonSharp] " + name + " plugin is already loaded.");
            }

            try
            {
                string        code   = GetPluginScriptText(name);
                DirectoryInfo path   = new DirectoryInfo(Path.Combine(pluginDirectory.FullName, name));
                LuaPlugin     plugin = new LuaPlugin(name, code, path);
                InstallHooks(plugin);
                plugins.Add(name, plugin);
                GlobalPluginCollector.GetPluginCollector().AddPlugin(name, plugin, "Lua");
                Logger.Log("[MoonSharp] " + name + " plugin by " + plugin.Author + " V" + plugin.Version + " was loaded successfully.");
                if (!string.IsNullOrEmpty(plugin.About))
                {
                    Logger.Log("[MoonSharp] Description: " + plugin.About);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("[MoonSharp] " + name + " couldn't be loaded.");
                Logger.LogException(ex);
            }
        }
Пример #3
0
        public override void Load(string code = "")
        {
            try
            {
                Engine = new JintEngine(Options.Ecmascript5)
                         .AllowClr(true);

                Engine.SetParameter("Plugin", this)
                .SetParameter("Server", Fougerite.Server.GetServer())
                .SetParameter("DataStore", DataStore.GetInstance())
                .SetParameter("Data", Data.GetData())
                .SetParameter("Web", new Fougerite.Web())
                .SetParameter("Util", Util.GetUtil())
                .SetParameter("World", World.GetWorld())
                    #pragma warning disable 618
                .SetParameter("PluginCollector", GlobalPluginCollector.GetPluginCollector())
                    #pragma warning restore 618
                .SetParameter("Loom", Fougerite.Loom.Current)
                .SetParameter("JSON", Fougerite.JsonAPI.GetInstance)
                .SetParameter("MySQL", Fougerite.MySQLConnector.GetInstance)
                .SetParameter("SQLite", Fougerite.SQLiteConnector.GetInstance)
                .SetFunction("importClass", new importit(importClass));
                Program = JintEngine.Compile(code, false);

                Globals = (from statement in Program.Statements
                           where statement.GetType() == typeof(FunctionDeclarationStatement)
                           select((FunctionDeclarationStatement)statement).Name).ToList <string>();

                Engine.Run(Program);

                object author  = GetGlobalObject("Author");
                object about   = GetGlobalObject("About");
                object version = GetGlobalObject("Version");
                Author  = author == null || (string)author == "undefined" ? "Unknown" : author.ToString();
                About   = about == null || (string)about == "undefined" ? "" : about.ToString();
                Version = version == null || (string)version == "undefined" ? "1.0" : version.ToString();

                State = PluginState.Loaded;
            }
            catch (Exception ex)
            {
                Logger.LogError("[Error] Failed to load lua plugin: " + ex);
                State = PluginState.FailedToLoad;
                PluginLoader.GetInstance().CurrentlyLoadingPlugins.Remove(Name);
            }

            PluginLoader.GetInstance().OnPluginLoaded(this);
        }
Пример #4
0
 public void InitGlobals()
 {
     Engine.SetParameter("Server", Fougerite.Server.GetServer());
     Engine.SetParameter("Data", MagmaModule.Data.GetData());
     Engine.SetParameter("DataStore", Fougerite.DataStore.GetInstance());
     Engine.SetParameter("Util", Fougerite.Util.GetUtil());
     Engine.SetParameter("Web", new Fougerite.Web());
     Engine.SetParameter("Time", this);
     Engine.SetParameter("World", Fougerite.World.GetWorld());
     Engine.SetParameter("Plugin", this);
     Engine.SetParameter("PluginCollector", GlobalPluginCollector.GetPluginCollector());
     Engine.SetParameter("Loom", Loom.Current);
     Engine.SetParameter("JSON", JsonAPI.GetInstance);
     Engine.SetParameter("MySQL", MySQLConnector.GetInstance);
     Engine.SetParameter("SQLite", SQLiteConnector.GetInstance);
 }
Пример #5
0
        public override void Load(string code = "")
        {
            Engine = IronPython.Hosting.Python.CreateEngine();
            Engine.SetSearchPaths(new string[] { ManagedFolder, LibPath });
            Engine.GetBuiltinModule().RemoveVariable("exit");
            Engine.GetBuiltinModule().RemoveVariable("reload");
            Scope = Engine.CreateScope();
            Scope.SetVariable("Plugin", this);
            Scope.SetVariable("Server", Fougerite.Server.GetServer());
            Scope.SetVariable("DataStore", DataStore.GetInstance());
            Scope.SetVariable("Data", Data.GetData());
            Scope.SetVariable("Web", new Fougerite.Web());
            Scope.SetVariable("Util", Util.GetUtil());
            Scope.SetVariable("World", World.GetWorld());
            #pragma warning disable 618
            Scope.SetVariable("PluginCollector", GlobalPluginCollector.GetPluginCollector());
            #pragma warning restore 618
            Scope.SetVariable("Loom", Fougerite.Loom.Current);
            Scope.SetVariable("JSON", Fougerite.JsonAPI.GetInstance);
            Scope.SetVariable("MySQL", Fougerite.MySQLConnector.GetInstance);
            Scope.SetVariable("SQLite", Fougerite.SQLiteConnector.GetInstance);

            try
            {
                Engine.Execute(code, Scope);
                Class   = Engine.Operations.Invoke(Scope.GetVariable(Name));
                Globals = Engine.Operations.GetMemberNames(Class);

                object author  = GetGlobalObject("__author__");
                object about   = GetGlobalObject("__about__");
                object version = GetGlobalObject("__version__");
                Author  = author == null ? "" : author.ToString();
                About   = about == null ? "" : about.ToString();
                Version = version == null ? "" : version.ToString();

                State = PluginState.Loaded;
            }
            catch (Exception ex)
            {
                Logger.LogError("[Error] Failed to load Python plugin: " + ex);
                State = PluginState.FailedToLoad;
            }

            PluginLoader.GetInstance().OnPluginLoaded(this);
        }
Пример #6
0
        public override void Load(string code = "")
        {
            try
            {
                UserData.RegistrationPolicy = InteropRegistrationPolicy.Automatic;
                script = new Script();
                script.DoString(code);
                script.Globals.Set("Util", UserData.Create(Fougerite.Util.GetUtil()));
                script.Globals.Set("Plugin", UserData.Create(this));
                script.Globals.Set("Server", UserData.Create(Fougerite.Server.GetServer()));
                script.Globals.Set("DataStore", UserData.Create(Fougerite.DataStore.GetInstance()));
                script.Globals.Set("Data", UserData.Create(Fougerite.Data.GetData()));
                script.Globals.Set("Web", UserData.Create(new Fougerite.Web()));
                script.Globals.Set("World", UserData.Create(Fougerite.World.GetWorld()));
                #pragma warning disable 618
                script.Globals.Set("PluginCollector", UserData.Create(GlobalPluginCollector.GetPluginCollector()));
                #pragma warning restore 618
                script.Globals.Set("Loom", UserData.Create(Loom.Current));
                script.Globals.Set("JSON", UserData.Create(JsonAPI.GetInstance));
                script.Globals.Set("MySQL", UserData.Create(MySQLConnector.GetInstance));
                script.Globals.Set("SQLite", UserData.Create(Fougerite.SQLiteConnector.GetInstance));
                foreach (DynValue v in script.Globals.Keys)
                {
                    Globals.Add(v.ToString().Replace("\"", ""));
                }
                Author  = string.IsNullOrEmpty(script.Globals.Get("Author").String) ? "Unknown" : script.Globals.Get("Author").String;
                Version = string.IsNullOrEmpty(script.Globals.Get("Version").String) ? "1.0" : script.Globals.Get("Version").String;
                About   = script.Globals.Get("About").String;

                State  = PluginState.Loaded;
                Tables = script.Globals;
            }
            catch (Exception ex)
            {
                Logger.LogError("[Error] Failed to load Lua plugin: " + ex);
                State = PluginState.FailedToLoad;
            }

            PluginLoader.GetInstance().OnPluginLoaded(this);
        }
Пример #7
0
        public JintPlugin(DirectoryInfo directory, string name, string code)
        {
            Name           = name;
            Code           = code;
            RootDirectory  = directory;
            FunctionNames  = new List <string>();
            CommandList    = new List <string>();
            Timers         = new Dictionary <string, TimedEvent>();
            AdvancedTimers = new AdvancedTimer(this);

            Engine = new Engine(cfg => cfg.AllowClr(typeof(UnityEngine.GameObject).Assembly,
                                                    typeof(uLink.NetworkPlayer).Assembly,
                                                    typeof(PlayerInventory).Assembly))
                     .SetValue("Server", Server.GetServer())
                     .SetValue("DataStore", DataStore.GetInstance())
                     .SetValue("Util", Util.GetUtil())
                     .SetValue("World", World.GetWorld())
                     .SetValue("Web", new Web())
                     .SetValue("Plugin", this)
                     .SetValue("Data", Data.GetData())
                     .SetValue("PluginCollector", GlobalPluginCollector.GetPluginCollector())
                     .SetValue("Loom", Loom.Current)
                     .SetValue("JSON", JsonAPI.GetInstance)
                     .SetValue("MySQL", MySQLConnector.GetInstance)
                     .SetValue("SQLite", SQLiteConnector.GetInstance)
                     .Execute(code);

            object author  = GetGlobalObject("Author");
            object about   = GetGlobalObject("About");
            object version = GetGlobalObject("Version");

            Author  = author == null || author == "undefined" ? "Unknown" : author.ToString();
            About   = about == null || about == "undefined" ? "" : about.ToString();
            Version = version == null || version == "undefined" ? "1.0" : version.ToString();
            Logger.LogDebug(string.Format("{0} AllowClr for Assemblies: {1} {2} {3}", brktname,
                                          typeof(UnityEngine.GameObject).Assembly.GetName().Name,
                                          typeof(uLink.NetworkPlayer).Assembly.GetName().Name,
                                          typeof(PlayerInventory).Assembly.GetName().Name));
        }
Пример #8
0
        public void UnloadPlugin(string name, bool removeFromDict = true)
        {
            Logger.LogDebug("[IPModule] Unloading " + name + " plugin.");

            if (plugins.ContainsKey(name))
            {
                IPPlugin plugin = plugins[name];
                plugin.OnPluginShutdown();
                plugin.KillTimers();
                RemoveHooks(plugin);
                if (removeFromDict)
                {
                    plugins.Remove(name);
                }
                GlobalPluginCollector.GetPluginCollector().RemovePlugin(name);
                Logger.Log("[IPModule] " + name + " plugin was unloaded successfully.");
            }
            else
            {
                Logger.LogError("[IPModule] Can't unload " + name + ". Plugin is not loaded.");
                //throw new InvalidOperationException("[IPModule] Can't unload " + name + ". Plugin is not loaded.");
            }
        }
Пример #9
0
        public IPPlugin(string name, string code, DirectoryInfo path)
        {
            Name           = name;
            Code           = code;
            RootDir        = path;
            Timers         = new Dictionary <string, IPTimedEvent>();
            CommandList    = new List <string>();
            ParallelTimers = new List <IPTimedEvent>();
            Engine         = IronPython.Hosting.Python.CreateEngine();
            Engine.SetSearchPaths(new string[] { ManagedFolder, LibPath });
            Engine.GetBuiltinModule().RemoveVariable("exit");
            Engine.GetBuiltinModule().RemoveVariable("reload");
            Scope = Engine.CreateScope();
            Scope.SetVariable("Plugin", this);
            Scope.SetVariable("Server", Fougerite.Server.GetServer());
            Scope.SetVariable("DataStore", DataStore.GetInstance());
            Scope.SetVariable("Data", Data.GetData());
            Scope.SetVariable("Web", new Fougerite.Web());
            Scope.SetVariable("Util", Util.GetUtil());
            Scope.SetVariable("World", World.GetWorld());
            Scope.SetVariable("PluginCollector", GlobalPluginCollector.GetPluginCollector());
            Scope.SetVariable("Loom", Fougerite.Loom.Current);
            Scope.SetVariable("JSON", Fougerite.JsonAPI.GetInstance);
            Scope.SetVariable("MySQL", Fougerite.MySQLConnector.GetInstance);
            Scope.SetVariable("SQLite", Fougerite.SQLiteConnector.GetInstance);
            Engine.Execute(code, Scope);
            Class   = Engine.Operations.Invoke(Scope.GetVariable(name));
            Globals = Engine.Operations.GetMemberNames(Class);
            object ath = GetGlobalObject("__author__");
            object abt = GetGlobalObject("__about__");
            object vr  = GetGlobalObject("__version__");

            Author  = ath == null ? "Unknown" : ath.ToString();
            About   = abt == null ? "" : abt.ToString();
            Version = vr == null ? "1.0" : vr.ToString();
        }
Пример #10
0
        public void UnloadPlugin(string name, bool removeFromDict = true)
        {
            Logger.LogDebug(string.Format("{0} Unloading {1}  plugin.", brktname, name));

            if (plugins.ContainsKey(name))
            {
                var plugin = plugins[name];
                plugin.OnPluginShutdown();
                plugin.RemoveHooks();
                plugin.KillTimers();
                plugin.AdvancedTimers.KillTimers();
                if (removeFromDict)
                {
                    plugins.Remove(name);
                }
                GlobalPluginCollector.GetPluginCollector().RemovePlugin(name);
                Logger.Log(string.Format("{0} {1} plugin was unloaded successfully.", brktname, name));
            }
            else
            {
                Logger.LogError(string.Format("{0} Can't unload {1}. Plugin is not loaded.", brktname, name));
                throw new InvalidOperationException(string.Format("{0} Can't unload {1}. Plugin is not loaded.", brktname, name));
            }
        }
Пример #11
0
        public void LoadPlugin(string name)
        {
            Logger.LogDebug("[IPModule] Loading plugin " + name + ".");

            if (plugins.ContainsKey(name))
            {
                Logger.LogError("[IPModule] " + name + " plugin is already loaded.");
                return;
                //throw new InvalidOperationException("[IPModule] " + name + " plugin is already loaded.");
            }

            try
            {
                string        code   = GetPluginScriptText(name);
                string[]      lines  = code.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                DirectoryInfo path   = new DirectoryInfo(Path.Combine(pluginDirectory.FullName, name));
                IPPlugin      plugin = new IPPlugin(name, code, path);
                InstallHooks(plugin);
                string cmdname = null;
                bool   d = false, f = false;
                foreach (string line in lines)
                {
                    if (line.Contains("On_Command"))
                    {
                        string[] spl = line.Split(Convert.ToChar(","));
                        cmdname = spl[2].Trim();
                        if (plugin.CommandList.Count == 0)
                        {
                            f = true;
                        }
                        continue;
                    }
                    if (cmdname != null)
                    {
                        string n = line.Trim();
                        string l = n.ToLower();
                        if (n.Contains(cmdname) && n.Contains("=="))
                        {
                            if ((l.Contains("getsetting") || l.Contains("datastore")) && !d)
                            {
                                if (!d && f)
                                {
                                    Logger.LogDebug("I detected the usage of custom commands in: " + plugin.Name);
                                    Logger.LogDebug("Make sure you add the commands manually to: Plugin.CommandList");
                                    Logger.LogDebug("Example: Plugin.CommandList.Add(ini.GetSetting(...))");
                                    Logger.LogDebug("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.LogDebug("I detected the usage of custom commands in " + plugin.Name);
                                    Logger.LogDebug("Make sure you add the commands manually to: Plugin.CommandList");
                                    Logger.LogDebug("Example: Plugin.CommandList.Add(ini.GetSetting(...))");
                                    Logger.LogDebug("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.Add(name, plugin);
                GlobalPluginCollector.GetPluginCollector().AddPlugin(name, plugin, "Python");

                Logger.Log("[IPModule] " + name + " plugin by " + plugin.Author + " V" + plugin.Version + " was loaded successfully.");
                if (!string.IsNullOrEmpty(plugin.About))
                {
                    Logger.Log("[IPModule] Description: " + plugin.About);
                }
            } catch (Exception ex) {
                Logger.LogError("[IPModule] " + name + " plugin could not be loaded.");
                Logger.LogException(ex);
            }
        }
Пример #12
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));
                return;
                //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));
                JintPlugin    plugin = new JintPlugin(dir, name, text);
                plugin.InstallHooks();
                plugin.Invoke("On_PluginInit");
                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.LogDebug("I detected the usage of custom commands in " + plugin.Name);
                                    Logger.LogDebug("Make sure you add the commands manually to: Plugin.CommandList");
                                    Logger.LogDebug("Example: Plugin.CommandList.Add(ini.GetSetting(...))");
                                    Logger.LogDebug("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.LogDebug("I detected the usage of custom commands in: " + plugin.Name);
                                    Logger.LogDebug("Make sure you add the commands manually to: Plugin.CommandList");
                                    Logger.LogDebug("Example: Plugin.CommandList.Add(ini.GetSetting(...))");
                                    Logger.LogDebug("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;
                GlobalPluginCollector.GetPluginCollector().AddPlugin(name, plugin, "JavaScript2");
                Logger.Log(string.Format("{0} {1} plugin by {2} V{3} was loaded successfully.", brktname, name, plugin.Author, plugin.Version));
                if (!string.IsNullOrEmpty(plugin.About) && plugin.About != "undefined")
                {
                    Logger.LogError(string.Format("{0} Description: {1}", brktname, plugin.About));
                }
            } catch (Exception ex) {
                Logger.LogError(string.Format("{0} {1} plugin could not be loaded.", brktname, name));
                Logger.LogException(ex);
            }
        }