Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove old config options and logger; Rearrange existing config options #395

Merged
merged 3 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 28 additions & 32 deletions EOLib.Config.Test/ConfigFileLoadActionsTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using NUnit.Framework;

Expand Down Expand Up @@ -45,9 +46,6 @@ public void InvalidConfigFileThatExists_UsesConfigurationValueDefaults()
Assert.That(_configurationRepository.Host, Is.EqualTo(ConfigDefaults.Host));
Assert.That(_configurationRepository.Port, Is.EqualTo(ConfigDefaults.Port));

Assert.That(_configurationRepository.NPCDropProtectTime, Is.EqualTo(ConfigDefaults.NPCDropProtectionSeconds));
Assert.That(_configurationRepository.PlayerDropProtectTime, Is.EqualTo(ConfigDefaults.PlayerDropProtectionSeconds));

Assert.That(_configurationRepository.Language, Is.EqualTo(EOLanguage.English));
Assert.That(_configurationRepository.CurseFilterEnabled, Is.False);
Assert.That(_configurationRepository.StrictFilterEnabled, Is.False);
Expand All @@ -62,14 +60,13 @@ public void InvalidConfigFileThatExists_UsesConfigurationValueDefaults()
Assert.That(_configurationRepository.HearWhispers, Is.True);
Assert.That(_configurationRepository.Interaction, Is.True);
Assert.That(_configurationRepository.LogChatToFile, Is.False);
Assert.That(_configurationRepository.EnableLog, Is.False);
}

[Test]
public void ValidConfigFile_LoadsSpecifiedSettings()
{
const string contents = @"[CONNECTION]
Host=ewmoffat.ddns.net
Host=eoserv.moffat.io
Port=12345
[VERSION]
Major=10
Expand All @@ -80,13 +77,11 @@ public void ValidConfigFile_LoadsSpecifiedSettings()
Sound=on
ShowBaloons=off
ShowShadows=no
ShowTransition=true
EnableLogging=true
[CUSTOM]
InGameWidth=123
InGameHeight=321
[CUSTOM]
NPCDropProtectTime=5000
PlayerDropProtectTime=10000
ShowTransition=true
AccountCreateTimeout=12345
[LANGUAGE]
Language=2
[CHAT]
Expand All @@ -100,33 +95,34 @@ public void ValidConfigFile_LoadsSpecifiedSettings()

_configFileLoadActions.LoadConfigFile();

Assert.That(_configurationRepository.VersionMajor, Is.EqualTo(10));
Assert.That(_configurationRepository.VersionMinor, Is.EqualTo(20));
Assert.That(_configurationRepository.VersionBuild, Is.EqualTo(30));
Assert.Multiple(() =>
{
Assert.That(_configurationRepository.VersionMajor, Is.EqualTo(10));
Assert.That(_configurationRepository.VersionMinor, Is.EqualTo(20));
Assert.That(_configurationRepository.VersionBuild, Is.EqualTo(30));

Assert.That(_configurationRepository.Host, Is.EqualTo("ewmoffat.ddns.net"));
Assert.That(_configurationRepository.Port, Is.EqualTo(12345));
Assert.That(_configurationRepository.Host, Is.EqualTo("eoserv.moffat.io"));
Assert.That(_configurationRepository.Port, Is.EqualTo(12345));

Assert.That(_configurationRepository.NPCDropProtectTime, Is.EqualTo(5000));
Assert.That(_configurationRepository.PlayerDropProtectTime, Is.EqualTo(10000));
Assert.That(_configurationRepository.Language, Is.EqualTo(EOLanguage.Swedish));
Assert.That(_configurationRepository.CurseFilterEnabled, Is.True);
Assert.That(_configurationRepository.StrictFilterEnabled, Is.True);

Assert.That(_configurationRepository.Language, Is.EqualTo(EOLanguage.Swedish));
Assert.That(_configurationRepository.CurseFilterEnabled, Is.True);
Assert.That(_configurationRepository.StrictFilterEnabled, Is.True);
Assert.That(_configurationRepository.ShowShadows, Is.False);
Assert.That(_configurationRepository.ShowChatBubbles, Is.False);

Assert.That(_configurationRepository.ShowShadows, Is.False);
Assert.That(_configurationRepository.ShowChatBubbles, Is.False);
Assert.That(_configurationRepository.ShowTransition, Is.True);
Assert.That(_configurationRepository.InGameWidth, Is.EqualTo(123));
Assert.That(_configurationRepository.InGameHeight, Is.EqualTo(321));
Assert.That(_configurationRepository.ShowTransition, Is.True);
Assert.That(_configurationRepository.InGameWidth, Is.EqualTo(123));
Assert.That(_configurationRepository.InGameHeight, Is.EqualTo(321));
Assert.That(_configurationRepository.AccountCreateTimeout, Is.EqualTo(TimeSpan.FromMilliseconds(12345)));

Assert.That(_configurationRepository.MusicEnabled, Is.True);
Assert.That(_configurationRepository.SoundEnabled, Is.True);
Assert.That(_configurationRepository.MusicEnabled, Is.True);
Assert.That(_configurationRepository.SoundEnabled, Is.True);

Assert.That(_configurationRepository.HearWhispers, Is.False);
Assert.That(_configurationRepository.Interaction, Is.False);
Assert.That(_configurationRepository.LogChatToFile, Is.True);
Assert.That(_configurationRepository.EnableLog, Is.True);
Assert.That(_configurationRepository.HearWhispers, Is.False);
Assert.That(_configurationRepository.Interaction, Is.False);
Assert.That(_configurationRepository.LogChatToFile, Is.True);
});
}

