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:
@@ -8,6 +8,7 @@ func start_client(address: String = "127.0.0.1", port: int = 8080) -> void:
|
||||
if peer: return
|
||||
|
||||
push_warning("Client Starting... Address: ", address, " Port: ", port)
|
||||
# TODO: Add throbber or other indication of connection attempt.
|
||||
|
||||
peer = ENetMultiplayerPeer.new()
|
||||
peer.create_client(address, port)
|
||||
|
||||
@@ -40,30 +40,8 @@ func close_connection() -> void:
|
||||
peer.close()
|
||||
peer = null
|
||||
|
||||
func server_client_connected(id: int) -> void:
|
||||
push_warning("Client Connected... ID: ", id)
|
||||
func server_client_connected(_id: int) -> void:
|
||||
assert(false, "This method needs to be overridden...")
|
||||
|
||||
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)
|
||||
|
||||
# TODO: Fix call structure
|
||||
#if id == Globals.game_data.client1:
|
||||
#LobbyNetworking.rpc_id(
|
||||
#Globals.game_data.client1,
|
||||
#"go_back_to_match_screen"
|
||||
#)
|
||||
#elif id == Globals.game_data.client2:
|
||||
#LobbyNetworking.rpc_id(
|
||||
#Globals.game_data.client2,
|
||||
#"go_back_to_match_screen"
|
||||
#)
|
||||
func server_client_disconnected(_id: int) -> void:
|
||||
assert(false, "This method needs to be overridden...")
|
||||
|
||||
Reference in New Issue
Block a user