diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-24 20:35:26 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-24 20:35:26 +0200 |
commit | 7c15d7c2ae45c1694cb6b6def98ad5c79a414d08 (patch) | |
tree | 100fe0d9265a3eeee0972b8590d3126e4e5efbd3 /client/multiplayer.gd | |
parent | dbb52c813e64fbe4e733dbfec4e29889d288873e (diff) | |
download | hurrycurry-7c15d7c2ae45c1694cb6b6def98ad5c79a414d08.tar hurrycurry-7c15d7c2ae45c1694cb6b6def98ad5c79a414d08.tar.bz2 hurrycurry-7c15d7c2ae45c1694cb6b6def98ad5c79a414d08.tar.zst |
show websocket errors
Diffstat (limited to 'client/multiplayer.gd')
-rw-r--r-- | client/multiplayer.gd | 20 |
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) |