Skip to content

Commit

Permalink
Add AppDataPath, reuse Stopwatch, & cleanup all
Browse files Browse the repository at this point in the history
  • Loading branch information
Dankrushen committed Dec 1, 2019
1 parent 999c6d7 commit 4dd2e2a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 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
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 = 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

0 comments on commit 4dd2e2a

Please sign in to comment.