WIP: Handle player disconnected

This commit is contained in:
2025-01-30 10:09:40 +01:00
parent c62b2d7a09
commit c877e81562
5 changed files with 11 additions and 10 deletions

View File

@ -34,11 +34,11 @@ func _ready() -> void:
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
var active_players = player_spawner._get_root().get_children()
for n in active_players:
if n.owner:
if not GameServerManager.players.has(n.owner):
_remove_player(n.owner)
if multiplayer.is_server():
var active_players = player_spawner._get_root().get_children()
for n in active_players:
if not GameServerManager.players.has(n.owner_id):
_remove_player(n.owner_id)
@rpc("call_local", "reliable", "any_peer")
func _request_spawn(id: int):

View File

@ -32,6 +32,10 @@ func spawn_players(spawn_location: SpawnController, id: int) -> Error:
func remove_player(id: int) -> Error:
if multiplayer.is_server():
_get_root().find_child("PlayerPlaceholder_" + str(id)).queue_free()
var found_childen: Array[Node] =_get_root().get_children()
for found_child in found_childen:
if found_child.owner_id:
if found_child.owner_id == id:
found_child.queue_free()
return OK
return ERR_UNAUTHORIZED