mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
CommandRequestPacket limit protocol
This commit is contained in:
parent
fde62f48a3
commit
45f0a7fd0a
2 changed files with 14 additions and 13 deletions
|
|
@ -39,6 +39,7 @@ import org.cloudburstmc.protocol.bedrock.codec.v407.serializer.InventorySlotSeri
|
|||
import org.cloudburstmc.protocol.bedrock.codec.v407.serializer.ItemStackRequestSerializer_v407;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v486.serializer.BossEventSerializer_v486;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v557.serializer.SetEntityDataSerializer_v557;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v567.serializer.CommandRequestSerializer_v567;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v630.serializer.SetPlayerInventoryOptionsSerializer_v360;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v662.serializer.SetEntityMotionSerializer_v662;
|
||||
import org.cloudburstmc.protocol.bedrock.data.inventory.InventoryLayout;
|
||||
|
|
@ -132,6 +133,16 @@ class CodecProcessor {
|
|||
}
|
||||
};
|
||||
|
||||
private static final BedrockPacketSerializer<CommandRequestPacket> COMMAND_REQUEST_SERIALIZER = new CommandRequestSerializer_v567() {
|
||||
@Override
|
||||
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, CommandRequestPacket packet) {
|
||||
packet.setCommand(helper.readStringMaxLen(buffer, 513));
|
||||
packet.setCommandOriginData(helper.readCommandOrigin(buffer));
|
||||
packet.setInternal(buffer.readBoolean());
|
||||
packet.setVersion(VarInts.readInt(buffer));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Serializer that does nothing when trying to deserialize BossEventPacket since it is not used from the client.
|
||||
*/
|
||||
|
|
@ -269,9 +280,8 @@ class CodecProcessor {
|
|||
codecBuilder.updateSerializer(TickSyncPacket.class, IGNORED_SERIALIZER);
|
||||
}
|
||||
|
||||
if (codec.getProtocolVersion() >= 630) { // >= 1.20.50
|
||||
codecBuilder.updateSerializer(SetPlayerInventoryOptionsPacket.class, SET_PLAYER_INVENTORY_OPTIONS_SERIALIZER);
|
||||
}
|
||||
codecBuilder.updateSerializer(CommandRequestPacket.class, COMMAND_REQUEST_SERIALIZER);
|
||||
codecBuilder.updateSerializer(SetPlayerInventoryOptionsPacket.class, SET_PLAYER_INVENTORY_OPTIONS_SERIALIZER);
|
||||
|
||||
return codecBuilder.build();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import org.cloudburstmc.protocol.bedrock.packet.CommandRequestPacket;
|
|||
import org.geysermc.geyser.GeyserImpl;
|
||||
import org.geysermc.geyser.api.util.PlatformType;
|
||||
import org.geysermc.geyser.session.GeyserSession;
|
||||
import org.geysermc.geyser.text.GeyserLocale;
|
||||
import org.geysermc.geyser.translator.protocol.PacketTranslator;
|
||||
import org.geysermc.geyser.translator.protocol.Translator;
|
||||
import org.geysermc.geyser.translator.text.MessageTranslator;
|
||||
|
|
@ -39,15 +38,7 @@ public class BedrockCommandRequestTranslator extends PacketTranslator<CommandReq
|
|||
|
||||
@Override
|
||||
public void translate(GeyserSession session, CommandRequestPacket packet) {
|
||||
String command = packet.getCommand();
|
||||
if (command.length() > 512) {
|
||||
// A legitimate player cannot send more than 512 characters
|
||||
// This is necessary so that the conversion to plain text is not clogged
|
||||
session.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.chat.too_long", session.locale(), command.length()));
|
||||
return;
|
||||
}
|
||||
command = MessageTranslator.convertToPlainText(packet.getCommand());
|
||||
handleCommand(session, MessageTranslator.normalizeSpace(command).substring(1));
|
||||
handleCommand(session, MessageTranslator.normalizeSpace(MessageTranslator.convertToPlainText(packet.getCommand())).substring(1));
|
||||
}
|
||||
|
||||
static void handleCommand(GeyserSession session, String command) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue