aboutsummaryrefslogtreecommitdiff
path: root/client/multiplayer.gd
diff options
context:
space:
mode:
Diffstat (limited to 'client/multiplayer.gd')
-rw-r--r--client/multiplayer.gd20
1 files changed, 9 insertions, 11 deletions
diff --git a/client/multiplayer.gd b/client/multiplayer.gd
index 2d4b9533..b9242a41 100644
--- a/client/multiplayer.gd
+++ b/client/multiplayer.gd
@@ -2,19 +2,19 @@
# Copyright 2024 nokoe
# Copyright 2024 metamuffin
# Copyright 2024 tpart
-#
+#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, version 3 of the License only.
-#
+#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
-#
+#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
-#
+#
class_name Multiplayer
extends Node
@@ -35,6 +35,8 @@ signal remove_player_item(player: int)
signal set_progress(tile: Vector2i, progress: float, warn: bool)
signal set_finished(tile: Vector2i, warn: bool)
+signal connection_closed(reason: String)
+
var connected := false
var socket := WebSocketPeer.new()
@@ -51,6 +53,7 @@ func _ready():
print("Multiplayer connect");
socket.connect_to_url(Global.server_url)
connected = true
+
func _notification(what):
if what == NOTIFICATION_PREDELETE:
print("Multiplayer disconnect");
@@ -64,16 +67,11 @@ func _process(_delta):
if state == WebSocketPeer.STATE_OPEN:
while socket.get_available_packet_count():
handle_packet(socket.get_packet())
- elif state == WebSocketPeer.STATE_CONNECTING:
- print("connecting")
- elif state == WebSocketPeer.STATE_CLOSING:
- # Keep polling to achieve proper close.
- print("closing")
- pass
elif state == WebSocketPeer.STATE_CLOSED:
var code = socket.get_close_code()
var reason = socket.get_close_reason()
- print("WebSocket closed with code: %d, reason %s. Clean: %s" % [code, reason, code != - 1])
+ emit_signal("connection_closed", "WebSocket closed with code: %d, reason %s. Clean: %s" % [code, reason, code != -1])
+ self.queue_free()
func handle_packet(bytes: PackedByteArray):
var decoded = decode_packet(bytes)