diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2023-04-20 19:58:46 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2023-04-20 19:58:46 -0400 |
commit | cc45280174e9c52eb83d85ae9fb06149dfb17f66 (patch) | |
tree | a43e3df6c715d4d600af3b8827b78c2a8d9ff9c2 /Archipelago/client.gd | |
parent | 6abbf98ea15d80a0870d4b14fa5707a7992ab485 (diff) | |
download | lingo-archipelago-cc45280174e9c52eb83d85ae9fb06149dfb17f66.tar.gz lingo-archipelago-cc45280174e9c52eb83d85ae9fb06149dfb17f66.tar.bz2 lingo-archipelago-cc45280174e9c52eb83d85ae9fb06149dfb17f66.zip |
Show error message if failure to connect
Diffstat (limited to 'Archipelago/client.gd')
-rw-r--r-- | Archipelago/client.gd | 69 |
1 files changed, 65 insertions, 4 deletions
diff --git a/Archipelago/client.gd b/Archipelago/client.gd index 293bf7b..a6a78e2 100644 --- a/Archipelago/client.gd +++ b/Archipelago/client.gd | |||
@@ -17,8 +17,8 @@ const kNO_PANEL_SHUFFLE = 0 | |||
17 | const kREARRANGE_PANELS = 1 | 17 | const kREARRANGE_PANELS = 1 |
18 | 18 | ||
19 | var _client = WebSocketClient.new() | 19 | var _client = WebSocketClient.new() |
20 | var _last_state = WebSocketPeer.STATE_CLOSED | ||
21 | var _should_process = false | 20 | var _should_process = false |
21 | var _initiated_disconnect = false | ||
22 | 22 | ||
23 | var _datapackages = {} | 23 | var _datapackages = {} |
24 | var _item_id_to_name = {} # All games | 24 | var _item_id_to_name = {} # All games |
@@ -26,6 +26,8 @@ var _location_id_to_name = {} # All games | |||
26 | var _item_name_to_id = {} # LINGO only | 26 | var _item_name_to_id = {} # LINGO only |
27 | var _location_name_to_id = {} # LINGO only | 27 | var _location_name_to_id = {} # LINGO only |
28 | 28 | ||
29 | var _remote_version = {"major": 0, "minor": 0, "build": 0} | ||
30 | |||
29 | const uuid_util = preload("user://maps/Archipelago/vendor/uuid.gd") | 31 | const uuid_util = preload("user://maps/Archipelago/vendor/uuid.gd") |
30 | 32 | ||
31 | # TODO: caching per MW/slot, reset between connections | 33 | # TODO: caching per MW/slot, reset between connections |
@@ -60,6 +62,7 @@ var _last_new_item = -1 | |||
60 | var _tower_floors = 0 | 62 | var _tower_floors = 0 |
61 | var _has_colors = ["white"] | 63 | var _has_colors = ["white"] |
62 | 64 | ||
65 | signal could_not_connect | ||
63 | signal client_connected | 66 | signal client_connected |
64 | signal evaluate_solvability | 67 | signal evaluate_solvability |
65 | 68 | ||
@@ -88,16 +91,34 @@ func _init(): | |||
88 | 91 | ||
89 | func _ready(): | 92 | func _ready(): |
90 | _client.connect("connection_closed", self, "_closed") | 93 | _client.connect("connection_closed", self, "_closed") |
91 | _client.connect("connection_error", self, "_closed") | 94 | _client.connect("connection_failed", self, "_closed") |
95 | _client.connect("server_disconnected", self, "_closed") | ||
96 | _client.connect("connection_error", self, "_errored") | ||
92 | _client.connect("connection_established", self, "_connected") | 97 | _client.connect("connection_established", self, "_connected") |
93 | _client.connect("data_received", self, "_on_data") | 98 | _client.connect("data_received", self, "_on_data") |
94 | 99 | ||
95 | 100 | ||
96 | func _closed(was_clean = false): | 101 | func _errored(): |
97 | global._print("Closed, clean: " + was_clean) | 102 | global._print("AP connection failed") |
103 | _should_process = false | ||
104 | _authenticated = false | ||
105 | |||
106 | emit_signal( | ||
107 | "could_not_connect", | ||
108 | "Could not connect to Archipelago. Check that your server and port are correct. See the error log for more information." | ||
109 | ) | ||
110 | |||
111 | |||
112 | func _closed(): | ||
113 | global._print("Connection closed") | ||
98 | _should_process = false | 114 | _should_process = false |
99 | _authenticated = false | 115 | _authenticated = false |
100 | 116 | ||
117 | if not _initiated_disconnect: | ||
118 | emit_signal("could_not_connect", "Disconnected from Archipelago") | ||
119 | |||
120 | _initiated_disconnect = false | ||
121 | |||
101 | 122 | ||
102 | func _connected(_proto = ""): | 123 | func _connected(_proto = ""): |
103 | global._print("Connected!") | 124 | global._print("Connected!") |
@@ -117,6 +138,7 @@ func _on_data(): | |||
117 | 138 | ||
118 | if cmd == "RoomInfo": | 139 | if cmd == "RoomInfo": |
119 | _seed = message["seed_name"] | 140 | _seed = message["seed_name"] |
141 | _remote_version = message["version"] | ||
120 | 142 | ||
121 | var needed_games = [] | 143 | var needed_games = [] |
122 | for game in message["datapackage_checksums"].keys(): | 144 | for game in message["datapackage_checksums"].keys(): |
@@ -204,6 +226,42 @@ func _on_data(): | |||
204 | emit_signal("client_connected") | 226 | emit_signal("client_connected") |
205 | 227 | ||
206 | elif cmd == "ConnectionRefused": | 228 | elif cmd == "ConnectionRefused": |
229 | var error_message = "" | ||
230 | for error in message["errors"]: | ||
231 | var submsg = "" | ||
232 | if error == "InvalidSlot": | ||
233 | submsg = "Invalid player name." | ||
234 | elif error == "InvalidGame": | ||
235 | submsg = "The specified player is not playing Lingo." | ||
236 | elif error == "IncompatibleVersion": | ||
237 | submsg = ( | ||
238 | "The Archipelago server is not the correct version for this client. Expected v%d.%d.%d. Found v%d.%d.%d." | ||
239 | % [ | ||
240 | ap_version["major"], | ||
241 | ap_version["minor"], | ||
242 | ap_version["build"], | ||
243 | _remote_version["major"], | ||
244 | _remote_version["minor"], | ||
245 | _remote_version["build"] | ||
246 | ] | ||
247 | ) | ||
248 | elif error == "InvalidPassword": | ||
249 | submsg = "Incorrect password." | ||
250 | elif error == "InvalidItemsHandling": | ||
251 | submsg = "Invalid item handling flag. This is a bug with the client. Please report it to the lingo-archipelago GitHub." | ||
252 | |||
253 | if submsg != "": | ||
254 | if error_message != "": | ||
255 | error_message += " " | ||
256 | error_message += submsg | ||
257 | |||
258 | if error_message == "": | ||
259 | error_message = "Unknown error." | ||
260 | |||
261 | _initiated_disconnect = true | ||
262 | _client.disconnect_from_host() | ||
263 | |||
264 | emit_signal("could_not_connect", error_message) | ||
207 | global._print("Connection to AP refused") | 265 | global._print("Connection to AP refused") |
208 | global._print(message) | 266 | global._print(message) |
209 | 267 | ||
@@ -325,9 +383,12 @@ func getSaveFileName(): | |||
325 | 383 | ||
326 | 384 | ||
327 | func connectToServer(): | 385 | func connectToServer(): |
386 | _initiated_disconnect = false | ||
387 | |||
328 | var url = "ws://" + ap_server | 388 | var url = "ws://" + ap_server |
329 | var err = _client.connect_to_url(url) | 389 | var err = _client.connect_to_url(url) |
330 | if err != OK: | 390 | if err != OK: |
391 | emit_signal("could_not_connect", "Could not connect to Archipelago. Error code: %d." % err) | ||
331 | global._print("Could not connect to AP: " + err) | 392 | global._print("Could not connect to AP: " + err) |
332 | return | 393 | return |
333 | _should_process = true | 394 | _should_process = true |