Added propper disconnect behaviour
This commit is contained in:
parent
c4909db2a5
commit
10066090b1
3 changed files with 22 additions and 0 deletions
18
Game.gd
18
Game.gd
|
|
@ -11,8 +11,26 @@ func _ready():
|
|||
GameEvents.insect_tile_finished_moving.connect(_on_insect_tile_finished_moving)
|
||||
GameEvents.insect_tile_created.connect(_on_insect_tile_created)
|
||||
|
||||
# since we sealed in webrtc,
|
||||
# and limited players to 1 in enet
|
||||
# this should only happen when the opponent disconnects
|
||||
# as opposed to someone (3rd) connecting DURING the game
|
||||
# and disconnecting again
|
||||
multiplayer.peer_disconnected.connect(_on_peer_disconnected)
|
||||
multiplayer.server_disconnected.connect(_on_server_disconnected)
|
||||
|
||||
GameEvents.game_started.emit()
|
||||
|
||||
func _on_peer_disconnected(id: int) -> void:
|
||||
GameData.disconnect_reason = "Connection to other peer closed unexpectedly"
|
||||
Networking.disconnect_all()
|
||||
get_tree().change_scene_to_file("res://UI/main_menu.tscn")
|
||||
|
||||
func _on_server_disconnected() -> void:
|
||||
GameData.disconnect_reason = "Connection to other peer closed unexpectedly"
|
||||
Networking.disconnect_all()
|
||||
get_tree().change_scene_to_file("res://UI/main_menu.tscn")
|
||||
|
||||
func advance_turn():
|
||||
GameEvents.turn_ended.emit(current_turn, map)
|
||||
is_blacks_turn = !is_blacks_turn
|
||||
|
|
|
|||
|
|
@ -28,6 +28,9 @@ func stop_webrtc() -> void:
|
|||
ws_client.stop()
|
||||
offline_mode()
|
||||
|
||||
func seal_webrtc() -> void:
|
||||
ws_client.seal_lobby()
|
||||
|
||||
func start_webrtc_lobby() -> void:
|
||||
if not multiplayer.multiplayer_peer is WebRTCMultiplayerPeer:
|
||||
disconnect_all()
|
||||
|
|
|
|||
|
|
@ -34,4 +34,5 @@ func load_game() -> void:
|
|||
get_tree().change_scene_to_file("res://Game.tscn")
|
||||
|
||||
func _on_start_game_button_pressed():
|
||||
Networking.seal_webrtc()
|
||||
load_game.rpc()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue