about summary refs log tree commit diff stats
path: root/Archipelago
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2023-04-20 19:58:46 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2023-04-20 19:58:46 -0400
commitcc45280174e9c52eb83d85ae9fb06149dfb17f66 (patch)
treea43e3df6c715d4d600af3b8827b78c2a8d9ff9c2 /Archipelago
parent6abbf98ea15d80a0870d4b14fa5707a7992ab485 (diff)
downloadlingo-archipelago-cc45280174e9c52eb83d85ae9fb06149dfb17f66.tar.gz
lingo-archipelago-cc45280174e9c52eb83d85ae9fb06149dfb17f66.tar.bz2
lingo-archipelago-cc45280174e9c52eb83d85ae9fb06149dfb17f66.zip
Show error message if failure to connect
Diffstat (limited to 'Archipelago')
-rw-r--r--Archipelago/client.gd69
-rw-r--r--Archipelago/load.gd8
-rw-r--r--Archipelago/settings_screen.gd9
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
17const kREARRANGE_PANELS = 1 17const kREARRANGE_PANELS = 1
18 18
19var _client = WebSocketClient.new() 19var _client = WebSocketClient.new()
20var _last_state = WebSocketPeer.STATE_CLOSED
21var _should_process = false 20var _should_process = false
21var _initiated_disconnect = false
22 22
23var _datapackages = {} 23var _datapackages = {}
24var _item_id_to_name = {} # All games 24var _item_id_to_name = {} # All games
@@ -26,6 +26,8 @@ var _location_id_to_name = {} # All games
26var _item_name_to_id = {} # LINGO only 26var _item_name_to_id = {} # LINGO only
27var _location_name_to_id = {} # LINGO only 27var _location_name_to_id = {} # LINGO only
28 28
29var _remote_version = {"major": 0, "minor": 0, "build": 0}
30
29const uuid_util = preload("user://maps/Archipelago/vendor/uuid.gd") 31const 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
60var _tower_floors = 0 62var _tower_floors = 0
61var _has_colors = ["white"] 63var _has_colors = ["white"]
62 64
65signal could_not_connect
63signal client_connected 66signal client_connected
64signal evaluate_solvability 67signal evaluate_solvability
65 68
@@ -88,16 +91,34 @@ func _init():
88 91
89func _ready(): 92func _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
96func _closed(was_clean = false): 101func _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
112func _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
102func _connected(_proto = ""): 123func _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
327func connectToServer(): 385func 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
264func 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
68func 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()