/// <inheritdoc />
        public void Register(IDependencyContainer container, IDependencyResolver resolver)
        {
            container.RegisterSingletonType <IHost, EcoHost>(null, "eco", "game");
            container.RegisterSingletonType <IEcoSettingsProvider, EcoSettingsProvider>();

            IEcoSettingsProvider settingsProvider = container.Resolve <IEcoSettingsProvider>();

            settingsProvider.Load();

            container.RegisterSingletonType <ICommandProvider, EcoCommandProvider>("eco_commands");
            container.RegisterSingletonInstance <ICommandProvider>(new EcoNativeCommandProvider(container, settingsProvider), "eco_vanilla_commands");
            container.RegisterSingletonType <IPermissionProvider, EcoPermissionProvider>("eco_vanilla_permissions");
            container.RegisterSingletonType <ITaskScheduler, EcoTaskScheduler>(null, "eco", "game");

            IPlayerManager playerManager = new EcoPlayerManager(container);

            container.RegisterSingletonInstance(playerManager, null, "eco", "game");
            container.RegisterSingletonInstance <IUserManager>(playerManager, "eco", "game");
            container.RegisterSingletonType <IUserManager, StdConsoleUserManager>("stdconsole");

#if DEBUG
            container.RegisterSingletonType <IGovernment, EcoGovernment>(null, "eco", "game");
            container.RegisterSingletonType <IEconomyProvider, EcoEconomyProvider>(null, "eco", "game");
#endif
        }
        public void Register(IDependencyContainer container, IDependencyResolver resolver)
        {
            container.RegisterSingletonType <IPluginManager, JavaScriptScriptingProvider>("javascript_plugins");
            var instance = (JavaScriptScriptingProvider)container.Resolve <IPluginManager>("javascript_plugins");

            container.RegisterSingletonInstance <IScriptingProvider>(instance, "javascript");
        }
Esempio n. 3
0
        public virtual void RegisterCommands(IDependencyContainer pluginContainer, object @object)
        {
            foreach (MethodInfo method in @object.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance))
            {
                CommandAttribute cmdAttr =
                    (CommandAttribute)method.GetCustomAttributes(typeof(CommandAttribute), true).FirstOrDefault();

                if (cmdAttr == null)
                {
                    continue;
                }

                IEnumerable <CommandAliasAttribute> aliasAttrs = method
                                                                 .GetCustomAttributes(typeof(CommandAliasAttribute),
                                                                                      true)
                                                                 .Cast <CommandAliasAttribute>();

                IEnumerable <CommandUserAttribute> supportedTypeAttrs = method
                                                                        .GetCustomAttributes(
                    typeof(CommandUserAttribute), true)
                                                                        .Cast <CommandUserAttribute>();

                CommandAttributeWrapper wrapper = new CommandAttributeWrapper(@object, method, cmdAttr,
                                                                              aliasAttrs.Select(c => c.AliasName).ToArray(),
                                                                              supportedTypeAttrs.Select(c => c.UserType).ToArray());

                pluginContainer.RegisterSingletonInstance <ICommand>(wrapper, wrapper.Name);
            }
        }
Esempio n. 4
0
        public void Register(IDependencyContainer container, IDependencyResolver resolver)
        {
            container.RegisterSingletonType <IPluginManager, CSharpScriptingProvider>("csharp_plugins");
            var instance = (CSharpScriptingProvider)container.Resolve <IPluginManager>("csharp_plugins");

            container.RegisterSingletonInstance <IScriptingProvider>(instance, "csharp");
        }
        public void Register(IDependencyContainer container, IDependencyResolver resolver)
        {
            GameObject obj = new GameObject("Rocket.Rust");

            UnityEngine.Object.DontDestroyOnLoad(obj);

            container.RegisterSingletonInstance <IImplementation>(obj.AddComponent <Rust>());
            container.RegisterType <ILogger, UnityLogger>();
            container.RegisterType <IPlayerManager, RustPlayerManager>();
        }
Esempio n. 6
0
        public void Register(IDependencyContainer container, IDependencyResolver resolver)
        {
            container.RegisterSingletonType <IHost, RocketUnturnedHost>(null, "unturned", "game");
            container.RegisterSingletonType <IPlayerManager, UnturnedPlayerManager>(null, "game", "unturned");
            var mgr = container.Resolve <IPlayerManager>("unturned");

            container.RegisterSingletonInstance <IUserManager>(mgr, null, "game", "unturned");

            container.RegisterSingletonType <ICommandProvider, VanillaCommandProvider>("unturned_commands");
            container.RegisterSingletonType <ICommandProvider, RocketUnturnedCommandProvider>("rocket_unturned_commands");
        }
