From 65f66921a90df6bd38097c5d085735d74fc1d25c Mon Sep 17 00:00:00 2001 From: Lucia Ceionia Date: Fri, 8 Nov 2024 03:54:34 -0600 Subject: [PATCH] 0.6 features --- Godot/mods/Lucy.LucysTools/lucys_menu.gd | 38 +- Godot/mods/Lucy.LucysTools/lucys_menu.tscn | 165 ++++--- Godot/mods/Lucy.LucysTools/main.gd | 503 +++++++++++++++------ 3 files changed, 503 insertions(+), 203 deletions(-) diff --git a/Godot/mods/Lucy.LucysTools/lucys_menu.gd b/Godot/mods/Lucy.LucysTools/lucys_menu.gd index 2a136d4..ac34425 100644 --- a/Godot/mods/Lucy.LucysTools/lucys_menu.gd +++ b/Godot/mods/Lucy.LucysTools/lucys_menu.gd @@ -8,17 +8,23 @@ func setup(): get_node("%lucy_servername").text = MANAGER.custom_server_name get_node("%lucy_servername_preview").bbcode_text = MANAGER.custom_server_name get_node("%lucy_servermsg").text = MANAGER.server_join_message - get_node("%lucy_servermsg_preview").bbcode_text = MANAGER.server_join_message - var srv_m_bb = MANAGER.bbcode_process(MANAGER.server_join_message) + var srv_m_bb = MANAGER.bbcode_process(MANAGER.server_join_message, 512) + get_node("%lucy_servermsg_preview").bbcode_text = srv_m_bb.fin get_node("%lucy_servermsg_preview2").bbcode_text = srv_m_bb.stripped get_node("%lucy_intbbcode").pressed = MANAGER.allow_intrusive_bbcode get_node("%lucy_chatcolor_bool").pressed = MANAGER.custom_color_enabled get_node("%lucy_chatcolor").color = Color(MANAGER.custom_color) + get_node("%lucy_chatcolor_bool2").pressed = MANAGER.custom_text_color_enabled + get_node("%lucy_chatcolor2").color = Color(MANAGER.custom_text_color) get_node("%lucy_name").text = MANAGER.custom_name + get_node("%lucy_bug_bb").pressed = MANAGER.bug_bbcode + + get_node("%lucy_srv_bbcode").pressed = MANAGER.srv_bbcode + update() @@ -27,10 +33,7 @@ func update(): func _on_lucy_name_text_changed(new_text): - var result = MANAGER.bbcode_process(new_text) - #print("[fin] ", result.fin) - #print("[tags] ", result.tags) - #print("[stripped] ", result.stripped) + var result = MANAGER.bbcode_process(new_text, 512) var lol_steam_username = Network.STEAM_USERNAME.replace("[", "").replace("]", "") var good = result.stripped == lol_steam_username @@ -54,6 +57,8 @@ func _ready(): get_node("%lucy_freezerain").disabled = not can_spawn get_node("%lucy_clearrain").disabled = not can_spawn get_node("%lucy_clearmeteor").disabled = not can_spawn + + get_node("%lucy_srv_bbcode").disabled = not (Network.GAME_MASTER or Network.PLAYING_OFFLINE) func _input(event): if event is InputEventKey and event.scancode == KEY_F5 && event.pressed: @@ -79,7 +84,7 @@ func _on_lucy_servername_text_changed(new_text): get_node("%lucy_servername_preview").bbcode_text = new_text MANAGER.custom_server_name = new_text func _on_lucy_servermsg_text_changed(new_text): - var result = MANAGER.bbcode_process(new_text) + var result = MANAGER.bbcode_process(new_text, 512) get_node("%lucy_servermsg_preview").bbcode_text = result.fin get_node("%lucy_servermsg_preview2").bbcode_text = result.stripped MANAGER.server_join_message = new_text @@ -87,11 +92,20 @@ func _on_lucy_chatcolor_bool_toggled(button_pressed): MANAGER.custom_color_enabled = button_pressed func _on_lucy_chatcolor_color_changed(color): MANAGER.custom_color = color +func _on_lucy_chatcolor_bool2_toggled(button_pressed): + MANAGER.custom_text_color_enabled = button_pressed +func _on_lucy_chatcolor2_color_changed(color): + MANAGER.custom_text_color = color func _on_lucy_intbbcode_toggled(button_pressed): MANAGER.allow_intrusive_bbcode = button_pressed +func _on_lucy_bug_bb_toggled(button_pressed): + MANAGER.bug_bbcode = button_pressed +func _on_lucy_srv_bbcode_toggled(button_pressed): + if (not Network.GAME_MASTER and not Network.PLAYING_OFFLINE): return + MANAGER.srv_bbcode = button_pressed func _on_lucy_raincloud_pressed(): - if not MANAGER.ingame: return + if not MANAGER.ingame or (not Network.GAME_MASTER and not Network.PLAYING_OFFLINE): return print("[LUCY] Spawning raincloud") var player = MANAGER.get_player() var pos = Vector3(player.global_transform.origin.x, 42, player.global_transform.origin.z) @@ -99,7 +113,7 @@ func _on_lucy_raincloud_pressed(): Network._sync_create_actor("raincloud", pos, zone, - 1, Network.STEAM_ID) func _on_lucy_meteor_pressed(): - if not MANAGER.ingame: return + if not MANAGER.ingame or (not Network.GAME_MASTER and not Network.PLAYING_OFFLINE): return if get_tree().get_nodes_in_group("meteor").size() > 10: return print("[LUCY] Spawning meteor") var player_pos = MANAGER.get_player().global_transform.origin @@ -115,7 +129,7 @@ func _on_lucy_meteor_pressed(): Network._sync_create_actor("fish_spawn_alien", pos, zone, - 1, Network.STEAM_ID) func _on_lucy_freezerain_pressed(): - if not MANAGER.ingame or not Network.GAME_MASTER: return + if not MANAGER.ingame or (not Network.GAME_MASTER and not Network.PLAYING_OFFLINE): return print("[LUCY] Freezing rain") for cloud in get_tree().get_nodes_in_group("raincloud"): if cloud.controlled == true: @@ -123,7 +137,7 @@ func _on_lucy_freezerain_pressed(): cloud.decay = false func _on_lucy_clearrain_pressed(): - if not MANAGER.ingame or not Network.GAME_MASTER: return + if not MANAGER.ingame or (not Network.GAME_MASTER and not Network.PLAYING_OFFLINE): return print("[LUCY] Clearing rain") for cloud in get_tree().get_nodes_in_group("raincloud"): cloud._deinstantiate(true) @@ -133,7 +147,7 @@ func _on_lucy_clearchat_pressed(): Network.emit_signal("_chat_update") func _on_lucy_clearmeteor_pressed(): - if not MANAGER.ingame or not Network.GAME_MASTER: return + if not MANAGER.ingame or (not Network.GAME_MASTER and not Network.PLAYING_OFFLINE): return print("[LUCY] Clearing meteor") for meteor in get_tree().get_nodes_in_group("meteor"): meteor._deinstantiate(true) diff --git a/Godot/mods/Lucy.LucysTools/lucys_menu.tscn b/Godot/mods/Lucy.LucysTools/lucys_menu.tscn index f293963..55c4ae2 100644 --- a/Godot/mods/Lucy.LucysTools/lucys_menu.tscn +++ b/Godot/mods/Lucy.LucysTools/lucys_menu.tscn @@ -4,24 +4,24 @@ [node name="lucys_menu" type="Control"] margin_right = 800.0 -margin_bottom = 329.0 +margin_bottom = 400.0 script = ExtResource( 1 ) [node name="PanelContainer" type="PanelContainer" parent="."] anchor_right = 1.0 anchor_bottom = 1.0 -margin_bottom = 71.0 +margin_bottom = 100.0 [node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"] margin_left = 7.0 margin_top = 7.0 margin_right = 793.0 -margin_bottom = 393.0 +margin_bottom = 493.0 [node name="Label" type="Label" parent="PanelContainer/VBoxContainer"] margin_right = 786.0 margin_bottom = 14.0 -text = "Lucy's Options 0.5.0 - F5 to Toggle Menu" +text = "Lucy's Options 0.6.0 - F5 to Toggle Menu" [node name="HSeparator" type="HSeparator" parent="PanelContainer/VBoxContainer"] margin_top = 18.0 @@ -32,7 +32,7 @@ margin_bottom = 22.0 margin_top = 26.0 margin_right = 786.0 margin_bottom = 40.0 -text = "BBCode is only visible to LucysTools-compatible users" +text = "BBCode is only visible to LucysTools-compatible users, unless Bug BBCode is enabled" [node name="HFlowContainer" type="HFlowContainer" parent="PanelContainer/VBoxContainer"] margin_top = 44.0 @@ -55,44 +55,81 @@ margin_bottom = 40.0 [node name="Label3" type="Label" parent="PanelContainer/VBoxContainer/HFlowContainer"] margin_left = 173.0 margin_top = 13.0 -margin_right = 323.0 +margin_right = 372.0 margin_bottom = 27.0 -text = "Allow Intrusive BBCode" +text = "Allow Intrusive BBCode (Client)" [node name="lucy_intbbcode" type="CheckButton" parent="PanelContainer/VBoxContainer/HFlowContainer"] unique_name_in_owner = true -margin_left = 327.0 -margin_right = 403.0 +margin_left = 376.0 +margin_right = 452.0 margin_bottom = 40.0 -[node name="Label2" type="Label" parent="PanelContainer/VBoxContainer/HFlowContainer"] -margin_left = 407.0 +[node name="Label5" type="Label" parent="PanelContainer/VBoxContainer/HFlowContainer"] +margin_left = 456.0 margin_top = 13.0 -margin_right = 542.0 +margin_right = 591.0 margin_bottom = 27.0 text = "Punch back on Punch" [node name="lucy_punchback" type="CheckButton" parent="PanelContainer/VBoxContainer/HFlowContainer"] unique_name_in_owner = true -margin_left = 546.0 -margin_right = 622.0 +margin_left = 595.0 +margin_right = 671.0 margin_bottom = 40.0 -[node name="HSeparator3" type="HSeparator" parent="PanelContainer/VBoxContainer"] +[node name="HFlowContainer3" type="HFlowContainer" parent="PanelContainer/VBoxContainer"] margin_top = 88.0 margin_right = 786.0 -margin_bottom = 92.0 +margin_bottom = 128.0 + +[node name="Label5" type="Label" parent="PanelContainer/VBoxContainer/HFlowContainer3"] +margin_top = 13.0 +margin_right = 202.0 +margin_bottom = 27.0 +text = "Allow Intrusive BBCode (Server)" + +[node name="lucy_srv_bbcode" type="CheckButton" parent="PanelContainer/VBoxContainer/HFlowContainer3"] +unique_name_in_owner = true +margin_left = 206.0 +margin_right = 282.0 +margin_bottom = 40.0 + +[node name="Label" type="Label" parent="PanelContainer/VBoxContainer/HFlowContainer3"] +margin_left = 286.0 +margin_top = 13.0 +margin_right = 397.0 +margin_bottom = 27.0 +text = "Use Bug BBCode:" + +[node name="lucy_bug_bb" type="CheckBox" parent="PanelContainer/VBoxContainer/HFlowContainer3"] +unique_name_in_owner = true +margin_left = 401.0 +margin_right = 425.0 +margin_bottom = 40.0 + +[node name="Label2" type="Label" parent="PanelContainer/VBoxContainer/HFlowContainer3"] +margin_left = 429.0 +margin_top = 13.0 +margin_right = 520.0 +margin_bottom = 27.0 +text = "May be buggy!" + +[node name="HSeparator3" type="HSeparator" parent="PanelContainer/VBoxContainer"] +margin_top = 132.0 +margin_right = 786.0 +margin_bottom = 136.0 [node name="Label2" type="Label" parent="PanelContainer/VBoxContainer"] -margin_top = 96.0 +margin_top = 140.0 margin_right = 786.0 -margin_bottom = 110.0 +margin_bottom = 154.0 text = "Custom Server Name - Only shown for LucysTools users (base game field for others)" [node name="HFlowContainer4" type="HFlowContainer" parent="PanelContainer/VBoxContainer"] -margin_top = 114.0 +margin_top = 158.0 margin_right = 786.0 -margin_bottom = 138.0 +margin_bottom = 182.0 rect_pivot_offset = Vector2( -141, -49 ) [node name="lucy_servername" type="LineEdit" parent="PanelContainer/VBoxContainer/HFlowContainer4"] @@ -104,9 +141,9 @@ expand_to_text_length = true placeholder_text = "Name" [node name="HFlowContainer6" type="HFlowContainer" parent="PanelContainer/VBoxContainer"] -margin_top = 142.0 +margin_top = 186.0 margin_right = 786.0 -margin_bottom = 156.0 +margin_bottom = 200.0 rect_pivot_offset = Vector2( -141, -49 ) [node name="Label" type="Label" parent="PanelContainer/VBoxContainer/HFlowContainer6"] @@ -126,20 +163,20 @@ text = "'s Lobby" scroll_active = false [node name="HSeparator4" type="HSeparator" parent="PanelContainer/VBoxContainer"] -margin_top = 160.0 +margin_top = 204.0 margin_right = 786.0 -margin_bottom = 164.0 +margin_bottom = 208.0 [node name="Label3" type="Label" parent="PanelContainer/VBoxContainer"] -margin_top = 168.0 +margin_top = 212.0 margin_right = 786.0 -margin_bottom = 182.0 -text = "Server Join Message - Will be shown without BBCode for people without LucysTools" +margin_bottom = 226.0 +text = "Server Join Message - Will be shown without BBCode for people without LucysTools (without bug enabled)" [node name="HFlowContainer5" type="HFlowContainer" parent="PanelContainer/VBoxContainer"] -margin_top = 186.0 +margin_top = 230.0 margin_right = 786.0 -margin_bottom = 210.0 +margin_bottom = 254.0 rect_pivot_offset = Vector2( -141, -49 ) [node name="lucy_servermsg" type="LineEdit" parent="PanelContainer/VBoxContainer/HFlowContainer5"] @@ -151,9 +188,9 @@ expand_to_text_length = true placeholder_text = "Message" [node name="HFlowContainer7" type="HFlowContainer" parent="PanelContainer/VBoxContainer"] -margin_top = 214.0 +margin_top = 258.0 margin_right = 786.0 -margin_bottom = 228.0 +margin_bottom = 272.0 rect_pivot_offset = Vector2( -141, -49 ) [node name="Label" type="Label" parent="PanelContainer/VBoxContainer/HFlowContainer7"] @@ -171,9 +208,9 @@ bbcode_enabled = true scroll_active = false [node name="HFlowContainer10" type="HFlowContainer" parent="PanelContainer/VBoxContainer"] -margin_top = 232.0 +margin_top = 276.0 margin_right = 786.0 -margin_bottom = 246.0 +margin_bottom = 290.0 rect_pivot_offset = Vector2( -141, -49 ) [node name="Label" type="Label" parent="PanelContainer/VBoxContainer/HFlowContainer10"] @@ -191,14 +228,14 @@ bbcode_enabled = true scroll_active = false [node name="HSeparator5" type="HSeparator" parent="PanelContainer/VBoxContainer"] -margin_top = 250.0 +margin_top = 294.0 margin_right = 786.0 -margin_bottom = 254.0 +margin_bottom = 298.0 [node name="HFlowContainer8" type="HFlowContainer" parent="PanelContainer/VBoxContainer"] -margin_top = 258.0 +margin_top = 302.0 margin_right = 786.0 -margin_bottom = 282.0 +margin_bottom = 326.0 rect_pivot_offset = Vector2( -141, -49 ) [node name="Label" type="Label" parent="PanelContainer/VBoxContainer/HFlowContainer8"] @@ -222,22 +259,44 @@ margin_bottom = 24.0 rect_min_size = Vector2( 42, 0 ) edit_alpha = false +[node name="Label2" type="Label" parent="PanelContainer/VBoxContainer/HFlowContainer8"] +margin_left = 281.0 +margin_top = 5.0 +margin_right = 519.0 +margin_bottom = 19.0 +text = " Chat Text Color (LucysTools or bug)" + +[node name="lucy_chatcolor_bool2" type="CheckBox" parent="PanelContainer/VBoxContainer/HFlowContainer8"] +unique_name_in_owner = true +margin_left = 523.0 +margin_right = 593.0 +margin_bottom = 24.0 +text = "Enable" + +[node name="lucy_chatcolor2" type="ColorPickerButton" parent="PanelContainer/VBoxContainer/HFlowContainer8"] +unique_name_in_owner = true +margin_left = 597.0 +margin_right = 639.0 +margin_bottom = 24.0 +rect_min_size = Vector2( 42, 0 ) +edit_alpha = false + [node name="HFlowContainer9" type="HFlowContainer" parent="PanelContainer/VBoxContainer"] -margin_top = 286.0 +margin_top = 330.0 margin_right = 786.0 -margin_bottom = 300.0 +margin_bottom = 344.0 rect_pivot_offset = Vector2( -141, -49 ) hint_tooltip = "Must match Steam username" [node name="Label" type="Label" parent="PanelContainer/VBoxContainer/HFlowContainer9"] -margin_right = 379.0 +margin_right = 392.0 margin_bottom = 14.0 -text = "Custom Name - Must match Steam Name (LucysTools only)" +text = "Custom Name - Must match Steam Name (LucysTools or bug)" [node name="lucy_namegood" type="RichTextLabel" parent="PanelContainer/VBoxContainer/HFlowContainer9"] unique_name_in_owner = true -margin_left = 383.0 -margin_right = 433.0 +margin_left = 396.0 +margin_right = 446.0 margin_bottom = 14.0 rect_min_size = Vector2( 50, 0 ) bbcode_enabled = true @@ -247,17 +306,17 @@ scroll_active = false [node name="lucy_name" type="LineEdit" parent="PanelContainer/VBoxContainer"] unique_name_in_owner = true -margin_top = 304.0 +margin_top = 348.0 margin_right = 786.0 -margin_bottom = 328.0 +margin_bottom = 372.0 expand_to_text_length = true placeholder_text = "Name" [node name="lucy_name_preview" type="RichTextLabel" parent="PanelContainer/VBoxContainer"] unique_name_in_owner = true -margin_top = 332.0 +margin_top = 376.0 margin_right = 786.0 -margin_bottom = 347.0 +margin_bottom = 391.0 rect_min_size = Vector2( 0, 15 ) size_flags_horizontal = 3 bbcode_enabled = true @@ -266,14 +325,14 @@ text = "If you see this, modify your custom name" scroll_active = false [node name="HSeparator6" type="HSeparator" parent="PanelContainer/VBoxContainer"] -margin_top = 351.0 +margin_top = 395.0 margin_right = 786.0 -margin_bottom = 355.0 +margin_bottom = 399.0 [node name="HFlowContainer2" type="HFlowContainer" parent="PanelContainer/VBoxContainer"] -margin_top = 359.0 +margin_top = 403.0 margin_right = 786.0 -margin_bottom = 379.0 +margin_bottom = 423.0 [node name="lucy_clearchat" type="Button" parent="PanelContainer/VBoxContainer/HFlowContainer2"] margin_right = 76.0 @@ -319,10 +378,14 @@ text = "Clear Meteor" [connection signal="toggled" from="PanelContainer/VBoxContainer/HFlowContainer/lucy_bbcode" to="." method="_on_lucy_bbcode_toggled"] [connection signal="toggled" from="PanelContainer/VBoxContainer/HFlowContainer/lucy_intbbcode" to="." method="_on_lucy_intbbcode_toggled"] [connection signal="toggled" from="PanelContainer/VBoxContainer/HFlowContainer/lucy_punchback" to="." method="_on_lucy_punchback_toggled"] +[connection signal="toggled" from="PanelContainer/VBoxContainer/HFlowContainer3/lucy_srv_bbcode" to="." method="_on_lucy_srv_bbcode_toggled"] +[connection signal="toggled" from="PanelContainer/VBoxContainer/HFlowContainer3/lucy_bug_bb" to="." method="_on_lucy_bug_bb_toggled"] [connection signal="text_changed" from="PanelContainer/VBoxContainer/HFlowContainer4/lucy_servername" to="." method="_on_lucy_servername_text_changed"] [connection signal="text_changed" from="PanelContainer/VBoxContainer/HFlowContainer5/lucy_servermsg" to="." method="_on_lucy_servermsg_text_changed"] [connection signal="toggled" from="PanelContainer/VBoxContainer/HFlowContainer8/lucy_chatcolor_bool" to="." method="_on_lucy_chatcolor_bool_toggled"] [connection signal="color_changed" from="PanelContainer/VBoxContainer/HFlowContainer8/lucy_chatcolor" to="." method="_on_lucy_chatcolor_color_changed"] +[connection signal="toggled" from="PanelContainer/VBoxContainer/HFlowContainer8/lucy_chatcolor_bool2" to="." method="_on_lucy_chatcolor_bool2_toggled"] +[connection signal="color_changed" from="PanelContainer/VBoxContainer/HFlowContainer8/lucy_chatcolor2" to="." method="_on_lucy_chatcolor2_color_changed"] [connection signal="text_changed" from="PanelContainer/VBoxContainer/lucy_name" to="." method="_on_lucy_name_text_changed"] [connection signal="pressed" from="PanelContainer/VBoxContainer/HFlowContainer2/lucy_clearchat" to="." method="_on_lucy_clearchat_pressed"] [connection signal="pressed" from="PanelContainer/VBoxContainer/HFlowContainer2/lucy_raincloud" to="." method="_on_lucy_raincloud_pressed"] diff --git a/Godot/mods/Lucy.LucysTools/main.gd b/Godot/mods/Lucy.LucysTools/main.gd index a26d26f..96d0fc6 100644 --- a/Godot/mods/Lucy.LucysTools/main.gd +++ b/Godot/mods/Lucy.LucysTools/main.gd @@ -5,72 +5,247 @@ const LUCYS_MENU_SCENE = preload("res://mods/Lucy.LucysTools/lucys_menu.tscn") var lucys_menu = null onready var root = get_tree().root -var INCERCEPT_MSG = false -var INCERCEPT_SEND_MSG = false +var INCERCEPT_MSG: bool = false +var INCERCEPT_SEND_MSG: bool = false -var do_punchback = false -var allow_bbcode = false -var custom_server_name = "" setget set_server_name -var server_join_message = "[color=#5BCEFA]TRAN[/color][color=#F5A9B8]S RIG[/color][color=#ffffff]HTS![/color]" setget set_join_message +var do_punchback: bool = false +var allow_bbcode: bool = false +var custom_server_name: String = "" setget set_server_name +var server_join_message: String = "[color=#5BCEFA]TRAN[/color][color=#F5A9B8]S RIG[/color][color=#ffffff]HTS![/color]" setget set_join_message -var custom_color_enabled = false -var custom_color = Color("009cd0") setget set_custom_color +var custom_color_enabled: bool = false +var custom_color: Color = Color("009cd0") setget set_custom_color -var custom_name_enabled = false -var real_custom_name = "" -var custom_name = "" setget set_custom_name +var custom_name_enabled: bool = false +var real_custom_name: String = "" +var custom_name: String = "" setget set_custom_name -var allow_intrusive_bbcode = false setget set_allow_intrusive_bbcode +var allow_intrusive_bbcode: bool = false setget set_allow_intrusive_bbcode +var srv_bbcode: bool = false setget set_srv_bbcode -var log_messages = false setget set_log_messages +var log_messages: bool = false setget set_log_messages -var lucys_menu_visible = true +var DEBUG: bool = false -var allowed_tags = ["b", "i", "u", "s", "color"] -var escape_invalid = true -var bbcode_matcher = null +var lucys_menu_visible: bool = true + +var custom_text_color: Color = Color("00ff00") +var custom_text_color_enabled: bool = false + +var bug_bbcode: bool = false func set_custom_name(val): custom_name = val - var bb = bbcode_process(val) + var bb = bbcode_process(val, 256) real_custom_name = bb.fin -# i know this sucks -# but i have things to do -func bbcode_recurse(text, data): - var m = bbcode_matcher.search(text) - if m == null: - var escaped = text.replace('[lb]','[').replace('[','[lb]') if escape_invalid else text - data.fin += escaped - data.stripped += escaped - else: - #print("Found ", m.strings, " in '", text, "'") - bbcode_recurse(m.get_string(1), data) - var tag = m.get_string(2) - var junk = m.get_string(3) - var allowed = tag in allowed_tags - if allowed: - data.fin += "[" + tag + junk + "]" - else: - data.fin += "[lb]" + tag + junk + "]" - data.stripped += "[lb]" + tag + junk + "]" - #print("TAG ", m.get_string(2), " JUNK ", m.get_string(3)) - data.tags.append([tag, junk]) - bbcode_recurse(m.get_string(4), data) - if allowed: - data.fin += "[/" + tag + "]" - else: - data.fin += "[lb]/" + tag + "]" - data.stripped += "[lb]/" + tag + "]" - bbcode_recurse(m.get_string(5), data) +func set_log_messages(val): + log_messages = val + Network.LUCY_LOG_MESSAGES = val -func bbcode_process(text): +func set_allow_intrusive_bbcode(bbcode): + allow_intrusive_bbcode = bbcode + bbcode_changes() + +func set_srv_bbcode(bbcode): + srv_bbcode = bbcode + if Network.GAME_MASTER: send_lucy_sync() + bbcode_changes() + +func set_server_name(name): + custom_server_name = name + Network.LUCY_SRV_NAME = name + +func set_join_message(msg): + server_join_message = msg + +func set_custom_color(val): + custom_color = Color(val) if Color(val) != Color("d5aa73") else Color("739ed5") + custom_color.a = 1 + +var allowed_tags: Array = ["b", "i", "u", "s", "color"] +var escape_invalid: bool = true +var strip_disallowed: bool = true +var check_alpha: bool = true setget set_check_alpha +var bbcode_matcher = null + +var junk_checkers: Dictionary = {} + +var alpha_lim := 0.5 + +var alpha_getter: RegEx = null +func do_alpha_check(junk) -> String: + if not alpha_getter: + alpha_getter = RegEx.new() + alpha_getter.compile("\\s*=\\s*(\\S*)") + + var color: Color = Color(alpha_getter.search(junk).get_string(1)) + + if color.a < alpha_lim: + color.a = alpha_lim + return "=#" + color.to_html() + + return "" + +func set_check_alpha(val): + check_alpha = val + if val: junk_checkers["color"] = funcref(self, "do_alpha_check") + else: junk_checkers.erase("color") + +var INNER_MAX_LEN: int = 0 + +# ouch oof this sucks +func bbcode_process(text, max_len) -> Dictionary: + var end: int + var all: String + var before: String + var whole_tag: String + var tag_open: String + var junk: String + var tag_close: String + var tag: String + var is_close: bool + var inner_full: String + var inner_stripped: String + var prev_full: String + var prev_stripped: String + var checked: String + var last_tag + + if DEBUG: + var thing = {"max_len":max_len,"allowed_tags":allowed_tags,"strip_disallowed":strip_disallowed,"escape_invalid":escape_invalid} + print("[BBCODE NEW] processing '", text, "' params ", thing) + bbcode_matcher = RegEx.new() - bbcode_matcher.compile("^(.*?)\\[(\\w+?)([^\\]]*)\\](.+?)\\[/\\2\\](.*?)$") - #print("processing '", text, "'") - var data = {"fin": "", "tags": [], "stripped": ""} - bbcode_recurse(text, data) - return data + bbcode_matcher.compile("(.*?)(\\[(\\w+)([^\\[\\]]*?)\\]|\\[/(\\w+)\\])") + + var linear_matches: Array = bbcode_matcher.search_all(text) + if linear_matches.empty(): + var processed = {"fin": text.replace('[','[lb]'), "stripped": text} + if DEBUG: print("[BBCODE NEW] processed ", processed) + return processed + + var tag_stack := [] + var full_text_stack := [""] + var stripped_text_stack := [""] + + var last_end: int = 0 + + # all this popping and pushing sucks. whatever + for m in linear_matches: + if DEBUG: print("[MATCH] ", m.strings) + if DEBUG: print("[STACKS] ", { + "tag stack": tag_stack, + "full text": full_text_stack, + "stripped text": stripped_text_stack + }) + end = m.get_end() + if end != -1: last_end = end + all = m.get_string(0) + before = m.get_string(1) + whole_tag = m.get_string(2) + tag_open = m.get_string(3) + junk = m.get_string(4) + tag_close = m.get_string(5) + tag = tag_open + is_close = false + if tag_open == "": + tag = tag_close + is_close = true + + if is_close: + # get the tag on the stack + last_tag = tag_stack.pop_back() + # get the full text on the stack + inner_full = full_text_stack.pop_back() + # get the stripped text on the stack + inner_stripped = stripped_text_stack.pop_back() + if last_tag == null: + if DEBUG: print("[UNOPENED CLOSE]") + # no tags on stack + # add stripped tag to all text + # and go back on stack + full_text_stack.push_back(inner_full+before.replace('[','[lb]')+"[lb]/"+tag+"]") + stripped_text_stack.push_back(inner_stripped+before.replace('[','[lb]')+"[lb]/"+tag+"]") + continue + elif last_tag[0] == tag: + if DEBUG: print("[CLOSED TAG]") + # we have closure. + # check junk + if junk_checkers.has(tag): + checked = junk_checkers[tag].call_func(last_tag[1]) + junk = last_tag[1] if checked == "" else checked + if DEBUG: print("[BB NEW JUNK] ", junk) + else: + junk = last_tag[1] + # add tag in full text + # but not in stripped + prev_full = full_text_stack.pop_back() + prev_stripped = stripped_text_stack.pop_back() + if tag in allowed_tags: + full_text_stack.push_back(prev_full + "["+tag+junk+"]" + inner_full + before.replace('[','[lb]') + "[/"+tag+"]") + stripped_text_stack.push_back(prev_stripped + inner_stripped + before.replace('[','[lb]')) + else: + full_text_stack.push_back(prev_full + inner_full + before.replace('[','[lb]')) + stripped_text_stack.push_back(prev_stripped + inner_stripped + before.replace('[','[lb]')) + continue + else: + if DEBUG: print("[WRONG CLOSE]") + # open followed by different close + # escape and add the text to previous on stack + prev_full = full_text_stack.pop_back() + prev_stripped = stripped_text_stack.pop_back() + full_text_stack.push_back(prev_full + "[lb]"+last_tag[0]+last_tag[1]+"]" + inner_full + before.replace('[','[lb]') + "[lb]/"+tag+"]") + stripped_text_stack.push_back(prev_stripped + "[lb]"+last_tag[0]+last_tag[1]+"]" + inner_stripped + before.replace('[','[lb]') + "[lb]/"+tag+"]") + continue + else: + # special case + if tag == "lb" or tag == "rb": + if DEBUG: print("[LB/RB]") + # add directly to current inner + inner_full = full_text_stack.pop_back() + inner_stripped = stripped_text_stack.pop_back() + full_text_stack.push_back(inner_full + before.replace('[','[lb]') + whole_tag) + stripped_text_stack.push_back(inner_stripped + before.replace('[','[lb]') + whole_tag) + continue + if DEBUG: print("[OPEN TAG]") + # add to stack + tag_stack.push_back([tag, junk]) + # add before text escaped to prev + inner_full = full_text_stack.pop_back() + inner_stripped = stripped_text_stack.pop_back() + full_text_stack.push_back(inner_full + before.replace('[','[lb]')) + stripped_text_stack.push_back(inner_stripped + before.replace('[','[lb]')) + # new inner text + full_text_stack.push_back("") + stripped_text_stack.push_back("") + continue + + if DEBUG: print("[FINAL STACKS] ", { + "tag stack": tag_stack, + "full text": full_text_stack, + "stripped text": stripped_text_stack + }) + + # unroll opens at end + # TODO probably should write this in as escaped + # but im getting tired + while not tag_stack.empty(): + tag_stack.pop_back() + full_text_stack.pop_back() + stripped_text_stack.pop_back() + + if DEBUG: print("[LAST END] ", last_end) + var processed = {"fin": full_text_stack.pop_back(), "stripped": stripped_text_stack.pop_back()} + # end stuff isnt caught by the regex + if last_end != 0: + var end_str = text.substr(last_end).replace('[','[lb]') + if DEBUG: print("[END STR] ", end_str) + processed.fin += end_str + processed.stripped += end_str + + if DEBUG: print("[BBCODE NEW] processed ", processed) + return processed var ingame = false @@ -79,39 +254,58 @@ func get_user_color() -> Color: var color = custom_color if custom_color_enabled else base_color return color -func safe_message(user_id, color, boring_msg, local, lucy_user, lucy_msg): - var username = Network._get_username_from_id(user_id) if lucy_user == "" else lucy_user - var bb_user = bbcode_process(username) - username = bb_user.fin - - var msg = lucy_msg if lucy_msg != "" else boring_msg - var bb_data = bbcode_process(msg) - var filter_message = bb_data.fin - - if bb_user.stripped != Network._get_username_from_id(user_id): - filter_message = "(" + Network._get_username_from_id(user_id) + ") " + filter_message +func safe_message(user_id, color, boring_msg, local, lucy_user, lucy_msg, require_name): + var msg: String = boring_msg + if lucy_msg != "": msg = lucy_msg + var net_name: String = Network._get_username_from_id(user_id).replace('[','').replace(']','') + var name: String = net_name if lucy_user == "" else lucy_user if OptionsMenu.chat_filter: - filter_message = SwearFilter._filter_string(filter_message) + msg = SwearFilter._filter_string(msg) - var final_message = filter_message.replace("%u", "[color=#" + str(color) + "]" + username + "[/color]") - var thing = {"username":username, "color":color, "filter_message":filter_message, - "final_message":final_message,"lucy_user":lucy_user,"lucy_msg":lucy_msg} - #print("FUCK2 ", thing) - Network._update_chat(final_message, local) + msg = msg.replace("%u", "[color=#" + str(color) + "]" + name + "[/color]") + if DEBUG: print("[MSG B4 PROC] ", msg) + + # process message + var bb_msg = bbcode_process(msg, 512) + if require_name and not net_name in bb_msg.stripped: + msg = net_name + ": " + msg + bb_msg = bbcode_process(msg, 512) + + if log_messages: + var thing = {"user_id":user_id, "steam name":Network._get_username_from_id(user_id), + "username":name, "color":color, + "final": bb_msg.fin, "message": boring_msg, + "bb_user":lucy_user,"bb_msg":lucy_msg} + print("[MESSAGE] ", thing) + Network._update_chat(bb_msg.fin, local) # this is stinky func process_message(lit_text, final, prefix, suffix, endcap, spoken_text, local, colon, playerhud): - var thing = { - "lit_text": lit_text, "final": final, "prefix": prefix, "suffix": suffix, - "endcap": endcap, - "custom_color_enabled": custom_color_enabled, - "custom_name_enabled": custom_name_enabled, "allow_bbcode": allow_bbcode, - "allowed_tags": allowed_tags - } - #print("FUCK ", thing) - if Network.GAME_MASTER and lit_text.begins_with("%"): - var bb_dat = bbcode_process(lit_text) + if log_messages: + var thing = { + "lit_text": lit_text, "final": final, "prefix": prefix, "suffix": suffix, + "endcap": endcap, + "custom_color_enabled": custom_color_enabled, + "custom_name_enabled": custom_name_enabled, "allow_bbcode": allow_bbcode, + "allowed_tags": allowed_tags + } + print("process_message ", thing) + + if (Network.GAME_MASTER or Network.PLAYING_OFFLINE) and lit_text.begins_with("%"): + var bb_dat = bbcode_process(lit_text.trim_prefix('%'), 512) + + if bug_bbcode: + print("Using color field...") + var evil_color = "00ff0000]"\ + + "[color=#ffeed5]"\ + + bb_dat.fin\ + + "[/color]" + + if bb_dat.fin != "": + lucy_send_message("", "%u", false, evil_color) + return [true] + lucy_send_message(lit_text.trim_prefix('%'), bb_dat.stripped, false) # we sent the message ourself return [true] @@ -119,16 +313,42 @@ func process_message(lit_text, final, prefix, suffix, endcap, spoken_text, local var msg = final var boring_msg = final var speak = spoken_text - if allow_bbcode: - var p = bbcode_process(lit_text) - if not p.tags.empty(): - msg = prefix + "%u" + endcap + p.fin + suffix - boring_msg = prefix + "%u" + endcap + p.stripped + suffix - speak = p.stripped - #print("FUCK3 ", {"msg":msg,"boring_msg":boring_msg,"p":p}) + if bug_bbcode: + print("Using color field...") + var p = bbcode_process(lit_text, 512) + var name = real_custom_name if custom_name_enabled else Network.STEAM_USERNAME + var name_color = get_user_color().to_html() + var text_color = "ffffeed5" if not custom_text_color_enabled else custom_text_color.to_html() + var evil_color = "00ff0000]"\ + + "[color=#" + text_color + "]"\ + + prefix\ + + "[color=#" + name_color + "]"\ + + name\ + + "[/color]"\ + + endcap + p.fin + suffix\ + + "[/color]" + boring_msg = "%u" + var bb_msg = "" + var bb_user = "" + speak = p.stripped + + if p.fin != "": + lucy_send_message(bb_msg, boring_msg, local, evil_color) + + if speak != "" and colon: playerhud.emit_signal("_message_sent", speak) + return [true] + elif allow_bbcode: + var p = bbcode_process(lit_text, 512) + var txt_col_start = "" if not custom_text_color_enabled else\ + "[color=#"+custom_text_color.to_html()+"]" + var txt_col_end = "" if not custom_text_color_enabled else\ + "[/color]" + msg = prefix + "%u" + txt_col_start + endcap + p.fin + suffix + txt_col_end + boring_msg = prefix + "%u" + endcap + p.stripped + suffix + speak = p.stripped if msg != "": lucy_send_message(msg, boring_msg, local) - if spoken_text != "" and colon: playerhud.emit_signal("_message_sent", speak) + if speak != "" and colon: playerhud.emit_signal("_message_sent", speak) # we did it ourselves return [true] @@ -137,7 +357,7 @@ func process_message(lit_text, final, prefix, suffix, endcap, spoken_text, local var LUCYSTOOLS_USERS = [] -func lucy_send_message(message, boring_msg, local = false): +func lucy_send_message(message, boring_msg, local = false, evil_color = ""): if not Network._message_cap(Network.STEAM_ID): Network._update_chat("Sending too many messages too quickly!", false) Network._update_chat("Sending too many messages too quickly!", true) @@ -145,10 +365,10 @@ func lucy_send_message(message, boring_msg, local = false): var msg_pos = Network.MESSAGE_ORIGIN.round() - var lucy_user = real_custom_name if custom_name_enabled else "" - var color = get_user_color().to_html() + var lucy_user = real_custom_name if custom_name_enabled and not bug_bbcode else "" + var color = get_user_color().to_html() if not bug_bbcode else evil_color - safe_message(Network.STEAM_ID, color, boring_msg, local, lucy_user, message) + safe_message(Network.STEAM_ID, color, boring_msg, local, lucy_user, message, false) Network._send_P2P_Packet( {"type": "message", "message": boring_msg, "color": color, "local": local, "position": Network.MESSAGE_ORIGIN, "zone": Network.MESSAGE_ZONE, @@ -158,51 +378,58 @@ func lucy_send_message(message, boring_msg, local = false): -func process_read(DATA, PACKET_SENDER, from_host): +func process_read(DATA, PACKET_SENDER, from_host) -> bool: match DATA["type"]: "lucy_packet": print("[LUCY PACKET]") if not PACKET_SENDER in LUCYSTOOLS_USERS: LUCYSTOOLS_USERS.append(PACKET_SENDER) + if Network.GAME_MASTER or not from_host: return true + if not Network._validate_packet_information(DATA, ["srv_bbcode"], [TYPE_BOOL]): return true + self.srv_bbcode = DATA["srv_bbcode"] return true "message": - if DATA.has("message"): - if typeof(DATA["message"]) == TYPE_STRING: - if not "%u" in DATA["message"] and not from_host: - DATA["message"] = "(%u)" + DATA["message"] - if DATA.has("bb_msg"): - if typeof(DATA["bb_msg"]) == TYPE_STRING: - if not "%u" in DATA["bb_msg"] and not from_host: - DATA["bb_msg"] = "(%u)" + DATA["bb_msg"] - - if DATA.has("bb_msg") or DATA.has("bb_user"): - if not PACKET_SENDER in LUCYSTOOLS_USERS: - LUCYSTOOLS_USERS.append(PACKET_SENDER) - else: - return false - # yay! this is a lucy user :3 - if PlayerData.players_muted.has(PACKET_SENDER) or PlayerData.players_hidden.has(PACKET_SENDER): return - + var has_bb = true if not Network._validate_packet_information(DATA, ["message", "color", "local", "position", "zone", "zone_owner", "bb_user", "bb_msg"], [TYPE_STRING, TYPE_STRING, TYPE_BOOL, TYPE_VECTOR3, TYPE_STRING, TYPE_INT, TYPE_STRING, TYPE_STRING]): - return + has_bb = false + if not Network._validate_packet_information(DATA, + ["message", "color", "local", "position", "zone", "zone_owner"], + [TYPE_STRING, TYPE_STRING, TYPE_BOOL, TYPE_VECTOR3, TYPE_STRING, TYPE_INT]): + # invalid packet + if log_messages: + print("[MALFORMED MESSAGE] sender: ", Network._get_username_from_id(PACKET_SENDER), "(", PACKET_SENDER + ") " + DATA) + return true - if not Network._message_cap(PACKET_SENDER): return + if has_bb: + if not PACKET_SENDER in LUCYSTOOLS_USERS: + LUCYSTOOLS_USERS.append(PACKET_SENDER) + + if PlayerData.players_muted.has(PACKET_SENDER) or PlayerData.players_hidden.has(PACKET_SENDER): + return false + + if not Network._message_cap(PACKET_SENDER): return false var user_id: int = PACKET_SENDER var user_color: String = DATA["color"] var user_message: String = DATA["message"] - var lucy_user: String = DATA["bb_user"] - var lucy_msg: String = DATA["bb_msg"] + # if host, don't care about visibility + check_alpha = not from_host + var bb_user: String = "" + var bb_msg: String = "" + if has_bb: + bb_user = DATA["bb_user"] + bb_msg = DATA["bb_msg"] + if not DATA["local"]: - safe_message(user_id, user_color, user_message, false, lucy_user, lucy_msg) + safe_message(user_id, user_color, user_message, false, bb_user, bb_msg, not from_host) else : var dist = DATA["position"].distance_to(Network.MESSAGE_ORIGIN) if DATA["zone"] == Network.MESSAGE_ZONE and DATA["zone_owner"] == PlayerData.player_saved_zone_owner: - if dist < 25.0: safe_message(user_id, user_color, user_message, true, lucy_user, lucy_msg) + if dist < 25.0: safe_message(user_id, user_color, user_message, true, bb_user, bb_msg, not from_host) # don't process it again! return true @@ -217,7 +444,7 @@ func process_read(DATA, PACKET_SENDER, from_host): return false func bbcode_changes(): - if allow_intrusive_bbcode: + if allow_intrusive_bbcode and srv_bbcode: allowed_tags = [ "b", "i", "u", "s", "color", "wave", "rainbow", "shake", "tornado", "font"] @@ -226,24 +453,8 @@ func bbcode_changes(): "b", "i", "u", "s", "color"] if lucys_menu != null: lucys_menu.update() -func set_log_messages(val): - log_messages = val - Network.LUCY_LOG_MESSAGES = val - -func set_allow_intrusive_bbcode(bbcode): - allow_intrusive_bbcode = bbcode - bbcode_changes() -func set_server_name(name): - custom_server_name = name - Network.LUCY_SRV_NAME = name -func set_join_message(msg): - server_join_message = msg -func set_custom_color(val): - custom_color = Color(val) if Color(val) != Color("d5aa73") else Color("739ed5") - custom_color.a = 1 - func _ready(): - print("[LUCY] Loaded LucysTools") + print("[LUCY] Loaded LucysTools 0.6.0") load_settings() root.connect("child_entered_tree", self, "_on_enter") Network.connect("_new_player_join", self, "new_player") @@ -257,7 +468,7 @@ func inject_lobby_data(connect, lobby_id): func send_lucy_sync(to = "peers"): if not Network.GAME_MASTER: return - Network._send_P2P_Packet({"type": "lucy_packet"}, to, Network.CHANNELS.GAME_STATE) + Network._send_P2P_Packet({"type": "lucy_packet", "srv_bbcode": srv_bbcode}, to, Network.CHANNELS.GAME_STATE) func get_player() -> Actor: for p in get_tree().get_nodes_in_group("player"): @@ -276,8 +487,17 @@ func new_player(id): print("[LUCY] new player!") if server_join_message.empty() or not Network.GAME_MASTER: return print("[LUCY] sending join message") - var bb_msg = bbcode_process(server_join_message) - lucy_send_message(bb_msg.fin, bb_msg.stripped, false) + var bb_msg = bbcode_process(server_join_message, 512) + if not bug_bbcode: + lucy_send_message(bb_msg.fin, bb_msg.stripped, false) + else: + var evil_color = "00ff0000]"\ + + "[color=#ffeed5]"\ + + bb_msg.fin\ + + "[/color]" + + if bb_msg.fin != "": + lucy_send_message("", "%u", false, evil_color) send_lucy_sync(str(id)) func _on_enter(node: Node): @@ -300,7 +520,9 @@ const save_keys = [ "custom_server_name", "server_join_message", "custom_color_enabled", "custom_color", "log_messages", "custom_name", - "allow_intrusive_bbcode" + "allow_intrusive_bbcode", "DEBUG", + "bug_bbcode", "custom_text_color", + "custom_text_color_enabled" ] func load_settings(): @@ -317,11 +539,12 @@ func load_settings(): func save_settings(): print("[LUCY] Saving settings") - custom_color = Color(custom_color).to_html() - var settings = {} for key in save_keys: - settings[key] = self[key] + if key in ["custom_color", "custom_text_color"]: + settings[key] = self[key].to_html() + else: + settings[key] = self[key] var file = File.new() if file.open(OS.get_executable_path().get_base_dir().plus_file("GDWeave/configs/LucysTools.json"),File.WRITE) == OK: