Release 2.4.6: Add SafeNakamaMultiplayerBridge subclass to fix dictionary lookup crashes
Release / Build & Release (push) Successful in 7m22s
Release / Build & Release (push) Successful in 7m22s
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
class_name SafeNakamaMultiplayerBridge
|
||||
extends NakamaMultiplayerBridge
|
||||
|
||||
func _init(p_nakama_socket: NakamaSocket) -> void:
|
||||
super._init(p_nakama_socket)
|
||||
|
||||
func _map_id_to_session(peer_id: int, session_id: String) -> void:
|
||||
_id_map[peer_id] = session_id
|
||||
if not _users.has(session_id):
|
||||
_users[session_id] = NakamaMultiplayerBridge.User.new(null)
|
||||
_users[session_id].peer_id = peer_id
|
||||
|
||||
func _on_multiplayer_peer_packet_generated(peer_id: int, buffer: PackedByteArray) -> void:
|
||||
if match_state == MatchState.CONNECTED:
|
||||
var target_presences = null
|
||||
if peer_id > 0:
|
||||
if not _id_map.has(peer_id) or not _users.has(_id_map[peer_id]) or _users[_id_map[peer_id]].presence == null:
|
||||
push_error("Attempting to send RPC to unknown or uninitialized peer id: %s" % peer_id)
|
||||
return
|
||||
target_presences = [ _users[_id_map[peer_id]].presence ]
|
||||
_nakama_socket.send_match_state_raw_async(_match_id, rpc_op_code, buffer, target_presences)
|
||||
else:
|
||||
push_error("RPC sent while the NakamaMultiplayerBridge isn't connected!")
|
||||
Reference in New Issue
Block a user