WIP: Handle player disconnected
This commit is contained in:
parent
c62b2d7a09
commit
c877e81562
@ -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):
|
||||
|
@ -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
|
||||
|
@ -64,10 +64,8 @@ func send_position(x: float, y: float, z: float):
|
||||
var real_position: Vector3 = server_node.global_position
|
||||
var difference: Vector3 = desired_position - real_position
|
||||
if is_vector_a_lower_than_b(difference, Vector3(0.1, 0.1, 0.1)):
|
||||
print("trustin")
|
||||
server_node.global_position = desired_position
|
||||
else:
|
||||
print("not trustin")
|
||||
adjust_position.rpc_id(owner_id, real_position.x, real_position.y, real_position.z)
|
||||
|
||||
@rpc("authority", "call_local")
|
||||
|
@ -5,7 +5,6 @@ var player_manager: PlayerManager = PlayerManager.new()
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
if OS.has_feature("dedicated_server"):
|
||||
print("I'm here")
|
||||
var chosen_map = "lowpoly_tdm_2.tscn"
|
||||
var path_tmpl := "res://scenes/maps/maps/%s"
|
||||
var path := path_tmpl % chosen_map
|
||||
|
@ -22,7 +22,7 @@ func register_player(id: int, name: String):
|
||||
player_state.name = name
|
||||
players[multiplayer.get_remote_sender_id()] = player_state
|
||||
|
||||
@rpc("any_peer", "reliable", "call_remote")
|
||||
@rpc("any_peer", "reliable", "call_local")
|
||||
func remove_player(id: int):
|
||||
if multiplayer.is_server():
|
||||
if players.has(id):
|
||||
|
Loading…
x
Reference in New Issue
Block a user