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:
@@ -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 {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user