Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AdminPanel" /> class.
        /// </summary>
        /// <param name="port">The port.</param>
        /// <param name="servers">All manageable servers, including game servers, connect servers etc.</param>
        /// <param name="persistenceContextProvider">The persistence context provider.</param>
        /// <param name="changeListener">The change listener.</param>
        /// <param name="loggingConfigurationPath">The logging configuration file path.</param>
        public AdminPanel(ushort port, IList <IManageableServer> servers, IPersistenceContextProvider persistenceContextProvider, IServerConfigurationChangeListener changeListener, string loggingConfigurationPath)
        {
            Configuration.Default.MemoryAllocator = ArrayPoolMemoryAllocator.CreateWithMinimalPooling();

            // you might need to allow it first with netsh:
            // netsh http add urlacl http://+:1234/ user=[Username]
            var host = Host.CreateDefaultBuilder()
                       .ConfigureLogging(configureLogging =>
            {
                configureLogging.ClearProviders();
                var settings = new Log4NetSettings {
                    ConfigFile = loggingConfigurationPath, Watch = true
                };

                configureLogging.AddLog4Net(settings);
            })
                       .ConfigureServices(serviceCollection =>
            {
                serviceCollection.AddSingleton(servers);
                serviceCollection.AddSingleton(persistenceContextProvider);
                serviceCollection.AddSingleton(changeListener);
            })
                       .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup <Startup>();
                webBuilder.UseStaticWebAssets();

                // For testing purposes, we use http. Later we need to switch to https.
                // The self-signed certificate would otherwise cause a lot of warnings in the browser.
                webBuilder.UseUrls($"http://*:{port}");
            })
                       .Build();

            host.Start();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AdminPanel" /> class.
        /// </summary>
        /// <param name="port">The port.</param>
        /// <param name="servers">All manageable servers, including game servers, connect servers etc.</param>
        /// <param name="persistenceContextProvider">The persistence context provider.</param>
        /// <param name="changeListener">The change listener.</param>
        /// <param name="loggingConfigurationPath">The logging configuration file path.</param>
        public AdminPanel(ushort port, IList <IManageableServer> servers, IPersistenceContextProvider persistenceContextProvider, IServerConfigurationChangeListener changeListener, string loggingConfigurationPath)
        {
            // you might need to allow it first with netsh:
            // netsh http add urlacl http://+:1234/ user=[Username]
            var host = WebHost.CreateDefaultBuilder()
                       .ConfigureLogging(configureLogging =>
            {
                configureLogging.ClearProviders();
                var settings = new Log4NetSettings {
                    ConfigFile = loggingConfigurationPath, Watch = true
                };

                configureLogging.AddLog4Net(settings);
            })
                       .ConfigureServices(serviceCollection =>
            {
                serviceCollection.AddSingleton(servers);
                serviceCollection.AddSingleton(persistenceContextProvider);
                serviceCollection.AddSingleton(changeListener);
            })
                       .UseKestrel(options =>
            {
                // Default port
                options.ListenAnyIP(port);
            })
                       .UseStartup <Startup>()
                       .Build();

            host.Start();
            SignalRGameServerStateObserver.Services = host.Services;
            SignalRMapStateObserver.Services        = host.Services;
        }
        /// <summary>
        /// Adds log4net support using the settings defined in the passed in <see cref="IConfiguration"/> section
        /// </summary>
        /// <param name="self">The logger factory to update for log4net support</param>
        /// <param name="configuration">The settings to use for configuring log4net.
        /// These settings are defined in <see cref="Log4NetSettings"/></param>
        /// <returns>The passed in logger factory</returns>
        public static ILoggerFactory AddLog4Net(this ILoggerFactory self, IConfiguration configuration)
        {
            var settings = new Log4NetSettings();

            configuration.Bind(settings);
            return(AddLog4Net(self, settings));
        }
Esempio n. 4
0
        /// <summary>
        /// Runs the host.
        /// </summary>
        /// <param name="gameServers">The game servers.</param>
        /// <param name="connectServers">The connect servers.</param>
        /// <param name="loggingConfigurationPath">The path to the logging configuration.</param>
        /// <returns>The async task.</returns>
        public static Task RunAsync(ICollection <IGameServer> gameServers, IEnumerable <IConnectServer> connectServers, string?loggingConfigurationPath)
        {
            var builder = Host.CreateDefaultBuilder();

            if (!string.IsNullOrEmpty(loggingConfigurationPath))
            {
                builder = builder.ConfigureLogging(configureLogging =>
                {
                    configureLogging.ClearProviders();
                    var settings = new Log4NetSettings {
                        ConfigFile = loggingConfigurationPath, Watch = true
                    };

                    configureLogging.AddLog4Net(settings);
                });
            }

            return(builder
                   .ConfigureServices(s =>
            {
                s.Add(new ServiceDescriptor(typeof(ICollection <IGameServer>), gameServers));
                s.Add(new ServiceDescriptor(typeof(IEnumerable <IConnectServer>), connectServers));
            })
                   .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder
                .UseStartup <Startup>()
                .UseUrls("http://*:80", "https://*:443");
            })
                   .Build()
                   .RunAsync());
        }
