From 3fc813b2d8bc12d79e3a5ec6e39024c96d4bcb37 Mon Sep 17 00:00:00 2001 From: oldnapalm <38410858+oldnapalm@users.noreply.github.com> Date: Sun, 22 Oct 2023 17:14:50 -0300 Subject: [PATCH] Fix bug disconnecting from server --- RageCoop.Client/Main.cs | 3 ++- RageCoop.Client/Networking/Networking.cs | 14 +++++++------- RageCoop.Client/Sync/EntityPool.cs | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/RageCoop.Client/Main.cs b/RageCoop.Client/Main.cs index f1c6999..1a8f1a9 100644 --- a/RageCoop.Client/Main.cs +++ b/RageCoop.Client/Main.cs @@ -326,7 +326,8 @@ namespace RageCoop.Client WorldThread.Traffic(true); Function.Call(Hash.SET_ENABLE_VEHICLE_SLIPSTREAMING, false); CoopMenu.DisconnectedMenuSetting(); - GTA.UI.Notification.Show("~r~Disconnected: " + reason); + if (reason != "Abort") + GTA.UI.Notification.Show("~r~Disconnected: " + reason); LocalPlayerID = default; }); Memory.RestorePatches(); diff --git a/RageCoop.Client/Networking/Networking.cs b/RageCoop.Client/Networking/Networking.cs index 6feec5d..5b637c7 100644 --- a/RageCoop.Client/Networking/Networking.cs +++ b/RageCoop.Client/Networking/Networking.cs @@ -30,16 +30,16 @@ namespace RageCoop.Client public static void ToggleConnection(string address, string username = null, string password = null, PublicKey publicKey = null) { Menus.CoopMenu.Menu.Visible = false; - Peer?.Shutdown("Bye"); - if (IsOnServer) - { - // ? - } - else if (IsConnecting) + if (IsConnecting) { _publicKeyReceived.Set(); IsConnecting = false; - Notification.Show("Connection has been canceled"); + Main.QueueAction(() => Notification.Show("Connection has been canceled")); + Peer?.Shutdown("Bye"); + } + else if (IsOnServer) + { + Peer?.Shutdown("Bye"); } else { diff --git a/RageCoop.Client/Sync/EntityPool.cs b/RageCoop.Client/Sync/EntityPool.cs index b79922e..891e386 100644 --- a/RageCoop.Client/Sync/EntityPool.cs +++ b/RageCoop.Client/Sync/EntityPool.cs @@ -43,7 +43,7 @@ namespace RageCoop.Client #endregion public static void Cleanup(bool keepPlayer = true, bool keepMine = true) { - foreach (var ped in PedsByID.Values) + foreach (var ped in PedsByID.Values.ToArray()) { if ((keepPlayer && (ped.ID == Main.LocalPlayerID)) || (keepMine && (ped.OwnerID == Main.LocalPlayerID))) { continue; } RemovePed(ped.ID);