network: 22w42a unsigned chat message

This commit is contained in:
Bixilon 2022-10-25 18:22:28 +02:00
parent e927232261
commit 1537eeee95
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
6 changed files with 97 additions and 22 deletions

View File

@ -0,0 +1,41 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.data.chat.message
import de.bixilon.minosoft.data.chat.ChatUtil
import de.bixilon.minosoft.data.language.lang.Language
import de.bixilon.minosoft.data.registries.chat.ChatMessageType
import de.bixilon.minosoft.data.registries.chat.ChatParameter
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.KUtil.toResourceLocation
open class FormattedChatMessage(
private val connection: PlayConnection,
final override val type: ChatMessageType,
val parameters: Map<ChatParameter, ChatComponent>,
) : ChatMessage {
final override val text: ChatComponent
init {
// ToDo: parent (formatting)
val data = type.chat.formatParameters(parameters)
text = if (connection.language.canTranslate(type.chat.translationKey.toResourceLocation())) {
connection.language.translate(type.chat.translationKey.toResourceLocation(), data = data)
} else {
Language.translate(type.chat.translationKey, data = data)
}
text.setFallbackColor(ChatUtil.DEFAULT_CHAT_COLOR)
}
}

View File

@ -13,38 +13,22 @@
package de.bixilon.minosoft.data.chat.message package de.bixilon.minosoft.data.chat.message
import de.bixilon.minosoft.data.chat.ChatUtil
import de.bixilon.minosoft.data.chat.filter.Filter import de.bixilon.minosoft.data.chat.filter.Filter
import de.bixilon.minosoft.data.chat.sender.MessageSender import de.bixilon.minosoft.data.chat.sender.MessageSender
import de.bixilon.minosoft.data.language.lang.Language
import de.bixilon.minosoft.data.registries.chat.ChatMessageType import de.bixilon.minosoft.data.registries.chat.ChatMessageType
import de.bixilon.minosoft.data.registries.chat.ChatParameter import de.bixilon.minosoft.data.registries.chat.ChatParameter
import de.bixilon.minosoft.data.text.ChatComponent import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.util.KUtil.toResourceLocation
import java.time.Instant import java.time.Instant
class SignedChatMessage( class SignedChatMessage(
private val connection: PlayConnection, private val connection: PlayConnection,
val message: String, val message: String,
override val type: ChatMessageType, type: ChatMessageType,
override val sender: MessageSender, override val sender: MessageSender,
val parameters: Map<ChatParameter, ChatComponent>, parameters: Map<ChatParameter, ChatComponent>,
val filter: Filter?, val filter: Filter?,
val error: Exception?, val error: Exception?,
val sent: Instant, val sent: Instant,
val received: Instant, val received: Instant,
) : ChatMessage, PlayerSentMessage { ) : FormattedChatMessage(connection, type, parameters), ChatMessage, PlayerSentMessage
override val text: ChatComponent
init {
// ToDo: parent (formatting)
val data = type.chat.formatParameters(parameters)
text = if (connection.language.canTranslate(type.chat.translationKey.toResourceLocation())) {
connection.language.translate(type.chat.translationKey.toResourceLocation(), data = data)
} else {
Language.translate(type.chat.translationKey, data = data)
}
text.setFallbackColor(ChatUtil.DEFAULT_CHAT_COLOR)
}
}

View File

@ -82,8 +82,7 @@ class SignedChatMessageS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
} }
val type = readRegistryItem(connection.registries.messageTypeRegistry) val type = readRegistryItem(connection.registries.messageTypeRegistry)
parameters[ChatParameter.SENDER] = readChatComponent() readChatMessageParameters(parameters)
readOptional { readChatComponent() }?.let { parameters[ChatParameter.TARGET] = it }
val sender = connection.getMessageSender(header.sender) val sender = connection.getMessageSender(header.sender)
val received = Instant.now() val received = Instant.now()

View File

