Skip to content

Commit

Permalink
Improved handling of broken server connection
Browse files Browse the repository at this point in the history
  • Loading branch information
kaczy93 committed Sep 24, 2024
1 parent 3caf532 commit ef24629
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions CentrED/UI/Windows/ConnectWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ protected override void InternalDraw()
{
CEDGame.MapManager.Client.Disconnect();
CEDGame.MapManager.Reset();
Info = "Disconnected";
}
}
else
{
if (ImGui.Button("Connect") || ImGui.IsWindowFocused() && ImGui.IsKeyPressed(ImGuiKey.Enter))
{
CEDClient.ClearStatus();
CEDGame.MapManager.Reset();
_buttonDisabled = true;
new Task
Expand All @@ -166,8 +166,6 @@ protected override void InternalDraw()
CEDGame.MapManager.Load(_clientPath, _clientVersion);
Info = "Connecting";
CEDClient.Connect(_hostname, _port, _username, _password);
Info = CEDClient.Status;
InfoColor = CEDClient.Running ? UIManager.Green : UIManager.Red;
}
catch (SocketException)
{
Expand All @@ -188,6 +186,11 @@ protected override void InternalDraw()
).Start();
}
}
if (CEDClient.Status != "")
{
Info = CEDClient.Status;
InfoColor = CEDClient.Running ? UIManager.Green : UIManager.Red;
}
ImGui.EndDisabled();
ImGui.End();
}
Expand Down
6 changes: 6 additions & 0 deletions Client/CentrEDClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public string Status
internal set => _status = value;
}

public void ClearStatus()
{
Status = "";
}

public void Connect(string hostname, int port, string username, string password)
{
Password = password;
Expand Down Expand Up @@ -86,6 +91,7 @@ public void Disconnect()
Landscape = null;
Initialized = false;
Disconnected?.Invoke();
Status = "Disconnected";
}

public void Dispose()
Expand Down
1 change: 1 addition & 0 deletions Shared/Network/NetState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public bool Flush()
LogError("Flush Error");
Console.WriteLine(e);
Disconnect();
FlushPending = false;
}

return Running;
Expand Down

0 comments on commit ef24629

Please sign in to comment.