private static void CreateTestConfigurationInDirectory(string contents)
Expand Down
3 changes: 0 additions & 3 deletions EOLib.Config/ConfigDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ public static class ConfigDefaults
public const string Host = "127.0.0.1";
public const int Port = 8078;

public const int NPCDropProtectionSeconds = 30;
public const int PlayerDropProtectionSeconds = 5;

public const int AccountCreateTimeout = 2000;
}
}
24 changes: 5 additions & 19 deletions EOLib.Config/ConfigFileLoadActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,28 @@ public void LoadConfigFile()
? (EOLanguage)tempInt
: EOLanguage.English;

_configRepository.PlayerDropProtectTime = configFile.GetValue(ConfigStrings.Custom,
ConfigStrings.PlayerDropProtectTime, out tempInt)
? tempInt
: ConfigDefaults.PlayerDropProtectionSeconds;

_configRepository.NPCDropProtectTime = configFile.GetValue(ConfigStrings.Custom, ConfigStrings.NPCDropProtectTime,
out tempInt)
? tempInt
: ConfigDefaults.NPCDropProtectionSeconds;

bool tempBool;
_configRepository.CurseFilterEnabled = configFile.GetValue(ConfigStrings.Chat, ConfigStrings.Filter, out tempBool) && tempBool;
_configRepository.StrictFilterEnabled = configFile.GetValue(ConfigStrings.Chat, ConfigStrings.FilterAll, out tempBool) && tempBool;

_configRepository.ShowShadows = !configFile.GetValue(ConfigStrings.Settings, ConfigStrings.ShowShadows, out tempBool) || tempBool;
_configRepository.ShowTransition = configFile.GetValue(ConfigStrings.Settings, ConfigStrings.ShowTransition, out tempBool) && tempBool;
_configRepository.MusicEnabled = configFile.GetValue(ConfigStrings.Settings, ConfigStrings.Music, out tempBool) && tempBool;
_configRepository.SoundEnabled = configFile.GetValue(ConfigStrings.Settings, ConfigStrings.Sound, out tempBool) && tempBool;
_configRepository.ShowChatBubbles = !configFile.GetValue(ConfigStrings.Settings, ConfigStrings.ShowBaloons, out tempBool) || tempBool;

_configRepository.EnableLog = configFile.GetValue(ConfigStrings.Settings, ConfigStrings.EnableLogging, out tempBool) && tempBool;
_configRepository.HearWhispers = !configFile.GetValue(ConfigStrings.Chat, ConfigStrings.HearWhisper, out tempBool) || tempBool;
_configRepository.Interaction = !configFile.GetValue(ConfigStrings.Chat, ConfigStrings.Interaction, out tempBool) || tempBool;
_configRepository.LogChatToFile = configFile.GetValue(ConfigStrings.Chat, ConfigStrings.LogChat, out tempBool) && tempBool;

