From fdd90cefc1dc7fbdd85243add6ec8e553e3d88ea Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Sun, 8 Oct 2023 00:36:08 +0200 Subject: [PATCH] signed chat message s2cp test (23w40a) --- .../connection/play/ConnectionTestUtil.kt | 2 + .../play/chat/SignedChatMessageS2CPTest.kt | 49 ++++++++++++++++++ .../signed_chat_message/vanilla_23w40a.bin | Bin 0 -> 524 bytes .../minosoft/data/chat/type/MessageType.kt | 24 --------- 4 files changed, 51 insertions(+), 24 deletions(-) create mode 100644 src/integration-test/kotlin/de/bixilon/minosoft/protocol/packets/s2c/play/chat/SignedChatMessageS2CPTest.kt create mode 100644 src/integration-test/resources/packets/signed_chat_message/vanilla_23w40a.bin delete mode 100644 src/main/java/de/bixilon/minosoft/data/chat/type/MessageType.kt diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/protocol/network/connection/play/ConnectionTestUtil.kt b/src/integration-test/kotlin/de/bixilon/minosoft/protocol/network/connection/play/ConnectionTestUtil.kt index 1666e103d..b7c029ded 100644 --- a/src/integration-test/kotlin/de/bixilon/minosoft/protocol/network/connection/play/ConnectionTestUtil.kt +++ b/src/integration-test/kotlin/de/bixilon/minosoft/protocol/network/connection/play/ConnectionTestUtil.kt @@ -22,6 +22,7 @@ import de.bixilon.minosoft.config.profile.ProfileTestUtil.createProfiles import de.bixilon.minosoft.data.accounts.types.test.TestAccount import de.bixilon.minosoft.data.entities.entities.player.local.LocalPlayerEntity import de.bixilon.minosoft.data.entities.entities.player.local.SignatureKeyManagement +import de.bixilon.minosoft.data.language.lang.LanguageList import de.bixilon.minosoft.data.registries.registries.Registries import de.bixilon.minosoft.data.world.WorldTestUtil.createWorld import de.bixilon.minosoft.data.world.WorldTestUtil.initialize @@ -47,6 +48,7 @@ object ConnectionTestUtil { fun createConnection(worldSize: Int = 0, light: Boolean = false, version: String? = null): PlayConnection { val connection = IT.OBJENESIS.newInstance(PlayConnection::class.java) + connection::language.forceSet(LanguageList(mutableListOf())) val version = if (version == null) IT.VERSION else Versions[version] ?: throw IllegalArgumentException("Can not find version: $version") connection::sequence.forceSet(AtomicInteger(1)) connection::account.forceSet(TestAccount) diff --git a/src/integration-test/kotlin/de/bixilon/minosoft/protocol/packets/s2c/play/chat/SignedChatMessageS2CPTest.kt b/src/integration-test/kotlin/de/bixilon/minosoft/protocol/packets/s2c/play/chat/SignedChatMessageS2CPTest.kt new file mode 100644 index 000000000..13089ad73 --- /dev/null +++ b/src/integration-test/kotlin/de/bixilon/minosoft/protocol/packets/s2c/play/chat/SignedChatMessageS2CPTest.kt @@ -0,0 +1,49 @@ +/* + * Minosoft + * Copyright (C) 2020-2023 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.protocol.packets.s2c.play.chat + +import de.bixilon.kutil.reflection.ReflectionUtil.forceSet +import de.bixilon.kutil.uuid.UUIDUtil.toUUID +import de.bixilon.minosoft.data.chat.ChatTextPositions +import de.bixilon.minosoft.data.chat.sender.UnknownMessageSender +import de.bixilon.minosoft.data.entities.entities.player.tab.TabList +import de.bixilon.minosoft.data.language.lang.LanguageList +import de.bixilon.minosoft.data.registries.chat.ChatMessageType +import de.bixilon.minosoft.data.registries.chat.TypeProperties +import de.bixilon.minosoft.data.registries.identified.Namespaces.minecraft +import de.bixilon.minosoft.protocol.network.connection.play.ConnectionTestUtil.createConnection +import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection +import de.bixilon.minosoft.protocol.packets.s2c.play.PacketReadingTestUtil +import org.testng.Assert.assertEquals +import org.testng.annotations.Test + +@Test(groups = ["packet"]) +class SignedChatMessageS2CPTest { + + private fun connection(): PlayConnection { + val connection = createConnection() + connection::language.forceSet(LanguageList(mutableListOf())) + connection::tabList.forceSet(TabList()) + connection.registries.messageType[0] = ChatMessageType(minecraft("dummy"), TypeProperties("test", emptyList(), emptyMap()), null, ChatTextPositions.CHAT) + + return connection + } + + fun vanilla_23w40a() { + val packet = PacketReadingTestUtil.read("signed_chat_message/vanilla_23w40a", "23w40a", connection(), constructor = ::SignedChatMessageS2CP) + assertEquals(packet.message.message, "abc") + assertEquals(packet.message.sender, UnknownMessageSender("a21a6c65-bbd4-48ca-9d79-e07139e1780d".toUUID())) + } +} + diff --git a/src/integration-test/resources/packets/signed_chat_message/vanilla_23w40a.bin b/src/integration-test/resources/packets/signed_chat_message/vanilla_23w40a.bin new file mode 100644 index 0000000000000000000000000000000000000000..d0729d879f666bea8c19b84675bb921fd7354c34 GIT binary patch literal 524 zcmZ1^m6N*ripQzBl@AInA6D=(FxrRy?<+F&oN-3!%OaV*XMftgy|%ORbzDp&cYDW? zjTvgrdnc{B%5`;lKmVn@t9QEmGTGmI*yic|`(K)4OXzWXl#C=QN@3fFwa;#bBl-o?QeM&2>8d-XKo%c7_|lce;2u1Z*TlI6eH zJI{qV!J5CLmev`_9b)zF6=?CXyBLxy+bQO%WBkrO=8;%zl#db1_9}@iruPyjw|jk4 zTlrb--unaH?2g|14%vBSZaVcM*l*I7*P%C`FYn`LPE1N>U|{U#F>cs!opVO>iU)48 z3_!re#lV%3UzS?rT9%qu!o|RmoS#<$WEFETu;eA?rZR9Q<&>soXQt*Z{9+|0bx T5!h^m6G1LXttdfqGy?+wD8AS* literal 0 HcmV?d00001 diff --git a/src/main/java/de/bixilon/minosoft/data/chat/type/MessageType.kt b/src/main/java/de/bixilon/minosoft/data/chat/type/MessageType.kt deleted file mode 100644 index 10fe272e2..000000000 --- a/src/main/java/de/bixilon/minosoft/data/chat/type/MessageType.kt +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Minosoft - * Copyright (C) 2020-2022 Moritz Zwerger - * - * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with this program. If not, see . - * - * This software is not affiliated with Mojang AB, the original developer of Minecraft. - */ - -package de.bixilon.minosoft.data.chat.type - -import de.bixilon.minosoft.data.registries.chat.ChatMessageType -import de.bixilon.minosoft.data.text.ChatComponent - -@Deprecated("Refactor") -class MessageType( - val type: ChatMessageType, - val text: ChatComponent, - val targetName: ChatComponent?, -)