Esempio n. 7
0
        protected async Task <bool> RegisterAndLoadPluginFromContainer(IDependencyContainer container)
        {
            IPlugin plugin = container.Resolve <IPlugin>();

            Logger.LogDebug($"[{GetType().Name}] Trying to load plugin: " + plugin.Name);

            PluginCommandProvider cmdProvider = new PluginCommandProvider(plugin);

            ParentContainer.RegisterSingletonInstance <ICommandProvider>(cmdProvider, plugin.Name);

            var    asm       = plugin.GetType().Assembly;
            string pluginDir = plugin.WorkingDirectory;

            //if (!Directory.Exists(pluginDir))
            //    Directory.CreateDirectory(pluginDir);

            foreach (string s in asm.GetManifestResourceNames())
            {
                using (Stream stream = asm.GetManifestResourceStream(s))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        if (stream != null)
                        {
                            stream.CopyTo(ms);
                            byte[] data     = ms.ToArray();
                            string fileName = s.Replace(plugin.GetType().Namespace, "");
                            File.WriteAllBytes(Path.Combine(pluginDir, fileName), data);
                        }
                    }
                }
            }

            bool success = await plugin.ActivateAsync(false);

            if (!success)
            {
                return(false);
            }

            IEnumerable <Type> listeners = plugin.FindTypes <IAutoRegisteredEventListener>(false);

            foreach (Type listener in listeners)
            {
                IAutoRegisteredEventListener instance = (IAutoRegisteredEventListener)container.Activate(listener);
                EventBus.AddEventListener(plugin, instance);
            }

            return(true);
        }
Esempio n. 8
0
        public void Register(IDependencyContainer container, IDependencyResolver resolver)
        {
            container.RegisterSingletonType <IHost, RocketUnturnedHost>(null, "unturned", "host");
            container.RegisterSingletonType <IPlayerManager, UnturnedPlayerManager>(null, "host", "unturned");
            var mgr = container.Resolve <IPlayerManager>("unturned");

            container.RegisterSingletonInstance <IUserManager>(mgr, null, "host", "unturned");
            container.RegisterSingletonType <IUserManager, StdConsoleUserManager>("stdconsole");

            container.RegisterSingletonType <ICommandProvider, VanillaCommandProvider>("unturned_commands");
            container.RegisterSingletonType <ICommandProvider, RocketUnturnedCommandProvider>("rocket_unturned_commands");

            container.RegisterSingletonType <IPermissionChecker, UnturnedAdminPermissionChecker>("unturned_admins");
        }
Esempio n. 9
0
        public virtual void Init()
        {
            Logger.LogDebug($"[{GetType().Name}] Initializing plugins.");

            assemblies = LoadAssemblies();

            IRuntime runtime = Container.Resolve <IRuntime>();

            PluginManagerInitEvent pluginManagerInitEvent =
                new PluginManagerInitEvent(this, EventExecutionTargetContext.Sync);

            EventManager.Emit(runtime, pluginManagerInitEvent);

            if (pluginManagerInitEvent.IsCancelled)
            {
                Logger.LogDebug($"[{GetType().Name}] Loading of plugins was canacelled.");
                return;
            }


            List <IDependencyContainer> pluginContainers = new List <IDependencyContainer>();

            foreach (Assembly assembly in assemblies)
            {
                try
                {
                    Logger.LogDebug($"[{GetType().Name}] Loading from assembly: " + assembly.GetName().Name);
                    LoadPluginFromAssembly(assembly, out IDependencyContainer container);

                    if (container != null)
                    {
                        pluginContainers.Add(container);
                        Logger.LogDebug($"[{GetType().Name}] Plugin found in: " + assembly.GetName().Name);
                    }
                    else
                    {
                        Logger.LogDebug($"[{GetType().Name}] No plugins found in: " + assembly.GetName().Name);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError($"[{GetType().Name}] Failed to load from assembly: " + assembly.GetName().Name, ex);
                }
            }

            foreach (IDependencyContainer childContainer in pluginContainers)
            {
                IPlugin plugin = childContainer.Resolve <IPlugin>();
                Logger.LogDebug($"[{GetType().Name}] Trying to load plugin: " + plugin.Name);

                PluginCommandProvider cmdProvider = new PluginCommandProvider(plugin, childContainer);
                ParentContainer.RegisterSingletonInstance <ICommandProvider>(cmdProvider, plugin.Name);

                Assembly asm       = plugin.GetType().Assembly;
                string   pluginDir = plugin.WorkingDirectory;
                if (!Directory.Exists(pluginDir))
                {
                    Directory.CreateDirectory(pluginDir);
                }

                foreach (string s in asm.GetManifestResourceNames())
                {
                    using (Stream stream = asm.GetManifestResourceStream(s))
                    {
                        using (MemoryStream ms = new MemoryStream())
                        {
                            if (stream == null)
                            {
                                return;
                            }

                            stream.CopyTo(ms);
                            byte[] data     = ms.ToArray();
                            string fileName = s.Replace(plugin.GetType().Namespace, "");
                            File.WriteAllBytes(Path.Combine(pluginDir, fileName), data);
                        }
                    }
                }

                plugin.Load(false);

                IEnumerable <Type> listeners = plugin.FindTypes <IAutoRegisteredEventListener>(false);
                foreach (Type listener in listeners)
                {
                    IAutoRegisteredEventListener instance = (IAutoRegisteredEventListener)childContainer.Activate(listener);
                    EventManager.AddEventListener(plugin, instance);
                }
            }
        }
Esempio n. 10
0
        protected virtual IPlugin LoadPluginFromAssembly(Assembly pluginAssembly, out IDependencyContainer childContainer)
        {
            childContainer = null;

            string loc = GetAssemblyLocationSafe(pluginAssembly);

            if (!string.IsNullOrEmpty(loc) &&
                !cachedAssemblies.ContainsKey(loc))
            {
                cachedAssemblies.Add(loc, pluginAssembly);
            }

            Type[] types;
            try
            {
                types = pluginAssembly.GetTypes();
            }
            catch (ReflectionTypeLoadException e)
            {
                types = e.Types;
            }

            Type pluginType = null;

            foreach (Type type in types.Where(t => t != null))
            {
                if (type.IsAbstract || type.IsInterface)
                {
                    continue;
                }

                if (type.GetCustomAttributes(typeof(DontAutoRegisterAttribute), true).Any())
                {
                    continue;
                }

                if (pluginType == null && typeof(IPlugin) != type && typeof(IPlugin).IsAssignableFrom(type))
                {
                    pluginType = type;
                }
            }

            if (pluginType == null)
            {
                return(null);
            }

            childContainer = Container.CreateChildContainer();
            childContainer.RegisterInstance <IPluginManager>(this);

            IPlugin pluginInstance = (IPlugin)childContainer.Activate(pluginType);

            if (pluginInstance == null)
            {
                throw new Exception("Failed to activate: " + pluginType.FullName + ". Is your plugin constructor public?");
            }

            Container.RegisterInstance(pluginInstance, pluginInstance.Name);

            childContainer.RegisterInstance(pluginInstance);

            IEnumerable <Type> pluginCommands =
                pluginInstance.FindTypes <ICommand>(false, c => !typeof(IChildCommand).IsAssignableFrom(c) &&
                                                    c.GetCustomAttributes(typeof(DontAutoRegisterAttribute), true).Length == 0);
            IEnumerable <Type> dependencyRegistrators = pluginInstance.FindTypes <IDependencyRegistrator>(false);

            foreach (Type registrator in dependencyRegistrators)
            {
                ((IDependencyRegistrator)Activator.CreateInstance(registrator)).Register(Container, Container);
            }

            foreach (Type command in pluginCommands)
            {
                try
                {
                    ICommand cmdInstance = (ICommand)childContainer.Activate(command);
                    if (cmdInstance != null)
                    {
                        childContainer.RegisterSingletonInstance(cmdInstance, cmdInstance.Name);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogError(null, ex);
                }
            }

            return(pluginInstance);
        }
Esempio n. 11
0
 public void Register(IDependencyContainer container, IDependencyResolver resolver)
 {
     container.RegisterSingletonType <IPermissionProvider, RconRootPermissionProvider>("rcon");
     container.RegisterSingletonType <IUserManager, RconServer>("rcon");
     container.RegisterSingletonInstance <ILogger>(new RconLogger(container), "rcon");
 }