Skip to content

Commit

Permalink
Fix server stalling after CLI invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden committed Oct 1, 2023
1 parent 50be1e8 commit 3843476
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Refresh.GameServer/CommandLineManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void StartWithOptions(Options options)

if (options.GenerateDocumentation)
{
DocumentationService service = new(new Logger());
DocumentationService service = new(this._server.Logger);
service.Initialize();

string json = JsonConvert.SerializeObject(service.Documentation, Formatting.Indented);
Expand Down
19 changes: 13 additions & 6 deletions Refresh.GameServer/RefreshGameServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
namespace Refresh.GameServer;

[SuppressMessage("ReSharper", "InconsistentNaming")]
public class RefreshGameServer
public class RefreshGameServer : IDisposable
{
protected readonly Logger _logger;
public readonly Logger Logger;

protected readonly BunkumHttpServer _server;
protected WorkerManager? _workerManager;
Expand Down Expand Up @@ -61,8 +61,8 @@ public RefreshGameServer(
#endif
};

this._logger = new Logger(logConfig);
this._logger.LogDebug(RefreshContext.Startup, "Successfully initialized " + this.GetType().Name);
this.Logger = new Logger(logConfig);
this.Logger.LogDebug(RefreshContext.Startup, "Successfully initialized " + this.GetType().Name);

this._databaseProvider = databaseProvider.Invoke();
this._dataStore = dataStore;
Expand All @@ -74,7 +74,7 @@ public RefreshGameServer(
GameDatabaseProvider provider = databaseProvider.Invoke();

this._workerManager?.Stop();
this._workerManager = new WorkerManager(this._logger, this._dataStore, provider);
this._workerManager = new WorkerManager(this.Logger, this._dataStore, provider);

this.SetupConfiguration();
authProvider ??= new GameAuthenticationProvider(this._config!);
Expand Down Expand Up @@ -171,7 +171,7 @@ public virtual void Start()

if (this._config!.MaintenanceMode)
{
this._logger.LogWarning(RefreshContext.Startup, "The server is currently in maintenance mode! " +
this.Logger.LogWarning(RefreshContext.Startup, "The server is currently in maintenance mode! " +
"Only administrators will be able to log in and interact with the server.");
}
}
Expand Down Expand Up @@ -242,4 +242,11 @@ public void SetAdminFromEmailAddress(string emailAddress)

context.SetUserRole(user, GameUserRole.Admin);
}

public void Dispose()
{
this.Logger.Dispose();
this._databaseProvider.Dispose();
GC.SuppressFinalize(this);
}
}
4 changes: 3 additions & 1 deletion Refresh.GameServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
Console.WriteLine("Starting Refresh with NuGet Bunkum");
#endif

RefreshGameServer server = new();
using RefreshGameServer server = new();

if (args.Length > 0)
{
CommandLineManager cli = new(server);
cli.StartWithArgs(args);

server.Dispose();
return;
}

Expand Down
2 changes: 1 addition & 1 deletion Refresh.GameServer/Workers/WorkerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private bool RunWorkCycle()
if (workerDidWork) didWork = true;
}

// this._logger.LogTrace(RefreshContext.Worker, "Ran work cycle, didWork: " + didWork);
// this.Logger.LogTrace(RefreshContext.Worker, "Ran work cycle, didWork: " + didWork);
return didWork;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TestRefreshGameServer : RefreshGameServer
{}

public BunkumHttpServer Server => this._server;
public Logger Logger => this._logger;
public Logger Logger => base.Logger;

protected override void SetupConfiguration()
{
Expand Down

0 comments on commit 3843476

Please sign in to comment.