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:
@@ -23,8 +23,17 @@ func set_active_player_id(id: int) -> void:
|
||||
|
||||
current_turn_player_id = id
|
||||
|
||||
func reset() -> void:
|
||||
multiplayer_synchronizer = MultiplayerSynchronizer.new()
|
||||
synchronizer_config = SceneReplicationConfig.new()
|
||||
current_turn_player_id = -1
|
||||
|
||||
func init_match():
|
||||
is_multiplayer_active = true
|
||||
multiplayer_synchronizer.name = "multiplayer_synchronizer"
|
||||
multiplayer_synchronizer.replication_config = synchronizer_config
|
||||
multiplayer_synchronizer.root_path = "/root/billiards"
|
||||
|
||||
func init_match() -> void:
|
||||
var match_entry = Dictionary()
|
||||
match_entry.set("type", Globals.game_data.game_mode)
|
||||
|
||||
|
||||
@@ -28,7 +28,11 @@ func _on_home_bttn_pressed() -> void:
|
||||
)
|
||||
|
||||
func _on_host_connect_bttn_pressed() -> void:
|
||||
client.start_client(host_address_input.text, int(host_port_range.value))
|
||||
Globals.game_data.game_address = host_address_input.text
|
||||
Globals.game_data.game_port = int(host_port_range.value)
|
||||
client.start_client(
|
||||
Globals.game_data.game_address, Globals.game_data.game_port
|
||||
)
|
||||
|
||||
func _on_host_disconnect_bttn_pressed() -> void:
|
||||
match_create_vbox.visible = false
|
||||
|
||||
@@ -55,7 +55,7 @@ size_flags_horizontal = 3
|
||||
text = "127.0.0.1"
|
||||
placeholder_text = "Server Address: (Eg. 0.0.0.0)"
|
||||
alignment = 1
|
||||
max_length = 12
|
||||
max_length = 15
|
||||
emoji_menu_enabled = false
|
||||
clear_button_enabled = true
|
||||
caret_blink = true
|
||||
@@ -65,7 +65,7 @@ layout_mode = 2
|
||||
min_value = 1.0
|
||||
max_value = 65535.0
|
||||
page = 10.0
|
||||
value = 31315.0
|
||||
value = 8080.0
|
||||
rounded = true
|
||||
alignment = 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user