From 42ef39854434bf67b6cf168de9671ec37f784d41 Mon Sep 17 00:00:00 2001 From: teatov Date: Sat, 15 Feb 2025 00:56:09 +1000 Subject: [PATCH] add escaping bbcode tags to chat --- scripts/ui/chat.gd | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/scripts/ui/chat.gd b/scripts/ui/chat.gd index 860fed9..90d37d7 100644 --- a/scripts/ui/chat.gd +++ b/scripts/ui/chat.gd @@ -1,6 +1,10 @@ class_name Chat extends Menu +const BBCODE_TAGS_TO_ESCAPE: PackedStringArray = [ + "url", "img", "font", "dropcap", "opentype_features", "outline_size" +] + var _chat_message_scene := preload("res://scenes/ui/chat_message.tscn") var _message_history: PackedStringArray = [] @@ -72,7 +76,7 @@ func _send_message(message: String) -> void: func _make_message_node(player_name: String, message: String) -> RichTextLabel: var node := _chat_message_scene.instantiate() as RichTextLabel - node.text = "[b]" + player_name + ":[/b] " + message + node.text = "[b]" + player_name + ":[/b] " + _escape_bbcode_tags(message) return node @@ -85,6 +89,14 @@ func _set_message_from_history() -> void: _message_edit.text = "" +func _escape_bbcode_tags(message: String) -> String: + for tag_name in BBCODE_TAGS_TO_ESCAPE: + var tag := "[" + tag_name + if tag in message: + message = message.replace(tag, "[lb]" + tag_name) + return message + + func _on_message_edit_text_submitted(message: String) -> void: if _message_edit.text == "": return