From e8fe3852cd42e7dce76b10e996b0ed6ecd614798 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Fri, 4 Sep 2020 22:42:15 -0700 Subject: [PATCH] Fixes email configurations (#225) Fixes email configuration and bumps release --- .../Configuration/ServerConfiguration.cs | 6 +- .../Configuration/EmailConfiguration.cs | 97 +++++++++++++------ Projects/UOContent/Misc/ServerList.cs | 2 +- 3 files changed, 73 insertions(+), 32 deletions(-) diff --git a/Projects/Server/Configuration/ServerConfiguration.cs b/Projects/Server/Configuration/ServerConfiguration.cs index 7bdacaf9b..75186089e 100644 --- a/Projects/Server/Configuration/ServerConfiguration.cs +++ b/Projects/Server/Configuration/ServerConfiguration.cs @@ -36,7 +36,7 @@ namespace Server public static string GetSetting(string key, string defaultValue) { m_Settings.settings.TryGetValue(key, out var value); - return value == "(-null-)" ? null : value ?? defaultValue; + return value ?? defaultValue; } public static int GetSetting(string key, int defaultValue) @@ -139,7 +139,7 @@ namespace Server if (File.Exists(m_FilePath)) { - Console.Write($"Core: Reading configuration from {m_RelPath}..."); + Console.Write($"Core: Reading server configuration from {m_RelPath}..."); m_Settings = JsonConfig.Deserialize(m_FilePath); if (m_Settings == null) @@ -183,7 +183,7 @@ namespace Server { Save(); Utility.PushColor(ConsoleColor.Green); - Console.WriteLine($"Core: Configuration saved to {m_RelPath}."); + Console.WriteLine($"Core: Server configuration saved to {m_RelPath}."); Utility.PopColor(); } } diff --git a/Projects/UOContent/Configuration/EmailConfiguration.cs b/Projects/UOContent/Configuration/EmailConfiguration.cs index d0233627c..48200de4d 100644 --- a/Projects/UOContent/Configuration/EmailConfiguration.cs +++ b/Projects/UOContent/Configuration/EmailConfiguration.cs @@ -13,6 +13,7 @@ * along with this program. If not, see . * *************************************************************************/ +using System; using System.IO; using System.Text.Json.Serialization; using MimeKit; @@ -22,29 +23,50 @@ namespace Server.Configurations { public static class EmailConfiguration { - public static readonly bool EmailEnabled; - public static readonly MailboxAddress FromAddress; - public static readonly MailboxAddress CrashAddress; - public static readonly MailboxAddress SpeechLogPageAddress; - public static readonly string EmailServer; - public static readonly int EmailPort; - public static readonly string EmailServerUsername; - public static readonly string EmailServerPassword; - public static readonly int EmailSendRetryCount = 5; // seconds - public static readonly int EmailSendRetryDelay = 2; // seconds + private const string m_RelPath = "Configuration/email-settings.json"; - static EmailConfiguration() + public static bool EmailEnabled { get; private set; } + public static MailboxAddress FromAddress { get; private set; } + public static MailboxAddress CrashAddress { get; private set; } + public static MailboxAddress SpeechLogPageAddress { get; private set; } + public static string EmailServer { get; private set; } + public static int EmailPort { get; private set; } + public static string EmailServerUsername { get; private set; } + public static string EmailServerPassword { get; private set; } + public static int EmailSendRetryCount { get; private set; } // seconds + public static int EmailSendRetryDelay { get; private set; } // seconds + + public static void Configure() { - var filePath = Path.Join(Core.BaseDirectory, "Configuration/email-settings.json"); - var settings = JsonConfig.Deserialize(filePath) ?? new Settings(); + var path = Path.Join(Core.BaseDirectory, m_RelPath); - if (settings.emailServer == null || settings.fromAddress == null) + Settings settings; + + if (File.Exists(path)) { - JsonConfig.Serialize(filePath, settings); - return; + Console.Write($"Core: Reading email configuration from {m_RelPath}..."); + settings = JsonConfig.Deserialize(path); + + if (settings == null) + { + Utility.PushColor(ConsoleColor.Red); + Console.WriteLine("failed"); + Utility.PopColor(); + throw new Exception("Core: Email configuration failed to deserialize."); + } + + Console.WriteLine("done"); + } + else + { + settings = new Settings(); + JsonConfig.Serialize(path, settings); + Utility.PushColor(ConsoleColor.Green); + Console.WriteLine($"Core: Email Configuration saved to {m_RelPath}."); + Utility.PopColor(); } - EmailEnabled = true; + EmailEnabled = settings.enabled; FromAddress = new MailboxAddress(settings.fromName, settings.fromAddress); CrashAddress = new MailboxAddress(settings.crashName, settings.crashAddress); SpeechLogPageAddress = new MailboxAddress(settings.speechLogPageName, settings.speechLogPageAddress); @@ -52,31 +74,50 @@ namespace Server.Configurations EmailPort = settings.emailPort; EmailServerUsername = settings.emailUsername; EmailServerPassword = settings.emailPassword; + EmailSendRetryCount = settings.emailSendRetryCount; + EmailSendRetryDelay = settings.emailSendRetryDelay; } - internal class Settings + public class Settings { - [JsonPropertyName("fromAddress")] internal string fromAddress { get; set; } + [JsonPropertyName("enabled")] + public bool enabled { get; set; } = false; - [JsonPropertyName("fromName")] internal string fromName { get; set; } + [JsonPropertyName("fromAddress")] + public string fromAddress { get; set; } = "support@modernuo.com"; - [JsonPropertyName("crashAddress")] internal string crashAddress { get; set; } + [JsonPropertyName("fromName")] + public string fromName { get; set; } = "ModernUO Team"; - [JsonPropertyName("crashName")] internal string crashName { get; set; } + [JsonPropertyName("crashAddress")] + public string crashAddress { get; set; } = "crashes@modernuo.com"; + + [JsonPropertyName("crashName")] + public string crashName { get; set; } = "Crash Log"; [JsonPropertyName("speechLogPageAddress")] - internal string speechLogPageAddress { get; set; } + public string speechLogPageAddress { get; set; } = "support@modernuo.com"; [JsonPropertyName("speechLogPageName")] - internal string speechLogPageName { get; set; } + public string speechLogPageName { get; set; } = "GM Support Conversation"; - [JsonPropertyName("emailServer")] internal string emailServer { get; set; } + [JsonPropertyName("emailServer")] + public string emailServer { get; set; } = "smtp.gmail.com"; - [JsonPropertyName("emailPort")] internal int emailPort { get; set; } + [JsonPropertyName("emailPort")] + public int emailPort { get; set; } = 465; - [JsonPropertyName("emailUsername")] internal string emailUsername { get; set; } + [JsonPropertyName("emailUsername")] + public string emailUsername { get; set; } = "support@modernuo.com"; - [JsonPropertyName("emailPassword")] internal string emailPassword { get; set; } + [JsonPropertyName("emailPassword")] + public string emailPassword { get; set; } = "Some Password 123"; + + [JsonPropertyName("emailSendRetryCount")] + public int emailSendRetryCount { get; set; } = 5; + + [JsonPropertyName("emailSendRetryDelay")] + public int emailSendRetryDelay { get; set; } = 3; } } } diff --git a/Projects/UOContent/Misc/ServerList.cs b/Projects/UOContent/Misc/ServerList.cs index 0c7e81408..32d9d6bf7 100644 --- a/Projects/UOContent/Misc/ServerList.cs +++ b/Projects/UOContent/Misc/ServerList.cs @@ -45,7 +45,7 @@ namespace Server.Misc public static void Initialize() { - Address = ServerConfiguration.GetOrUpdateSetting("serverListing.address", "(-null-)"); + Address = ServerConfiguration.GetOrUpdateSetting("serverListing.address", null); AutoDetect = ServerConfiguration.GetOrUpdateSetting("serverListing.autoDetect", true); ServerName = ServerConfiguration.GetOrUpdateSetting("serverListing.serverName", "ModernUO");