@ -0,0 +1,45 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* 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.minosoft.data.chat.message.FormattedChatMessage
import de.bixilon.minosoft.data.registries.chat.ChatParameter
import de.bixilon.minosoft.data.text.ChatComponent
import de.bixilon.minosoft.modding.event.EventInitiators
import de.bixilon.minosoft.modding.event.events.chat.ChatMessageReceiveEvent
import de.bixilon.minosoft.protocol.network.connection.play.PlayConnection
import de.bixilon.minosoft.protocol.packets.factory.LoadPacket
import de.bixilon.minosoft.protocol.packets.s2c.PlayS2CPacket
import de.bixilon.minosoft.protocol.protocol.PlayInByteBuffer
import de.bixilon.minosoft.util.logging.Log
import de.bixilon.minosoft.util.logging.LogLevels
import de.bixilon.minosoft.util.logging.LogMessageType
@LoadPacket(threadSafe = false)
class UnsignedChatMessageS2CP(buffer: PlayInByteBuffer) : PlayS2CPacket {
val text: ChatComponent = buffer.readChatComponent()
val type = buffer.readRegistryItem(buffer.connection.registries.messageTypeRegistry)
val parameters: Map<ChatParameter, ChatComponent> = mutableMapOf<ChatParameter, ChatComponent>().apply {
buffer.readChatMessageParameters(this)
this[ChatParameter.CONTENT] = text
}
override fun handle(connection: PlayConnection) {
val message = FormattedChatMessage(connection, type, parameters)
connection.fireEvent(ChatMessageReceiveEvent(connection, EventInitiators.SERVER, message))
}
override fun log(reducedLog: Boolean) {
Log.log(LogMessageType.NETWORK_PACKETS_IN, level = LogLevels.VERBOSE) { "Chat message (text=$text, parameters=$parameters)" }
}
}

View File

@ -28,6 +28,7 @@ import de.bixilon.minosoft.data.container.stack.ItemStack
import de.bixilon.minosoft.data.entities.entities.player.properties.PlayerProperties import de.bixilon.minosoft.data.entities.entities.player.properties.PlayerProperties
import de.bixilon.minosoft.data.entities.entities.player.properties.textures.PlayerTextures import de.bixilon.minosoft.data.entities.entities.player.properties.textures.PlayerTextures
import de.bixilon.minosoft.data.registries.biomes.Biome import de.bixilon.minosoft.data.registries.biomes.Biome
import de.bixilon.minosoft.data.registries.chat.ChatParameter
import de.bixilon.minosoft.data.registries.particle.ParticleType import de.bixilon.minosoft.data.registries.particle.ParticleType
import de.bixilon.minosoft.data.registries.particle.data.BlockParticleData import de.bixilon.minosoft.data.registries.particle.data.BlockParticleData
import de.bixilon.minosoft.data.registries.particle.data.DustParticleData import de.bixilon.minosoft.data.registries.particle.data.DustParticleData
@ -383,4 +384,9 @@ class PlayInByteBuffer : InByteBuffer {
} }
return set return set
} }
fun readChatMessageParameters(parameters: MutableMap<ChatParameter, ChatComponent>) {
parameters[ChatParameter.SENDER] = readChatComponent()
readOptional { readChatComponent() }?.let { parameters[ChatParameter.TARGET] = it }
}
} }

View File

