Disconnect client by throwing exception in handler

This makes it easier to add checks in handlers, which should improve security over time.
I think this approach is more readable and testable than calling Client#disconnect straight up,
while it also decentralizes the handling.
This commit is contained in:
P0nk
2023-08-06 15:48:49 +02:00
parent e9819fac87
commit 2686b2b02d
36 changed files with 180 additions and 106 deletions

View File

@@ -26,6 +26,7 @@ import client.Client;
import client.SkillMacro;
import client.autoban.AutobanFactory;
import net.AbstractPacketHandler;
import net.netty.GameViolationException;
import net.packet.InPacket;
public final class SkillMacroHandler extends AbstractPacketHandler {
@@ -42,8 +43,7 @@ public final class SkillMacroHandler extends AbstractPacketHandler {
String name = p.readString();
if (name.length() > 12) {
AutobanFactory.PACKET_EDIT.alert(chr, "Invalid name length " + name + " (" + name.length() + ") for skill macro.");
c.disconnect(false, false);
break;
throw GameViolationException.textLength(name);
}
int shout = p.readByte();