diff options
author | nokoe <nokoe@mailbox.org> | 2024-07-20 00:30:44 +0200 |
---|---|---|
committer | nokoe <nokoe@mailbox.org> | 2024-07-20 00:30:44 +0200 |
commit | b7b3799ae537566ff4afd97ecbbddb8e2bd79d91 (patch) | |
tree | b7a191dc07a122d2c049e8ef4e7e6a342630823b /client/menu/main.gd | |
parent | 047cb1a40185da63249d33eae1ac77bdf2d4f09c (diff) | |
download | hurrycurry-b7b3799ae537566ff4afd97ecbbddb8e2bd79d91.tar hurrycurry-b7b3799ae537566ff4afd97ecbbddb8e2bd79d91.tar.bz2 hurrycurry-b7b3799ae537566ff4afd97ecbbddb8e2bd79d91.tar.zst |
check url and append missing default parts
Diffstat (limited to 'client/menu/main.gd')
-rw-r--r-- | client/menu/main.gd | 19 |
1 files changed, 18 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 |