Skip to content

Commit

Permalink
improve tagparser crash
Browse files Browse the repository at this point in the history
  • Loading branch information
xGinko committed Feb 16, 2024
1 parent 84c7e68 commit d2c8671
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

public class TabCompleteListener extends PacketAdapter {

private static final String[] INVALID_SEQUENCES = new String[] { "@", "=", "[", "]", "{", "}", "nbt" };

public TabCompleteListener() {
super(AnarchyExploitFixes.getInstance(), ListenerPriority.HIGHEST, PacketType.Play.Client.TAB_COMPLETE);
}
Expand All @@ -23,22 +25,22 @@ protected void register() {

@Override
public void onPacketReceiving(PacketEvent event) {
if (event.isPlayerTemporary()) return;
if (event.isPlayerTemporary() || event.getPlayer().isOp()) return;

final PacketContainer packet = event.getPacket();

try {
final String command = packet.getStrings().read(0);
final String partialCommand = packet.getStrings().read(0);

if (command.contains("@") || command.contains("nbt")) {
if (!event.getPlayer().isOp()) {
for (String invalidSeq : INVALID_SEQUENCES) {
if (partialCommand.indexOf(invalidSeq) >= 0) {
event.setCancelled(true);
return;
}
}

if (command.length() > 64) {
final int index = command.indexOf(' ');
if (partialCommand.length() > 64) {
final int index = partialCommand.indexOf(' ');
if (index == -1 || index >= 64) {
event.setCancelled(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

public class TabCompleteListener extends PacketAdapter {

private static final String[] INVALID_SEQUENCES = new String[] { "@", "=", "[", "]", "{", "}", "nbt" };

public TabCompleteListener() {
super(AnarchyExploitFixes.getInstance(), ListenerPriority.HIGHEST, PacketType.Play.Client.TAB_COMPLETE);
}
Expand All @@ -23,22 +25,22 @@ protected void register() {

@Override
public void onPacketReceiving(PacketEvent event) {
if (event.isPlayerTemporary()) return;
if (event.isPlayerTemporary() || event.getPlayer().isOp()) return;

final PacketContainer packet = event.getPacket();

try {
final String command = packet.getStrings().read(0);
final String partialCommand = packet.getStrings().read(0);

if (command.contains("@") || command.contains("nbt")) {
if (!event.getPlayer().isOp()) {
for (String invalidSeq : INVALID_SEQUENCES) {
if (partialCommand.indexOf(invalidSeq) >= 0) {
event.setCancelled(true);
return;
}
}

if (command.length() > 64) {
final int index = command.indexOf(' ');
if (partialCommand.length() > 64) {
final int index = partialCommand.indexOf(' ');
if (index == -1 || index >= 64) {
event.setCancelled(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "me.moomoo.anarchyexploitfixes"
version = "2.6.6"
version = "2.6.7"
description = "Prevent many exploits that affect anarchy servers."
var url: String? = "github.com/moom0o/AnarchyExploitFixes"

Expand Down

0 comments on commit d2c8671

Please sign in to comment.