@ -4,7 +4,7 @@
"protocol_id": 1073741928, "protocol_id": 1073741928,
"packets": { "packets": {
"c2s": ["confirm_teleport", "block_nbt", "difficulty", "message_acknowledgement", "command", "signed_chat_message", "client_action", "settings", "command_suggestions", "container_button", "container_click", "close_container", "plugin", "book", "entity_nbt", "entity_interact", "generate_structure", "heartbeat", "lock_difficulty", "position", "position_rotation", "rotation", "ground_change", "move_vehicle", "steer_boat", "item_pick", "crafting_recipe", "toggle_fly", "player_action", "entity_action", "steer_vehicle", "pong", "displayed_recipe", "recipe_book", "anvil_item_name", "resourcepack", "advancement_tab", "trade", "beacon_effect", "hotbar_slot", "command_block", "minecart_command_block", "item_stack_create", "jigsaw_block", "structure_block", "sign_text", "swing_arm", "entity_spectate", "block_interact", "use_item"], "c2s": ["confirm_teleport", "block_nbt", "difficulty", "message_acknowledgement", "command", "signed_chat_message", "client_action", "settings", "command_suggestions", "container_button", "container_click", "close_container", "plugin", "book", "entity_nbt", "entity_interact", "generate_structure", "heartbeat", "lock_difficulty", "position", "position_rotation", "rotation", "ground_change", "move_vehicle", "steer_boat", "item_pick", "crafting_recipe", "toggle_fly", "player_action", "entity_action", "steer_vehicle", "pong", "displayed_recipe", "recipe_book", "anvil_item_name", "resourcepack", "advancement_tab", "trade", "beacon_effect", "hotbar_slot", "command_block", "minecart_command_block", "item_stack_create", "jigsaw_block", "structure_block", "sign_text", "swing_arm", "entity_spectate", "block_interact", "use_item"],
"s2c": ["entity_object_spawn", "entity_experience_orb", "entity_player", "entity_animation", "statistics", "block_break", "block_break_animation", "block_data", "block_action", "block", "bossbar", "difficulty", "clear_title", "command_suggestions", "commands", "close_container", "container_items", "container_properties", "container_item", "item_cooldown", "chat_suggestions", "plugin", "named_sound", "hide_message", "kick", "profileless_chat_message", "entity_status", "explosion", "unload_chunk", "game_event", "open_horse_container", "initialize_world_border", "heartbeat", "chunk", "world_event", "particle", "chunk_light", "initialize", "map", "villager_trades", "relative_move", "movement_rotation", "rotation", "move_vehicle", "book", "open_container", "sign_editor", "ping", "crafting_recipe", "player_abilities", "signed_chat_message", "end_combat_event", "enter_combat_event", "kill_combat_event", "player_remove", "tab_list", "player_face", "position_rotation", "unlock_recipes", "entity_destroy", "entity_remove_effect", "resourcepack", "respawn", "head_rotation", "blocks", "advancement_tab", "play_status", "hotbar_text", "center_world_border", "interpolate_world_border", "size_world_border", "warn_time_world_border", "warn_blocks_world_border", "camera", "hotbar_slot", "chunk_center", "view_distance", "compass_position", "objective_position", "entity_data", "entity_attach", "velocity", "entity_equipment", "experience", "health", "objective", "entity_passenger", "teams", "scoreboard_score", "simulation_distance", "subtitle", "time", "title_text", "title_times", "entity_sound", "sound_event", "stop_sound", "chat_message", "tab_list_text", "nbt_response", "entity_collect", "teleport", "advancements", "entity_attributes", "features", "entity_effect", "recipes", "tags"] "s2c": ["entity_object_spawn", "entity_experience_orb", "entity_player", "entity_animation", "statistics", "block_break", "block_break_animation", "block_data", "block_action", "block", "bossbar", "difficulty", "clear_title", "command_suggestions", "commands", "close_container", "container_items", "container_properties", "container_item", "item_cooldown", "chat_suggestions", "plugin", "named_sound", "hide_message", "kick", "unsigned_chat_message", "entity_status", "explosion", "unload_chunk", "game_event", "open_horse_container", "initialize_world_border", "heartbeat", "chunk", "world_event", "particle", "chunk_light", "initialize", "map", "villager_trades", "relative_move", "movement_rotation", "rotation", "move_vehicle", "book", "open_container", "sign_editor", "ping", "crafting_recipe", "player_abilities", "signed_chat_message", "end_combat_event", "enter_combat_event", "kill_combat_event", "player_remove", "tab_list", "player_face", "position_rotation", "unlock_recipes", "entity_destroy", "entity_remove_effect", "resourcepack", "respawn", "head_rotation", "blocks", "advancement_tab", "play_status", "hotbar_text", "center_world_border", "interpolate_world_border", "size_world_border", "warn_time_world_border", "warn_blocks_world_border", "camera", "hotbar_slot", "chunk_center", "view_distance", "compass_position", "objective_position", "entity_data", "entity_attach", "velocity", "entity_equipment", "experience", "health", "objective", "entity_passenger", "teams", "scoreboard_score", "simulation_distance", "subtitle", "time", "title_text", "title_times", "entity_sound", "sound_event", "stop_sound", "chat_message", "tab_list_text", "nbt_response", "entity_collect", "teleport", "advancements", "entity_attributes", "features", "entity_effect", "recipes", "tags"]
} }
}, },
"862": { "862": {