From ef2462928a967bd49b3d35199742e851afbe4fcc Mon Sep 17 00:00:00 2001 From: kaczy Date: Tue, 24 Sep 2024 09:00:58 +0200 Subject: [PATCH] Improved handling of broken server connection --- CentrED/UI/Windows/ConnectWindow.cs | 9 ++++++--- Client/CentrEDClient.cs | 6 ++++++ Shared/Network/NetState.cs | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CentrED/UI/Windows/ConnectWindow.cs b/CentrED/UI/Windows/ConnectWindow.cs index 8a215f7..74ac987 100644 --- a/CentrED/UI/Windows/ConnectWindow.cs +++ b/CentrED/UI/Windows/ConnectWindow.cs @@ -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 @@ -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) { @@ -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(); } diff --git a/Client/CentrEDClient.cs b/Client/CentrEDClient.cs index b6a78aa..fe7127c 100644 --- a/Client/CentrEDClient.cs +++ b/Client/CentrEDClient.cs @@ -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; @@ -86,6 +91,7 @@ public void Disconnect() Landscape = null; Initialized = false; Disconnected?.Invoke(); + Status = "Disconnected"; } public void Dispose() diff --git a/Shared/Network/NetState.cs b/Shared/Network/NetState.cs index d667732..efc9d71 100644 --- a/Shared/Network/NetState.cs +++ b/Shared/Network/NetState.cs @@ -156,6 +156,7 @@ public bool Flush() LogError("Flush Error"); Console.WriteLine(e); Disconnect(); + FlushPending = false; } return Running;