Fix SignalingHelper notification

This commit is contained in:
RipleyTom 2025-02-17 03:43:40 +01:00 committed by Elad
parent 7b9aaacc4b
commit 0e5014788b
3 changed files with 54 additions and 60 deletions

View file

@ -1157,21 +1157,23 @@ namespace np
auto notifications = rpcn->get_notifications(); auto notifications = rpcn->get_notifications();
for (auto& notif : notifications) for (auto& notif : notifications)
{ {
vec_stream noti_data(notif.second);
switch (notif.first) switch (notif.first)
{ {
case rpcn::NotificationType::UserJoinedRoom: notif_user_joined_room(notif.second); break; case rpcn::NotificationType::UserJoinedRoom: notif_user_joined_room(noti_data); break;
case rpcn::NotificationType::UserLeftRoom: notif_user_left_room(notif.second); break; case rpcn::NotificationType::UserLeftRoom: notif_user_left_room(noti_data); break;
case rpcn::NotificationType::RoomDestroyed: notif_room_destroyed(notif.second); break; case rpcn::NotificationType::RoomDestroyed: notif_room_destroyed(noti_data); break;
case rpcn::NotificationType::UpdatedRoomDataInternal: notif_updated_room_data_internal(notif.second); break; case rpcn::NotificationType::UpdatedRoomDataInternal: notif_updated_room_data_internal(noti_data); break;
case rpcn::NotificationType::UpdatedRoomMemberDataInternal: notif_updated_room_member_data_internal(notif.second); break; case rpcn::NotificationType::UpdatedRoomMemberDataInternal: notif_updated_room_member_data_internal(noti_data); break;
case rpcn::NotificationType::RoomMessageReceived: notif_room_message_received(notif.second); break; case rpcn::NotificationType::RoomMessageReceived: notif_room_message_received(noti_data); break;
case rpcn::NotificationType::SignalingHelper: notif_signaling_helper(notif.second); break; case rpcn::NotificationType::SignalingHelper: notif_signaling_helper(noti_data); break;
case rpcn::NotificationType::MemberJoinedRoomGUI: notif_member_joined_room_gui(notif.second); break; case rpcn::NotificationType::MemberJoinedRoomGUI: notif_member_joined_room_gui(noti_data); break;
case rpcn::NotificationType::MemberLeftRoomGUI: notif_member_left_room_gui(notif.second); break; case rpcn::NotificationType::MemberLeftRoomGUI: notif_member_left_room_gui(noti_data); break;
case rpcn::NotificationType::RoomDisappearedGUI: notif_room_disappeared_gui(notif.second); break; case rpcn::NotificationType::RoomDisappearedGUI: notif_room_disappeared_gui(noti_data); break;
case rpcn::NotificationType::RoomOwnerChangedGUI: notif_room_owner_changed_gui(notif.second); break; case rpcn::NotificationType::RoomOwnerChangedGUI: notif_room_owner_changed_gui(noti_data); break;
case rpcn::NotificationType::UserKickedGUI: notif_user_kicked_gui(notif.second); break; case rpcn::NotificationType::UserKickedGUI: notif_user_kicked_gui(noti_data); break;
case rpcn::NotificationType::QuickMatchCompleteGUI: notif_quickmatch_complete_gui(notif.second); break; case rpcn::NotificationType::QuickMatchCompleteGUI: notif_quickmatch_complete_gui(noti_data); break;
default: fmt::throw_exception("Unknown notification(%d) received!", notif.first); break; default: fmt::throw_exception("Unknown notification(%d) received!", notif.first); break;
} }
} }

View file

@ -293,22 +293,22 @@ namespace np
bool error_and_disconnect(const std::string& error_msg); bool error_and_disconnect(const std::string& error_msg);
// Notification handlers // Notification handlers
void notif_user_joined_room(std::vector<u8>& data); void notif_user_joined_room(vec_stream& noti);
void notif_user_left_room(std::vector<u8>& data); void notif_user_left_room(vec_stream& noti);
void notif_room_destroyed(std::vector<u8>& data); void notif_room_destroyed(vec_stream& noti);
void notif_updated_room_data_internal(std::vector<u8>& data); void notif_updated_room_data_internal(vec_stream& noti);
void notif_updated_room_member_data_internal(std::vector<u8>& data); void notif_updated_room_member_data_internal(vec_stream& noti);
void notif_signaling_helper(std::vector<u8>& data); void notif_signaling_helper(vec_stream& noti);
void notif_room_message_received(std::vector<u8>& data); void notif_room_message_received(vec_stream& noti);
void generic_gui_notification_handler(std::vector<u8>& data, std::string_view name, s32 notification_type); void generic_gui_notification_handler(vec_stream& noti, std::string_view name, s32 notification_type);
void notif_member_joined_room_gui(std::vector<u8>& data); void notif_member_joined_room_gui(vec_stream& noti);
void notif_member_left_room_gui(std::vector<u8>& data); void notif_member_left_room_gui(vec_stream& noti);
void notif_room_disappeared_gui(std::vector<u8>& data); void notif_room_disappeared_gui(vec_stream& noti);
void notif_room_owner_changed_gui(std::vector<u8>& data); void notif_room_owner_changed_gui(vec_stream& noti);
void notif_user_kicked_gui(std::vector<u8>& data); void notif_user_kicked_gui(vec_stream& noti);
void notif_quickmatch_complete_gui(std::vector<u8>& data); void notif_quickmatch_complete_gui(vec_stream& noti);
// Reply handlers // Reply handlers
void reply_get_world_list(u32 req_id, rpcn::ErrorType error, vec_stream& reply); void reply_get_world_list(u32 req_id, rpcn::ErrorType error, vec_stream& reply);

View file

@ -13,9 +13,8 @@ LOG_CHANNEL(rpcn_log, "rpcn");
namespace np namespace np
{ {
void np_handler::notif_user_joined_room(std::vector<u8>& data) void np_handler::notif_user_joined_room(vec_stream& noti)
{ {
vec_stream noti(data);
const auto* notification = noti.get_flatbuffer<NotificationUserJoinedRoom>(); const auto* notification = noti.get_flatbuffer<NotificationUserJoinedRoom>();
if (noti.is_error()) if (noti.is_error())
@ -72,9 +71,8 @@ namespace np
} }
} }
void np_handler::notif_user_left_room(std::vector<u8>& data) void np_handler::notif_user_left_room(vec_stream& noti)
{ {
vec_stream noti(data);
u64 room_id = noti.get<u64>(); u64 room_id = noti.get<u64>();
const auto* update_info = noti.get_flatbuffer<RoomMemberUpdateInfo>(); const auto* update_info = noti.get_flatbuffer<RoomMemberUpdateInfo>();
@ -112,9 +110,8 @@ namespace np
} }
} }
void np_handler::notif_room_destroyed(std::vector<u8>& data) void np_handler::notif_room_destroyed(vec_stream& noti)
{ {
vec_stream noti(data);
u64 room_id = noti.get<u64>(); u64 room_id = noti.get<u64>();
const auto* update_info = noti.get_flatbuffer<RoomUpdateInfo>(); const auto* update_info = noti.get_flatbuffer<RoomUpdateInfo>();
@ -146,9 +143,8 @@ namespace np
} }
} }
void np_handler::notif_updated_room_data_internal(std::vector<u8>& data) void np_handler::notif_updated_room_data_internal(vec_stream& noti)
{ {
vec_stream noti(data);
SceNpMatching2RoomId room_id = noti.get<u64>(); SceNpMatching2RoomId room_id = noti.get<u64>();
const auto* update_info = noti.get_flatbuffer<RoomDataInternalUpdateInfo>(); const auto* update_info = noti.get_flatbuffer<RoomDataInternalUpdateInfo>();
@ -182,9 +178,8 @@ namespace np
} }
} }
void np_handler::notif_updated_room_member_data_internal(std::vector<u8>& data) void np_handler::notif_updated_room_member_data_internal(vec_stream& noti)
{ {
vec_stream noti(data);
SceNpMatching2RoomId room_id = noti.get<u64>(); SceNpMatching2RoomId room_id = noti.get<u64>();
const auto* update_info = noti.get_flatbuffer<RoomMemberDataInternalUpdateInfo>(); const auto* update_info = noti.get_flatbuffer<RoomMemberDataInternalUpdateInfo>();
@ -221,9 +216,8 @@ namespace np
} }
} }
void np_handler::notif_room_message_received(std::vector<u8>& data) void np_handler::notif_room_message_received(vec_stream& noti)
{ {
vec_stream noti(data);
u64 room_id = noti.get<u64>(); u64 room_id = noti.get<u64>();
u16 member_id = noti.get<u16>(); u16 member_id = noti.get<u16>();
const auto* message_info = noti.get_flatbuffer<RoomMessageInfo>(); const auto* message_info = noti.get_flatbuffer<RoomMessageInfo>();
@ -254,29 +248,28 @@ namespace np
} }
} }
void np_handler::notif_signaling_helper(std::vector<u8>& data) void np_handler::notif_signaling_helper(vec_stream& noti)
{ {
vec_stream noti(data); const auto* matching_info = noti.get_flatbuffer<MatchingSignalingInfo>();
const u32 addr_p2p = noti.get<u32>();
const u32 port_p2p = noti.get<u16>();
const std::string str_npid = noti.get_string(false);
if (noti.is_error()) if (noti.is_error() || !matching_info->addr() || !matching_info->npid() || !matching_info->addr()->ip())
{ {
rpcn_log.error("Received faulty SignalingHelper notification"); rpcn_log.error("Received faulty SignalingHelper notification");
return; return;
} }
SceNpId npid_p2p; SceNpId npid_p2p;
string_to_npid(str_npid, npid_p2p); string_to_npid(matching_info->npid()->string_view(), npid_p2p);
const u32 addr_p2p = register_ip(matching_info->addr()->ip());
const u16 port_p2p = matching_info->addr()->port();
auto& sigh = g_fxo->get<named_thread<signaling_handler>>(); auto& sigh = g_fxo->get<named_thread<signaling_handler>>();
sigh.send_information_packets(addr_p2p, port_p2p, npid_p2p); sigh.send_information_packets(addr_p2p, port_p2p, npid_p2p);
} }
void np_handler::generic_gui_notification_handler(std::vector<u8>& data, std::string_view name, s32 notification_type) void np_handler::generic_gui_notification_handler(vec_stream& noti, std::string_view name, s32 notification_type)
{ {
vec_stream noti(data);
const auto* update_info = noti.get_flatbuffer<MatchingRoomStatus>(); const auto* update_info = noti.get_flatbuffer<MatchingRoomStatus>();
if (noti.is_error()) if (noti.is_error())
@ -329,36 +322,35 @@ namespace np
ctx->queue_callback(req_id, notification_type, 0); ctx->queue_callback(req_id, notification_type, 0);
} }
void np_handler::notif_member_joined_room_gui(std::vector<u8>& data) void np_handler::notif_member_joined_room_gui(vec_stream& noti)
{ {
return generic_gui_notification_handler(data, "MemberJoinedRoomGUI", SCE_NP_MATCHING_EVENT_ROOM_UPDATE_NEW_MEMBER); return generic_gui_notification_handler(noti, "MemberJoinedRoomGUI", SCE_NP_MATCHING_EVENT_ROOM_UPDATE_NEW_MEMBER);
} }
void np_handler::notif_member_left_room_gui(std::vector<u8>& data) void np_handler::notif_member_left_room_gui(vec_stream& noti)
{ {
return generic_gui_notification_handler(data, "MemberLeftRoomGUI", SCE_NP_MATCHING_EVENT_ROOM_UPDATE_MEMBER_LEAVE); return generic_gui_notification_handler(noti, "MemberLeftRoomGUI", SCE_NP_MATCHING_EVENT_ROOM_UPDATE_MEMBER_LEAVE);
} }
void np_handler::notif_room_disappeared_gui(std::vector<u8>& data) void np_handler::notif_room_disappeared_gui(vec_stream& noti)
{ {
return generic_gui_notification_handler(data, "RoomDisappearedGUI", SCE_NP_MATCHING_EVENT_ROOM_DISAPPEARED); return generic_gui_notification_handler(noti, "RoomDisappearedGUI", SCE_NP_MATCHING_EVENT_ROOM_DISAPPEARED);
} }
void np_handler::notif_room_owner_changed_gui(std::vector<u8>& data) void np_handler::notif_room_owner_changed_gui(vec_stream& noti)
{ {
return generic_gui_notification_handler(data, "RoomOwnerChangedGUI", SCE_NP_MATCHING_EVENT_ROOM_UPDATE_OWNER_CHANGE); return generic_gui_notification_handler(noti, "RoomOwnerChangedGUI", SCE_NP_MATCHING_EVENT_ROOM_UPDATE_OWNER_CHANGE);
} }
void np_handler::notif_user_kicked_gui(std::vector<u8>& data) void np_handler::notif_user_kicked_gui(vec_stream& noti)
{ {
return generic_gui_notification_handler(data, "UserKickedGUI", SCE_NP_MATCHING_EVENT_ROOM_KICKED); return generic_gui_notification_handler(noti, "UserKickedGUI", SCE_NP_MATCHING_EVENT_ROOM_KICKED);
} }
void gui_epilog(const shared_ptr<matching_ctx>& ctx); void gui_epilog(const shared_ptr<matching_ctx>& ctx);
void np_handler::notif_quickmatch_complete_gui(std::vector<u8>& data) void np_handler::notif_quickmatch_complete_gui(vec_stream& noti)
{ {
vec_stream noti(data);
const auto* update_info = noti.get_flatbuffer<MatchingRoomStatus>(); const auto* update_info = noti.get_flatbuffer<MatchingRoomStatus>();
if (noti.is_error()) if (noti.is_error())