mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Update CodecProcessor.java
Fix from qrvprox
This commit is contained in:
parent
689ca4d535
commit
70e0361c56
1 changed files with 48 additions and 2 deletions
|
|
@ -29,13 +29,21 @@ import io.netty.buffer.ByteBuf;
|
|||
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodecHelper;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.BedrockPacketSerializer;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.*;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.MobArmorEquipmentSerializer_v291;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.MobEquipmentSerializer_v291;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.PlayerHotbarSerializer_v291;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.SetEntityLinkSerializer_v291;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v390.serializer.PlayerSkinSerializer_v390;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v407.serializer.InventoryContentSerializer_v407;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v407.serializer.InventorySlotSerializer_v407;
|
||||
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.v630.serializer.SetPlayerInventoryOptionsSerializer_v360;
|
||||
import org.cloudburstmc.protocol.bedrock.codec.v662.serializer.SetEntityMotionSerializer_v662;
|
||||
import org.cloudburstmc.protocol.bedrock.data.inventory.InventoryLayout;
|
||||
import org.cloudburstmc.protocol.bedrock.data.inventory.InventoryTabLeft;
|
||||
import org.cloudburstmc.protocol.bedrock.data.inventory.InventoryTabRight;
|
||||
import org.cloudburstmc.protocol.bedrock.packet.*;
|
||||
import org.cloudburstmc.protocol.common.util.VarInts;
|
||||
|
||||
|
|
@ -94,6 +102,36 @@ class CodecProcessor {
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* The player can cause a packet error themselves, which hackers can exploit to spam legitimate errors
|
||||
*/
|
||||
private static final BedrockPacketSerializer<SetPlayerInventoryOptionsPacket> SET_PLAYER_INVENTORY_OPTIONS_SERIALIZER = new SetPlayerInventoryOptionsSerializer_v360() {
|
||||
@Override
|
||||
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, SetPlayerInventoryOptionsPacket packet) {
|
||||
int leftTabIndex = VarInts.readInt(buffer);
|
||||
int rightTabIndex = VarInts.readInt(buffer);
|
||||
|
||||
packet.setLeftTab(leftTabIndex >= 0 && leftTabIndex < InventoryTabLeft.VALUES.length ? InventoryTabLeft.VALUES[leftTabIndex] : InventoryTabLeft.NONE);
|
||||
packet.setRightTab(rightTabIndex >= 0 && rightTabIndex < InventoryTabRight.VALUES.length ? InventoryTabRight.VALUES[rightTabIndex] : InventoryTabRight.NONE);
|
||||
|
||||
packet.setFiltering(buffer.readBoolean());
|
||||
|
||||
int layoutIndex = VarInts.readInt(buffer);
|
||||
packet.setLayout(layoutIndex >= 0 && layoutIndex < InventoryLayout.VALUES.length ? InventoryLayout.VALUES[layoutIndex] : InventoryLayout.NONE);
|
||||
|
||||
int craftingLayoutIndex = VarInts.readInt(buffer);
|
||||
packet.setCraftingLayout(craftingLayoutIndex >= 0 && craftingLayoutIndex < InventoryLayout.VALUES.length ? InventoryLayout.VALUES[craftingLayoutIndex] : InventoryLayout.NONE);
|
||||
}
|
||||
};
|
||||
|
||||
private static final BedrockPacketSerializer<ItemStackRequestPacket> ITEM_STACK_REQUEST_SERIALIZER = new ItemStackRequestSerializer_v407() {
|
||||
@Override
|
||||
public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, ItemStackRequestPacket packet) {
|
||||
helper.readArray(buffer, packet.getRequests(), helper::readItemStackRequest, 110); // 64 is NOT enough, cloudburst
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Serializer that does nothing when trying to deserialize BossEventPacket since it is not used from the client.
|
||||
*/
|
||||
|
|
@ -221,12 +259,20 @@ class CodecProcessor {
|
|||
// Ignored bidirectional packets
|
||||
.updateSerializer(ClientCacheStatusPacket.class, IGNORED_SERIALIZER)
|
||||
.updateSerializer(SimpleEventPacket.class, IGNORED_SERIALIZER)
|
||||
.updateSerializer(MultiplayerSettingsPacket.class, IGNORED_SERIALIZER);
|
||||
.updateSerializer(MultiplayerSettingsPacket.class, IGNORED_SERIALIZER)
|
||||
// Small limit
|
||||
.updateSerializer(ItemStackRequestPacket.class, ITEM_STACK_REQUEST_SERIALIZER);
|
||||
|
||||
|
||||
if (codec.getProtocolVersion() < 685) {
|
||||
// Ignored bidirectional packets
|
||||
codecBuilder.updateSerializer(TickSyncPacket.class, IGNORED_SERIALIZER);
|
||||
}
|
||||
|
||||
if (codec.getProtocolVersion() >= 630) { // >= 1.20.50
|
||||
codecBuilder.updateSerializer(SetPlayerInventoryOptionsPacket.class, SET_PLAYER_INVENTORY_OPTIONS_SERIALIZER);
|
||||
}
|
||||
|
||||
return codecBuilder.build();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue