-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
158 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
AnarchyExploitFixesFolia/src/main/java/me/xginko/aef/modules/packets/BigMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package me.xginko.aef.modules.packets; | ||
|
||
import com.github.retrooper.packetevents.event.PacketListenerPriority; | ||
import com.github.retrooper.packetevents.event.PacketReceiveEvent; | ||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper; | ||
import com.github.retrooper.packetevents.protocol.packettype.PacketType; | ||
import com.github.retrooper.packetevents.wrapper.PacketWrapper; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public class BigMessages extends PacketModule { | ||
|
||
private final int charLimit; | ||
private final boolean log, kick; | ||
|
||
public BigMessages() { | ||
super("patches.message-char-limit", PacketListenerPriority.HIGHEST); | ||
config.addComment(configPath + ".enable", """ | ||
Sets a character limit for command and message packets to prevent a lag exploit."""); | ||
this.charLimit = config.getInt(configPath + ".max-characters", 512); | ||
this.log = config.getBoolean(configPath + ".log", false); | ||
this.kick = config.getBoolean(configPath + ".kick-player", false); | ||
} | ||
|
||
@Override | ||
public boolean shouldEnable() { | ||
return config.getBoolean(configPath + ".enable", true); | ||
} | ||
|
||
@Override | ||
public void onPacketReceive(PacketReceiveEvent event) { | ||
if (event.isCancelled()) return; | ||
|
||
if ( | ||
event.getPacketType() == PacketType.Play.Client.CHAT_MESSAGE | ||
|| event.getPacketType() == PacketType.Play.Client.CHAT_COMMAND | ||
|| event.getPacketType() == PacketType.Play.Client.CHAT_COMMAND_UNSIGNED | ||
) { | ||
if (isStringTooBig(new PacketWrapper<>(event))) { | ||
event.setCancelled(true); | ||
onCancel(log, kick, event.getUser()); | ||
} | ||
} | ||
} | ||
|
||
private boolean isStringTooBig(PacketWrapper<?> packetWrapper) { | ||
int strBufLen = packetWrapper.readVarInt(); | ||
|
||
// Check if the received encoded string buffer length is zero or longer than maximum allowed | ||
if (strBufLen < 0 || strBufLen > charLimit * 4) { | ||
return true; | ||
} | ||
|
||
// The received string length is longer than maximum allowed | ||
return ByteBufHelper.toString(packetWrapper.buffer, ByteBufHelper.readerIndex(packetWrapper.buffer), strBufLen, StandardCharsets.UTF_8) | ||
.length() > charLimit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
AnarchyExploitFixesLegacy/src/main/java/me/xginko/aef/modules/packets/BigMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package me.xginko.aef.modules.packets; | ||
|
||
import com.github.retrooper.packetevents.event.PacketListenerPriority; | ||
import com.github.retrooper.packetevents.event.PacketReceiveEvent; | ||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper; | ||
import com.github.retrooper.packetevents.protocol.packettype.PacketType; | ||
import com.github.retrooper.packetevents.wrapper.PacketWrapper; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
public class BigMessages extends PacketModule { | ||
|
||
private final int charLimit; | ||
private final boolean log, kick; | ||
|
||
public BigMessages() { | ||
super("patches.message-char-limit", PacketListenerPriority.HIGHEST); | ||
config.addComment(configPath + ".enable", | ||
"Sets a character limit for command and message packets to prevent a lag exploit."); | ||
this.charLimit = config.getInt(configPath + ".max-characters", 512); | ||
this.log = config.getBoolean(configPath + ".log", false); | ||
this.kick = config.getBoolean(configPath + ".kick-player", false); | ||
} | ||
|
||
@Override | ||
public boolean shouldEnable() { | ||
return config.getBoolean(configPath + ".enable", true); | ||
} | ||
|
||
@Override | ||
public void onPacketReceive(PacketReceiveEvent event) { | ||
if (event.isCancelled()) return; | ||
|
||
if ( | ||
event.getPacketType() == PacketType.Play.Client.CHAT_MESSAGE | ||
|| event.getPacketType() == PacketType.Play.Client.CHAT_COMMAND | ||
|| event.getPacketType() == PacketType.Play.Client.CHAT_COMMAND_UNSIGNED | ||
) { | ||
if (isStringTooBig(new PacketWrapper<>(event))) { | ||
event.setCancelled(true); | ||
onCancel(log, kick, event.getUser()); | ||
} | ||
} | ||
} | ||
|
||
private boolean isStringTooBig(PacketWrapper<?> packetWrapper) { | ||
int strBufLen = packetWrapper.readVarInt(); | ||
|
||
// Check if the received encoded string buffer length is zero or longer than maximum allowed | ||
if (strBufLen < 0 || strBufLen > charLimit * 4) { | ||
return true; | ||
} | ||
|
||
// The received string length is longer than maximum allowed | ||
return ByteBufHelper.toString(packetWrapper.buffer, ByteBufHelper.readerIndex(packetWrapper.buffer), strBufLen, StandardCharsets.UTF_8) | ||
.length() > charLimit; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.