Skip to content

Commit

Permalink
Merge pull request #218 from Grover-c13/3.2.2
Browse files Browse the repository at this point in the history
MultiAdmin Version 3.2.2 Update
  • Loading branch information
Dankrushen authored Sep 21, 2019
2 parents 5389c06 + 6330542 commit eced3a1
Show file tree
Hide file tree
Showing 32 changed files with 937 additions and 222 deletions.
8 changes: 7 additions & 1 deletion MultiAdmin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2026
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiAdmin", "MultiAdmin/MultiAdmin.csproj", "{8384BF3C-5FC8-4395-A3DE-440C6C531D36}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiAdmin", "MultiAdmin\MultiAdmin.csproj", "{8384BF3C-5FC8-4395-A3DE-440C6C531D36}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultiAdminTests", "MultiAdminTests\MultiAdminTests.csproj", "{D56F8899-C7BB-4ADE-A62C-DEC4DC8C2EE8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -14,6 +16,10 @@ Global
{8384BF3C-5FC8-4395-A3DE-440C6C531D36}.Debug|Any CPU.Build.0 = Release|Any CPU
{8384BF3C-5FC8-4395-A3DE-440C6C531D36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8384BF3C-5FC8-4395-A3DE-440C6C531D36}.Release|Any CPU.Build.0 = Release|Any CPU
{D56F8899-C7BB-4ADE-A62C-DEC4DC8C2EE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D56F8899-C7BB-4ADE-A62C-DEC4DC8C2EE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D56F8899-C7BB-4ADE-A62C-DEC4DC8C2EE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D56F8899-C7BB-4ADE-A62C-DEC4DC8C2EE8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
37 changes: 36 additions & 1 deletion MultiAdmin/Config/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using MultiAdmin.ConsoleTools;
using MultiAdmin.Utility;

namespace MultiAdmin.Config
{
Expand Down Expand Up @@ -59,7 +60,7 @@ public void ReadConfigFile()

public bool Contains(string key)
{
return rawData != null && rawData.Any(entry => entry.ToLower().StartsWith(key.ToLower() + ":"));
return rawData != null && rawData.Any(entry => entry.StartsWith($"{key}:", StringComparison.CurrentCultureIgnoreCase));
}

private static string CleanValue(string value)
Expand Down Expand Up @@ -184,6 +185,40 @@ public float GetFloat(string key, float def = 0)
return def;
}

public double GetDouble(string key, double def = 0)
{
try
{
string value = GetString(key);

if (!string.IsNullOrEmpty(value) && double.TryParse(value, out double parsedValue))
return parsedValue;
}
catch (Exception e)
{
Program.LogDebugException(nameof(GetDouble), e);
}

return def;
}

public decimal GetDecimal(string key, decimal def = 0)
{
try
{
string value = GetString(key);

if (!string.IsNullOrEmpty(value) && decimal.TryParse(value, out decimal parsedValue))
return parsedValue;
}
catch (Exception e)
{
Program.LogDebugException(nameof(GetDecimal), e);
}

return def;
}

public bool GetBool(string key, bool def = false)
{
try
Expand Down
56 changes: 43 additions & 13 deletions MultiAdmin/Config/MultiAdminConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Reflection;
using MultiAdmin.Config.ConfigHandler;
using MultiAdmin.ConsoleTools;
using MultiAdmin.ServerIO;
using MultiAdmin.Utility;

namespace MultiAdmin.Config
{
Expand Down Expand Up @@ -33,7 +35,7 @@ public class MultiAdminConfig : InheritableConfigRegister
"MultiAdmin Debug Logging", "Enables MultiAdmin debug logging, this logs to a separate file than any other logs");

public ConfigEntry<string[]> DebugLogBlacklist { get; } =
new ConfigEntry<string[]>("multiadmin_debug_log_blacklist", new string[] {"ProcessFile"},
new ConfigEntry<string[]>("multiadmin_debug_log_blacklist", new string[] {nameof(OutputHandler.ProcessFile), nameof(Utils.StringMatches)},
"MultiAdmin Debug Logging Blacklist", "Which tags to block for MultiAdmin debug logging");

public ConfigEntry<string[]> DebugLogWhitelist { get; } =
Expand Down Expand Up @@ -84,22 +86,26 @@ public class MultiAdminConfig : InheritableConfigRegister
new ConfigEntry<bool>("manual_start", false,
"Manual Start", "Whether or not to start the server automatically when launching MultiAdmin");

public ConfigEntry<float> MaxMemory { get; } =
new ConfigEntry<float>("max_memory", 2048,
public ConfigEntry<decimal> MaxMemory { get; } =
new ConfigEntry<decimal>("max_memory", 2048,
"Max Memory", "The amount of memory in megabytes for MultiAdmin to check against");

public ConfigEntry<float> RestartLowMemory { get; } =
new ConfigEntry<float>("restart_low_memory", 400,
public ConfigEntry<decimal> RestartLowMemory { get; } =
new ConfigEntry<decimal>("restart_low_memory", 400,
"Restart Low Memory", "Restart if the game's remaining memory falls below this value in megabytes");

public ConfigEntry<float> RestartLowMemoryRoundEnd { get; } =
new ConfigEntry<float>("restart_low_memory_roundend", 450,
public ConfigEntry<decimal> RestartLowMemoryRoundEnd { get; } =
new ConfigEntry<decimal>("restart_low_memory_roundend", 450,
"Restart Low Memory Round-End", "Restart at the end of the round if the game's remaining memory falls below this value in megabytes");

public ConfigEntry<int> MaxPlayers { get; } =
new ConfigEntry<int>("max_players", 20,
"Max Players", "The number of players to display as the maximum for the server (within MultiAdmin, not in-game)");

public ConfigEntry<int> OutputReadAttempts { get; } =
new ConfigEntry<int>("output_read_attempts", 100,
"Output Read Attempts", "The number of times to attempt reading a message from the server before giving up");

public ConfigEntry<bool> RandomInputColors { get; } =
new ConfigEntry<bool>("random_input_colors", false,
"Random Input Colors", "Randomize the new input system's colors every time a message is input");
Expand All @@ -108,16 +114,28 @@ public class MultiAdminConfig : InheritableConfigRegister
new ConfigEntry<int>("restart_every_num_rounds", -1,
"Restart Every Number of Rounds", "Restart the server every number of rounds");

public ConfigEntry<bool> RestartEveryNumRoundsCounting { get; } =
new ConfigEntry<bool>("restart_every_num_rounds_counting", false,
"Restart Every Number of Rounds Counting", "Whether to print the count of rounds passed after each round if the server is set to restart after a number of rounds");

public ConfigEntry<bool> SafeServerShutdown { get; } =
new ConfigEntry<bool>("safe_server_shutdown", true,
"Safe Server Shutdown", "When MultiAdmin closes, if this is true, MultiAdmin will attempt to safely shutdown all the servers");
"Safe Server Shutdown", "When MultiAdmin closes, if this is true, MultiAdmin will attempt to safely shutdown all servers");

public ConfigEntry<int> SafeShutdownCheckDelay { get; } =
new ConfigEntry<int>("safe_shutdown_check_delay", 100,
"Safe Shutdown Check Delay", "The time in milliseconds between checking if a server is still running when safely shutting down");

public ConfigEntry<float> ServerRestartTimeout { get; } =
new ConfigEntry<float>("server_restart_timeout", 10,
public ConfigEntry<int> SafeShutdownTimeout { get; } =
new ConfigEntry<int>("safe_shutdown_timeout", 10000,
"Safe Shutdown Timeout", "The time in milliseconds before MultiAdmin gives up on safely shutting down a server");

public ConfigEntry<double> ServerRestartTimeout { get; } =
new ConfigEntry<double>("server_restart_timeout", 10,
"Server Restart Timeout", "The time in seconds before MultiAdmin forces a server restart if it doesn't respond to the regular restart command");

public ConfigEntry<float> ServerStopTimeout { get; } =
new ConfigEntry<float>("server_stop_timeout", 10,
public ConfigEntry<double> ServerStopTimeout { get; } =
new ConfigEntry<double>("server_stop_timeout", 10,
"Server Stop Timeout", "The time in seconds before MultiAdmin forces a server shutdown if it doesn't respond to the regular shutdown command");

public ConfigEntry<string> ServersFolder { get; } =
Expand Down Expand Up @@ -241,6 +259,18 @@ public override void UpdateConfigValueInheritable(ConfigEntry configEntry)
break;
}

case ConfigEntry<double> config:
{
config.Value = Config.GetDouble(config.Key, config.Default);
break;
}

case ConfigEntry<decimal> config:
{
config.Value = Config.GetDecimal(config.Key, config.Default);
break;
}

case ConfigEntry<bool> config:
{
config.Value = Config.GetBool(config.Key, config.Default);
Expand Down Expand Up @@ -283,7 +313,7 @@ public MultiAdminConfig[] GetConfigHierarchy(bool highestToLowest = true)
{
List<MultiAdminConfig> configHierarchy = new List<MultiAdminConfig>();

foreach (InheritableConfigRegister configRegister in GetConfigRegisterHierarchy(highestToLowest))
foreach (ConfigRegister configRegister in GetConfigRegisterHierarchy(highestToLowest))
{
if (configRegister is MultiAdminConfig config)
configHierarchy.Add(config);
Expand Down
54 changes: 53 additions & 1 deletion MultiAdmin/ConsoleTools/ColoredConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace MultiAdmin.ConsoleTools
{
public class ColoredConsole
public static class ColoredConsole
{
public static readonly object WriteLock = new object();

Expand Down Expand Up @@ -94,6 +94,58 @@ public ColoredMessage(string text, ConsoleColor? textColor = null, ConsoleColor?
this.backgroundColor = backgroundColor;
}

public bool Equals(ColoredMessage other)
{
return string.Equals(text, other.text) && textColor == other.textColor && backgroundColor == other.backgroundColor;
}

public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}

if (ReferenceEquals(this, obj))
{
return true;
}

if (obj.GetType() != GetType())
{
return false;
}

return Equals((ColoredMessage)obj);
}

public override int GetHashCode()
{
unchecked
{
int hashCode = text != null ? text.GetHashCode() : 0;
hashCode = (hashCode * 397) ^ textColor.GetHashCode();
hashCode = (hashCode * 397) ^ backgroundColor.GetHashCode();
return hashCode;
}
}

public static bool operator ==(ColoredMessage firstMessage, ColoredMessage secondMessage)
{
if (ReferenceEquals(firstMessage, secondMessage))
return true;

if (ReferenceEquals(firstMessage, null) || ReferenceEquals(secondMessage, null))
return false;

return firstMessage.Equals(secondMessage);
}

public static bool operator !=(ColoredMessage firstMessage, ColoredMessage secondMessage)
{
return !(firstMessage == secondMessage);
}

public override string ToString()
{
return text;
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions MultiAdmin/Features/ConfigReload.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Linq;
using MultiAdmin.Features.Attributes;
using MultiAdmin.Utility;

namespace MultiAdmin.Features
{
Expand Down Expand Up @@ -27,7 +27,7 @@ public string GetUsage()

public void OnCall(string[] args)
{
if (!args.Any() || !args[0].ToLower().Equals("reload")) return;
if (args.IsNullOrEmpty() || !args[0].ToLower().Equals("reload")) return;

Server.Write("Reloading configs...");

Expand All @@ -48,7 +48,7 @@ public override string GetFeatureDescription()

public override string GetFeatureName()
{
return "Config reload";
return "Config Reload";
}

public override void Init()
Expand Down
4 changes: 2 additions & 2 deletions MultiAdmin/Features/FolderCopyRoundQueue.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Linq;
using MultiAdmin.Features.Attributes;
using MultiAdmin.Utility;

namespace MultiAdmin.Features
{
Expand All @@ -17,7 +17,7 @@ public FileCopyRoundQueue(Server server) : base(server)
{
}

public bool HasValidQueue => queue != null && queue.Any();
public bool HasValidQueue => !queue.IsNullOrEmpty();

public void OnRoundEnd()
{
Expand Down
20 changes: 16 additions & 4 deletions MultiAdmin/Features/GithubGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using MultiAdmin.Config;
using MultiAdmin.Config.ConfigHandler;
using MultiAdmin.Features.Attributes;
using MultiAdmin.Utility;

namespace MultiAdmin.Features
{
Expand Down Expand Up @@ -35,15 +35,15 @@ public string GetUsage()

public void OnCall(string[] args)
{
if (!args.Any())
if (args.IsEmpty())
{
Server.Write("You must specify the location of the file.");
return;
}

string dir = string.Join(" ", args);

List<string> lines = new List<string> {"# MultiAdmin", string.Empty, "## Features"};
List<string> lines = new List<string> {"# MultiAdmin", string.Empty, "## Features", string.Empty};

foreach (Feature feature in Server.features)
{
Expand Down Expand Up @@ -80,7 +80,7 @@ public void OnCall(string[] args)

case ConfigEntry<string[]> config:
{
stringBuilder.Append($"String List{ColumnSeparator}{(!config.Default?.Any() ?? true ? EmptyIndicator : string.Join(", ", config.Default))}");
stringBuilder.Append($"String List{ColumnSeparator}{(config.Default?.IsEmpty() ?? true ? EmptyIndicator : string.Join(", ", config.Default))}");
break;
}

Expand All @@ -102,6 +102,18 @@ public void OnCall(string[] args)
break;
}

case ConfigEntry<double> config:
{
stringBuilder.Append($"Double{ColumnSeparator}{config.Default}");
break;
}

case ConfigEntry<decimal> config:
{
stringBuilder.Append($"Decimal{ColumnSeparator}{config.Default}");
break;
}

case ConfigEntry<bool> config:
{
stringBuilder.Append($"Boolean{ColumnSeparator}{config.Default}");
Expand Down
4 changes: 2 additions & 2 deletions MultiAdmin/Features/HelpCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MultiAdmin.Features.Attributes;
using MultiAdmin.Utility;

namespace MultiAdmin.Features
{
Expand Down Expand Up @@ -29,7 +29,7 @@ public void OnCall(string[] args)
foreach (KeyValuePair<string, ICommand> command in Server.commands)
{
string usage = command.Value.GetUsage();
if (usage.Any()) usage = " " + usage;
if (!usage.IsEmpty()) usage = " " + usage;
string output = $"{command.Key.ToUpper()}{usage}: {command.Value.GetCommandDescription()}";
helpOutput.Add(output);
}
Expand Down
Loading

0 comments on commit eced3a1

Please sign in to comment.