Merge multiplayer to dev branch #2

Merged
chrisbell merged 21 commits from multiplayer into develop 2025-08-07 22:06:02 +00:00
Showing only changes of commit 767244d814 - Show all commits

View File

@@ -96,7 +96,7 @@ func init_steam() -> bool:
func setup_multiplayer_peer(is_host: bool = false) -> void: func setup_multiplayer_peer(is_host: bool = false) -> void:
## ADDED: Check if a peer is already active before creating a new one. ## ADDED: Check if a peer is already active before creating a new one.
if multiplayer.multiplayer_peer and multiplayer.get_connection_status() != MultiplayerPeer.CONNECTION_DISCONNECTED: if multiplayer.multiplayer_peer and multiplayer.multiplayer_peer.get_connection_status() != MultiplayerPeer.CONNECTION_DISCONNECTED:
print("[Multiplayer] Peer already exists. Disconnecting old one.") print("[Multiplayer] Peer already exists. Disconnecting old one.")
multiplayer.multiplayer_peer.close() multiplayer.multiplayer_peer.close()
@@ -104,7 +104,7 @@ func setup_multiplayer_peer(is_host: bool = false) -> void:
if is_host: if is_host:
print("[Multiplayer] Creating Host...") print("[Multiplayer] Creating Host...")
var err = peer.create_host() ## REMOVED: Channel is handled by the peer automatically now. var err = peer.create_host(0) ## REMOVED: Channel is handled by the peer automatically now.
if err != OK: if err != OK:
print("[Multiplayer] !!! Failed to create host. Error: %s" % err) print("[Multiplayer] !!! Failed to create host. Error: %s" % err)
return return
@@ -160,9 +160,17 @@ func _on_lobby_joined(this_lobby_id: int, permissions: int, locked: bool, respon
print("Successfully joined lobby: %s" % lobby_id) print("Successfully joined lobby: %s" % lobby_id)
get_lobby_members() get_lobby_members()
# is_server() is the most reliable check for host status # FIXED: Use Steam.getLobbyOwner() to determine if we should be host or client
if not multiplayer.is_server(): var lobby_owner_id = Steam.getLobbyOwner(lobby_id)
setup_multiplayer_peer() # Setup as client var am_i_owner = (lobby_owner_id == steam_id)
print("[Multiplayer] Lobby Owner: %s, My Steam ID: %s, Am I Owner?: %s" % [lobby_owner_id, steam_id, am_i_owner])
if not am_i_owner:
print("[Multiplayer] I am not the lobby owner, setting up as client...")
setup_multiplayer_peer(false) # Setup as client
else:
print("[Multiplayer] I am the lobby owner, but multiplayer peer should already be set up as host.")
else: else:
## ADDED: Log the specific reason for the join failure. ## ADDED: Log the specific reason for the join failure.
print("!!! Failed to join lobby. Reason: %s" % get_join_fail_reason(response)) print("!!! Failed to join lobby. Reason: %s" % get_join_fail_reason(response))
@@ -245,16 +253,19 @@ func log_multiplayer_info():
print("## Multiplayer Status:") print("## Multiplayer Status:")
if multiplayer.multiplayer_peer: if multiplayer.multiplayer_peer:
print(" - Peer State: Active") print(" - Peer State: Active")
print(" - Connection Status: %s" % get_connection_status_string(multiplayer.get_connection_status())) print(" - Connection Status: %s" % get_connection_status_string(multiplayer.multiplayer_peer.get_connection_status()))
print(" - Is Server?: %s" % multiplayer.is_server()) print(" - Is Server?: %s" % multiplayer.is_server())
print(" - My Peer ID: %s" % multiplayer.get_unique_id()) print(" - My Peer ID: %s" % multiplayer.get_unique_id())
print(" - Connected Peer IDs: %s" % multiplayer.get_peer_ids()) print(" - Connected Peer IDs: %s" % multiplayer.get_peers())
else: else:
print(" - Peer State: Inactive (null)") print(" - Peer State: Inactive (null)")
print("\n## Steam Lobby Info:") print("\n## Steam Lobby Info:")
print(" - In Lobby?: %s" % (lobby_id != 0)) print(" - In Lobby?: %s" % (lobby_id != 0))
print(" - Lobby ID: %s" % lobby_id) print(" - Lobby ID: %s" % lobby_id)
if lobby_id != 0:
print(" - Lobby Owner Steam ID: %s" % Steam.getLobbyOwner(lobby_id))
print(" - My Steam ID: %s" % steam_id)
print(" - Lobby Members Array (%s):" % lobby_members.size()) print(" - Lobby Members Array (%s):" % lobby_members.size())
for member in lobby_members: for member in lobby_members:
print(" - %s (%s)" % [member.steam_name, member.steam_id]) print(" - %s (%s)" % [member.steam_name, member.steam_id])