blob: f509a34e9fba5e52901cc496eaa10fc585459f5a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# Hurry Curry! - a game about cooking
# Copyright 2024 tpart
#
# 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/>.
#
extends Node
signal update_loading(status: bool)
signal update_server_list(list: Array)
var current_list := []
var loading := false
@onready var req: HTTPRequest = $HTTPRequest
func fetch_server_list():
if loading:
push_warning("Server list is already loading")
return
loading = true
update_loading.emit(true)
req.request_completed.connect(_on_request_completed)
req.request("https://hurrycurry-registry.metamuffin.org/v1/list", [
"Accept: application/json",
"User-Agent: Hurry Curry! %s" % Global.VERSION
])
func _on_request_completed(result: int, _response_code: int, _headers: PackedStringArray, body: PackedByteArray):
loading = false
update_loading.emit(false)
if result != 0:
push_warning("Fetching server list failed with code %d" % result)
return
var json = JSON.parse_string(body.get_string_from_utf8())
if json == null:
push_error("Server list response invalid")
return
current_list = json
update_server_list.emit(json)
|