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:
@@ -35,6 +35,7 @@ import constants.id.ItemId;
|
||||
import constants.inventory.ItemConstants;
|
||||
import database.character.CharacterSaver;
|
||||
import net.AbstractPacketHandler;
|
||||
import net.netty.GameViolationException;
|
||||
import net.packet.InPacket;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -674,8 +675,7 @@ public final class PlayerInteractionHandler extends AbstractPacketHandler {
|
||||
if (slot >= shop.getItems().size() || slot < 0) {
|
||||
AutobanFactory.PACKET_EDIT.alert(chr, chr.getName() + " tried to packet edit with a player shop.");
|
||||
log.warn("Chr {} tried to remove item at slot {}", chr.getName(), slot);
|
||||
c.disconnect(true, false);
|
||||
return;
|
||||
throw new GameViolationException("Remove item from invalid slot in shop");
|
||||
}
|
||||
|
||||
shop.takeItemBack(slot, chr);
|
||||
@@ -740,9 +740,9 @@ public final class PlayerInteractionHandler extends AbstractPacketHandler {
|
||||
if (quantity < 1) {
|
||||
AutobanFactory.PACKET_EDIT.alert(chr, chr.getName() + " tried to packet edit with a hired merchant and or player shop.");
|
||||
log.warn("Chr {} tried to buy item {} with quantity {}", chr.getName(), itemid, quantity);
|
||||
c.disconnect(true, false);
|
||||
return;
|
||||
throw new GameViolationException("Buy item with invalid quantity");
|
||||
}
|
||||
|
||||
PlayerShop shop = chr.getPlayerShop();
|
||||
HiredMerchant merchant = chr.getHiredMerchant();
|
||||
if (shop != null && shop.isVisitor(chr)) {
|
||||
@@ -769,8 +769,7 @@ public final class PlayerInteractionHandler extends AbstractPacketHandler {
|
||||
if (slot >= merchant.getItems().size() || slot < 0) {
|
||||
AutobanFactory.PACKET_EDIT.alert(chr, chr.getName() + " tried to packet edit with a hired merchant.");
|
||||
log.warn("Chr {} tried to remove item at slot {}", chr.getName(), slot);
|
||||
c.disconnect(true, false);
|
||||
return;
|
||||
throw new GameViolationException("Withdraw item from merchant with invalid slot");
|
||||
}
|
||||
|
||||
merchant.takeItemBack(slot, chr, chrSaver);
|
||||
|
||||
Reference in New Issue
Block a user