Esempio n. 5
0
        public void InitializingTwoProvidersDoesNotThrow()
        {
            var settings  = new Log4NetSettings();
            var providerA = new Log4NetProvider();
            var providerB = new Log4NetProvider();

            providerA.Initialize(settings);
            providerB.Initialize(settings);
        }
        /// <summary>
        /// Adds log4net support using the provided <see cref="Log4NetSettings"/>
        /// </summary>
        /// <param name="self">The logger factory to update for log4net support</param>
        /// <param name="settings">The settings to use for configuring log4net.</param>
        /// <returns>The passed in logger factory</returns>
        public static ILoggerFactory AddLog4Net(this ILoggerFactory self, Log4NetSettings settings)
        {
            var provider = new Log4NetProvider();

            provider.Initialize(settings);

            self.AddProvider(provider);
            return(self);
        }
Esempio n. 7
0
        private static Log4NetProvider CreateProvider(XDocument configuration)
        {
            var settings = new Log4NetSettings {
                RootRepository = Guid.NewGuid().ToString()
            };
            var provider = new Log4NetProvider(x => configuration, x => true);

            provider.Initialize(settings);
            return(provider);
        }
Esempio n. 8
0
        public void InitializingTwoProvidersDoesNotThrow()
        {
            var settings = new Log4NetSettings {
                RootRepository = Guid.NewGuid().ToString()
            };
            var providerA = new Log4NetProvider();
            var providerB = new Log4NetProvider();

            providerA.Initialize(settings);
            providerB.Initialize(settings);
        }