_configRepository.AccountCreateTimeout = TimeSpan.FromMilliseconds(
configFile.GetValue(ConfigStrings.Custom, ConfigStrings.AccountCreateTimeout, out tempInt)
? tempInt
: ConfigDefaults.AccountCreateTimeout);
var timeoutValue = configFile.GetValue(ConfigStrings.Custom, ConfigStrings.AccountCreateTimeout, out tempInt) ? tempInt : ConfigDefaults.AccountCreateTimeout;
_configRepository.AccountCreateTimeout = TimeSpan.FromMilliseconds(timeoutValue);
_configRepository.ShowTransition = configFile.GetValue(ConfigStrings.Custom, ConfigStrings.ShowTransition, out tempBool) && tempBool;
_configRepository.InGameWidth = configFile.GetValue(ConfigStrings.Custom, ConfigStrings.InGameWidth, out tempInt) ? tempInt : 0;
_configRepository.InGameHeight = configFile.GetValue(ConfigStrings.Custom, ConfigStrings.InGameHeight, out tempInt) ? tempInt : 0;

string host;
_configRepository.Host = configFile.GetValue(ConfigStrings.Connection, ConfigStrings.Host, out host) ? host : ConfigDefaults.Host;
_configRepository.Port = configFile.GetValue(ConfigStrings.Connection, ConfigStrings.Port, out tempInt) ? tempInt : ConfigDefaults.Port;

_configRepository.InGameWidth = configFile.GetValue(ConfigStrings.Settings, ConfigStrings.InGameWidth, out tempInt) ? tempInt : 0;
_configRepository.InGameHeight = configFile.GetValue(ConfigStrings.Settings, ConfigStrings.InGameHeight, out tempInt) ? tempInt : 0;
}
}
}
4 changes: 0 additions & 4 deletions EOLib.Config/ConfigStrings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public static class ConfigStrings
public const string Settings = "SETTINGS";
public const string ShowShadows = "ShowShadows";
public const string ShowTransition = "ShowTransition";
public const string EnableLogging = "EnableLogging";
public const string Music = "Music";
public const string Sound = "Sound";
public const string ShowBaloons = "ShowBaloons";
Expand All @@ -28,9 +27,6 @@ public static class ConfigStrings
public static string InGameHeight = nameof(InGameHeight);

public const string Custom = "CUSTOM";
public const string NPCDropProtectTime = "NPCDropProtectTime";
public const string PlayerDropProtectTime = "PlayerDropProtectTime";
public const string MainCloneCompat = nameof(MainCloneCompat);
public const string AccountCreateTimeout = nameof(AccountCreateTimeout);

public const string LANGUAGE = "LANGUAGE";
Expand Down
18 changes: 0 additions & 18 deletions EOLib.Config/IConfigurationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ public interface IConfigurationRepository
bool ShowShadows { get; set; }
bool ShowChatBubbles { get; set; }
bool ShowTransition { get; set; }
int PlayerDropProtectTime { get; set; }
int NPCDropProtectTime { get; set; }

bool MusicEnabled { get; set; }
bool SoundEnabled { get; set; }
Expand All @@ -32,12 +30,8 @@ public interface IConfigurationRepository

TimeSpan AccountCreateTimeout { get; set; }

bool EnableLog { get; set; }

int InGameWidth { get; set; }
int InGameHeight { get; set; }

bool DebugCrashes { get; set; }
}

public interface IConfigurationProvider
Expand All @@ -57,8 +51,6 @@ public interface IConfigurationProvider
bool ShowShadows { get; }
bool ShowChatBubbles { get; }
bool ShowTransition { get; }
int PlayerDropProtectTime { get; }
int NPCDropProtectTime { get; }

bool MusicEnabled { get; }
bool SoundEnabled { get; }
Expand All @@ -69,12 +61,8 @@ public interface IConfigurationProvider

TimeSpan AccountCreateTimeout { get; }

bool EnableLog { get; }

int InGameWidth { get; }
int InGameHeight { get; }

bool DebugCrashes { get; }
}

[AutoMappedType(IsSingleton = true)]
Expand All @@ -95,8 +83,6 @@ public class ConfigurationRepository : IConfigurationRepository, IConfigurationP
public bool ShowShadows { get; set; }
public bool ShowChatBubbles { get; set; }
public bool ShowTransition { get; set; }
public int PlayerDropProtectTime { get; set; }
public int NPCDropProtectTime { get; set; }

public bool MusicEnabled { get; set; }
public bool SoundEnabled { get; set; }
Expand All @@ -107,11 +93,7 @@ public class ConfigurationRepository : IConfigurationRepository, IConfigurationP

public TimeSpan AccountCreateTimeout { get; set; }

public bool EnableLog { get; set; }

public int InGameWidth { get; set; }
public int InGameHeight { get; set; }

public bool DebugCrashes { get; set; }
}
}
123 changes: 0 additions & 123 deletions EOLib.Logger/DebugOnlyLogger.cs

This file was deleted.

Loading