Merge multiplayer to dev branch #2

Merged
chrisbell merged 21 commits from multiplayer into develop 2025-08-07 22:06:02 +00:00
2 changed files with 23 additions and 20 deletions
Showing only changes of commit 00e408d46e - Show all commits

View File

@@ -4,7 +4,7 @@
[ext_resource type="PackedScene" uid="uid://b5xb0fsfpn7r3" path="res://levels/lobby-scene/lobby-terrain.blend" id="3_f73ky"] [ext_resource type="PackedScene" uid="uid://b5xb0fsfpn7r3" path="res://levels/lobby-scene/lobby-terrain.blend" id="3_f73ky"]
[ext_resource type="PackedScene" uid="uid://csmfxg011xisf" path="res://player/Player.tscn" id="4_0aw1h"] [ext_resource type="PackedScene" uid="uid://csmfxg011xisf" path="res://player/Player.tscn" id="4_0aw1h"]
[ext_resource type="PackedScene" uid="uid://dgi81jdv7gs76" path="res://levels/lobby-scene/tent.blend" id="4_qjimh"] [ext_resource type="PackedScene" uid="uid://dgi81jdv7gs76" path="res://levels/lobby-scene/tent.blend" id="4_qjimh"]
[ext_resource type="PackedScene" uid="uid://wcsd1tb0quj3" path="res://levels/lobby-scene/campfire.tscn" id="5_qjimh"] [ext_resource type="PackedScene" path="res://levels/lobby-scene/campfire.tscn" id="5_qjimh"]
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_f73ky"] [sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_f73ky"]

View File

@@ -82,25 +82,19 @@ func setup_multiplayer_peer(is_host: bool = false) -> void:
return return
print("Created host") print("Created host")
else: else:
pass if lobby_id == 0:
return
var host_id = Steam.getLobbyOwner(lobby_id)
var err = peer.create_client(host_id, 0)
if err != OK:
print("Failed to create client, error: %s" % err)
return
print("Client created, connecting to host: %s" % host_id)
multiplayer.multiplayer_peer = peer multiplayer.multiplayer_peer = peer
func setup_multiplayer_peer_client() -> void:
if lobby_id == 0:
return
var host_id = Steam.getLobbyOwner(lobby_id)
var err = peer.create_client(host_id, 0)
if err != OK:
print("Failed to create client, error: %s" % err)
return
multiplayer.multiplayer_peer = peer
print("Client created, connecting to host: %s" % host_id)
func create_lobby(): func create_lobby():
if lobby_id == 0: if lobby_id == 0:
print("Creating lobby...") print("Creating lobby...")
@@ -113,7 +107,7 @@ func _on_lobby_created(connect: int, this_lobby_id: int):
print("Created lobby with id `%s`" % lobby_id) print("Created lobby with id `%s`" % lobby_id)
Steam.setLobbyJoinable(lobby_id, true) Steam.setLobbyJoinable(lobby_id, true)
Steam.setLobbyData(lobby_id, "name", "%'s Lobby" % steam_username) Steam.setLobbyData(lobby_id, "name", steam_username + "'s Lobby")
Steam.setLobbyData(lobby_id, "mode", "Splunk") Steam.setLobbyData(lobby_id, "mode", "Splunk")
Steam.allowP2PPacketRelay(true) Steam.allowP2PPacketRelay(true)
@@ -135,7 +129,8 @@ func _on_lobby_joined(this_lobby_id: int, permissions: int, locked: bool, respon
get_lobby_members() get_lobby_members()
if not multiplayer.is_server(): if not multiplayer.is_server():
setup_multiplayer_peer_client() setup_multiplayer_peer()
func get_lobby_members() -> void: func get_lobby_members() -> void:
@@ -152,8 +147,16 @@ func get_lobby_members() -> void:
print("Lobby member: %s (%s)" % [member_name, member_id]) print("Lobby member: %s (%s)" % [member_name, member_id])
func _on_lobby_data_update(success: int) -> void: func _on_lobby_data_update(lobby: int, user: int, success: int) -> void:
pass if success:
# Check if the lobby data itself was updated (not a specific member)
if lobby == user:
print("Lobby data for lobby %s has been updated." % lobby)
var lobby_name = Steam.getLobbyData(lobby, "name")
print("New lobby name: %s" % lobby_name)
else:
# A specific lobby member's data was updated
print("Data for member %s in lobby %s has been updated." % [user, lobby])
func _on_persona_change(steam_id_changed: int, flag: int) -> void: func _on_persona_change(steam_id_changed: int, flag: int) -> void: