about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Archipelago/client.gd69
-rw-r--r--Archipelago/load.gd8
-rw-r--r--Archipelago/settings_screen.gd9
-rw-r--r--archipelago.tscn31
4 files changed, 101 insertions, 16 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()
diff --git a/archipelago.tscn b/archipelago.tscn index def9ce4..284b73f 100644 --- a/archipelago.tscn +++ b/archipelago.tscn
@@ -73,31 +73,34 @@ text = "BACK"
73script = ExtResource( 4 ) 73script = ExtResource( 4 )
74 74
75[node name="credit2" parent="Panel" instance=ExtResource( 1 )] 75[node name="credit2" parent="Panel" instance=ExtResource( 1 )]
76margin_left = 267.0 76margin_left = 75.0
77margin_top = 347.0 77margin_top = 346.0
78margin_right = 857.0 78margin_right = 665.0
79margin_bottom = 411.0 79margin_bottom = 410.0
80custom_fonts/font = ExtResource( 2 ) 80custom_fonts/font = ExtResource( 2 )
81custom_styles/normal = SubResource( 1 ) 81custom_styles/normal = SubResource( 1 )
82text = "SERVER" 82text = "SERVER"
83align = 2
83 84
84[node name="credit3" parent="Panel" instance=ExtResource( 1 )] 85[node name="credit3" parent="Panel" instance=ExtResource( 1 )]
85margin_left = 263.0 86margin_left = 75.0
86margin_top = 515.0 87margin_top = 519.0
87margin_right = 853.0 88margin_right = 665.0
88margin_bottom = 579.0 89margin_bottom = 583.0
89custom_fonts/font = ExtResource( 2 ) 90custom_fonts/font = ExtResource( 2 )
90custom_styles/normal = SubResource( 1 ) 91custom_styles/normal = SubResource( 1 )
91text = "PLAYER" 92text = "PLAYER"
93align = 2
92 94
93[node name="credit4" parent="Panel" instance=ExtResource( 1 )] 95[node name="credit4" parent="Panel" instance=ExtResource( 1 )]
94margin_left = 199.0 96margin_left = 75.0
95margin_top = 691.0 97margin_top = 704.0
96margin_right = 789.0 98margin_right = 665.0
97margin_bottom = 755.0 99margin_bottom = 768.0
98custom_fonts/font = ExtResource( 2 ) 100custom_fonts/font = ExtResource( 2 )
99custom_styles/normal = SubResource( 1 ) 101custom_styles/normal = SubResource( 1 )
100text = "PASSWORD" 102text = "PASSWORD"
103align = 2
101 104
102[node name="server_box" type="LineEdit" parent="Panel"] 105[node name="server_box" type="LineEdit" parent="Panel"]
103margin_left = 682.0 106margin_left = 682.0
@@ -129,5 +132,9 @@ custom_colors/font_color = Color( 0, 0, 0, 1 )
129custom_styles/focus = SubResource( 2 ) 132custom_styles/focus = SubResource( 2 )
130align = 1 133align = 1
131 134
135[node name="AcceptDialog" type="AcceptDialog" parent="Panel"]
136margin_right = 83.0
137margin_bottom = 58.0
138
132[connection signal="pressed" from="Panel/connect_button" to="Panel/connect_button" method="_connect_pressed"] 139[connection signal="pressed" from="Panel/connect_button" to="Panel/connect_button" method="_connect_pressed"]
133[connection signal="pressed" from="Panel/quit_button" to="Panel/quit_button" method="_back_pressed"] 140[connection signal="pressed" from="Panel/quit_button" to="Panel/quit_button" method="_back_pressed"]