mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-13 01:16:46 -04:00
handling of broken packets
This commit is contained in:
parent
11f95213d3
commit
3d5a1249da
@ -136,29 +136,32 @@ public class Network {
|
|||||||
while (binQueueIn.size() > 0) {
|
while (binQueueIn.size() > 0) {
|
||||||
|
|
||||||
// read data
|
// read data
|
||||||
byte[] raw = binQueueIn.get(0);
|
byte[] decrypted = binQueueIn.get(0);
|
||||||
InPacketBuffer inPacketBuffer;
|
InPacketBuffer inPacketBuffer;
|
||||||
if (encryptionEnabled) {
|
if (encryptionEnabled) {
|
||||||
// decrypt
|
// decrypt
|
||||||
byte[] decrypted = cipherDecrypt.update(raw);
|
decrypted = cipherDecrypt.update(decrypted);
|
||||||
inPacketBuffer = new InPacketBuffer(decrypted);
|
|
||||||
} else {
|
|
||||||
inPacketBuffer = new InPacketBuffer(raw);
|
|
||||||
}
|
|
||||||
Packets.Clientbound p = connection.getVersion().getProtocol().getPacketByCommand(connection.getConnectionState(), inPacketBuffer.getCommand());
|
|
||||||
Class<? extends ClientboundPacket> clazz = Protocol.getPacketByPacket(p);
|
|
||||||
|
|
||||||
if (clazz == null) {
|
|
||||||
Log.warn(String.format("[IN] Unknown packet with command 0x%x (%s)", inPacketBuffer.getCommand(), ((p != null) ? p.name() : "UNKNOWN")));
|
|
||||||
binQueueIn.remove(0);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
ClientboundPacket packet = clazz.getConstructor().newInstance();
|
inPacketBuffer = new InPacketBuffer(decrypted);
|
||||||
packet.read(inPacketBuffer, connection.getVersion());
|
Packets.Clientbound p = connection.getVersion().getProtocol().getPacketByCommand(connection.getConnectionState(), inPacketBuffer.getCommand());
|
||||||
connection.handle(packet);
|
Class<? extends ClientboundPacket> clazz = Protocol.getPacketByPacket(p);
|
||||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
|
||||||
// safety first, but will not occur
|
if (clazz == null) {
|
||||||
|
Log.warn(String.format("[IN] Unknown packet with command 0x%x (%s)", inPacketBuffer.getCommand(), ((p != null) ? p.name() : "UNKNOWN")));
|
||||||
|
binQueueIn.remove(0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ClientboundPacket packet = clazz.getConstructor().newInstance();
|
||||||
|
packet.read(inPacketBuffer, connection.getVersion());
|
||||||
|
connection.handle(packet);
|
||||||
|
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
|
||||||
|
// safety first, but will not occur
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
Log.protocol("Received broken packet!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user