public virtual async Task ConfigureAsync(string configFile) { MasterPath = Path.GetDirectoryName(configFile); var serializer = new XmlSerializer(typeof(Configuration)); if (!File.Exists(configFile)) { throw new ArgumentException($"{configFile} config file does not exist."); } await using (var fs = File.OpenRead(configFile)) { Logger.Config = Config = (Configuration)serializer.Deserialize(fs); UchuContextBase.Config = Config; } await SetupApiAsync().ConfigureAwait(false); if (!string.IsNullOrWhiteSpace(Config.ResourcesConfiguration?.GameResourceFolder)) { Resources = new LocalResources(Config); } var certificateFilePath = Path.Combine(MasterPath, Config.Networking.Certificate); if (Config.Networking?.Certificate != default && File.Exists(certificateFilePath)) { var cert = new X509Certificate2(certificateFilePath); Logger.Information($"PRIVATE KEY: {cert.HasPrivateKey} {cert.PrivateKey}"); Certificate = cert; RakNetServer = new TcpUdpServer(Port, "3.25 ND1", Certificate, 150); } else { RakNetServer = new TcpUdpServer(Port, "3.25 ND1"); } SsoService = new SsoService(Config.SsoConfig?.Domain ?? ""); try { SessionCache = new RedisSessionCache(); } catch (RedisConnectionException) { Logger.Error("Failed to establish Redis connection, falling back to database."); SessionCache = new DatabaseCache(); } Logger.Information($"Server {Id} configured on port: {Port}"); }
/// <summary> /// Configures the server by parsing config files and setting up certificates. /// </summary> /// <param name="configFile">The config file to use as configuration</param> /// <exception cref="ArgumentException">If the provided config file can't be found</exception> public virtual async Task ConfigureAsync(string configFile) { if (configFile == null) { throw new ArgumentNullException(nameof(configFile), ResourceStrings.Server_ConfigureAsync_ConfigFileNullException); } MasterPath = Path.GetDirectoryName(configFile); Config = UchuConfiguration.Load(configFile); if (!Config.DebugConfig.StartInstancesAsThreads) { Logger.SetConfiguration(Config); } UchuContextBase.Config = Config; if (!File.Exists(configFile)) { throw new ArgumentException($"{configFile} config file does not exist."); } await SetupApiAsync().ConfigureAwait(false); if (!string.IsNullOrWhiteSpace(Config.ResourcesConfiguration?.GameResourceFolder)) { Resources = new LocalResources(Config); } // Setup the RakNet server and possible certificate var certificateFilePath = Path.Combine(MasterPath, Config.Networking.Certificate); if (Config.Networking?.Certificate != default && File.Exists(certificateFilePath)) { var cert = new X509Certificate2(certificateFilePath); Logger.Information($"PRIVATE KEY: {cert.HasPrivateKey} {cert.PrivateKey}"); Certificate = cert; RakNetServer = new TcpUdpServer(Port, "3.25 ND1", Certificate, 150); } else { RakNetServer = new TcpUdpServer(Port, "3.25 ND1"); } SsoService = new SsoService(Config.SsoConfig?.Domain ?? ""); // Try to connect to Redis, otherwise fallback to DB caching if (Config.CacheConfig.UseService) { try { SessionCache = new RedisSessionCache(Config.CacheConfig); Logger.Information($"Established Redis connection at {Config.CacheConfig.Host}:{Config.CacheConfig.Port}"); } catch (RedisConnectionException) { Logger.Error("Failed to establish Redis connection, falling back to database."); SessionCache = new DatabaseCache(); } } else { Logger.Information("Caching service is disabled, falling back to database."); SessionCache = new DatabaseCache(); } HeartBeatsPerInterval = Config.Networking.WorldServerHeartBeatsPerInterval; HeartBeatIntervalInMinutes = Config.Networking.WorldServerHeartBeatIntervalInMinutes; Logger.Information($"Server {Id} configured on port: {Port}"); }