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 {