From 30cbc54ecae0f077cfb0994ed368f659631a0a13 Mon Sep 17 00:00:00 2001 From: Spirtix Date: Sat, 9 Sep 2023 23:28:19 +0200 Subject: [PATCH] more fixes --- src/Core/Client.cs | 7 ++++++- src/Server.cs | 11 ++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Core/Client.cs b/src/Core/Client.cs index 08e09ec..4c17fb8 100644 --- a/src/Core/Client.cs +++ b/src/Core/Client.cs @@ -35,7 +35,12 @@ public class Client { } public void Send(NetworkPacket packet) { - socket.Send(packet.SendData); + try { + socket.Send(packet.SendData); + } catch (SocketException) { + LeaveRoom(); + SheduleDisconnect(); + } } public void LeaveRoom() { diff --git a/src/Server.cs b/src/Server.cs index fefb45a..ac8fa32 100644 --- a/src/Server.cs +++ b/src/Server.cs @@ -31,8 +31,9 @@ public class Server { listener.Listen(100); while (true) { Socket handler = await listener.AcceptAsync(); + handler.SendTimeout = 200; Console.WriteLine($"New connection from {((IPEndPoint)handler.RemoteEndPoint!).Address}"); - _ = HandleClient(handler); + _ = Task.Run(() => HandleClient(handler)); } } @@ -45,7 +46,7 @@ public class Server { while (client.TryGetNextPacket(out NetworkPacket packet)) networkObjects.Add(packet.GetObject()); - _ = Task.Run(() => HandleObjects(networkObjects, client)); + HandleObjects(networkObjects, client); } } finally { try { @@ -62,14 +63,14 @@ public class Server { short commandId = obj.Get("a"); ICommandHandler handler; if (commandId != 13) { - Console.WriteLine($"System command: {commandId} IID: {client.ClientID}"); + if (commandId == 0 || commandId == 1) + Console.WriteLine($"System command: {commandId} IID: {client.ClientID}"); handler = moduleManager.GetCommandHandler(commandId); } else handler = moduleManager.GetCommandHandler(obj.Get("p").Get("c")); handler.Handle(client, obj.Get("p")); } catch (Exception ex) { - if (!ex.Message.Contains("ID 7")) // Missing command 7 flooding the log - Console.WriteLine($"Exception IID: {client.ClientID} - {ex}"); + Console.WriteLine($"Exception IID: {client.ClientID} - {ex}"); } } }