-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlobby_client.gd
37 lines (31 loc) · 1.1 KB
/
lobby_client.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
extends LobbyClient
@export var reconnects = 0
func _ready() -> void:
var config = ConfigFile.new()
config.load("user://blazium.cfg")
reconnection_token = config.get_value("LobbyClient", "reconnection_token", "")
disconnected_from_lobby.connect(_disconnected_from_lobby)
log_updated.connect(_on_log_updated)
#server_url = "ws://localhost:8080/connect"
connected_to_lobby.connect(_connected_to_lobby)
connect_to_lobby()
func _on_log_updated(command: String, message: String):
print(command, ": ", message)
func _connected_to_lobby(_peer: LobbyPeer, new_reconnection_token: String):
reconnects = 0
var config = ConfigFile.new()
config.set_value("LobbyClient", "reconnection_token", new_reconnection_token)
var err = config.save("user://blazium.cfg")
if err != OK:
push_error(error_string(err))
func _disconnected_from_lobby(reason: String):
if reason == "Reconnect Close":
reconnection_token = ""
print("Disconnected. ", reason)
if reconnects > 10:
push_error("Cannot connect")
return
reconnects += 1
if is_inside_tree():
await get_tree().create_timer(0.2 * reconnects).timeout
connect_to_lobby()