diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/menu/play.gd | 4 | ||||
-rw-r--r-- | client/menu/settings/number_setting.gd | 41 | ||||
-rw-r--r-- | client/menu/settings/number_setting.gd.uid | 1 | ||||
-rw-r--r-- | client/service/server.gd | 15 | ||||
-rw-r--r-- | client/service/service.gd | 5 | ||||
-rw-r--r-- | client/settings.gd | 3 |
6 files changed, 65 insertions, 4 deletions
diff --git a/client/menu/play.gd b/client/menu/play.gd index 2633163e..afc257f3 100644 --- a/client/menu/play.gd +++ b/client/menu/play.gd @@ -143,10 +143,10 @@ func _on_editor_control_pressed(): Service.State.FAILED: Editor.start() func _on_server_connect_pressed(): - connect_to("ws://127.0.0.1:27032/") + connect_to("ws://%s:%d" % [Server.connect_address(), Global.get_setting("server.bind_port")]) func _on_editor_connect_pressed(): - connect_to("ws://127.0.0.1:27035/") + connect_to("ws://[::1]:27032/") func _process(_delta): server_control.disabled = false diff --git a/client/menu/settings/number_setting.gd b/client/menu/settings/number_setting.gd new file mode 100644 index 00000000..2326eef1 --- /dev/null +++ b/client/menu/settings/number_setting.gd @@ -0,0 +1,41 @@ +# Hurry Curry! - a game about cooking +# Copyright 2025 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 +# the Free Software Foundation, version 3 of the License only. +# +# 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. +# +class_name NumberSetting +extends GameSetting + +var placeholder: String +var min: int +var max: int + +func _init(new_id: String, default: int, min: int, max: int): + super(new_id, default) + self.min = min + self.max = max + +func create_row(): + var row = super() + var input := SpinBox.new() + input.min_value = min + input.max_value = max + + input.value_changed.connect(func(value): Global.set_setting(key, value as int)) + Settings.hook_changed_init(key, true, + func(v): + if is_instance_valid(input): + input.value = v + ) + row.value_node = input + return row diff --git a/client/menu/settings/number_setting.gd.uid b/client/menu/settings/number_setting.gd.uid new file mode 100644 index 00000000..4301c642 --- /dev/null +++ b/client/menu/settings/number_setting.gd.uid @@ -0,0 +1 @@ +uid://babmw2ohuhmuk diff --git a/client/service/server.gd b/client/service/server.gd index b2db04de..0c656c10 100644 --- a/client/service/server.gd +++ b/client/service/server.gd @@ -33,6 +33,8 @@ func arguments(): args.push_back("--upnp") if Global.get_setting("server.register"): args.push_back("--register") + args.push_back("--listen") + args.push_back("%s:%d" % [bind_address(), Global.get_setting("server.bind_port")]) return args func exe_path() -> String: @@ -41,4 +43,15 @@ func exe_path() -> String: else: return "hurrycurry-server" func test_port(): - return 27032 + return Global.get_setting("server.bind_port") +func test_host(): + return "::1" if Global.get_setting("server.enable_ipv6") else "127.0.0.1" + +static func bind_address() -> String: + if Global.get_setting("server.allow_external_connections"): + return "[::]" if Global.get_setting("server.enable_ipv6") else "0.0.0.0" + else: + return connect_address() + +static func connect_address() -> String: + return "[::1]" if Global.get_setting("server.enable_ipv6") else "127.0.0.1" diff --git a/client/service/service.gd b/client/service/service.gd index 9695714f..d06ad364 100644 --- a/client/service/service.gd +++ b/client/service/service.gd @@ -27,6 +27,9 @@ func exe_path(): return "false" func test_port(): return 25565 +func test_host(): + return "127.0.0.1" + var thread = null var pid = null @@ -82,7 +85,7 @@ func _server_exec(): var ok = false while not ok: var conn = StreamPeerTCP.new() - if conn.connect_to_host("127.0.0.1", test_port()) == OK: + if conn.connect_to_host(test_host(), test_port()) == OK: while conn.poll() == OK: if conn.get_status() == StreamPeerTCP.STATUS_ERROR: break elif conn.get_status() == StreamPeerTCP.STATUS_CONNECTED: ok = true; break diff --git a/client/settings.gd b/client/settings.gd index fea17b41..a9c03456 100644 --- a/client/settings.gd +++ b/client/settings.gd @@ -70,6 +70,9 @@ static func get_root(): PathSetting.new("editor_binary_path", "", FileDialog.FileMode.FILE_MODE_OPEN_DIR), PathSetting.new("data_path", "", FileDialog.FileMode.FILE_MODE_OPEN_DIR), TextSetting.new("name", "A Hurry Curry! Server"), + ToggleSetting.new("allow_external_connections", true), + ToggleSetting.new("enable_ipv6", true), + NumberSetting.new("bind_port", 27032, 1, 65535), ToggleSetting.new("upnp", false), ToggleSetting.new("mdns", true), ToggleSetting.new("register", false), |