about summary refs log tree commit diff stats
path: root/Archipelago/client.gd
diff options
context:
space:
mode:
Diffstat (limited to 'Archipelago/client.gd')
-rw-r--r--Archipelago/client.gd47
1 files changed, 47 insertions, 0 deletions
diff --git a/Archipelago/client.gd b/Archipelago/client.gd index 489ec70..62f4d71 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd
@@ -4,6 +4,8 @@ var ap_server = ""
4var ap_user = "" 4var ap_user = ""
5var ap_pass = "" 5var ap_pass = ""
6 6
7const ap_version = {"major": 0, "minor": 4, "build": 0, "class": "Version"}
8
7var _client = WebSocketClient.new() 9var _client = WebSocketClient.new()
8var _last_state = WebSocketPeer.STATE_CLOSED 10var _last_state = WebSocketPeer.STATE_CLOSED
9var _should_process = false 11var _should_process = false
@@ -12,6 +14,15 @@ var _datapackage_checksum = ""
12var _item_name_to_id = {} 14var _item_name_to_id = {}
13var _location_name_to_id = {} 15var _location_name_to_id = {}
14 16
17const uuid_util = preload("user://maps/Archipelago/vendor/uuid.gd")
18
19var _authenticated = false
20var _team = 0
21var _slot = 0
22var _players = []
23var _checked_locations = []
24var _slot_data = {}
25
15 26
16func _init(): 27func _init():
17 global._print("Instantiated APClient") 28 global._print("Instantiated APClient")
@@ -47,6 +58,7 @@ func _ready():
47func _closed(was_clean = false): 58func _closed(was_clean = false):
48 global._print("Closed, clean: " + was_clean) 59 global._print("Closed, clean: " + was_clean)
49 _should_process = false 60 _should_process = false
61 _authenticated = false
50 62
51 63
52func _connected(_proto = ""): 64func _connected(_proto = ""):
@@ -69,6 +81,9 @@ func _on_data():
69 if message["datapackage_checksums"].has("Lingo"): 81 if message["datapackage_checksums"].has("Lingo"):
70 if _datapackage_checksum != message["datapackage_checksums"]["Lingo"]: 82 if _datapackage_checksum != message["datapackage_checksums"]["Lingo"]:
71 requestDatapackage() 83 requestDatapackage()
84 else:
85 connectToRoom()
86
72 elif cmd == "DataPackage": 87 elif cmd == "DataPackage":
73 if message["data"]["games"].has("Lingo"): 88 if message["data"]["games"].has("Lingo"):
74 var lingo_pkg = message["data"]["games"]["Lingo"] 89 var lingo_pkg = message["data"]["games"]["Lingo"]
@@ -77,6 +92,20 @@ func _on_data():
77 _location_name_to_id = lingo_pkg["location_name_to_id"] 92 _location_name_to_id = lingo_pkg["location_name_to_id"]
78 saveSettings() 93 saveSettings()
79 94
95 connectToRoom()
96
97 elif cmd == "Connected":
98 _authenticated = true
99 _team = message["team"]
100 _slot = message["slot"]
101 _players = message["players"]
102 _checked_locations = message["checked_locations"]
103 _slot_data = message["slot_data"]
104
105 elif cmd == "ConnectionRefused":
106 global._print("Connection to AP refused")
107 global._print(message)
108
80 109
81func _process(_delta): 110func _process(_delta):
82 if _should_process: 111 if _should_process:
@@ -119,3 +148,21 @@ func sendMessage(msg):
119 148
120func requestDatapackage(): 149func requestDatapackage():
121 sendMessage([{"cmd": "GetDataPackage", "games": ["Lingo"]}]) 150 sendMessage([{"cmd": "GetDataPackage", "games": ["Lingo"]}])
151
152
153func connectToRoom():
154 sendMessage(
155 [
156 {
157 "cmd": "Connect",
158 "password": ap_pass,
159 "game": "Lingo",
160 "name": ap_user,
161 "uuid": uuid_util.v4(),
162 "version": ap_version,
163 "items_handling": 0b111, # always receive our items
164 "tags": [],
165 "slot_data": true
166 }
167 ]
168 )