refactor: improve multiplayer connection lifecycle
* Move client/server connection handling into game-specific networking classes * Add multiplayer data reset for disconnected clients * Clean up invalid MessageBus listeners after disconnects * Persist lobby host address and port in game data * Standardize the default server port to 8080 * Increase server address input length to support valid addresses * Remove obsolete connection and match initialization logic from base networking
This commit is contained in:
@@ -6,6 +6,26 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func setup_signals() -> void:
|
||||
#MessageBus.subscribe("game_wait_for_connection", _wait_for_connection)
|
||||
#MessageBus.subscribe("game_close_connection", _wait_close_connection)
|
||||
pass
|
||||
|
||||
func server_client_connected(id: int) -> void:
|
||||
push_warning("Client Connected... ID: ", id)
|
||||
|
||||
if not Globals.game_data.client1:
|
||||
Globals.game_data.client1 = id
|
||||
elif not Globals.game_data.client2:
|
||||
Globals.game_data.client2 = id
|
||||
|
||||
if Globals.game_data.client1 and Globals.game_data.client2:
|
||||
Globals.multiplayer_data.init_match()
|
||||
|
||||
# TODO: Add watch match feature...
|
||||
|
||||
func server_client_disconnected(id: int) -> void:
|
||||
push_warning("Client Disconnected... ID: ", id)
|
||||
|
||||
MessageBus.emit_propagation_clients_only.rpc("game_peer_disconnected", null)
|
||||
|
||||
await get_tree().create_timer(5.0).timeout
|
||||
# NOTE: Quits game server instance.
|
||||
get_tree().quit()
|
||||
|
||||
Reference in New Issue
Block a user