diff options
Diffstat (limited to 'Archipelago')
-rw-r--r-- | Archipelago/client.gd | 69 | ||||
-rw-r--r-- | Archipelago/load.gd | 8 | ||||
-rw-r--r-- | Archipelago/settings_screen.gd | 9 |
3 files changed, 82 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 |
diff --git a/Archipelago/load.gd b/Archipelago/load.gd index 9632d61..a83d055 100644 --- a/Archipelago/load.gd +++ b/Archipelago/load.gd | |||
@@ -205,6 +205,9 @@ func _load(): | |||
205 | messages.set_name("AP_Messages") | 205 | messages.set_name("AP_Messages") |
206 | self.add_child(messages) | 206 | self.add_child(messages) |
207 | 207 | ||
208 | # Hook up the scene to be able to handle connection failures. | ||
209 | apclient.connect("could_not_connect", self, "archipelago_disconnected") | ||
210 | |||
208 | # Proceed with the rest of the load. | 211 | # Proceed with the rest of the load. |
209 | global._print("Hooked Load End") | 212 | global._print("Hooked Load End") |
210 | ._load() | 213 | ._load() |
@@ -256,3 +259,8 @@ func instantiate_painting(name, scene): | |||
256 | new_painting.add_child(mps_inst) | 259 | new_painting.add_child(mps_inst) |
257 | old_painting.queue_free() | 260 | old_painting.queue_free() |
258 | return mps_inst | 261 | return mps_inst |
262 | |||
263 | |||
264 | func archipelago_disconnected(reason): | ||
265 | var messages_node = self.get_node("AP_Messages") | ||
266 | messages_node.show_message(reason) | ||
diff --git a/Archipelago/settings_screen.gd b/Archipelago/settings_screen.gd index 9c4d59a..0eb68cf 100644 --- a/Archipelago/settings_screen.gd +++ b/Archipelago/settings_screen.gd | |||
@@ -26,6 +26,7 @@ func _ready(): | |||
26 | installScriptExtension("user://maps/Archipelago/panelEnd.gd") | 26 | installScriptExtension("user://maps/Archipelago/panelEnd.gd") |
27 | 27 | ||
28 | global.get_node("Archipelago").connect("client_connected", self, "connectionSuccessful") | 28 | global.get_node("Archipelago").connect("client_connected", self, "connectionSuccessful") |
29 | global.get_node("Archipelago").connect("could_not_connect", self, "connectionUnsuccessful") | ||
29 | 30 | ||
30 | # Populate textboxes with AP settings. | 31 | # Populate textboxes with AP settings. |
31 | self.get_node("Panel/server_box").text = global.get_node("Archipelago").ap_server | 32 | self.get_node("Panel/server_box").text = global.get_node("Archipelago").ap_server |
@@ -62,3 +63,11 @@ func connectionSuccessful(): | |||
62 | global.map = "level1" | 63 | global.map = "level1" |
63 | global.save_file = apclient.getSaveFileName() | 64 | global.save_file = apclient.getSaveFileName() |
64 | var _discard = get_tree().change_scene("res://scenes/load_screen.tscn") | 65 | var _discard = get_tree().change_scene("res://scenes/load_screen.tscn") |
66 | |||
67 | |||
68 | func connectionUnsuccessful(error_message): | ||
69 | var popup = self.get_node("Panel/AcceptDialog") | ||
70 | popup.window_title = "Could not connect to Archipelago" | ||
71 | popup.dialog_text = error_message | ||
72 | popup.popup_exclusive = true | ||
73 | popup.popup_centered() | ||