Esempio n. 9
0
        private async Task <IHost> CreateHost(string[] args)
        {
            // Ensure GameLogic and GameServer Assemblies are loaded
            _ = GameLogic.Rand.NextInt(1, 2);
            _ = OpenMU.GameServer.ClientVersionResolver.DefaultVersion;

            var host = Host.CreateDefaultBuilder()
                       .ConfigureLogging(configureLogging =>
            {
                configureLogging.ClearProviders();
                var settings = new Log4NetSettings {
                    ConfigFile = Log4NetConfigFilePath, Watch = true
                };
                configureLogging.AddLog4Net(settings);
            })
                       .ConfigureServices(c =>
                                          c.AddSingleton(this.servers)
                                          .AddSingleton(s => s.GetService <IPersistenceContextProvider>().CreateNewConfigurationContext().Get <ChatServerDefinition>().First())
                                          .AddSingleton(s => s.GetService <ChatServerDefinition>().ConvertToSettings())
                                          .AddIpResolver(args)
                                          .AddSingleton(this.gameServers)
                                          .AddSingleton(this.gameServers.Values)
                                          .AddSingleton(s => this.DeterminePersistenceContextProvider(args, s.GetService <ILoggerFactory>()))
                                          .AddSingleton <IServerConfigurationChangeListener, ServerConfigurationChangeListener>()
                                          .AddSingleton <ILoginServer, LoginServer>()
                                          .AddSingleton <IGuildServer, GuildServer>()
                                          .AddSingleton <IFriendServer, FriendServer>()
                                          .AddSingleton <IChatServer, ChatServer>()
                                          .AddSingleton <ConnectServerFactory>()
                                          .AddSingleton <ConnectServerContainer>()
                                          .AddSingleton <IEnumerable <IConnectServer> >(provider => provider.GetService <ConnectServerContainer>())
                                          .AddSingleton <GameServerContainer>()
                                          .AddSingleton <PlugInManager>()
                                          .AddSingleton <IPlugInConfigurationChangeListener, PlugInConfigurationChangeListener>()
                                          .AddSingleton <ICollection <PlugInConfiguration> >(s => s.GetService <IPersistenceContextProvider>().CreateNewTypedContext <PlugInConfiguration>().Get <PlugInConfiguration>().ToList())
                                          .AddHostedService(provider => provider.GetService <IChatServer>())
                                          .AddHostedService(provider => provider.GetService <ConnectServerContainer>())
                                          .AddHostedService(provider => provider.GetService <GameServerContainer>())
                                          .AddHostedService <AdminPanel>()
                                          .AddSingleton(new AdminPanelSettings(this.DetermineAdminPort(args)))
                                          .AddHostedService <ApiHost>())
                       .Build();

            Log.Info("Host created");
            NpgsqlLoggingProvider.Initialize(host.Services.GetService <ILoggerFactory>());
            this.servers.Add(host.Services.GetService <IChatServer>());
            this.LoadGameClientDefinitions(host.Services.GetService <IPersistenceContextProvider>().CreateNewConfigurationContext());
            Log.Info("Starting host...");
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            await host.StartAsync(default);
        /// <summary>
        /// Adds log4net support using the provided <see cref="Log4NetSettings"/>
        /// </summary>
        /// <param name="self">The logging builder to update for log4net support</param>
        /// <param name="settings">The settings to use for configuring log4net.</param>
        /// <returns>The passed in logging builder</returns>
        public static ILoggingBuilder AddLog4Net(this ILoggingBuilder self, Log4NetSettings settings)
        {
            var provider = new Log4NetProvider();

            provider.Initialize(settings);

            self.AddProvider(provider)
            .AddFilter <Log4NetProvider>((category, logLevel) =>
            {
                return(provider.CreateLogger(category).IsEnabled(logLevel));
            });
            return(self);
        }
        public void SettingsDefault()
        {
            // Arrange


            // Act
            var settings = new Log4NetSettings();

            // Assert
            Assert.Equal(1, settings.GlobalContextProperties.Count);
            Assert.Equal("log4net.config", settings.ConfigFilePath);
            Assert.False(settings.Watch);
        }
Esempio n. 12
0
        private async Task <IHost> CreateHost(string[] args)
        {
            var persistenceContextProvider = this.DeterminePersistenceContextProvider(args);
            var persistenceContext         = persistenceContextProvider.CreateNewConfigurationContext();

            this.LoadGameClientDefinitions(persistenceContext);
            var chatServerDefinition = persistenceContext.Get <ChatServerDefinition>().First();

            var host = Host.CreateDefaultBuilder()
                       .ConfigureLogging(configureLogging =>
            {
                configureLogging.ClearProviders();
                var settings = new Log4NetSettings {
                    ConfigFile = Log4NetConfigFilePath, Watch = true
                };
                configureLogging.AddLog4Net(settings);
            })
                       .ConfigureServices(c =>
                                          c.AddSingleton(this.servers)
                                          .AddSingleton(chatServerDefinition)
                                          .AddSingleton(chatServerDefinition.ConvertToSettings())
                                          .AddSingleton(IpAddressResolverFactory.DetermineIpResolver(args))
                                          .AddSingleton(this.gameServers)
                                          .AddSingleton(this.gameServers.Values)
                                          .AddSingleton(persistenceContextProvider)
                                          .AddSingleton <IServerConfigurationChangeListener, ServerConfigurationChangeListener>()
                                          .AddSingleton <ILoginServer, LoginServer>()
                                          .AddSingleton <IGuildServer, GuildServer>()
                                          .AddSingleton <IFriendServer, FriendServer>()
                                          .AddSingleton <IChatServer, ChatServer>()
                                          .AddSingleton <ConnectServerContainer>()
                                          .AddSingleton <IEnumerable <IConnectServer> >(provider => provider.GetService <ConnectServerContainer>())
                                          .AddSingleton <GameServerContainer>()
                                          .AddHostedService(provider => provider.GetService <IChatServer>())
                                          .AddHostedService(provider => provider.GetService <ConnectServerContainer>())
                                          .AddHostedService(provider => provider.GetService <GameServerContainer>())
                                          .AddHostedService <AdminPanel>()
                                          .AddSingleton(new AdminPanelSettings(this.DetermineAdminPort(args)))
                                          .AddHostedService <ApiHost>())
                       .Build();

            Log.Info("Host created");
            this.servers.Add(host.Services.GetService <IChatServer>());
            Log.Info("Starting host...");
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            await host.StartAsync(default);
Esempio n. 13
0
        /// <summary>
        /// Creates the Host instance.
        /// </summary>
        /// <param name="gameServers">The game servers.</param>
        /// <param name="connectServers">The connect servers.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="loggingConfigurationPath">The logging configuration path.</param>
        /// <returns>
        /// The created host.
        /// </returns>
        public static IHost BuildHost(ICollection <IGameServer> gameServers, IEnumerable <IConnectServer> connectServers, ILoggerFactory loggerFactory, string?loggingConfigurationPath)
        {
            var builder = Host.CreateDefaultBuilder();

            if (!string.IsNullOrEmpty(loggingConfigurationPath))
            {
                builder.ConfigureLogging(configureLogging =>
                {
                    configureLogging.ClearProviders();
                    var settings = new Log4NetSettings {
                        ConfigFile = loggingConfigurationPath, Watch = true
                    };

                    configureLogging.AddLog4Net(settings);
                });
            }

            return(builder
                   .ConfigureServices(s =>
            {
                if (loggerFactory != null)
                {
                    s.AddSingleton(loggerFactory);
                }

                s.AddSingleton(gameServers);
                s.AddSingleton(connectServers);
            })
                   .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder
                .UseStartup <Startup>()
                .UseUrls("http://*:80", "https://*:443");
            })
                   .Build());
        }