fix(network): prevent null multiplayer peer crashes offline/teardown and fix Nakama RPC session validation
This commit is contained in:
@@ -168,9 +168,10 @@ func simple_move_to(grid_position: Vector2i) -> bool:
|
||||
if gm and gm.active and gm.has_method("try_deliver"):
|
||||
var dist = abs(grid_position.x - 8) + abs(grid_position.y - 8)
|
||||
if dist <= 1:
|
||||
if multiplayer.is_server():
|
||||
var pid = player.get("peer_id") if "peer_id" in player else player.name.to_int()
|
||||
gm.try_deliver(pid)
|
||||
if player.can_rpc() and multiplayer.has_multiplayer_peer():
|
||||
if multiplayer.is_server():
|
||||
var pid = player.get("peer_id") if "peer_id" in player else player.name.to_int()
|
||||
gm.try_deliver(pid)
|
||||
|
||||
rotate_towards_target(grid_position)
|
||||
|
||||
@@ -249,10 +250,11 @@ func try_push(target_pos: Vector2i, direction: Vector2i) -> bool:
|
||||
if gm and gm.active and gm.has_method("try_knock"):
|
||||
var pid = player.get("peer_id") if "peer_id" in player else player.name.to_int()
|
||||
var other_pid = other_player.get("peer_id") if "peer_id" in other_player else other_player.name.to_int()
|
||||
if multiplayer.is_server():
|
||||
gm.try_knock(pid, other_pid)
|
||||
else:
|
||||
gm.rpc_id(1, "try_knock", pid, other_pid)
|
||||
if player.can_rpc() and multiplayer.has_multiplayer_peer():
|
||||
if multiplayer.is_server():
|
||||
gm.try_knock(pid, other_pid)
|
||||
else:
|
||||
gm.rpc_id(1, "try_knock", pid, other_pid)
|
||||
# Consume knock mode after use (toggle off)
|
||||
player.is_charged_strike = false
|
||||
return false
|
||||
@@ -315,7 +317,7 @@ func try_push(target_pos: Vector2i, direction: Vector2i) -> bool:
|
||||
print("[Move] Ghost mode bypassed push-into-sticky at %s" % pushed_to_pos)
|
||||
else:
|
||||
print("[Move] Player pushed into sticky cell at %s — slowed" % pushed_to_pos)
|
||||
if multiplayer.is_server() or other_player.is_multiplayer_authority():
|
||||
if other_player.can_rpc() and multiplayer.has_multiplayer_peer() and (multiplayer.is_server() or other_player.is_multiplayer_authority()):
|
||||
gm_sticky.apply_sticky_slow(other_player)
|
||||
|
||||
# 2. Apply freeze/stun effect
|
||||
@@ -342,10 +344,10 @@ func try_push(target_pos: Vector2i, direction: Vector2i) -> bool:
|
||||
if main_score:
|
||||
var gcm = main_score.get_node_or_null("GoalsCycleManager")
|
||||
if gcm:
|
||||
if multiplayer.is_server():
|
||||
if multiplayer.has_multiplayer_peer() and multiplayer.is_server():
|
||||
# Server/Bot: Directly add score to specific player ID
|
||||
gcm.add_score(player.name.to_int(), 200)
|
||||
else:
|
||||
elif player.can_rpc() and multiplayer.has_multiplayer_peer():
|
||||
# Client: Request score add (sender ID used)
|
||||
gcm.rpc("request_add_score", 200)
|
||||
NotificationManager.send_message(player, "Successful Attack! +200 Pts", NotificationManager.MessageType.GOAL)
|
||||
|
||||
Reference in New Issue
Block a user