From 899c03184002530ec25b027d52d84ae49822329d Mon Sep 17 00:00:00 2001 From: Ray Koopa Date: Fri, 18 Jan 2019 20:51:14 +0100 Subject: [PATCH] Use IOException to dismiss clients sending trash. --- .../Packets/AppConnection.cs | 12 ++++++------ .../Packets/PacketException.cs | 18 ------------------ 2 files changed, 6 insertions(+), 24 deletions(-) delete mode 100644 src/Syroot.Worms.Mgame.GameServer/Packets/PacketException.cs diff --git a/src/Syroot.Worms.Mgame.GameServer/Packets/AppConnection.cs b/src/Syroot.Worms.Mgame.GameServer/Packets/AppConnection.cs index d043dd9..99ba478 100644 --- a/src/Syroot.Worms.Mgame.GameServer/Packets/AppConnection.cs +++ b/src/Syroot.Worms.Mgame.GameServer/Packets/AppConnection.cs @@ -133,7 +133,7 @@ namespace Syroot.Worms.Mgame.GameServer.Packets return ReceiveOWServerPacket(tag); } } - catch (IOException) { return null; } // The underlying socket closed. + catch (IOException) { return null; } // The underlying socket closed or sent invalid data. catch (ObjectDisposedException) { return null; } // The underlying stream closed. } @@ -174,11 +174,11 @@ namespace Syroot.Worms.Mgame.GameServer.Packets { // Read head. if (!_tcpStream.ReadBoolean()) - throw new PacketException("Unexpected WWPA packet head2."); + throw new IOException("Unexpected WWPA packet head2."); if (_tcpStream.ReadBoolean()) - throw new PacketException("Unexpected WWPA packet head3."); + throw new IOException("Unexpected WWPA packet head3."); if (!_tcpStream.ReadBoolean()) - throw new PacketException("Unexpected WWPA packet bIsCompressed."); + throw new IOException("Unexpected WWPA packet bIsCompressed."); int decompressedSize = _tcpStream.ReadUInt16(); int compressedSize = _tcpStream.ReadInt32(); int idxPacket = _tcpStream.ReadInt32(); @@ -186,9 +186,9 @@ namespace Syroot.Worms.Mgame.GameServer.Packets byte[] compressedData = _tcpStream.ReadBytes(compressedSize); // Read tail. if (_tcpStream.ReadInt32() != idxPacket) - throw new PacketException("Invalid WWPA packet index."); + throw new IOException("Invalid WWPA packet index."); if (_tcpStream.ReadUInt16() != _wwpaTagEnd) - throw new PacketException("Invalid WWPA packet end tag."); + throw new IOException("Invalid WWPA packet end tag."); // Instantiate, deserialize, and return packet. SpanReader reader = new SpanReader(PacketCompression.Decompress(compressedData), encoding: Encodings.Win949); diff --git a/src/Syroot.Worms.Mgame.GameServer/Packets/PacketException.cs b/src/Syroot.Worms.Mgame.GameServer/Packets/PacketException.cs deleted file mode 100644 index 1bedf70..0000000 --- a/src/Syroot.Worms.Mgame.GameServer/Packets/PacketException.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Runtime.Serialization; - -namespace Syroot.Worms.Mgame.GameServer.Packets -{ - public class PacketException : Exception - { - // ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------ - - public PacketException() { } - - public PacketException(string message) : base(message) { } - - public PacketException(string message, Exception innerException) : base(message, innerException) { } - - protected PacketException(SerializationInfo info, StreamingContext context) : base(info, context) { } - } -}