From 689ca4d535bd84a73d3646e38e01f3546f930d65 Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Mon, 17 Jun 2024 11:20:05 +0300 Subject: [PATCH 01/21] EmoteListPacket RAM Overflow I do not know why they saved it if it is not used anywhere If they decide it is necessary, only one UUID is sent when changing emotions, with a limit of 50 I think that is sufficient, and the outdated ones can simply be deleted --- .../geyser/network/CodecProcessor.java | 57 +------------------ .../geyser/session/GeyserSession.java | 26 --------- 2 files changed, 3 insertions(+), 80 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java index e7cf81d4799..fed2211efc5 100644 --- a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java +++ b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java @@ -29,56 +29,14 @@ 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.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.v291.serializer.SetEntityMotionSerializer_v291; +import org.cloudburstmc.protocol.bedrock.codec.v291.serializer.*; 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.v486.serializer.BossEventSerializer_v486; import org.cloudburstmc.protocol.bedrock.codec.v557.serializer.SetEntityDataSerializer_v557; import org.cloudburstmc.protocol.bedrock.codec.v662.serializer.SetEntityMotionSerializer_v662; -import org.cloudburstmc.protocol.bedrock.packet.AnvilDamagePacket; -import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; -import org.cloudburstmc.protocol.bedrock.packet.BossEventPacket; -import org.cloudburstmc.protocol.bedrock.packet.ClientCacheBlobStatusPacket; -import org.cloudburstmc.protocol.bedrock.packet.ClientCacheStatusPacket; -import org.cloudburstmc.protocol.bedrock.packet.ClientCheatAbilityPacket; -import org.cloudburstmc.protocol.bedrock.packet.ClientToServerHandshakePacket; -import org.cloudburstmc.protocol.bedrock.packet.CodeBuilderSourcePacket; -import org.cloudburstmc.protocol.bedrock.packet.CraftingEventPacket; -import org.cloudburstmc.protocol.bedrock.packet.CreatePhotoPacket; -import org.cloudburstmc.protocol.bedrock.packet.DebugInfoPacket; -import org.cloudburstmc.protocol.bedrock.packet.EditorNetworkPacket; -import org.cloudburstmc.protocol.bedrock.packet.EntityFallPacket; -import org.cloudburstmc.protocol.bedrock.packet.GameTestRequestPacket; -import org.cloudburstmc.protocol.bedrock.packet.InventoryContentPacket; -import org.cloudburstmc.protocol.bedrock.packet.InventorySlotPacket; -import org.cloudburstmc.protocol.bedrock.packet.LabTablePacket; -import org.cloudburstmc.protocol.bedrock.packet.MapCreateLockedCopyPacket; -import org.cloudburstmc.protocol.bedrock.packet.MapInfoRequestPacket; -import org.cloudburstmc.protocol.bedrock.packet.MobArmorEquipmentPacket; -import org.cloudburstmc.protocol.bedrock.packet.MobEquipmentPacket; -import org.cloudburstmc.protocol.bedrock.packet.MultiplayerSettingsPacket; -import org.cloudburstmc.protocol.bedrock.packet.NpcRequestPacket; -import org.cloudburstmc.protocol.bedrock.packet.PhotoInfoRequestPacket; -import org.cloudburstmc.protocol.bedrock.packet.PhotoTransferPacket; -import org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket; -import org.cloudburstmc.protocol.bedrock.packet.PlayerHotbarPacket; -import org.cloudburstmc.protocol.bedrock.packet.PlayerSkinPacket; -import org.cloudburstmc.protocol.bedrock.packet.PurchaseReceiptPacket; -import org.cloudburstmc.protocol.bedrock.packet.RefreshEntitlementsPacket; -import org.cloudburstmc.protocol.bedrock.packet.ScriptMessagePacket; -import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; -import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; -import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket; -import org.cloudburstmc.protocol.bedrock.packet.SettingsCommandPacket; -import org.cloudburstmc.protocol.bedrock.packet.SimpleEventPacket; -import org.cloudburstmc.protocol.bedrock.packet.SubChunkRequestPacket; -import org.cloudburstmc.protocol.bedrock.packet.SubClientLoginPacket; -import org.cloudburstmc.protocol.bedrock.packet.TickSyncPacket; +import org.cloudburstmc.protocol.bedrock.packet.*; import org.cloudburstmc.protocol.common.util.VarInts; /** @@ -181,15 +139,6 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, SetEntityData } }; - /** - * Serializer that does nothing when trying to deserialize SetEntityMotionPacket since it is not used from the client for codec v291. - */ - private static final BedrockPacketSerializer SET_ENTITY_MOTION_SERIALIZER_V291 = new SetEntityMotionSerializer_v291() { - @Override - public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, SetEntityMotionPacket packet) { - } - }; - /** * Serializer that does nothing when trying to deserialize SetEntityMotionPacket since it is not used from the client for codec v662. */ @@ -251,6 +200,7 @@ static BedrockCodec processCodec(BedrockCodec codec) { .updateSerializer(SettingsCommandPacket.class, IGNORED_SERIALIZER) .updateSerializer(AnvilDamagePacket.class, IGNORED_SERIALIZER) .updateSerializer(RefreshEntitlementsPacket.class, IGNORED_SERIALIZER) + .updateSerializer(EmoteListPacket.class, IGNORED_SERIALIZER) // Illegal when serverbound due to Geyser specific setup .updateSerializer(InventoryContentPacket.class, INVENTORY_CONTENT_SERIALIZER) .updateSerializer(InventorySlotPacket.class, INVENTORY_SLOT_SERIALIZER) @@ -277,7 +227,6 @@ static BedrockCodec processCodec(BedrockCodec codec) { // Ignored bidirectional packets codecBuilder.updateSerializer(TickSyncPacket.class, IGNORED_SERIALIZER); } - return codecBuilder.build(); } diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index e228fc02fdc..ea40dc821e0 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -511,8 +511,6 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { @Setter private boolean waitingForStatistics = false; - private final Set emotes; - /** * Whether advanced tooltips will be added to the player's items. */ @@ -600,13 +598,6 @@ public GeyserSession(GeyserImpl geyser, BedrockServerSession bedrockServerSessio this.spawned = false; this.loggedIn = false; - if (geyser.getConfig().getEmoteOffhandWorkaround() != EmoteOffhandWorkaroundOption.NO_EMOTES) { - this.emotes = new HashSet<>(); - geyser.getSessionManager().getSessions().values().forEach(player -> this.emotes.addAll(player.getEmotes())); - } else { - this.emotes = null; - } - this.remoteServer = geyser.defaultRemoteServer(); } @@ -1866,23 +1857,6 @@ public void updateStatistics(@NonNull Object2IntMap statistics) { this.statistics.putAll(statistics); } - public void refreshEmotes(List emotes) { - this.emotes.addAll(emotes); - for (GeyserSession player : geyser.getSessionManager().getSessions().values()) { - List pieces = new ArrayList<>(); - for (UUID piece : emotes) { - if (!player.getEmotes().contains(piece)) { - pieces.add(piece); - } - player.getEmotes().add(piece); - } - EmoteListPacket emoteList = new EmoteListPacket(); - emoteList.setRuntimeEntityId(player.getPlayerEntity().getGeyserId()); - emoteList.getPieceIds().addAll(pieces); - player.sendUpstreamPacket(emoteList); - } - } - public boolean canUseCommandBlocks() { return instabuild && opPermissionLevel >= 2; } From 70e0361c56f50864b03430ac00e353de3804eeba Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Mon, 17 Jun 2024 11:27:58 +0300 Subject: [PATCH 02/21] Update CodecProcessor.java Fix from qrvprox --- .../geyser/network/CodecProcessor.java | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java index fed2211efc5..b92aeb715cc 100644 --- a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java +++ b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java @@ -29,13 +29,21 @@ 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 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventorySlot } }; + + /** + * The player can cause a packet error themselves, which hackers can exploit to spam legitimate errors + */ + private static final BedrockPacketSerializer 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 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 @@ static BedrockCodec processCodec(BedrockCodec codec) { // 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(); } From 575c8fd2e3a7fc567409e81e3e58d6838901a6a1 Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Mon, 17 Jun 2024 11:31:05 +0300 Subject: [PATCH 03/21] EmoteListPacket suk --- .../bedrock/BedrockEmoteListTranslator.java | 45 ------------------- 1 file changed, 45 deletions(-) delete mode 100644 core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockEmoteListTranslator.java diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockEmoteListTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockEmoteListTranslator.java deleted file mode 100644 index b20f7a2dd5b..00000000000 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockEmoteListTranslator.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2019-2022 GeyserMC. http://geysermc.org - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * @author GeyserMC - * @link https://github.com/GeyserMC/Geyser - */ - -package org.geysermc.geyser.translator.protocol.bedrock; - -import org.cloudburstmc.protocol.bedrock.packet.EmoteListPacket; -import org.geysermc.geyser.configuration.EmoteOffhandWorkaroundOption; -import org.geysermc.geyser.session.GeyserSession; -import org.geysermc.geyser.translator.protocol.PacketTranslator; -import org.geysermc.geyser.translator.protocol.Translator; - -@Translator(packet = EmoteListPacket.class) -public class BedrockEmoteListTranslator extends PacketTranslator { - - @Override - public void translate(GeyserSession session, EmoteListPacket packet) { - if (session.getGeyser().getConfig().getEmoteOffhandWorkaround() == EmoteOffhandWorkaroundOption.NO_EMOTES) { - return; - } - - session.refreshEmotes(packet.getPieceIds()); - } -} From a9973e7c1f6dfb39e06852a6ca3e732809bfd17d Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Mon, 17 Jun 2024 21:04:27 +0300 Subject: [PATCH 04/21] text limit TextPacket CommandRequestPacket --- .../BedrockCommandRequestTranslator.java | 10 +++++++++- .../bedrock/BedrockTextTranslator.java | 20 +++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockCommandRequestTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockCommandRequestTranslator.java index 8d4df6f3ffe..499ef180761 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockCommandRequestTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockCommandRequestTranslator.java @@ -29,6 +29,7 @@ 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; @@ -38,7 +39,14 @@ public class BedrockCommandRequestTranslator extends PacketTranslator 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)); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java index bac9b9ecc6c..6e657695b86 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java @@ -27,6 +27,7 @@ import org.cloudburstmc.protocol.bedrock.packet.TextPacket; 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; @@ -36,9 +37,24 @@ public class BedrockTextTranslator extends PacketTranslator { @Override public void translate(GeyserSession session, TextPacket packet) { + if (!(packet.getParameters().isEmpty())) { + // I don't know if the client sends something there on 1.1.5, the client doesn't send anything like that + // Add yourself for this text if you need it + session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.chat.parameters", session.locale(), packet.getParameters().size())); + return; + } + + String message = packet.getMessage(); + if (message.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(), message.length())); + return; + } + // Java trims all messages, and then checks for the leading slash - String message = MessageTranslator.convertToPlainText( - MessageTranslator.normalizeSpace(packet.getMessage()) + message = MessageTranslator.convertToPlainText( + MessageTranslator.normalizeSpace(message) ); if (message.isBlank()) { From be4a8e6906b5a382108efedc2c79c41452a2e081 Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Mon, 17 Jun 2024 22:20:54 +0300 Subject: [PATCH 05/21] Against possible leaks memory --- .../geyser/session/cache/FormCache.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java index 3f7df97c1b2..0e6291d76c7 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java @@ -25,18 +25,22 @@ package org.geysermc.geyser.session.cache; -import org.cloudburstmc.protocol.bedrock.packet.ModalFormRequestPacket; -import org.cloudburstmc.protocol.bedrock.packet.ModalFormResponsePacket; -import org.cloudburstmc.protocol.bedrock.packet.NetworkStackLatencyPacket; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import lombok.RequiredArgsConstructor; +import org.cloudburstmc.protocol.bedrock.data.ModalFormCancelReason; +import org.cloudburstmc.protocol.bedrock.packet.ModalFormRequestPacket; +import org.cloudburstmc.protocol.bedrock.packet.ModalFormResponsePacket; +import org.cloudburstmc.protocol.bedrock.packet.NetworkStackLatencyPacket; import org.geysermc.cumulus.form.Form; import org.geysermc.cumulus.form.SimpleForm; import org.geysermc.cumulus.form.impl.FormDefinitions; import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.session.GeyserSession; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -52,11 +56,22 @@ public class FormCache { private final FormDefinitions formDefinitions = FormDefinitions.instance(); private final AtomicInteger formIdCounter = new AtomicInteger(0); private final Int2ObjectMap
forms = new Int2ObjectOpenHashMap<>(); + List formsOrderList = new ArrayList<>(); private final GeyserSession session; public int addForm(Form form) { int formId = formIdCounter.getAndIncrement(); forms.put(formId, form); + formsOrderList.add(formId); + + if (formsOrderList.size() > 50) { + int removeFormId = formsOrderList.getFirst(); + ModalFormResponsePacket packet = new ModalFormResponsePacket(); + packet.setFormId(removeFormId); + packet.setCancelReason(Optional.of(ModalFormCancelReason.USER_CLOSED)); + packet.setFormData(null); + this.handleResponse(packet); + } return formId; } @@ -96,6 +111,7 @@ public void resendAllForms() { public void handleResponse(ModalFormResponsePacket response) { Form form = forms.remove(response.getFormId()); + formsOrderList.remove((Integer) response.getFormId()); if (form == null) { return; } From ea6dd5d4e5f5b20dbe9adc4c0feb706303116ffd Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Tue, 18 Jun 2024 00:07:49 +0300 Subject: [PATCH 06/21] Package limits check if the code is working correctly --- .../geyser/network/LoggingPacketHandler.java | 13 +++ .../geyser/network/PacketCooldownManager.java | 94 +++++++++++++++++++ .../geyser/network/UpstreamPacketHandler.java | 9 ++ .../geyser/session/GeyserSession.java | 3 +- 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java diff --git a/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java index 910f76ffb7b..18748f23dce 100644 --- a/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java @@ -39,13 +39,26 @@ public class LoggingPacketHandler implements BedrockPacketHandler { protected final GeyserImpl geyser; protected final GeyserSession session; + protected final PacketCooldownManager cooldownHandler; LoggingPacketHandler(GeyserImpl geyser, GeyserSession session) { this.geyser = geyser; this.session = session; + this.cooldownHandler = new PacketCooldownManager(session, 1000); + } + + public boolean handleLimit(BedrockPacket packet) { + boolean safePacket = this.cooldownHandler.handle(packet); + if (!safePacket) { + session.disconnect("many Packets " + packet.getClass().getSimpleName()); + } + return !safePacket; } PacketSignal defaultHandler(BedrockPacket packet) { + if (handleLimit(packet)) { + return PacketSignal.UNHANDLED; + } geyser.getLogger().debug("Handled packet: " + packet.getClass().getSimpleName()); return PacketSignal.HANDLED; } diff --git a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java new file mode 100644 index 00000000000..e18f86034df --- /dev/null +++ b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java @@ -0,0 +1,94 @@ +package org.geysermc.geyser.network; + +import lombok.Getter; +import lombok.Setter; +import org.cloudburstmc.protocol.bedrock.packet.*; +import org.geysermc.geyser.session.GeyserSession; + +import java.util.HashMap; +import java.util.Map; + +public class PacketCooldownManager { + private static final Map PACKET_COOLDOWN_SETTINGS = new HashMap<>(); + + static { + setPacketCooldown(LoginPacket.class, -1, 2); + setPacketCooldown(TextPacket.class, 1000, 10); + setPacketCooldown(CommandRequestPacket.class, 1000, 10); + setPacketCooldown(ModalFormResponsePacket.class, 1000, 10); + } + + private final GeyserSession session; + @Setter + private long cooldownMillisDebug; + private long expiryTimeMillisDebug; + + public static void setPacketCooldown(Class packetClass, int cooldownMillis, int maxCount) { + PACKET_COOLDOWN_SETTINGS.put(packetClass.getSimpleName(), new CooldownSettings(cooldownMillis, maxCount)); + } + + private final Map activeCooldowns = new HashMap<>(); + + private boolean isCooldownActive(String packetName) { + CooldownTracker tracker = activeCooldowns.get(packetName); + if (tracker != null && tracker.getCount() >= PACKET_COOLDOWN_SETTINGS.get(packetName).maxCount()) { + if (tracker.getExpiryTime() <= System.currentTimeMillis()) { + activeCooldowns.remove(packetName); + } else { + return true; + } + } + return false; + } + + private void updateCooldown(String packetName, long cooldownMillis) { + activeCooldowns.computeIfAbsent(packetName, k -> new CooldownTracker()); + CooldownTracker tracker = activeCooldowns.get(packetName); + tracker.incrementCount(); + tracker.setExpiryTime(System.currentTimeMillis() + cooldownMillis); + } + + public boolean handle(BedrockPacket packet) { + String packetName = packet.getClass().getSimpleName(); + if (PACKET_COOLDOWN_SETTINGS.containsKey(packetName)) { + CooldownSettings settings = PACKET_COOLDOWN_SETTINGS.get(packetName); + updateCooldown(packetName, settings.cooldownMillis()); + if (isCooldownActive(packetName)) { + if (expiryTimeMillisDebug <= System.currentTimeMillis()) { + CooldownTracker tracker = activeCooldowns.get(packetName); + String message = session.getSocketAddress().getAddress().toString() + " -> Attempted to send too many packets " + packet.getClass().getSimpleName() + "count " + tracker.getCount(); + if (session.isLoggedIn()) { + message += " by user " + session.bedrockUsername(); + } + session.getGeyser().getLogger().debug(message); + } + this.expiryTimeMillisDebug = System.currentTimeMillis() + cooldownMillisDebug; + return false; + } + } + return true; + } + + public PacketCooldownManager(GeyserSession session, long cooldownMillisDebug) { + this.session = session; + this.setCooldownMillisDebug(cooldownMillisDebug); + this.expiryTimeMillisDebug = 0; + } + + @Getter + private record CooldownSettings(int cooldownMillis, int maxCount) { + + } + + @Getter + private static class CooldownTracker { + private long count; + @Setter + private long expiryTime; + + public void incrementCount() { + this.count++; + } + + } +} diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index c7aabb8068c..9322a2b81ff 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -101,6 +101,9 @@ private PacketSignal translateAndDefault(BedrockPacket packet) { @Override PacketSignal defaultHandler(BedrockPacket packet) { + if (handleLimit(packet)) { + return PacketSignal.UNHANDLED; + } return translateAndDefault(packet); } @@ -169,6 +172,9 @@ public PacketSignal handle(RequestNetworkSettingsPacket packet) { @Override public PacketSignal handle(LoginPacket loginPacket) { + if(this.handleLimit(loginPacket)){ + return PacketSignal.UNHANDLED; + } if (geyser.isShuttingDown() || geyser.isReloading()) { // Don't allow new players in if we're no longer operating session.disconnect(GeyserLocale.getLocaleStringLog("geyser.core.shutdown.kick.message")); @@ -268,6 +274,9 @@ public PacketSignal handle(ResourcePackClientResponsePacket packet) { @Override public PacketSignal handle(ModalFormResponsePacket packet) { + if(this.handleLimit(packet)){ + return PacketSignal.UNHANDLED; + } session.executeInEventLoop(() -> session.getFormCache().handleResponse(packet)); return PacketSignal.HANDLED; } diff --git a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java index ea40dc821e0..64686d7ff1c 100644 --- a/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java +++ b/core/src/main/java/org/geysermc/geyser/session/GeyserSession.java @@ -80,7 +80,6 @@ import org.geysermc.geyser.api.network.RemoteServer; import org.geysermc.geyser.api.util.PlatformType; import org.geysermc.geyser.command.GeyserCommandSource; -import org.geysermc.geyser.configuration.EmoteOffhandWorkaroundOption; import org.geysermc.geyser.configuration.GeyserConfiguration; import org.geysermc.geyser.entity.EntityDefinitions; import org.geysermc.geyser.entity.GeyserEntityData; @@ -275,7 +274,9 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource { // Exposed for GeyserConnect usage protected boolean sentSpawnPacket; + @Getter private boolean loggedIn; + @Getter private boolean loggingIn; @Setter From cea4a4213c9f32b27b4e173229f08e6203adacd8 Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Thu, 20 Jun 2024 10:28:24 +0300 Subject: [PATCH 07/21] =?UTF-8?q?Fix=20=D0=BC=D0=BE=D0=B5=D0=B9=20=D1=82?= =?UTF-8?q?=D1=83=D0=BF=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Вроде все работает нет времени в данный момент --- .../org/geysermc/geyser/network/PacketCooldownManager.java | 6 ++---- .../java/org/geysermc/geyser/session/cache/FormCache.java | 5 ++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java index e18f86034df..a4ea29eb107 100644 --- a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java +++ b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java @@ -75,13 +75,12 @@ public PacketCooldownManager(GeyserSession session, long cooldownMillisDebug) { this.expiryTimeMillisDebug = 0; } - @Getter private record CooldownSettings(int cooldownMillis, int maxCount) { - } + @Getter - private static class CooldownTracker { + private class CooldownTracker { private long count; @Setter private long expiryTime; @@ -89,6 +88,5 @@ private static class CooldownTracker { public void incrementCount() { this.count++; } - } } diff --git a/core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java b/core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java index 0e6291d76c7..f14eac28f68 100644 --- a/core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java +++ b/core/src/main/java/org/geysermc/geyser/session/cache/FormCache.java @@ -38,8 +38,7 @@ import org.geysermc.geyser.GeyserImpl; import org.geysermc.geyser.session.GeyserSession; -import java.util.ArrayList; -import java.util.List; +import java.util.LinkedList; import java.util.Optional; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -56,7 +55,7 @@ public class FormCache { private final FormDefinitions formDefinitions = FormDefinitions.instance(); private final AtomicInteger formIdCounter = new AtomicInteger(0); private final Int2ObjectMap forms = new Int2ObjectOpenHashMap<>(); - List formsOrderList = new ArrayList<>(); + LinkedList formsOrderList = new LinkedList<>(); private final GeyserSession session; public int addForm(Form form) { From 383d16d49b8706cec28a2e92f66157125f4c2c55 Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Fri, 21 Jun 2024 13:59:39 +0300 Subject: [PATCH 08/21] ok --- .../org/geysermc/geyser/network/LoggingPacketHandler.java | 2 +- .../geysermc/geyser/network/UpstreamPacketHandler.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java index 18748f23dce..5adc652032e 100644 --- a/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java @@ -57,7 +57,7 @@ public boolean handleLimit(BedrockPacket packet) { PacketSignal defaultHandler(BedrockPacket packet) { if (handleLimit(packet)) { - return PacketSignal.UNHANDLED; + return PacketSignal.HANDLED; } geyser.getLogger().debug("Handled packet: " + packet.getClass().getSimpleName()); return PacketSignal.HANDLED; diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index 9322a2b81ff..23ce2777bc0 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -102,7 +102,7 @@ private PacketSignal translateAndDefault(BedrockPacket packet) { @Override PacketSignal defaultHandler(BedrockPacket packet) { if (handleLimit(packet)) { - return PacketSignal.UNHANDLED; + return PacketSignal.HANDLED; } return translateAndDefault(packet); } @@ -173,7 +173,7 @@ public PacketSignal handle(RequestNetworkSettingsPacket packet) { @Override public PacketSignal handle(LoginPacket loginPacket) { if(this.handleLimit(loginPacket)){ - return PacketSignal.UNHANDLED; + return PacketSignal.HANDLED; } if (geyser.isShuttingDown() || geyser.isReloading()) { // Don't allow new players in if we're no longer operating @@ -275,7 +275,7 @@ public PacketSignal handle(ResourcePackClientResponsePacket packet) { @Override public PacketSignal handle(ModalFormResponsePacket packet) { if(this.handleLimit(packet)){ - return PacketSignal.UNHANDLED; + return PacketSignal.HANDLED; } session.executeInEventLoop(() -> session.getFormCache().handleResponse(packet)); return PacketSignal.HANDLED; @@ -351,7 +351,7 @@ public PacketSignal handle(ResourcePackChunkRequestPacket packet) { private void sendPackDataInfo(String id) { ResourcePackDataInfoPacket data = new ResourcePackDataInfoPacket(); - String[] packID = id.split("_"); + String[] packID = id.split("_", 2); ResourcePack pack = this.resourcePackLoadEvent.getPacks().get(packID[0]); PackCodec codec = pack.codec(); ResourcePackManifest.Header header = pack.manifest().header(); From 644cbb05f8ee55dfdeaf162a9e1c9f81b0a13f36 Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Fri, 21 Jun 2024 17:15:42 +0300 Subject: [PATCH 09/21] ResourcePack limit --- .../geyser/network/PacketCooldownManager.java | 57 +++++++++-------- .../geyser/network/UpstreamPacketHandler.java | 61 +++++++++++-------- 2 files changed, 68 insertions(+), 50 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java index a4ea29eb107..f1fa9a6be15 100644 --- a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java +++ b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java @@ -9,30 +9,37 @@ import java.util.Map; public class PacketCooldownManager { - private static final Map PACKET_COOLDOWN_SETTINGS = new HashMap<>(); + private final Map packetCooldownSettings = new HashMap<>(); + + private final GeyserSession session; + @Setter + private long cooldownMillisDebug; + private long expiryTimeMillisDebug; + + public PacketCooldownManager(GeyserSession session, long cooldownMillisDebug) { + this.session = session; + this.setCooldownMillisDebug(cooldownMillisDebug); + this.expiryTimeMillisDebug = 0; - static { setPacketCooldown(LoginPacket.class, -1, 2); + setPacketCooldown(ResourcePackClientResponsePacket.class, -1, 4); + setPacketCooldown(ResourcePackChunkRequestPacket.class, -1, 0); setPacketCooldown(TextPacket.class, 1000, 10); setPacketCooldown(CommandRequestPacket.class, 1000, 10); setPacketCooldown(ModalFormResponsePacket.class, 1000, 10); } - private final GeyserSession session; - @Setter - private long cooldownMillisDebug; - private long expiryTimeMillisDebug; - - public static void setPacketCooldown(Class packetClass, int cooldownMillis, int maxCount) { - PACKET_COOLDOWN_SETTINGS.put(packetClass.getSimpleName(), new CooldownSettings(cooldownMillis, maxCount)); + public void setPacketCooldown(Class packetClass, int cooldownMillis, int maxCount) { + packetCooldownSettings.put(packetClass.getSimpleName(), new CooldownSettings(cooldownMillis, maxCount)); } private final Map activeCooldowns = new HashMap<>(); - private boolean isCooldownActive(String packetName) { + private boolean isCooldownActive(BedrockPacket packet) { + String packetName = packet.getClass().getSimpleName(); CooldownTracker tracker = activeCooldowns.get(packetName); - if (tracker != null && tracker.getCount() >= PACKET_COOLDOWN_SETTINGS.get(packetName).maxCount()) { - if (tracker.getExpiryTime() <= System.currentTimeMillis()) { + if (tracker != null && tracker.getCount() >= packetCooldownSettings.get(packetName).maxCount()) { + if (tracker.getExpiryTime() != -1 && tracker.getExpiryTime() <= System.currentTimeMillis()) { activeCooldowns.remove(packetName); } else { return true; @@ -41,22 +48,27 @@ private boolean isCooldownActive(String packetName) { return false; } - private void updateCooldown(String packetName, long cooldownMillis) { + private void updateCooldown(BedrockPacket packet) { + String packetName = packet.getClass().getSimpleName(); + CooldownSettings settings = packetCooldownSettings.get(packetName); activeCooldowns.computeIfAbsent(packetName, k -> new CooldownTracker()); CooldownTracker tracker = activeCooldowns.get(packetName); tracker.incrementCount(); - tracker.setExpiryTime(System.currentTimeMillis() + cooldownMillis); + if (settings.cooldownMillis() == -1) { + tracker.setExpiryTime(settings.cooldownMillis()); + } else { + tracker.setExpiryTime(System.currentTimeMillis() + settings.cooldownMillis()); + } } public boolean handle(BedrockPacket packet) { String packetName = packet.getClass().getSimpleName(); - if (PACKET_COOLDOWN_SETTINGS.containsKey(packetName)) { - CooldownSettings settings = PACKET_COOLDOWN_SETTINGS.get(packetName); - updateCooldown(packetName, settings.cooldownMillis()); - if (isCooldownActive(packetName)) { + if (packetCooldownSettings.containsKey(packetName)) { + updateCooldown(packet); + if (isCooldownActive(packet)) { if (expiryTimeMillisDebug <= System.currentTimeMillis()) { CooldownTracker tracker = activeCooldowns.get(packetName); - String message = session.getSocketAddress().getAddress().toString() + " -> Attempted to send too many packets " + packet.getClass().getSimpleName() + "count " + tracker.getCount(); + String message = session.getSocketAddress().getAddress().toString() + " -> Attempted to send too many packets " + packet.getClass().getSimpleName() + " count " + tracker.getCount(); if (session.isLoggedIn()) { message += " by user " + session.bedrockUsername(); } @@ -69,16 +81,9 @@ public boolean handle(BedrockPacket packet) { return true; } - public PacketCooldownManager(GeyserSession session, long cooldownMillisDebug) { - this.session = session; - this.setCooldownMillisDebug(cooldownMillisDebug); - this.expiryTimeMillisDebug = 0; - } - private record CooldownSettings(int cooldownMillis, int maxCount) { } - @Getter private class CooldownTracker { private long count; diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index 23ce2777bc0..9e280d7bdf7 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -36,20 +36,7 @@ import org.cloudburstmc.protocol.bedrock.netty.codec.compression.CompressionStrategy; import org.cloudburstmc.protocol.bedrock.netty.codec.compression.SimpleCompressionStrategy; import org.cloudburstmc.protocol.bedrock.netty.codec.compression.ZlibCompression; -import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; -import org.cloudburstmc.protocol.bedrock.packet.LoginPacket; -import org.cloudburstmc.protocol.bedrock.packet.ModalFormResponsePacket; -import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; -import org.cloudburstmc.protocol.bedrock.packet.NetworkSettingsPacket; -import org.cloudburstmc.protocol.bedrock.packet.PlayStatusPacket; -import org.cloudburstmc.protocol.bedrock.packet.RequestNetworkSettingsPacket; -import org.cloudburstmc.protocol.bedrock.packet.ResourcePackChunkDataPacket; -import org.cloudburstmc.protocol.bedrock.packet.ResourcePackChunkRequestPacket; -import org.cloudburstmc.protocol.bedrock.packet.ResourcePackClientResponsePacket; -import org.cloudburstmc.protocol.bedrock.packet.ResourcePackDataInfoPacket; -import org.cloudburstmc.protocol.bedrock.packet.ResourcePackStackPacket; -import org.cloudburstmc.protocol.bedrock.packet.ResourcePacksInfoPacket; -import org.cloudburstmc.protocol.bedrock.packet.SetTitlePacket; +import org.cloudburstmc.protocol.bedrock.packet.*; import org.cloudburstmc.protocol.common.PacketSignal; import org.cloudburstmc.protocol.common.util.Zlib; import org.geysermc.geyser.Constants; @@ -73,15 +60,12 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.SeekableByteChannel; -import java.util.ArrayDeque; -import java.util.Deque; import java.util.HashMap; import java.util.OptionalInt; public class UpstreamPacketHandler extends LoggingPacketHandler { private boolean networkSettingsRequested = false; - private final Deque packsToSent = new ArrayDeque<>(); private final CompressionStrategy compressionStrategy; private SessionLoadResourcePacksEventImpl resourcePackLoadEvent; @@ -226,6 +210,13 @@ public PacketSignal handle(LoginPacket loginPacket) { @Override public PacketSignal handle(ResourcePackClientResponsePacket packet) { + if (this.handleLimit(packet)) { + return PacketSignal.HANDLED; + } + if (packet.getPackIds().size() > this.resourcePackLoadEvent.getPacks().size()) { + session.disconnect("Packet " + packet.getClass().getName() + " PackIds max count"); + return PacketSignal.HANDLED; + } switch (packet.getStatus()) { case COMPLETED: if (geyser.getConfig().getRemote().authType() != AuthType.ONLINE) { @@ -238,8 +229,24 @@ public PacketSignal handle(ResourcePackClientResponsePacket packet) { break; case SEND_PACKS: - packsToSent.addAll(packet.getPackIds()); - sendPackDataInfo(packsToSent.pop()); + int chunkIndex = 1; + for (String id : packet.getPackIds()) { + + String[] packID = id.split("_", 2); + if (packID.length != 2) { + session.disconnect("Invalid packID id: " + id); + break; + } + ResourcePack pack = this.resourcePackLoadEvent.getPacks().get(packID[0]); + if (pack == null) { + session.disconnect("Invalid request unknown pack " + packID[0] + ", available packs: " + this.resourcePackLoadEvent.getPacks().keySet()); + break; + } + + sendPackDataInfo(id); + chunkIndex += (int) ((this.resourcePackLoadEvent.getPacks().get(packID[0]).codec().size() + GeyserResourcePack.CHUNK_SIZE) / GeyserResourcePack.CHUNK_SIZE); + } + cooldownHandler.setPacketCooldown(ResourcePackChunkRequestPacket.class, -1, chunkIndex); break; case HAVE_ALL_PACKS: @@ -317,8 +324,15 @@ public PacketSignal handle(MovePlayerPacket packet) { @Override public PacketSignal handle(ResourcePackChunkRequestPacket packet) { + if (this.handleLimit(packet)) { + return PacketSignal.HANDLED; + } ResourcePackChunkDataPacket data = new ResourcePackChunkDataPacket(); ResourcePack pack = this.resourcePackLoadEvent.getPacks().get(packet.getPackId().toString()); + if (pack == null) { + session.disconnect("Invalid request for chunk " + packet.getChunkIndex() + " of unknown pack " + packet.getPackId() + ", available packs: " + this.resourcePackLoadEvent.getPacks().keySet()); + return PacketSignal.HANDLED; + } PackCodec codec = pack.codec(); data.setChunkIndex(packet.getChunkIndex()); @@ -327,6 +341,10 @@ public PacketSignal handle(ResourcePackChunkRequestPacket packet) { data.setPackId(packet.getPackId()); int offset = packet.getChunkIndex() * GeyserResourcePack.CHUNK_SIZE; + if (offset < 0 || offset >= codec.size()) { + session.disconnect("Invalid out-of-bounds request for chunk " + packet.getChunkIndex() + " of " + packet.getPackId() + " offset " + offset + ", file size " + codec.size()); + return PacketSignal.HANDLED; + } long remainingSize = codec.size() - offset; byte[] packData = new byte[(int) MathUtils.constrain(remainingSize, 0, GeyserResourcePack.CHUNK_SIZE)]; @@ -341,11 +359,6 @@ public PacketSignal handle(ResourcePackChunkRequestPacket packet) { session.sendUpstreamPacket(data); - // Check if it is the last chunk and send next pack in queue when available. - if (remainingSize <= GeyserResourcePack.CHUNK_SIZE && !packsToSent.isEmpty()) { - sendPackDataInfo(packsToSent.pop()); - } - return PacketSignal.HANDLED; } From fde62f48a37fd2798fec660aca4699c25cd9aa16 Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Fri, 21 Jun 2024 17:21:21 +0300 Subject: [PATCH 10/21] soru --- .../java/org/geysermc/geyser/network/UpstreamPacketHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index 9e280d7bdf7..9f71f58b3a4 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -214,7 +214,7 @@ public PacketSignal handle(ResourcePackClientResponsePacket packet) { return PacketSignal.HANDLED; } if (packet.getPackIds().size() > this.resourcePackLoadEvent.getPacks().size()) { - session.disconnect("Packet " + packet.getClass().getName() + " PackIds max count"); + session.disconnect("Packet " + packet.getClass().getSimpleName() + " PackIds max count"); return PacketSignal.HANDLED; } switch (packet.getStatus()) { From 45f0a7fd0a2039524cc3431c43f1e2d5d64e207f Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Sat, 22 Jun 2024 13:54:45 +0300 Subject: [PATCH 11/21] CommandRequestPacket limit protocol --- .../geysermc/geyser/network/CodecProcessor.java | 16 +++++++++++++--- .../bedrock/BedrockCommandRequestTranslator.java | 11 +---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java index b92aeb715cc..74e3e2405b3 100644 --- a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java +++ b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java @@ -39,6 +39,7 @@ 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 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, ItemStackRequ } }; + private static final BedrockPacketSerializer 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 @@ static BedrockCodec processCodec(BedrockCodec codec) { 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(); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockCommandRequestTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockCommandRequestTranslator.java index 499ef180761..e96da1057e3 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockCommandRequestTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockCommandRequestTranslator.java @@ -29,7 +29,6 @@ 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 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) { From 958d13b1cc87374684400858a302c042e50632a9 Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Mon, 24 Jun 2024 18:30:59 +0300 Subject: [PATCH 12/21] Cooldown fix --- .../geyser/network/PacketCooldownManager.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java index f1fa9a6be15..56dd232197d 100644 --- a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java +++ b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java @@ -24,9 +24,9 @@ public PacketCooldownManager(GeyserSession session, long cooldownMillisDebug) { setPacketCooldown(LoginPacket.class, -1, 2); setPacketCooldown(ResourcePackClientResponsePacket.class, -1, 4); setPacketCooldown(ResourcePackChunkRequestPacket.class, -1, 0); - setPacketCooldown(TextPacket.class, 1000, 10); - setPacketCooldown(CommandRequestPacket.class, 1000, 10); - setPacketCooldown(ModalFormResponsePacket.class, 1000, 10); + setPacketCooldown(TextPacket.class, 1000, 50); + setPacketCooldown(CommandRequestPacket.class, 1000, 50); + setPacketCooldown(ModalFormResponsePacket.class, 1000, 50); } public void setPacketCooldown(Class packetClass, int cooldownMillis, int maxCount) { @@ -51,14 +51,17 @@ private boolean isCooldownActive(BedrockPacket packet) { private void updateCooldown(BedrockPacket packet) { String packetName = packet.getClass().getSimpleName(); CooldownSettings settings = packetCooldownSettings.get(packetName); - activeCooldowns.computeIfAbsent(packetName, k -> new CooldownTracker()); - CooldownTracker tracker = activeCooldowns.get(packetName); + CooldownTracker tracker = activeCooldowns.computeIfAbsent(packetName, k -> { + CooldownTracker newTracker = new CooldownTracker(); + long cooldownMillis = settings.cooldownMillis(); + if (cooldownMillis == -1) { + newTracker.setExpiryTime(-1); + } else { + newTracker.setExpiryTime(System.currentTimeMillis() + cooldownMillis); + } + return newTracker; + }); tracker.incrementCount(); - if (settings.cooldownMillis() == -1) { - tracker.setExpiryTime(settings.cooldownMillis()); - } else { - tracker.setExpiryTime(System.currentTimeMillis() + settings.cooldownMillis()); - } } public boolean handle(BedrockPacket packet) { From e33e8b542bb23fa0bd4e927b2d37461e0189261f Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Mon, 24 Jun 2024 18:32:06 +0300 Subject: [PATCH 13/21] TextPacket limits in the protocol --- .../geyser/network/CodecProcessor.java | 48 +++++++++++++++++++ .../bedrock/BedrockTextTranslator.java | 13 ----- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java index 74e3e2405b3..e2e651f5841 100644 --- a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java +++ b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java @@ -38,10 +38,12 @@ 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.v554.serializer.TextSerializer_v554; 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.codec.v685.serializer.TextSerializer_v685; import org.cloudburstmc.protocol.bedrock.data.inventory.InventoryLayout; import org.cloudburstmc.protocol.bedrock.data.inventory.InventoryTabLeft; import org.cloudburstmc.protocol.bedrock.data.inventory.InventoryTabRight; @@ -143,6 +145,47 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, CommandReques } }; + private static final BedrockPacketSerializer TEXT_SERIALIZER_V554 = new TextSerializer_v554() { + @Override + public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, TextPacket packet) { + TextPacket.Type type = TextPacket.Type.values()[buffer.readUnsignedByte()]; + packet.setType(type); + packet.setNeedsTranslation(buffer.readBoolean()); + + if (type == TextPacket.Type.CHAT) { + packet.setSourceName(helper.readString(buffer)); + //The client does not send more than 512 characters, and we do not need to decode other TextPacket.Type + packet.setMessage(helper.readStringMaxLen(buffer, 513)); + } else { + throw new IllegalArgumentException("Unsupported TextType " + type); + } + + packet.setXuid(helper.readString(buffer)); + packet.setPlatformChatId(helper.readString(buffer)); + } + }; + + private static final BedrockPacketSerializer TEXT_SERIALIZER = new TextSerializer_v685() { + @Override + public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, TextPacket packet) { + TextPacket.Type type = TextPacket.Type.values()[buffer.readUnsignedByte()]; + packet.setType(type); + packet.setNeedsTranslation(buffer.readBoolean()); + + if (type == TextPacket.Type.CHAT) { + packet.setSourceName(helper.readString(buffer)); + //The client does not send more than 512 characters, and we do not need to decode other TextPacket.Type + packet.setMessage(helper.readStringMaxLen(buffer, 513)); + } else { + throw new IllegalArgumentException("Unsupported TextType " + type); + } + + packet.setXuid(helper.readString(buffer)); + packet.setPlatformChatId(helper.readString(buffer)); + packet.setFilteredMessage(helper.readString(buffer)); + } + }; + /** * Serializer that does nothing when trying to deserialize BossEventPacket since it is not used from the client. */ @@ -282,6 +325,11 @@ static BedrockCodec processCodec(BedrockCodec codec) { codecBuilder.updateSerializer(CommandRequestPacket.class, COMMAND_REQUEST_SERIALIZER); codecBuilder.updateSerializer(SetPlayerInventoryOptionsPacket.class, SET_PLAYER_INVENTORY_OPTIONS_SERIALIZER); + if (codec.getProtocolVersion() >= 685) { + codecBuilder.updateSerializer(TextPacket.class, TEXT_SERIALIZER); + } else { + codecBuilder.updateSerializer(TextPacket.class, TEXT_SERIALIZER_V554); + } return codecBuilder.build(); } diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java index 6e657695b86..96118040081 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java @@ -37,20 +37,7 @@ public class BedrockTextTranslator extends PacketTranslator { @Override public void translate(GeyserSession session, TextPacket packet) { - if (!(packet.getParameters().isEmpty())) { - // I don't know if the client sends something there on 1.1.5, the client doesn't send anything like that - // Add yourself for this text if you need it - session.disconnect(GeyserLocale.getPlayerLocaleString("geyser.chat.parameters", session.locale(), packet.getParameters().size())); - return; - } - String message = packet.getMessage(); - if (message.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(), message.length())); - return; - } // Java trims all messages, and then checks for the leading slash message = MessageTranslator.convertToPlainText( From ba8ae5fca0b2b37bf4fc116bbfb5682099b99030 Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Mon, 24 Jun 2024 19:03:02 +0300 Subject: [PATCH 14/21] Emotes now work --- .../main/java/org/geysermc/geyser/entity/GeyserEntityData.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java index c9ef7a2dda2..bade88f1fc2 100644 --- a/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java +++ b/core/src/main/java/org/geysermc/geyser/entity/GeyserEntityData.java @@ -28,6 +28,7 @@ import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; +import org.cloudburstmc.protocol.bedrock.data.EmoteFlag; import org.cloudburstmc.protocol.bedrock.packet.EmotePacket; import org.geysermc.geyser.api.entity.EntityData; import org.geysermc.geyser.api.entity.type.GeyserEntity; @@ -71,6 +72,8 @@ public void showEmote(@NonNull GeyserPlayerEntity emoter, @NonNull String emoteI packet.setXuid(""); packet.setPlatformId(""); // BDS sends empty packet.setEmoteId(emoteId); + packet.getFlags().add(EmoteFlag.SERVER_SIDE); + packet.getFlags().add(EmoteFlag.MUTE_EMOTE_CHAT); session.sendUpstreamPacket(packet); } From ac51ec1bc6b77b811c0d0ec3b012bbed7750cb99 Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Wed, 26 Jun 2024 20:19:13 +0300 Subject: [PATCH 15/21] b --- .../geyser/network/CodecProcessor.java | 15 +---- .../geyser/network/LoggingPacketHandler.java | 2 +- .../geyser/network/PacketCooldownManager.java | 64 +++++++------------ .../bedrock/BedrockTextTranslator.java | 6 +- 4 files changed, 28 insertions(+), 59 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java index e2e651f5841..70380803f2b 100644 --- a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java +++ b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java @@ -105,10 +105,6 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, InventorySlot } }; - - /** - * The player can cause a packet error themselves, which hackers can exploit to spam legitimate errors - */ private static final BedrockPacketSerializer SET_PLAYER_INVENTORY_OPTIONS_SERIALIZER = new SetPlayerInventoryOptionsSerializer_v360() { @Override public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, SetPlayerInventoryOptionsPacket packet) { @@ -128,13 +124,6 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, SetPlayerInve } }; - private static final BedrockPacketSerializer 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 - } - }; - private static final BedrockPacketSerializer COMMAND_REQUEST_SERIALIZER = new CommandRequestSerializer_v567() { @Override public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, CommandRequestPacket packet) { @@ -313,9 +302,7 @@ static BedrockCodec processCodec(BedrockCodec codec) { // Ignored bidirectional packets .updateSerializer(ClientCacheStatusPacket.class, IGNORED_SERIALIZER) .updateSerializer(SimpleEventPacket.class, IGNORED_SERIALIZER) - .updateSerializer(MultiplayerSettingsPacket.class, IGNORED_SERIALIZER) - // Small limit - .updateSerializer(ItemStackRequestPacket.class, ITEM_STACK_REQUEST_SERIALIZER); + .updateSerializer(MultiplayerSettingsPacket.class, IGNORED_SERIALIZER); if (codec.getProtocolVersion() < 685) { diff --git a/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java index 5adc652032e..7f35e4c3368 100644 --- a/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java @@ -44,7 +44,7 @@ public class LoggingPacketHandler implements BedrockPacketHandler { LoggingPacketHandler(GeyserImpl geyser, GeyserSession session) { this.geyser = geyser; this.session = session; - this.cooldownHandler = new PacketCooldownManager(session, 1000); + this.cooldownHandler = new PacketCooldownManager(session); } public boolean handleLimit(BedrockPacket packet) { diff --git a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java index 56dd232197d..e98e2a408a6 100644 --- a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java +++ b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java @@ -1,25 +1,21 @@ package org.geysermc.geyser.network; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import lombok.Getter; import lombok.Setter; import org.cloudburstmc.protocol.bedrock.packet.*; import org.geysermc.geyser.session.GeyserSession; -import java.util.HashMap; import java.util.Map; public class PacketCooldownManager { - private final Map packetCooldownSettings = new HashMap<>(); private final GeyserSession session; - @Setter - private long cooldownMillisDebug; - private long expiryTimeMillisDebug; + private final Map packetCooldownSettings = new Object2ObjectOpenHashMap<>(); + private final Map activeCooldowns = new Object2ObjectOpenHashMap<>(); - public PacketCooldownManager(GeyserSession session, long cooldownMillisDebug) { + public PacketCooldownManager(GeyserSession session) { this.session = session; - this.setCooldownMillisDebug(cooldownMillisDebug); - this.expiryTimeMillisDebug = 0; setPacketCooldown(LoginPacket.class, -1, 2); setPacketCooldown(ResourcePackClientResponsePacket.class, -1, 4); @@ -33,24 +29,11 @@ public void setPacketCooldown(Class packetClass, int co packetCooldownSettings.put(packetClass.getSimpleName(), new CooldownSettings(cooldownMillis, maxCount)); } - private final Map activeCooldowns = new HashMap<>(); - - private boolean isCooldownActive(BedrockPacket packet) { - String packetName = packet.getClass().getSimpleName(); - CooldownTracker tracker = activeCooldowns.get(packetName); - if (tracker != null && tracker.getCount() >= packetCooldownSettings.get(packetName).maxCount()) { - if (tracker.getExpiryTime() != -1 && tracker.getExpiryTime() <= System.currentTimeMillis()) { - activeCooldowns.remove(packetName); - } else { - return true; - } - } - return false; - } - - private void updateCooldown(BedrockPacket packet) { + private boolean isCooldown(BedrockPacket packet) { String packetName = packet.getClass().getSimpleName(); CooldownSettings settings = packetCooldownSettings.get(packetName); + if (settings == null) return false; + CooldownTracker tracker = activeCooldowns.computeIfAbsent(packetName, k -> { CooldownTracker newTracker = new CooldownTracker(); long cooldownMillis = settings.cooldownMillis(); @@ -62,26 +45,27 @@ private void updateCooldown(BedrockPacket packet) { return newTracker; }); tracker.incrementCount(); + + if (tracker.getExpiryTime() != -1 && tracker.getExpiryTime() <= System.currentTimeMillis()) { + activeCooldowns.remove(packetName); + return false; + } + + return tracker.getCount() >= settings.maxCount(); } - public boolean handle(BedrockPacket packet) { + public void handle(BedrockPacket packet) { String packetName = packet.getClass().getSimpleName(); - if (packetCooldownSettings.containsKey(packetName)) { - updateCooldown(packet); - if (isCooldownActive(packet)) { - if (expiryTimeMillisDebug <= System.currentTimeMillis()) { - CooldownTracker tracker = activeCooldowns.get(packetName); - String message = session.getSocketAddress().getAddress().toString() + " -> Attempted to send too many packets " + packet.getClass().getSimpleName() + " count " + tracker.getCount(); - if (session.isLoggedIn()) { - message += " by user " + session.bedrockUsername(); - } - session.getGeyser().getLogger().debug(message); - } - this.expiryTimeMillisDebug = System.currentTimeMillis() + cooldownMillisDebug; - return false; + if (!isCooldown(packet)) return; + if (session.getGeyser().getConfig().isDebugMode()) { + CooldownTracker tracker = activeCooldowns.get(packetName); + String message = session.getSocketAddress().getAddress().toString() + " -> Attempted to send too many packets " + packetName + " count " + tracker.getCount(); + if (session.isLoggedIn()) { + message += " by user " + session.bedrockUsername(); } + session.getGeyser().getLogger().debug(message); } - return true; + session.disconnect("many Packets " + packetName); } private record CooldownSettings(int cooldownMillis, int maxCount) { @@ -97,4 +81,4 @@ public void incrementCount() { this.count++; } } -} +} \ No newline at end of file diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java index 96118040081..f600a486f2c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java @@ -37,11 +37,9 @@ public class BedrockTextTranslator extends PacketTranslator { @Override public void translate(GeyserSession session, TextPacket packet) { - String message = packet.getMessage(); - // Java trims all messages, and then checks for the leading slash - message = MessageTranslator.convertToPlainText( - MessageTranslator.normalizeSpace(message) + String message = MessageTranslator.convertToPlainText( + MessageTranslator.normalizeSpace(packet.getMessage()) ); if (message.isBlank()) { From c682c5a7b0607be57271311674865d9b52660af8 Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Wed, 26 Jun 2024 20:40:14 +0300 Subject: [PATCH 16/21] =?UTF-8?q?=D0=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../geyser/network/LoggingPacketHandler.java | 12 +---------- .../geyser/network/UpstreamPacketHandler.java | 20 +++++-------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java index 7f35e4c3368..d1ae569e741 100644 --- a/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/LoggingPacketHandler.java @@ -47,18 +47,8 @@ public class LoggingPacketHandler implements BedrockPacketHandler { this.cooldownHandler = new PacketCooldownManager(session); } - public boolean handleLimit(BedrockPacket packet) { - boolean safePacket = this.cooldownHandler.handle(packet); - if (!safePacket) { - session.disconnect("many Packets " + packet.getClass().getSimpleName()); - } - return !safePacket; - } - PacketSignal defaultHandler(BedrockPacket packet) { - if (handleLimit(packet)) { - return PacketSignal.HANDLED; - } + this.cooldownHandler.handle(packet); geyser.getLogger().debug("Handled packet: " + packet.getClass().getSimpleName()); return PacketSignal.HANDLED; } diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index 9f71f58b3a4..3a721d116ad 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -85,9 +85,7 @@ private PacketSignal translateAndDefault(BedrockPacket packet) { @Override PacketSignal defaultHandler(BedrockPacket packet) { - if (handleLimit(packet)) { - return PacketSignal.HANDLED; - } + this.cooldownHandler.handle(packet); return translateAndDefault(packet); } @@ -156,9 +154,7 @@ public PacketSignal handle(RequestNetworkSettingsPacket packet) { @Override public PacketSignal handle(LoginPacket loginPacket) { - if(this.handleLimit(loginPacket)){ - return PacketSignal.HANDLED; - } + this.cooldownHandler.handle(loginPacket); if (geyser.isShuttingDown() || geyser.isReloading()) { // Don't allow new players in if we're no longer operating session.disconnect(GeyserLocale.getLocaleStringLog("geyser.core.shutdown.kick.message")); @@ -210,9 +206,7 @@ public PacketSignal handle(LoginPacket loginPacket) { @Override public PacketSignal handle(ResourcePackClientResponsePacket packet) { - if (this.handleLimit(packet)) { - return PacketSignal.HANDLED; - } + this.cooldownHandler.handle(packet); if (packet.getPackIds().size() > this.resourcePackLoadEvent.getPacks().size()) { session.disconnect("Packet " + packet.getClass().getSimpleName() + " PackIds max count"); return PacketSignal.HANDLED; @@ -281,9 +275,7 @@ public PacketSignal handle(ResourcePackClientResponsePacket packet) { @Override public PacketSignal handle(ModalFormResponsePacket packet) { - if(this.handleLimit(packet)){ - return PacketSignal.HANDLED; - } + this.cooldownHandler.handle(packet); session.executeInEventLoop(() -> session.getFormCache().handleResponse(packet)); return PacketSignal.HANDLED; } @@ -324,9 +316,7 @@ public PacketSignal handle(MovePlayerPacket packet) { @Override public PacketSignal handle(ResourcePackChunkRequestPacket packet) { - if (this.handleLimit(packet)) { - return PacketSignal.HANDLED; - } + this.cooldownHandler.handle(packet); ResourcePackChunkDataPacket data = new ResourcePackChunkDataPacket(); ResourcePack pack = this.resourcePackLoadEvent.getPacks().get(packet.getPackId().toString()); if (pack == null) { From d7652bf73864c6b2df823bbcc409719d1bbef85d Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Wed, 26 Jun 2024 20:52:41 +0300 Subject: [PATCH 17/21] hadle RequestNetworkSettingsPacket --- .../java/org/geysermc/geyser/network/PacketCooldownManager.java | 1 + .../java/org/geysermc/geyser/network/UpstreamPacketHandler.java | 1 + 2 files changed, 2 insertions(+) diff --git a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java index e98e2a408a6..3fdbcf1d0a8 100644 --- a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java +++ b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java @@ -20,6 +20,7 @@ public PacketCooldownManager(GeyserSession session) { setPacketCooldown(LoginPacket.class, -1, 2); setPacketCooldown(ResourcePackClientResponsePacket.class, -1, 4); setPacketCooldown(ResourcePackChunkRequestPacket.class, -1, 0); + setPacketCooldown(RequestNetworkSettingsPacket.class, -1, 2); setPacketCooldown(TextPacket.class, 1000, 50); setPacketCooldown(CommandRequestPacket.class, 1000, 50); setPacketCooldown(ModalFormResponsePacket.class, 1000, 50); diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index 3a721d116ad..a56d8c7d9b7 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -135,6 +135,7 @@ public void onDisconnect(String reason) { @Override public PacketSignal handle(RequestNetworkSettingsPacket packet) { + this.cooldownHandler.handle(packet); if (!setCorrectCodec(packet.getProtocolVersion())) { return PacketSignal.HANDLED; } From e6ff3541d36985578f9b51368ceddba15200815f Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Wed, 26 Jun 2024 20:52:49 +0300 Subject: [PATCH 18/21] FIXME --- .../java/org/geysermc/geyser/network/netty/GeyserServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java b/core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java index a67bd8a3281..571e0f66734 100644 --- a/core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java +++ b/core/src/main/java/org/geysermc/geyser/network/netty/GeyserServer.java @@ -236,7 +236,7 @@ private ServerBootstrap createBootstrap() { .group(group, childGroup) .option(RakChannelOption.RAK_HANDLE_PING, true) .option(RakChannelOption.RAK_MAX_MTU, this.geyser.getConfig().getMtu()) - .option(RakChannelOption.RAK_PACKET_LIMIT, rakPacketLimit) + .option(RakChannelOption.RAK_PACKET_LIMIT, rakPacketLimit) // FIXME When using Velocity, the proxy server gets kicked for exceeding the limit, even if this value is increased tenfold. With an online count of 1000, this happens about 40 times a day at a value of 450. It is unclear why it detects the server's IP with Velocity, rather than the players' IPs. .option(RakChannelOption.RAK_GLOBAL_PACKET_LIMIT, rakGlobalPacketLimit) .option(RakChannelOption.RAK_SEND_COOKIE, rakSendCookie) .childHandler(serverInitializer); From 32380c35efeb1a1b8b221b7bc832783d39efa3f4 Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Wed, 26 Jun 2024 22:00:26 +0300 Subject: [PATCH 19/21] add packets --- .../org/geysermc/geyser/network/CodecProcessor.java | 12 ++++++++++-- .../geyser/network/PacketCooldownManager.java | 7 +++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java index 70380803f2b..260610da272 100644 --- a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java +++ b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java @@ -36,7 +36,7 @@ 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.v422.serializer.FilterTextSerializer_v422; import org.cloudburstmc.protocol.bedrock.codec.v486.serializer.BossEventSerializer_v486; import org.cloudburstmc.protocol.bedrock.codec.v554.serializer.TextSerializer_v554; import org.cloudburstmc.protocol.bedrock.codec.v557.serializer.SetEntityDataSerializer_v557; @@ -124,6 +124,14 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, SetPlayerInve } }; + private static final BedrockPacketSerializer FILTER_TEXT = new FilterTextSerializer_v422() { + @Override + public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, FilterTextPacket packet) { + packet.setText(helper.readStringMaxLen(buffer, 512)); + packet.setFromServer(buffer.readBoolean()); + } + }; + private static final BedrockPacketSerializer COMMAND_REQUEST_SERIALIZER = new CommandRequestSerializer_v567() { @Override public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, CommandRequestPacket packet) { @@ -309,7 +317,7 @@ static BedrockCodec processCodec(BedrockCodec codec) { // Ignored bidirectional packets codecBuilder.updateSerializer(TickSyncPacket.class, IGNORED_SERIALIZER); } - + codecBuilder.updateSerializer(FilterTextPacket.class, FILTER_TEXT); codecBuilder.updateSerializer(CommandRequestPacket.class, COMMAND_REQUEST_SERIALIZER); codecBuilder.updateSerializer(SetPlayerInventoryOptionsPacket.class, SET_PLAYER_INVENTORY_OPTIONS_SERIALIZER); if (codec.getProtocolVersion() >= 685) { diff --git a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java index 3fdbcf1d0a8..a2c91e638c2 100644 --- a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java +++ b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java @@ -24,6 +24,13 @@ public PacketCooldownManager(GeyserSession session) { setPacketCooldown(TextPacket.class, 1000, 50); setPacketCooldown(CommandRequestPacket.class, 1000, 50); setPacketCooldown(ModalFormResponsePacket.class, 1000, 50); + setPacketCooldown(BlockEntityDataPacket.class, 1000, 40); + setPacketCooldown(SetLocalPlayerAsInitializedPacket.class, 1000, 40); + setPacketCooldown(BlockPickRequestPacket.class, 1000, 40); + setPacketCooldown(EntityPickRequestPacket.class, 1000, 40); + setPacketCooldown(BookEditPacket.class, 1000, 40); + setPacketCooldown(FilterTextPacket.class, 1000, 40); + setPacketCooldown(LecternUpdatePacket.class, 1000, 10); } public void setPacketCooldown(Class packetClass, int cooldownMillis, int maxCount) { From 1ebb1b03efadc02b46cc8dd94a2ac725b012be2b Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Fri, 28 Jun 2024 14:53:38 +0300 Subject: [PATCH 20/21] del import --- .../main/java/org/geysermc/geyser/network/CodecProcessor.java | 2 +- .../translator/protocol/bedrock/BedrockTextTranslator.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java index 260610da272..e65d3d936ef 100644 --- a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java +++ b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java @@ -127,7 +127,7 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, SetPlayerInve private static final BedrockPacketSerializer FILTER_TEXT = new FilterTextSerializer_v422() { @Override public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, FilterTextPacket packet) { - packet.setText(helper.readStringMaxLen(buffer, 512)); + packet.setText(helper.readStringMaxLen(buffer, 513)); packet.setFromServer(buffer.readBoolean()); } }; diff --git a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java index f600a486f2c..bac9b9ecc6c 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/protocol/bedrock/BedrockTextTranslator.java @@ -27,7 +27,6 @@ import org.cloudburstmc.protocol.bedrock.packet.TextPacket; 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; From 6e0ded832ada8299f3503601c139239b1f2a60fc Mon Sep 17 00:00:00 2001 From: OurLobanov Date: Sun, 7 Jul 2024 11:23:23 +0300 Subject: [PATCH 21/21] import --- .../geyser/network/CodecProcessor.java | 55 +++++++++++++++++-- .../geyser/network/PacketCooldownManager.java | 18 +++++- .../geyser/network/UpstreamPacketHandler.java | 16 +++++- 3 files changed, 80 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java index e65d3d936ef..ff330e77194 100644 --- a/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java +++ b/core/src/main/java/org/geysermc/geyser/network/CodecProcessor.java @@ -47,7 +47,50 @@ 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.bedrock.packet.AnvilDamagePacket; +import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; +import org.cloudburstmc.protocol.bedrock.packet.BossEventPacket; +import org.cloudburstmc.protocol.bedrock.packet.ClientCacheBlobStatusPacket; +import org.cloudburstmc.protocol.bedrock.packet.ClientCacheStatusPacket; +import org.cloudburstmc.protocol.bedrock.packet.ClientCheatAbilityPacket; +import org.cloudburstmc.protocol.bedrock.packet.ClientToServerHandshakePacket; +import org.cloudburstmc.protocol.bedrock.packet.CodeBuilderSourcePacket; +import org.cloudburstmc.protocol.bedrock.packet.CommandRequestPacket; +import org.cloudburstmc.protocol.bedrock.packet.CraftingEventPacket; +import org.cloudburstmc.protocol.bedrock.packet.CreatePhotoPacket; +import org.cloudburstmc.protocol.bedrock.packet.DebugInfoPacket; +import org.cloudburstmc.protocol.bedrock.packet.EditorNetworkPacket; +import org.cloudburstmc.protocol.bedrock.packet.EmoteListPacket; +import org.cloudburstmc.protocol.bedrock.packet.EntityFallPacket; +import org.cloudburstmc.protocol.bedrock.packet.FilterTextPacket; +import org.cloudburstmc.protocol.bedrock.packet.GameTestRequestPacket; +import org.cloudburstmc.protocol.bedrock.packet.InventoryContentPacket; +import org.cloudburstmc.protocol.bedrock.packet.InventorySlotPacket; +import org.cloudburstmc.protocol.bedrock.packet.LabTablePacket; +import org.cloudburstmc.protocol.bedrock.packet.MapCreateLockedCopyPacket; +import org.cloudburstmc.protocol.bedrock.packet.MapInfoRequestPacket; +import org.cloudburstmc.protocol.bedrock.packet.MobArmorEquipmentPacket; +import org.cloudburstmc.protocol.bedrock.packet.MobEquipmentPacket; +import org.cloudburstmc.protocol.bedrock.packet.MultiplayerSettingsPacket; +import org.cloudburstmc.protocol.bedrock.packet.NpcRequestPacket; +import org.cloudburstmc.protocol.bedrock.packet.PhotoInfoRequestPacket; +import org.cloudburstmc.protocol.bedrock.packet.PhotoTransferPacket; +import org.cloudburstmc.protocol.bedrock.packet.PlayerAuthInputPacket; +import org.cloudburstmc.protocol.bedrock.packet.PlayerHotbarPacket; +import org.cloudburstmc.protocol.bedrock.packet.PlayerSkinPacket; +import org.cloudburstmc.protocol.bedrock.packet.PurchaseReceiptPacket; +import org.cloudburstmc.protocol.bedrock.packet.RefreshEntitlementsPacket; +import org.cloudburstmc.protocol.bedrock.packet.ScriptMessagePacket; +import org.cloudburstmc.protocol.bedrock.packet.SetEntityDataPacket; +import org.cloudburstmc.protocol.bedrock.packet.SetEntityLinkPacket; +import org.cloudburstmc.protocol.bedrock.packet.SetEntityMotionPacket; +import org.cloudburstmc.protocol.bedrock.packet.SetPlayerInventoryOptionsPacket; +import org.cloudburstmc.protocol.bedrock.packet.SettingsCommandPacket; +import org.cloudburstmc.protocol.bedrock.packet.SimpleEventPacket; +import org.cloudburstmc.protocol.bedrock.packet.SubChunkRequestPacket; +import org.cloudburstmc.protocol.bedrock.packet.SubClientLoginPacket; +import org.cloudburstmc.protocol.bedrock.packet.TextPacket; +import org.cloudburstmc.protocol.bedrock.packet.TickSyncPacket; import org.cloudburstmc.protocol.common.util.VarInts; /** @@ -320,11 +363,11 @@ static BedrockCodec processCodec(BedrockCodec codec) { codecBuilder.updateSerializer(FilterTextPacket.class, FILTER_TEXT); codecBuilder.updateSerializer(CommandRequestPacket.class, COMMAND_REQUEST_SERIALIZER); codecBuilder.updateSerializer(SetPlayerInventoryOptionsPacket.class, SET_PLAYER_INVENTORY_OPTIONS_SERIALIZER); - if (codec.getProtocolVersion() >= 685) { - codecBuilder.updateSerializer(TextPacket.class, TEXT_SERIALIZER); - } else { - codecBuilder.updateSerializer(TextPacket.class, TEXT_SERIALIZER_V554); - } + if (codec.getProtocolVersion() >= 685) { + codecBuilder.updateSerializer(TextPacket.class, TEXT_SERIALIZER); + } else { + codecBuilder.updateSerializer(TextPacket.class, TEXT_SERIALIZER_V554); + } return codecBuilder.build(); } diff --git a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java index a2c91e638c2..bf5ae2b22a1 100644 --- a/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java +++ b/core/src/main/java/org/geysermc/geyser/network/PacketCooldownManager.java @@ -3,7 +3,21 @@ import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import lombok.Getter; import lombok.Setter; -import org.cloudburstmc.protocol.bedrock.packet.*; +import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; +import org.cloudburstmc.protocol.bedrock.packet.BlockEntityDataPacket; +import org.cloudburstmc.protocol.bedrock.packet.BlockPickRequestPacket; +import org.cloudburstmc.protocol.bedrock.packet.BookEditPacket; +import org.cloudburstmc.protocol.bedrock.packet.CommandRequestPacket; +import org.cloudburstmc.protocol.bedrock.packet.EntityPickRequestPacket; +import org.cloudburstmc.protocol.bedrock.packet.FilterTextPacket; +import org.cloudburstmc.protocol.bedrock.packet.LecternUpdatePacket; +import org.cloudburstmc.protocol.bedrock.packet.LoginPacket; +import org.cloudburstmc.protocol.bedrock.packet.ModalFormResponsePacket; +import org.cloudburstmc.protocol.bedrock.packet.RequestNetworkSettingsPacket; +import org.cloudburstmc.protocol.bedrock.packet.ResourcePackChunkRequestPacket; +import org.cloudburstmc.protocol.bedrock.packet.ResourcePackClientResponsePacket; +import org.cloudburstmc.protocol.bedrock.packet.SetLocalPlayerAsInitializedPacket; +import org.cloudburstmc.protocol.bedrock.packet.TextPacket; import org.geysermc.geyser.session.GeyserSession; import java.util.Map; @@ -89,4 +103,4 @@ public void incrementCount() { this.count++; } } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java index a56d8c7d9b7..577af02defc 100644 --- a/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java +++ b/core/src/main/java/org/geysermc/geyser/network/UpstreamPacketHandler.java @@ -36,7 +36,21 @@ import org.cloudburstmc.protocol.bedrock.netty.codec.compression.CompressionStrategy; import org.cloudburstmc.protocol.bedrock.netty.codec.compression.SimpleCompressionStrategy; import org.cloudburstmc.protocol.bedrock.netty.codec.compression.ZlibCompression; -import org.cloudburstmc.protocol.bedrock.packet.*; +import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket; +import org.cloudburstmc.protocol.bedrock.packet.LecternUpdatePacket; +import org.cloudburstmc.protocol.bedrock.packet.LoginPacket; +import org.cloudburstmc.protocol.bedrock.packet.ModalFormResponsePacket; +import org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket; +import org.cloudburstmc.protocol.bedrock.packet.NetworkSettingsPacket; +import org.cloudburstmc.protocol.bedrock.packet.PlayStatusPacket; +import org.cloudburstmc.protocol.bedrock.packet.RequestNetworkSettingsPacket; +import org.cloudburstmc.protocol.bedrock.packet.ResourcePackChunkDataPacket; +import org.cloudburstmc.protocol.bedrock.packet.ResourcePackChunkRequestPacket; +import org.cloudburstmc.protocol.bedrock.packet.ResourcePackClientResponsePacket; +import org.cloudburstmc.protocol.bedrock.packet.ResourcePackDataInfoPacket; +import org.cloudburstmc.protocol.bedrock.packet.ResourcePackStackPacket; +import org.cloudburstmc.protocol.bedrock.packet.ResourcePacksInfoPacket; +import org.cloudburstmc.protocol.bedrock.packet.SetTitlePacket; import org.cloudburstmc.protocol.common.PacketSignal; import org.cloudburstmc.protocol.common.util.Zlib; import org.geysermc.geyser.Constants;