mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-11 08:23:45 +00:00
feat(multiplayer): handle planned shutdowns on clients
This commit is contained in:
@@ -321,6 +321,7 @@ var _max_spectators := -1
|
||||
var _last_emitted_countdown := -1
|
||||
var _in_overtime := false
|
||||
var _match_over := false
|
||||
var _planned_server_shutdown := false
|
||||
# Dedicated-export smoke hook (task 6.2). It is parsed only by the authoritative
|
||||
# server, cannot be triggered by an RPC, and defaults to disabled.
|
||||
var _smoke_force_goal_tick := -1
|
||||
@@ -391,6 +392,7 @@ func _ready() -> void:
|
||||
# is not connected" errors per run — it only ever left because a test
|
||||
# timer happened to fire.
|
||||
NetworkManager.disconnected_from_server.connect(_on_disconnected_from_server)
|
||||
MatchNet.server_shutdown.connect(_on_server_shutdown)
|
||||
_request_match_config_until_received()
|
||||
|
||||
|
||||
@@ -994,12 +996,23 @@ func _broadcast_clock_state() -> void:
|
||||
|
||||
|
||||
func _on_disconnected_from_server() -> void:
|
||||
if _planned_server_shutdown:
|
||||
return
|
||||
# Deferred: this arrives from inside NetworkManager's poll, and gotcha 27
|
||||
# requires change_scene_to_file never run synchronously from a callback
|
||||
# mid-traversal.
|
||||
get_tree().change_scene_to_file.call_deferred(ScenePaths.MAIN_MENU)
|
||||
|
||||
|
||||
func _on_server_shutdown(reason: String) -> void:
|
||||
if multiplayer.is_server() or _planned_server_shutdown:
|
||||
return
|
||||
_planned_server_shutdown = true
|
||||
print("NetworkedMatch: server shutdown notice: %s" % reason)
|
||||
NetworkManager.shutdown()
|
||||
get_tree().change_scene_to_file.call_deferred(ScenePaths.LOBBY)
|
||||
|
||||
|
||||
func _on_match_bootstrap_received(state: int, at_tick: int, new_score: Dictionary, end_tick: int, clock_running: bool, reset_gen: int, remaining_ticks: int) -> void:
|
||||
score = new_score.duplicate()
|
||||
score_changed.emit(score.duplicate())
|
||||
|
||||
Reference in New Issue
Block a user