Skip to content

Commit

Permalink
Packet safety in extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
sirjonasxx committed Dec 27, 2022
1 parent 76ce696 commit f10b847
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,18 @@ public void flagsRequest() {

@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())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected void onParentSet() {

extensionHandler.getObservable().addListener(e -> e.getExtensionObservable().addListener(new ExtensionListener() {
@Override
protected void log(String text) {
public void log(String text) {
extensionLogger.log(text);
}
}));
Expand Down

0 comments on commit f10b847

Please sign in to comment.