Skip to content

Commit

Permalink
A little bit more info on local server
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Nov 8, 2023
1 parent 4e56685 commit 1bf6745
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions CentrED/UI/Windows/ServerWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text;
using System.Numerics;
using System.Text;
using CentrED.Server;
using ImGuiNET;

Expand All @@ -8,7 +9,9 @@ public class ServerWindow : Window {
public ServerWindow(UIManager uiManager) : base(uiManager) { }
public override string Name => "Local Server";
private string _configPath = Config.ServerConfigPath;
private StreamReader? _logReader;
private Vector4 _statusColor = UIManager.Red;
private string _statusText = "Stopped"
; private StreamReader? _logReader;
private StringBuilder _log = new();

public override void Draw() {
Expand Down Expand Up @@ -45,19 +48,32 @@ public override void Draw() {

_log.Clear();
Config.ServerConfigPath = _configPath;
CentrED.Server = new CEDServer(new[] { _configPath }, new StreamWriter(File.Open("cedserver.log", FileMode.Create, FileAccess.Write, FileShare.ReadWrite)){AutoFlush = true});

new Task(() => {
try {
_statusColor = UIManager.Blue;
_statusText = "Starting";
var logWriter =
new StreamWriter(File.Open("cedserver.log", FileMode.Create, FileAccess.Write,
FileShare.ReadWrite)) { AutoFlush = true };
_logReader = new StreamReader(File.Open("cedserver.log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
CentrED.Server = new CEDServer(new[] { _configPath }, logWriter);
_statusColor = UIManager.Green;
_statusText = "Running";

CentrED.Server.Run();
}
catch (Exception e) {
Console.WriteLine("Server stopped");
Console.WriteLine(e);
_statusColor = UIManager.Red;
_statusText = "Stopped";
}
}).Start();
_logReader = new StreamReader(File.Open("cedserver.log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite));
}
}
ImGui.SameLine();
ImGui.TextColored(_statusColor, _statusText);

ImGui.Separator();
ImGui.Text("Server Log:");
Expand Down

0 comments on commit 1bf6745

Please sign in to comment.