Packet safety in extensions

This commit is contained in:
sirjonasxx 2022-12-27 23:54:59 +01:00
parent 76ce696186
commit f10b847830
3 changed files with 11 additions and 4 deletions

View File

@ -200,11 +200,18 @@ public class ExtensionHandler {
@Override
public void sendMessage(HMessage.Direction direction, HPacket packet) {
boolean success;
if (direction == HMessage.Direction.TOCLIENT) {
hConnection.sendToClient(packet);
success = hConnection.sendToClient(packet);
}
else {
hConnection.sendToServer(packet);
success = hConnection.sendToServer(packet);
}
if (!success && hConnection.isPacketSendingAllowed(direction, packet) && !hConnection.isPacketSendingSafe(direction, packet)) {
extension.getExtensionObservable().fireEvent(extensionListener ->
extensionListener.log(String.format("Extension %s attempted to send an unsafe packet, but had no permission",
extension.getTitle())));
}
}

View File

@ -9,7 +9,7 @@ public abstract class ExtensionListener {
protected void manipulatedPacket(HMessage hMessage) {}
protected void flagsRequest() {}
protected void sendMessage(HMessage.Direction direction, HPacket packet) {}
protected void log(String text) {}
public void log(String text) {}
protected void hasClosed() {}
protected void packetToStringRequest(HPacket packet) {}

View File

@ -75,7 +75,7 @@ public class ExtensionsController extends SubForm {
extensionHandler.getObservable().addListener(e -> e.getExtensionObservable().addListener(new ExtensionListener() {
@Override
protected void log(String text) {
public void log(String text) {
extensionLogger.log(text);
}
}));