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

@@ -2,6 +2,7 @@ package net.server.handlers.login;
import client.Client;
import net.AbstractPacketHandler;
import net.netty.GameViolationException;
import net.packet.InPacket;
import tools.PacketCreator;
@@ -16,11 +17,11 @@ public final class AcceptToSHandler extends AbstractPacketHandler {
}
@Override
public final void handlePacket(InPacket p, Client c) {
public void handlePacket(InPacket p, Client c) {
if (p.available() == 0 || p.readByte() != 1 || c.acceptToS()) {
c.disconnect(false, false);//Client dc's but just because I am cool I do this (:
return;
throw new GameViolationException("ToS not accepted");
}
if (c.finishLogin() == 0) {
c.sendPacket(PacketCreator.getAuthSuccess(c));
} else {

View File

@@ -27,6 +27,7 @@ import client.creator.novice.LegendCreator;
import client.creator.novice.NoblesseCreator;
import constants.id.ItemId;
import net.AbstractPacketHandler;
import net.netty.GameViolationException;
import net.packet.InPacket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -80,8 +81,7 @@ public final class CreateCharHandler extends AbstractPacketHandler {
for (int item : items) {
if (!isLegal(item)) {
log.warn("Owner from account {} tried to packet edit in chr creation", c.getAccountName());
c.disconnect(true, false);
return;
throw new GameViolationException("Create character with invalid equip");
}
}
@@ -105,4 +105,4 @@ public final class CreateCharHandler extends AbstractPacketHandler {
c.sendPacket(PacketCreator.deleteCharResponse(0, 9));
}
}
}
}