From 62db70c1c4ab72ef9af056e6c02cc391f59a2ac8 Mon Sep 17 00:00:00 2001 From: devbeni Date: Sun, 14 Dec 2025 23:18:23 +0100 Subject: [PATCH] Refactor packet sending to use SendReliable method for improved reliability and remove unnecessary logging --- Packets/Network/ClientConnected.cs | 5 +---- Packets/Packet.cs | 34 +++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/Packets/Network/ClientConnected.cs b/Packets/Network/ClientConnected.cs index d4f39a7..43b083f 100644 --- a/Packets/Network/ClientConnected.cs +++ b/Packets/Network/ClientConnected.cs @@ -99,10 +99,7 @@ namespace KCM.Packets.Network chunkSize = chunk.Length, saveDataIndex = sent, totalChunks = chunks.Count - }.Send(clientId, Riptide.MessageSendMode.Reliable); - - Main.helper.Log(" "); - + }.SendReliable(clientId); packetsSent++; sent += chunk.Length; } diff --git a/Packets/Packet.cs b/Packets/Packet.cs index 0764cff..0fecfd6 100644 --- a/Packets/Packet.cs +++ b/Packets/Packet.cs @@ -20,9 +20,6 @@ namespace KCM.Packets if (!Main.clientSteamIds.ContainsKey(clientId)) return null; - - //Main.helper.Log($"SteamID: {Main.GetPlayerByClientID(clientId).steamId} for {clientId} ({Main.GetPlayerByClientID(clientId).id})"); - if (Main.kCPlayers.TryGetValue(Main.GetPlayerByClientID(clientId).steamId, out p)) return p; else @@ -107,6 +104,37 @@ namespace KCM.Packets } } + public void SendReliable(ushort toClient) + { + try + { + if (KCServer.IsRunning && toClient != 0) + { + KCServer.server.Send(PacketHandler.SerialisePacket(this), toClient, Riptide.MessageSendMode.Reliable); + } + } + catch (Exception ex) + { + Main.helper.Log($"Error sending reliable packet {packetId} {this.GetType().Name} from {clientId}"); + + Main.helper.Log("----------------------- Main exception -----------------------"); + Main.helper.Log(ex.ToString()); + Main.helper.Log("----------------------- Main message -----------------------"); + Main.helper.Log(ex.Message); + Main.helper.Log("----------------------- Main stacktrace -----------------------"); + Main.helper.Log(ex.StackTrace); + if (ex.InnerException != null) + { + Main.helper.Log("----------------------- Inner exception -----------------------"); + Main.helper.Log(ex.InnerException.ToString()); + Main.helper.Log("----------------------- Inner message -----------------------"); + Main.helper.Log(ex.InnerException.Message); + Main.helper.Log("----------------------- Inner stacktrace -----------------------"); + Main.helper.Log(ex.InnerException.StackTrace); + } + } + } + public abstract void HandlePacketServer(); public abstract void HandlePacketClient(); }