Use IOException to dismiss clients sending trash.

This commit is contained in:
Ray Koopa 2019-01-18 20:51:14 +01:00
parent 519a01b6f6
commit 899c031840
2 changed files with 6 additions and 24 deletions

View File

@ -133,7 +133,7 @@ namespace Syroot.Worms.Mgame.GameServer.Packets
return ReceiveOWServerPacket(tag); 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. catch (ObjectDisposedException) { return null; } // The underlying stream closed.
} }
@ -174,11 +174,11 @@ namespace Syroot.Worms.Mgame.GameServer.Packets
{ {
// Read head. // Read head.
if (!_tcpStream.ReadBoolean()) if (!_tcpStream.ReadBoolean())
throw new PacketException("Unexpected WWPA packet head2."); throw new IOException("Unexpected WWPA packet head2.");
if (_tcpStream.ReadBoolean()) if (_tcpStream.ReadBoolean())
throw new PacketException("Unexpected WWPA packet head3."); throw new IOException("Unexpected WWPA packet head3.");
if (!_tcpStream.ReadBoolean()) if (!_tcpStream.ReadBoolean())
throw new PacketException("Unexpected WWPA packet bIsCompressed."); throw new IOException("Unexpected WWPA packet bIsCompressed.");
int decompressedSize = _tcpStream.ReadUInt16(); int decompressedSize = _tcpStream.ReadUInt16();
int compressedSize = _tcpStream.ReadInt32(); int compressedSize = _tcpStream.ReadInt32();
int idxPacket = _tcpStream.ReadInt32(); int idxPacket = _tcpStream.ReadInt32();
@ -186,9 +186,9 @@ namespace Syroot.Worms.Mgame.GameServer.Packets
byte[] compressedData = _tcpStream.ReadBytes(compressedSize); byte[] compressedData = _tcpStream.ReadBytes(compressedSize);
// Read tail. // Read tail.
if (_tcpStream.ReadInt32() != idxPacket) if (_tcpStream.ReadInt32() != idxPacket)
throw new PacketException("Invalid WWPA packet index."); throw new IOException("Invalid WWPA packet index.");
if (_tcpStream.ReadUInt16() != _wwpaTagEnd) 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. // Instantiate, deserialize, and return packet.
SpanReader reader = new SpanReader(PacketCompression.Decompress(compressedData), encoding: Encodings.Win949); SpanReader reader = new SpanReader(PacketCompression.Decompress(compressedData), encoding: Encodings.Win949);

View File

@ -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) { }
}
}