public override void UnmanagedAttach() { DASettingsManager.AddSettings(SettingsFilename); RegisterEvent(DAEventType.LevelLoaded); RegisterEvent(DAEventType.SettingsLoaded); RegisterEvent(DAEventType.PlayerLeave); RegisterObjectEvent(DAObjectEventType.Custom, DAObjectEventObjectType.Building); RegisterChatCommand(FundChatCommand, "!fund", 1); // !fund <acronym> [<amount>] RegisterChatCommand(TotalFundChatCommand, "!totalfund", 1); // !totalfund <acronym> RegisterChatCommand(ReFundChatCommand, "!refund"); // !refund [<acronym>] }
public override void ManagedRegistered() { DASettingsManager.AddSettings(SettingsFilename); RegisterEvent(DAEventType.SettingsLoaded); }
public override void SettingsLoadedEvent() { MimeTypes.Clear(); ErrorPages.Clear(); IDASettingsClass settings = DASettingsManager.GetSettings("RenWeb.ini"); if (settings != null) { IINISection section = settings.GetSection("RenWeb"); foreach (IINIEntry entry in section.EntryList) { switch (entry.Entry) { case "Port": if (int.TryParse(entry.Value, out int port)) { Port = port; } else { Engine.ConsoleOutput($"[RenWeb] Port value is invalid! Using default port 7550...\n"); Log(LogSeverity.Warning, $"Port value is invalid! Supplied value: \"{port}\". Using default port \"7550\""); Port = 7550; } break; case "RootHTTPFolder": RootHTTPFolder = entry.Value; break; case "IndexFile": IndexFile = entry.Value; break; case "LogFile": LogFile = entry.Value; break; case "MaxPendingConnections": if (int.TryParse(entry.Value, out int max)) { MaxPendingConnections = max; } else { Engine.ConsoleOutput($"[RenWeb] Max pending conections value is invalid! Using default 5...\n"); Log(LogSeverity.Warning, $"Max pending conections value is invalid! Supplied value: \"{max}\". Using default \"5\""); MaxPendingConnections = 5; } break; case "GameLog": if (bool.TryParse(entry.Value, out bool isit)) { GameLog = isit; } else { Engine.ConsoleOutput($"[RenWeb] Game log value is invalid! Using default true...\n"); Log(LogSeverity.Warning, $"Game log value is invalid! Supplied value: \"{isit}\". Using default \"true\""); GameLog = true; } break; default: Engine.ConsoleOutput($"[RenWeb] Invalid entry detected under RenWeb section in configuration file!\n" + $"[RenWeb] Key: \"{entry.Entry}\" | Value: \"{entry.Value}\"\n"); Log(LogSeverity.Warning, $"Invalid config value detected under [RenWeb]. Key: \"{entry.Entry}\" | Value: \"{entry.Value}\""); break; } } IINISection Mime = settings.GetSection("RenWeb_MimeTypes"); foreach (IINIEntry entry in Mime.EntryList) { MimeTypes.Add(entry.Entry, entry.Value); } IINISection Page = settings.GetSection("RenWeb_ErrorPages"); foreach (IINIEntry entry in Page.EntryList) { string[] Errors = entry.Entry.Split('|'); System.Collections.Generic.List <int> ErrCodes = new System.Collections.Generic.List <int>(); foreach (string s in Errors) { if (int.TryParse(s, out int Code)) { ErrCodes.Add(Code); } else { Engine.ConsoleOutput($"[RenWeb] Invalid error code detected under RenWeb_ErrorPages! Value: {s}\n"); Log(LogSeverity.Warning, $"Invalid error code under RenWeb_ErrorPages! Value: {s}. Skipping this code...\n"); } } ErrorPages.Add(ErrCodes, entry.Value); } if (!Directory.Exists(Main.RootHTTPFolder)) { Directory.CreateDirectory(Main.RootHTTPFolder); Setup(Main.RootHTTPFolder); } if (!File.Exists(Main.LogFile)) { MakeFile(Main.LogFile); } RestartServer(); //Start server if not running, restart if running. } else { string ServerRoot = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "RenWeb.ini"); if (!File.Exists(ServerRoot)) { Engine.ConsoleOutput("[RenWeb] Could not find RenWeb.ini in server folder. Creating a one with default settings...\n"); File.Create(ServerRoot).Close(); File.WriteAllBytes(ServerRoot, FileStorage.Config); DASettingsManager.AddSettings("RenWeb.ini"); Engine.ConsoleInput("reload"); } else { Engine.ConsoleOutput("[RenWeb] FATAL ERROR! Failed to load RenWeb settings file. Attempting to register configuration file into DA...\n"); DASettingsManager.AddSettings("RenWeb.ini"); Engine.ConsoleInput("reload"); } } }