aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornokoe <nokoe@mailbox.org>2024-07-20 00:30:44 +0200
committernokoe <nokoe@mailbox.org>2024-07-20 00:30:44 +0200
commitb7b3799ae537566ff4afd97ecbbddb8e2bd79d91 (patch)
treeb7a191dc07a122d2c049e8ef4e7e6a342630823b
parent047cb1a40185da63249d33eae1ac77bdf2d4f09c (diff)
downloadhurrycurry-b7b3799ae537566ff4afd97ecbbddb8e2bd79d91.tar
hurrycurry-b7b3799ae537566ff4afd97ecbbddb8e2bd79d91.tar.bz2
hurrycurry-b7b3799ae537566ff4afd97ecbbddb8e2bd79d91.tar.zst
check url and append missing default parts
-rw-r--r--client/menu/main.gd19
-rw-r--r--client/menu/main.tscn1
2 files changed, 19 insertions, 1 deletions
diff --git a/client/menu/main.gd b/client/menu/main.gd
index f2b9f021..e2c89798 100644
--- a/client/menu/main.gd
+++ b/client/menu/main.gd
@@ -1,5 +1,6 @@
# Hurry Curry! - a game about cooking
# Copyright 2024 metamuffin
+# Copyright 2024 nokoe
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
@@ -15,6 +16,8 @@
#
extends Menu
+var url_regex: RegEx = RegEx.new()
+
@onready var quit_button = $side/margin/options/quit
@onready var connect_uri = $side/margin/options/connect/uri
@onready var server = $side/margin/options/server
@@ -23,6 +26,7 @@ extends Menu
func _ready():
super()
+ url_regex.compile("^(?:(ws|wss)://)?([^:]+)(?::([0-9]+))?$")
if OS.has_feature("web"):
quit_button.hide()
server.hide()
@@ -39,9 +43,19 @@ func _on_credits_pressed():
func _on_connect_pressed():
var url = connect_uri.text
+ var result := url_regex.search(url)
+ if result != null:
+ print(result.strings)
+ if result.get_string(1) == "":
+ url = "ws://" + url
+ # only set default port for non-tls websocket connections
+ if result.get_string(3) == "" and result.get_string(1) != "wss":
+ url = url + ":27032"
+ connect_uri.text = url
Global.set_profile("last_server_url", url)
connect_to(url)
+
func _on_quick_connect_pressed():
if OS.has_feature("JavaScript"):
connect_to(JavaScriptBridge.eval("""
@@ -52,7 +66,7 @@ func _on_quick_connect_pressed():
else:
connect_to("wss://hurrycurry.metamuffin.org/")
-func connect_to(url):
+func connect_to(url: String):
print("Connecting to %s" % url)
Global.server_url = url
replace_menu("res://menu/game.tscn")
@@ -96,3 +110,6 @@ func _process(_delta):
server_control.text = tr("Server (Unavailable)")
server_control.disabled = true
server_control.tooltip_text = tr("Server binary was not found. Please install the server separately.")
+
+func _on_uri_text_changed(new_text):
+ connect_uri.modulate = Color.WHITE if url_regex.search(new_text) else Color.RED
diff --git a/client/menu/main.tscn b/client/menu/main.tscn
index ca77c09d..cdc3a4a8 100644
--- a/client/menu/main.tscn
+++ b/client/menu/main.tscn
@@ -108,6 +108,7 @@ text = "Quit"
alignment = 0
[connection signal="pressed" from="side/margin/options/quick_connect" to="." method="_on_quick_connect_pressed"]
+[connection signal="text_changed" from="side/margin/options/connect/uri" to="." method="_on_uri_text_changed"]
[connection signal="pressed" from="side/margin/options/connect/connect" to="." method="_on_connect_pressed"]
[connection signal="pressed" from="side/margin/options/change_character" to="." method="_on_change_character_pressed"]
[connection signal="pressed" from="side/margin/options/settings" to="." method="_on_settings_pressed"]