Compare commits
6 Commits
lobby-map
...
lobby-syst
| Author | SHA1 | Date | |
|---|---|---|---|
| 8445f5a944 | |||
| 0db8edef2a | |||
| 88b399f453 | |||
| eaaa3075d5 | |||
| 98cf12f533 | |||
| 52a34c8415 |
@@ -1,8 +1,8 @@
|
|||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
var players: Array[int] = []
|
var players: Dictionary[int, Player] = {}
|
||||||
|
|
||||||
var player_spawner: MultiplayerSpawner
|
var player_spawner: LobbyPlayerSpawner
|
||||||
|
|
||||||
@onready var debug_ui: PackedScene = preload("res://ui/multiplayer-debug-ui/multiplayer-debug-ui.tscn")
|
@onready var debug_ui: PackedScene = preload("res://ui/multiplayer-debug-ui/multiplayer-debug-ui.tscn")
|
||||||
var debug_ui_instance
|
var debug_ui_instance
|
||||||
@@ -29,3 +29,8 @@ func request_server_to_spawn_player(peer_id: int, player_name: String) -> void:
|
|||||||
data["player_name"] = player_name
|
data["player_name"] = player_name
|
||||||
|
|
||||||
player_spawner.spawn(data)
|
player_spawner.spawn(data)
|
||||||
|
|
||||||
|
|
||||||
|
@rpc("any_peer", "call_local", "reliable")
|
||||||
|
func request_server_to_delete_player(peer_id: int) -> void:
|
||||||
|
player_spawner.delete_player(peer_id)
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
|
class_name LobbyPlayerSpawner
|
||||||
extends MultiplayerSpawner
|
extends MultiplayerSpawner
|
||||||
|
|
||||||
@onready var player_scene: PackedScene = load("res://player/Player.tscn")
|
@onready var player_scene: PackedScene = load("res://player/Player.tscn")
|
||||||
|
|
||||||
|
var players_dict: Dictionary[int, Player] = {}
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
spawn_function = spawn_player
|
spawn_function = spawn_player
|
||||||
@@ -17,6 +20,12 @@ func spawn_player(data: Dictionary) -> Player:
|
|||||||
new_player.set_player_name(peer_id, player_name)
|
new_player.set_player_name(peer_id, player_name)
|
||||||
new_player.position = Vector3.UP
|
new_player.position = Vector3.UP
|
||||||
|
|
||||||
GameManager.players.append(int(peer_id))
|
GameManager.players[int(peer_id)] = new_player
|
||||||
|
|
||||||
return new_player
|
return new_player
|
||||||
|
|
||||||
|
|
||||||
|
func delete_player(id: int) -> void:
|
||||||
|
var player_to_delete = GameManager.players[id]
|
||||||
|
GameManager.players.erase(id)
|
||||||
|
player_to_delete.queue_free()
|
||||||
|
|||||||
@@ -26,10 +26,12 @@ func _ready() -> void:
|
|||||||
Steam.lobby_joined.connect(_on_lobby_joined)
|
Steam.lobby_joined.connect(_on_lobby_joined)
|
||||||
Steam.lobby_chat_update.connect(_on_lobby_chat_update)
|
Steam.lobby_chat_update.connect(_on_lobby_chat_update)
|
||||||
Steam.p2p_session_request.connect(_on_p2p_session_request)
|
Steam.p2p_session_request.connect(_on_p2p_session_request)
|
||||||
|
Steam.join_requested.connect(_on_lobby_join_requested)
|
||||||
|
|
||||||
multiplayer.peer_connected.connect(_on_peer_connected)
|
multiplayer.peer_connected.connect(_on_peer_connected)
|
||||||
multiplayer.peer_disconnected.connect(_on_peer_disconnected)
|
multiplayer.peer_disconnected.connect(_on_peer_disconnected)
|
||||||
multiplayer.connected_to_server.connect(_on_connected_to_server)
|
multiplayer.connected_to_server.connect(_on_connected_to_server)
|
||||||
|
multiplayer.server_disconnected.connect(_on_disconnected_from_server)
|
||||||
multiplayer.connection_failed.connect(_on_connection_failed)
|
multiplayer.connection_failed.connect(_on_connection_failed)
|
||||||
|
|
||||||
check_command_line()
|
check_command_line()
|
||||||
@@ -37,7 +39,6 @@ func _ready() -> void:
|
|||||||
multiplayer.server_relay = true
|
multiplayer.server_relay = true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if not steam_initialized:
|
if not steam_initialized:
|
||||||
return
|
return
|
||||||
@@ -46,8 +47,11 @@ func _process(delta):
|
|||||||
|
|
||||||
func create_lobby():
|
func create_lobby():
|
||||||
print("[HOST] 1. Attempting to create lobby...")
|
print("[HOST] 1. Attempting to create lobby...")
|
||||||
Steam.createLobby(Steam.LOBBY_TYPE_FRIENDS_ONLY, 4)
|
|
||||||
|
|
||||||
|
if lobby_id == 0:
|
||||||
|
Steam.createLobby(Steam.LOBBY_TYPE_FRIENDS_ONLY, 4)
|
||||||
|
else:
|
||||||
|
print("Cant host, already in a lobby")
|
||||||
|
|
||||||
func _on_lobby_created(connect: int, this_lobby_id: int):
|
func _on_lobby_created(connect: int, this_lobby_id: int):
|
||||||
if connect != 1:
|
if connect != 1:
|
||||||
@@ -72,6 +76,11 @@ func join_lobby(this_lobby_id: int):
|
|||||||
Steam.joinLobby(this_lobby_id)
|
Steam.joinLobby(this_lobby_id)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_lobby_join_requested(this_lobby_id: int, friend_id: int) -> void:
|
||||||
|
print("[CLIENT] 1. Attempting to join lobby (ID: %s)..." % this_lobby_id)
|
||||||
|
join_lobby(this_lobby_id)
|
||||||
|
|
||||||
|
|
||||||
func _on_lobby_joined(this_lobby_id: int, _p, _l, response: int):
|
func _on_lobby_joined(this_lobby_id: int, _p, _l, response: int):
|
||||||
if response != Steam.CHAT_ROOM_ENTER_RESPONSE_SUCCESS:
|
if response != Steam.CHAT_ROOM_ENTER_RESPONSE_SUCCESS:
|
||||||
print("[CLIENT] !!! Failed to join lobby: %s" % get_join_fail_reason(response))
|
print("[CLIENT] !!! Failed to join lobby: %s" % get_join_fail_reason(response))
|
||||||
@@ -91,6 +100,10 @@ func _on_connected_to_server():
|
|||||||
GameManager.request_server_to_spawn_player.rpc_id(1, multiplayer.get_unique_id(), steam_username)
|
GameManager.request_server_to_spawn_player.rpc_id(1, multiplayer.get_unique_id(), steam_username)
|
||||||
|
|
||||||
|
|
||||||
|
func _on_disconnected_from_server():
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
func _on_p2p_session_request(steam_id_remote: int) -> void:
|
func _on_p2p_session_request(steam_id_remote: int) -> void:
|
||||||
print("[P2P] ==> Session request from: %s. Accepting." % steam_id_remote)
|
print("[P2P] ==> Session request from: %s. Accepting." % steam_id_remote)
|
||||||
Steam.acceptP2PSessionWithUser(steam_id_remote)
|
Steam.acceptP2PSessionWithUser(steam_id_remote)
|
||||||
@@ -129,11 +142,12 @@ func _on_peer_connected(id: int):
|
|||||||
|
|
||||||
func _on_peer_disconnected(id: int):
|
func _on_peer_disconnected(id: int):
|
||||||
print("[INFO] Peer %s has disconnected." % id)
|
print("[INFO] Peer %s has disconnected." % id)
|
||||||
|
GameManager.request_server_to_delete_player.rpc_id(1, id)
|
||||||
if players.has(id):
|
if players.has(id):
|
||||||
#players[id].queue_free()
|
|
||||||
players.erase(id)
|
players.erase(id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
func _on_connection_failed() -> void:
|
func _on_connection_failed() -> void:
|
||||||
print("[CLIENT] !!! Connection to the host failed.")
|
print("[CLIENT] !!! Connection to the host failed.")
|
||||||
|
|
||||||
@@ -142,7 +156,9 @@ func _on_lobby_chat_update(_l_id, user_changed_id: int, _u_m_c_id, chat_state: i
|
|||||||
var state_string = "UNKNOWN"
|
var state_string = "UNKNOWN"
|
||||||
match chat_state:
|
match chat_state:
|
||||||
Steam.CHAT_MEMBER_STATE_CHANGE_ENTERED: state_string = "ENTERED"
|
Steam.CHAT_MEMBER_STATE_CHANGE_ENTERED: state_string = "ENTERED"
|
||||||
Steam.CHAT_MEMBER_STATE_CHANGE_LEFT: state_string = "LEFT"
|
Steam.CHAT_MEMBER_STATE_CHANGE_LEFT:
|
||||||
|
state_string = "LEFT"
|
||||||
|
|
||||||
Steam.CHAT_MEMBER_STATE_CHANGE_DISCONNECTED: state_string = "DISCONNECTED"
|
Steam.CHAT_MEMBER_STATE_CHANGE_DISCONNECTED: state_string = "DISCONNECTED"
|
||||||
print("[LOBBY INFO] User %s has %s the lobby." % [user_changed_id, state_string])
|
print("[LOBBY INFO] User %s has %s the lobby." % [user_changed_id, state_string])
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ config/icon="res://icon.svg"
|
|||||||
SteamManager="*res://networking/steam-manager.gd"
|
SteamManager="*res://networking/steam-manager.gd"
|
||||||
GameManager="*res://game-logic/game_manager.gd"
|
GameManager="*res://game-logic/game_manager.gd"
|
||||||
|
|
||||||
|
[display]
|
||||||
|
|
||||||
|
window/vsync/vsync_mode=0
|
||||||
|
|
||||||
[editor_plugins]
|
[editor_plugins]
|
||||||
|
|
||||||
enabled=PackedStringArray("res://addons/freecam_3D/plugin.cfg")
|
enabled=PackedStringArray("res://addons/freecam_3D/plugin.cfg")
|
||||||
|
|||||||
Reference in New Issue
Block a user