public async Task InitAsync(IRuntime runtime) { InstallTlsWorkaround(); BaseLogger.SkipTypeFromLogging(typeof(UnturnedPlayerManager)); this.runtime = runtime; rocketGameObject = new GameObject(); Object.DontDestroyOnLoad(rocketGameObject); container = runtime.Container; eventManager = container.Resolve <IEventBus>(); playerManager = (UnturnedPlayerManager)container.Resolve <IUserManager>("host"); ModuleTranslations = container.Resolve <ITranslationCollection>(); logger = container.Resolve <ILogger>(); logger.LogInformation("Loading Rocket Unturned Implementation..."); container.AddSingleton <AutomaticSaveWatchdog, AutomaticSaveWatchdog>(); container.Resolve <AutomaticSaveWatchdog>().Start(); await LoadTranslations(); Provider.onServerHosted += OnServerHosted; if (Environment.OSVersion.Platform == PlatformID.Unix || Environment.OSVersion.Platform == PlatformID.MacOSX) { rocketGameObject.SetActive(false); // deactivate object so it doesn't run Awake until all properties were set var console = rocketGameObject.AddComponent <UnturnedConsolePipe>(); console.Logger = logger; rocketGameObject.SetActive(true); // reactivate object } SteamChannel.onTriggerSend += TriggerSend; Provider.onCheckValid += OnCheckValid; Provider.onServerConnected += OnPlayerConnected; Provider.onServerDisconnected += OnPlayerDisconnected; DamageTool.playerDamaged += OnPlayerDamaged; Provider.onServerShutdown += OnServerShutdown; ChatManager.onChatted += (SteamPlayer player, EChatMode mode, ref Color color, ref bool isRich, string message, ref bool isVisible) => { UnturnedPlayer p = (UnturnedPlayer)playerManager.GetPlayerByIdAsync(player.playerID.steamID.m_SteamID.ToString()).GetAwaiter().GetResult(); UnturnedPlayerChatEvent @event = new UnturnedPlayerChatEvent(p, mode, color, isRich, message, !isVisible); eventManager.Emit(this, @event); color = @event.Color; isRich = @event.IsRichText; isVisible = [email protected]; }; CommandWindow.onCommandWindowOutputted += (text, color) => logger.LogNative(text?.ToString()); }
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.AddSingleton <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); }
public void ConfigureServices(IDependencyContainer container) { container.AddSingleton <IHost, RocketUnturnedHost>(null, "unturned", "host"); container.AddSingleton <IPlayerManager, UnturnedPlayerManager>(null, "host", "unturned"); var mgr = container.Resolve <IPlayerManager>("unturned"); container.AddSingleton <IUserManager>(mgr, null, "host", "unturned"); container.AddSingleton <IUserManager, StdConsoleUserManager>("stdconsole"); container.AddSingleton <ICommandProvider, VanillaCommandProvider>("unturned_commands"); container.AddSingleton <ICommandProvider, RocketUnturnedCommandProvider>("rocket_unturned_commands"); container.AddSingleton <IPermissionChecker, UnturnedAdminPermissionChecker>("unturned_admins"); }
public void ConfigureServices(IDependencyContainer container) { container.AddSingleton <IHost, TestHost>(); container.AddSingleton <IPlayerManager, TestPlayerManager>(); }
public void ConfigureServices(IDependencyContainer container) { container.AddSingleton <IHost, ConsoleHost>(); container.AddSingleton <IUserManager, StdConsoleUserManager>("host", "stdconsole"); }
public void ConfigureServices(IDependencyContainer container) { container.AddSingleton <ITaskScheduler, DefaultTaskScheduler>(); container.AddTransient <IConfiguration, YamlConfiguration>("yaml", null); container.AddTransient <IConfiguration, JsonConfiguration>("json"); container.AddTransient <IConfiguration, XmlConfiguration>("xml"); container.AddSingleton <IRocketConfigurationProvider, RocketConfigurationProvider>(); container.AddSingleton <ILogger, ConsoleLogger>("console_logger"); container.AddSingleton <ILogger, LoggerProxy>("proxy_logger", null); container.AddSingleton <IEventBus, EventBus>(); container.AddSingleton <ICommandHandler, DefaultCommandHandler>("default_cmdhandler"); container.AddSingleton <ICommandHandler, CommandHandlerProxy>("proxy_cmdhandler", null); container.AddSingleton <IPluginLoader, DefaultClrPluginLoader>("dll_plugins"); container.AddSingleton <IPluginLoader, NuGetPluginLoader>("nuget_plugins"); container.AddSingleton <IPluginLoader, PluginLoaderProxy>("proxy_plugins", null); container.AddSingleton <ICommandProvider, RocketCommandProvider>("rocket_cmdprovider"); container.AddSingleton <ICommandProvider, CommandProviderProxy>("proxy_cmdprovider", null); var configPermissions = container.Activate <ConfigurationPermissionProvider>(); container.AddTransient <IPermissionProvider>(configPermissions, "default_permissions", null); container.AddTransient <IPermissionChecker>(configPermissions, "default_permissions"); container.AddSingleton <IPermissionChecker, ConsolePermissionChecker>("console_checker"); container.AddSingleton <IPermissionChecker, PermissionProviderProxy>("proxy_checker", null); container.AddTransient <ITranslationCollection, TranslationCollection>(); container.AddSingleton <IUserManager, UserManagerProxy>(); }
protected virtual IPlugin LoadPluginFromAssembly(Assembly pluginAssembly, out IDependencyContainer pluginContainer) { pluginContainer = 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); } pluginContainer = Container.CreateChildContainer(); pluginContainer.AddTransient <IPluginLoader>(this); IPlugin pluginInstance = (IPlugin)pluginContainer.Activate(pluginType); if (pluginInstance == null) { throw new Exception("Failed to activate: " + pluginType.FullName + ". Is your plugin constructor public?"); } Container.AddTransient(pluginInstance, pluginInstance.Name); pluginContainer.AddTransient(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 <IServiceConfigurator>(false); foreach (Type registrator in dependencyRegistrators) { ((IServiceConfigurator)Activator.CreateInstance(registrator)).ConfigureServices(Container); } foreach (Type command in pluginCommands) { try { ICommand cmdInstance = (ICommand)pluginContainer.Activate(command); if (cmdInstance != null) { pluginContainer.AddSingleton(cmdInstance, cmdInstance.Name); } } catch (Exception ex) { Logger.LogError(null, ex); } } return(pluginInstance); }