Skip to content

Commit

Permalink
Fixes email configurations (#225)
Browse files Browse the repository at this point in the history
Fixes email configuration and bumps release
  • Loading branch information
kamronbatman authored Sep 5, 2020
1 parent 2de5e34 commit e8fe385
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 33 deletions.
6 changes: 3 additions & 3 deletions Projects/Server/Configuration/ServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static class ServerConfiguration
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)
Expand Down Expand Up @@ -139,7 +139,7 @@ public static void Load(bool mocked = false)

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<ServerSettings>(m_FilePath);

if (m_Settings == null)
Expand Down Expand Up @@ -183,7 +183,7 @@ public static void Load(bool mocked = false)
{
Save();
Utility.PushColor(ConsoleColor.Green);
Console.WriteLine($"Core: Configuration saved to {m_RelPath}.");
Console.WriteLine($"Core: Server configuration saved to {m_RelPath}.");
Utility.PopColor();
}
}
Expand Down
99 changes: 70 additions & 29 deletions Projects/UOContent/Configuration/EmailConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/

using System;
using System.IO;
using System.Text.Json.Serialization;
using MimeKit;
Expand All @@ -22,61 +23,101 @@ 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

static EmailConfiguration()
private const string m_RelPath = "Configuration/email-settings.json";

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<Settings>(filePath) ?? new Settings();
var path = Path.Join(Core.BaseDirectory, m_RelPath);

Settings settings;

if (File.Exists(path))
{
Console.Write($"Core: Reading email configuration from {m_RelPath}...");
settings = JsonConfig.Deserialize<Settings>(path);

if (settings.emailServer == null || settings.fromAddress == null)
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
{
JsonConfig.Serialize(filePath, settings);
return;
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);
EmailServer = settings.emailServer;
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("fromAddress")]
public string fromAddress { get; set; } = "support@modernuo.com";

[JsonPropertyName("fromName")] internal string fromName { get; set; }
[JsonPropertyName("fromName")]
public string fromName { get; set; } = "ModernUO Team";

[JsonPropertyName("crashAddress")] internal string crashAddress { get; set; }
[JsonPropertyName("crashAddress")]
public string crashAddress { get; set; } = "crashes@modernuo.com";

[JsonPropertyName("crashName")] internal string crashName { get; set; }
[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")]
public string emailServer { get; set; } = "smtp.gmail.com";

[JsonPropertyName("emailPort")]
public int emailPort { get; set; } = 465;

[JsonPropertyName("emailServer")] internal string emailServer { get; set; }
[JsonPropertyName("emailUsername")]
public string emailUsername { get; set; } = "support@modernuo.com";

[JsonPropertyName("emailPort")] internal int emailPort { get; set; }
[JsonPropertyName("emailPassword")]
public string emailPassword { get; set; } = "Some Password 123";

[JsonPropertyName("emailUsername")] internal string emailUsername { get; set; }
[JsonPropertyName("emailSendRetryCount")]
public int emailSendRetryCount { get; set; } = 5;

[JsonPropertyName("emailPassword")] internal string emailPassword { get; set; }
[JsonPropertyName("emailSendRetryDelay")]
public int emailSendRetryDelay { get; set; } = 3;
}
}
}
2 changes: 1 addition & 1 deletion Projects/UOContent/Misc/ServerList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static class ServerList

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");

Expand Down

0 comments on commit e8fe385

Please sign in to comment.