Skip to content

Commit

Permalink
Merge pull request #223 from Grover-c13/3.2.5
Browse files Browse the repository at this point in the history
MultiAdmin 3.2.5
  • Loading branch information
Dankrushen authored Jan 2, 2020
2 parents 999c6d7 + 96cc592 commit c2861bc
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 31 deletions.
4 changes: 4 additions & 0 deletions MultiAdmin/Config/MultiAdminConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class MultiAdminConfig : InheritableConfigRegister
new ConfigEntry<string>("config_location", "", false,
"Config Location", "The default location for the game to use for storing configuration files (a directory)");

public ConfigEntry<string> AppDataLocation { get; } =
new ConfigEntry<string>("appdata_location", "",
"AppData Location", "The location for the game to use for AppData (a directory)");

public ConfigEntry<bool> DisableConfigValidation { get; } =
new ConfigEntry<bool>("disable_config_validation", false,
"Disable Config Validation", "Disable the config validator");
Expand Down
18 changes: 9 additions & 9 deletions MultiAdmin/EventInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,47 @@ public interface IMAEvent
{
}

public interface IEventServerPreStart: IMAEvent
public interface IEventServerPreStart : IMAEvent
{
void OnServerPreStart();
}

public interface IEventServerStart: IMAEvent
public interface IEventServerStart : IMAEvent
{
void OnServerStart();
}

public interface IEventServerStop: IMAEvent
public interface IEventServerStop : IMAEvent
{
void OnServerStop();
}

public interface IEventRoundEnd: IMAEvent
public interface IEventRoundEnd : IMAEvent
{
void OnRoundEnd();
}

public interface IEventWaitingForPlayers: IMAEvent
public interface IEventWaitingForPlayers : IMAEvent
{
void OnWaitingForPlayers();
}

public interface IEventRoundStart: IMAEvent
public interface IEventRoundStart : IMAEvent
{
void OnRoundStart();
}

public interface IEventCrash: IMAEvent
public interface IEventCrash : IMAEvent
{
void OnCrash();
}

public interface IEventTick: IMAEvent
public interface IEventTick : IMAEvent
{
void OnTick();
}

public interface IServerMod: IMAEvent
public interface IServerMod : IMAEvent
{
}

Expand Down
2 changes: 2 additions & 0 deletions MultiAdmin/Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ namespace MultiAdmin
{
public static class Exceptions
{
[Serializable]
public class ServerNotRunningException : Exception
{
public ServerNotRunningException() : base("The server is not running")
{
}
}

[Serializable]
public class ServerAlreadyRunningException : Exception
{
public ServerAlreadyRunningException() : base("The server is already running")
Expand Down
1 change: 0 additions & 1 deletion MultiAdmin/Features/RestartRoundCounter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using MultiAdmin.Features.Attributes;

namespace MultiAdmin.Features
Expand Down
2 changes: 1 addition & 1 deletion MultiAdmin/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace MultiAdmin
{
public static class Program
{
public const string MaVersion = "3.2.4.3";
public const string MaVersion = "3.2.5.1";
public const string RecommendedMonoVersion = "5.18";

private static readonly List<Server> InstantiatedServers = new List<Server>();
Expand Down
12 changes: 10 additions & 2 deletions MultiAdmin/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,11 @@ private set

private void MainLoop()
{
Stopwatch timer = new Stopwatch();
while (IsGameProcessRunning)
{
Stopwatch timer = Stopwatch.StartNew();
timer.Reset();
timer.Start();

foreach (IEventTick tickEvent in tick) tickEvent.OnTick();

Expand Down Expand Up @@ -345,13 +347,19 @@ public void StartServer(bool restartOnCrash = true)
scpslArgs.Add($"-configpath \"{configLocation}\"");
}

string appDataPath = Utils.GetFullPathSafe(ServerConfig.AppDataLocation.Value);
if (!string.IsNullOrEmpty(appDataPath))
{
scpslArgs.Add($"-appdatapath \"{appDataPath}\"");
}

scpslArgs.RemoveAll(string.IsNullOrEmpty);

string argsString = string.Join(" ", scpslArgs);

Write($"Starting server with the following parameters:\n{scpslExe} {argsString}");

ProcessStartInfo startInfo = new ProcessStartInfo(scpslExe, argsString);
ProcessStartInfo startInfo = new ProcessStartInfo(scpslExe, argsString) {CreateNoWindow = true};

ForEachHandler<IEventServerPreStart>(eventPreStart => eventPreStart.OnServerPreStart());

Expand Down
11 changes: 9 additions & 2 deletions MultiAdmin/ServerIO/StringSections.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using MultiAdmin.ConsoleTools;
Expand Down Expand Up @@ -45,6 +46,12 @@ public StringSections(StringSection[] sections)

public static StringSections FromString(string fullString, int sectionLength, ColoredMessage leftIndicator = null, ColoredMessage rightIndicator = null, ColoredMessage sectionBase = null)
{
int rightIndicatorLength = rightIndicator?.Length ?? 0;
int totalIndicatorLength = (leftIndicator?.Length ?? 0) + rightIndicatorLength;

if (fullString.Length > sectionLength && sectionLength <= totalIndicatorLength)
throw new ArgumentException($"{nameof(sectionLength)} must be greater than the total length of {nameof(leftIndicator)} and {nameof(rightIndicator)}", nameof(sectionLength));

List<StringSection> sections = new List<StringSection>();

if (string.IsNullOrEmpty(fullString))
Expand All @@ -65,12 +72,12 @@ public static StringSections FromString(string fullString, int sectionLength, Co
curSecBuilder.Append(fullString[i]);

// If the section is less than the smallest possible section size, skip processing
if (curSecBuilder.Length < sectionLength - ((leftIndicator?.Length ?? 0) + (rightIndicator?.Length ?? 0))) continue;
if (curSecBuilder.Length < sectionLength - totalIndicatorLength) continue;

// Decide what the left indicator text should be accounting for the leftmost section
ColoredMessage leftIndicatorSection = sections.Count > 0 ? leftIndicator : null;
// Decide what the right indicator text should be accounting for the rightmost section
ColoredMessage rightIndicatorSection = i < fullString.Length - (1 + (rightIndicator?.Length ?? 0)) ? rightIndicator : null;
ColoredMessage rightIndicatorSection = i < fullString.Length - (1 + rightIndicatorLength) ? rightIndicator : null;

// Check the section length against the final section length
if (curSecBuilder.Length >= sectionLength - ((leftIndicatorSection?.Length ?? 0) + (rightIndicatorSection?.Length ?? 0)))
Expand Down
65 changes: 49 additions & 16 deletions MultiAdminTests/ServerIO/StringSectionsTests.cs
Original file line number Diff line number Diff line change
@@ -1,37 +1,70 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MultiAdmin.ConsoleTools;
using MultiAdmin.ServerIO;

namespace MultiAdminTests.ServerIO
{
[TestClass]
public class StringSectionsTests
{
private struct FromStringTemplate
{
public readonly string testString;
public readonly string[] expectedSections;

public readonly int sectionLength;
public readonly ColoredMessage leftIndictator;
public readonly ColoredMessage rightIndictator;

public FromStringTemplate(string testString, string[] expectedSections, int sectionLength, ColoredMessage leftIndictator = null, ColoredMessage rightIndictator = null)
{
this.testString = testString;
this.expectedSections = expectedSections;

this.sectionLength = sectionLength;
this.leftIndictator = leftIndictator;
this.rightIndictator = rightIndictator;
}
}

[TestMethod]
public void FromStringTest()
{
string[] expectedSections =
try
{
"te",
"st",
" s",
"tr",
"in",
"g"
StringSections.FromString("test string", 2, new ColoredMessage("."), new ColoredMessage("."));
Assert.Fail("This case should not be allowed, no further characters can be output because of the prefix and suffix");
}
catch (ArgumentException)
{
// Expected behaviour
}

FromStringTemplate[] sectionTests =
{
new FromStringTemplate("test string", new string[] {"te", "st", " s", "tr", "in", "g"}, 2),
new FromStringTemplate("test string", new string[] {"tes..", ".t ..", ".st..", ".ring"}, 5, new ColoredMessage("."), new ColoredMessage(".."))
};

StringSections sections = StringSections.FromString("test string", 2);
for (int i = 0; i < sectionTests.Length; i++)
{
FromStringTemplate sectionTest = sectionTests[i];

StringSections sections = StringSections.FromString(sectionTest.testString, sectionTest.sectionLength, sectionTest.leftIndictator, sectionTest.rightIndictator);

Assert.IsNotNull(sections);
Assert.IsNotNull(sections.Sections);
Assert.IsNotNull(sections);
Assert.IsNotNull(sections.Sections);

Assert.IsTrue(sections.Sections.Length == expectedSections.Length, $"Expected sections length \"{expectedSections.Length}\", got \"{sections.Sections.Length}\"");
Assert.IsTrue(sections.Sections.Length == sectionTest.expectedSections.Length, $"Failed at index {i}: Expected sections length \"{sectionTest.expectedSections.Length}\", got \"{sections.Sections.Length}\"");

for (int i = 0; i < expectedSections.Length; i++)
{
string expected = expectedSections[i];
string result = sections.Sections[i].Text?.text;
for (int j = 0; j < sectionTest.expectedSections.Length; j++)
{
string expected = sectionTest.expectedSections[j];
string result = sections.Sections[j].Section.GetText();

Assert.AreEqual(expected, result, $"Failed at section index {i}: Expected section text to be \"{expected ?? "null"}\", got \"{result ?? "null"}\"");
Assert.AreEqual(expected, result, $"Failed at index {i}: Failed at section index {j}: Expected section text to be \"{expected ?? "null"}\", got \"{result ?? "null"}\"");
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Any configuration files within the directory defined by `servers_folder` will ha
Config Option | Value Type | Default Value | Description
--- | :---: | :---: | :------:
config_location | String | **Empty** | The default location for the game to use for storing configuration files (a directory)
appdata_location | String | **Empty** | The location for the game to use for AppData (a directory)
disable_config_validation | Boolean | False | Disable the config validator
share_non_configs | Boolean | True | Makes all files other than the config files store in AppData
multiadmin_nolog | Boolean | False | Disable logging to file
Expand Down

0 comments on commit c2861bc

Please sign in to comment.