diff options
author | metamuffin <metamuffin@disroot.org> | 2025-07-07 19:42:57 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-07-07 19:42:57 +0200 |
commit | c5e2de764bb1ce1d38726b80636c3fa45b06c05e (patch) | |
tree | 7606abe3b47d123abb9cafe9c1bb7920aa3d3c7f /client/server_list.gd | |
parent | 9be9937f75c2711d5d7fd9759ed615397fff5c7f (diff) | |
download | hurrycurry-c5e2de764bb1ce1d38726b80636c3fa45b06c05e.tar hurrycurry-c5e2de764bb1ce1d38726b80636c3fa45b06c05e.tar.bz2 hurrycurry-c5e2de764bb1ce1d38726b80636c3fa45b06c05e.tar.zst |
implement discover tool as service.gd class
Diffstat (limited to 'client/server_list.gd')
-rw-r--r-- | client/server_list.gd | 48 |
1 files changed, 12 insertions, 36 deletions
diff --git a/client/server_list.gd b/client/server_list.gd index c3fc1f27..57c6e89f 100644 --- a/client/server_list.gd +++ b/client/server_list.gd @@ -35,9 +35,6 @@ var loading := false var mdns := HTTPRequest.new() var reg := HTTPRequest.new() -var thread: Thread -var pid: int = -1 - # Fallback to http, since there seems to be a problem related to mbed tls in Godot. # See: https://github.com/godotengine/godot/issues/96103 var using_http_fallback := false @@ -65,33 +62,19 @@ func _ready() -> void: add_child(timeout) mdns.request_completed.connect(_on_request_completed.bind(Registry.MDNS)) reg.request_completed.connect(_on_request_completed.bind(Registry.GLOBAL)) - if Global.get_setting("online.use_discovery"): - thread = Thread.new() - thread.start(func(): - # SAFETY: reading/writing arrays/dictionaries is allowed as long as - # the size is not changed. - # cf.: https://docs.godotengine.org/en/4.3/tutorials/performance/thread_safe_apis.html#gdscript-arrays-dictionaries - var res = OS.create_process(get_discovery_path(), [], false) - # SAFETY: since this is not read until the thread stops, this should - # probably be safe without synchronisation :) - pid = res - ) - -static func get_discovery_path() -> String: - var path: String = Global.get_setting("online.discovery_binary") - if path != "": - return path - else: - return "hurrycurry-discover" func fetch_server_list(registry: Registry) -> void: match registry: Registry.MDNS: - mdns.request(MDNS_URL, HEADERS) + if Global.get_setting("online.use_discover"): + match Discover.state: + Service.State.STOPPED: Discover.start() + Service.State.RUNNING: mdns.request(MDNS_URL, HEADERS) Registry.GLOBAL: - var url: String = Global.get_setting("online.registry_url") - url = url.replace("https:", "http:") if using_http_fallback else url - reg.request(url + "/v1/list", HEADERS) + if Global.get_setting("online.use_registry"): + var url: String = Global.get_setting("online.registry_url") + url = url.replace("https:", "http:") if using_http_fallback else url + reg.request(url + "/v1/list", HEADERS) loading = true update_loading.emit(true) @@ -116,12 +99,10 @@ func _on_request_completed(result: int, _response_code: int, _headers: PackedStr func start() -> void: timeout.stop() timeout.start() - if Global.get_setting("online.use_discovery"): - mdns_timer.start() - fetch_server_list(Registry.MDNS) - if Global.get_setting("online.use_registry"): - reg_timer.start() - fetch_server_list(Registry.GLOBAL) + mdns_timer.start() + fetch_server_list(Registry.MDNS) + reg_timer.start() + fetch_server_list(Registry.GLOBAL) func stop() -> void: timeout.stop() @@ -131,8 +112,3 @@ func stop() -> void: func one_shot() -> void: start() stop() - -func _exit_tree(): - if thread != null: thread.wait_to_finish() - if pid != -1: - OS.kill(pid) |