Moving some of lobby to use MessageBus

This commit is contained in:
2026-08-08 01:20:58 -05:00
parent de0da3de6e
commit 5ab970aec5
6 changed files with 109 additions and 66 deletions

View File

@@ -30,25 +30,17 @@ func _init() -> void:
func _delete_from_match_pool(match_id: String) -> Dictionary:
if not match_pool.get(match_id):
return {}
if not match_pool.has(match_id): return {}
var to_delete: Dictionary = match_pool[match_id].data
match_pool.erase(match_id)
return to_delete
func _signal_match_list_remove_entry(match_id: String) -> void:
lobby_ui.rpc_signals.rpc_id(1, "match_list_remove_entry", match_id)
for client in client_pool.values():
if client.in_match: continue
lobby_ui.rpc_signals.rpc_id(client.id, "match_list_remove_entry", match_id)
func _launch_game_server(
match_entry: Dictionary,
client1: Dictionary, client2: Dictionary
client1: Dictionary,
client2: Dictionary
) -> void:
var port: String = InstanceLauncher.launch_game_server(match_entry.data.type)
if port == "-1":
@@ -60,10 +52,10 @@ func _launch_game_server(
Globals.game_data.rpc_id(client2.id, "set_game_address", "127.0.0.1")
Globals.game_data.rpc_id(client1.id, "set_game_port", port)
Globals.game_data.rpc_id(client2.id, "set_game_port", port)
rpc_id(client1.id, "connect_to_game")
rpc_id(client2.id, "connect_to_game")
@rpc("any_peer", "reliable")
func match_list_add_entry(match_entry: Dictionary) -> void:
var client1 = client_pool.get( multiplayer.get_remote_sender_id() )
if not client1: return
@@ -79,25 +71,15 @@ func match_list_add_entry(match_entry: Dictionary) -> void:
match_pool[match_entry.match_id].data = match_entry
client1.match_id = match_entry.match_id
lobby_ui.rpc_signals.rpc_id(1, "match_list_add_entry", match_entry)
for client in client_pool.values():
if client.in_match: continue
lobby_ui.rpc_signals.rpc_id(client.id, "match_list_add_entry", match_entry)
lobby_ui.rpc_signals.rpc_id(client1.id, "match_list_activate_entry", match_entry.match_id)
@rpc("any_peer", "reliable")
func match_list_remove_entry(match_id: String) -> void:
var client1 = client_pool.get( multiplayer.get_remote_sender_id() )
if not client1: return
if not client1.match_id == match_id: return
client1.match_id = ""
_delete_from_match_pool(match_id)
_signal_match_list_remove_entry(match_id)
@rpc("any_peer", "reliable")
_delete_from_match_pool(match_id)
func match_list_join_entry(match_id: String) -> void:
var match_entry = match_pool.get(match_id)
if not match_entry: return
@@ -119,11 +101,9 @@ func match_list_join_entry(match_id: String) -> void:
active_match_pool[match_id] = match_entry
match_pool.erase(match_id)
client_pool.erase(client1.id)
client_pool.erase(client2.id)
_signal_match_list_remove_entry(match_id)
_launch_game_server(match_entry, client1, client2)
# NOTE: Needed for hash check to pass between client and server but isn't used by server...
@@ -131,10 +111,6 @@ func match_list_join_entry(match_id: String) -> void:
func connect_to_game() -> void:
pass
@rpc("authority", "call_local", "reliable")
func load_game_scene(_match_entry: Dictionary, _is_player_1: bool) -> void:
pass
@rpc("authority", "reliable")
func go_back_to_match_screen() -> void:
pass
@@ -150,7 +126,9 @@ func server_client_connected(id: int) -> void:
for match_entry in match_pool.values():
matches.append(match_entry.data)
lobby_ui.rpc_signals.rpc_id(id, "receive_match_list", matches)
MessageBus.emit_propagation_clients_only.rpc_id(
id, "receive_match_list", matches
)
func server_client_disconnected(id: int) -> void:
push_warning("Client Disconnected... ID: ", id)
@@ -162,13 +140,17 @@ func server_client_disconnected(id: int) -> void:
var match_entry = _delete_from_match_pool(client1.match_id)
if not client1.match_id.is_empty() and not match_entry.is_empty():
lobby_ui.rpc_signals.rpc_id(1, "match_list_remove_entry", match_entry.match_id)
MessageBus.emit_propagation(
"match_list_remove_entry", match_entry.match_id
)
for client in client_pool.values():
if client.in_match: continue
if client.id == id: continue
lobby_ui.rpc_signals.rpc_id(client.id, "match_list_remove_entry", match_entry.match_id)
MessageBus.emit_propagation_clients_only.rpc_id(
client.id, "match_list_remove_entry", match_entry.match_id
)
match_pool.erase(client1.match_id)