diff --git a/rpcs3/Emu/NP/np_handler.cpp b/rpcs3/Emu/NP/np_handler.cpp index 6c2ac08b48..527328d7f5 100644 --- a/rpcs3/Emu/NP/np_handler.cpp +++ b/rpcs3/Emu/NP/np_handler.cpp @@ -1157,21 +1157,23 @@ namespace np auto notifications = rpcn->get_notifications(); for (auto& notif : notifications) { + vec_stream noti_data(notif.second); + switch (notif.first) { - case rpcn::NotificationType::UserJoinedRoom: notif_user_joined_room(notif.second); break; - case rpcn::NotificationType::UserLeftRoom: notif_user_left_room(notif.second); break; - case rpcn::NotificationType::RoomDestroyed: notif_room_destroyed(notif.second); break; - case rpcn::NotificationType::UpdatedRoomDataInternal: notif_updated_room_data_internal(notif.second); break; - case rpcn::NotificationType::UpdatedRoomMemberDataInternal: notif_updated_room_member_data_internal(notif.second); break; - case rpcn::NotificationType::RoomMessageReceived: notif_room_message_received(notif.second); break; - case rpcn::NotificationType::SignalingHelper: notif_signaling_helper(notif.second); break; - case rpcn::NotificationType::MemberJoinedRoomGUI: notif_member_joined_room_gui(notif.second); break; - case rpcn::NotificationType::MemberLeftRoomGUI: notif_member_left_room_gui(notif.second); break; - case rpcn::NotificationType::RoomDisappearedGUI: notif_room_disappeared_gui(notif.second); break; - case rpcn::NotificationType::RoomOwnerChangedGUI: notif_room_owner_changed_gui(notif.second); break; - case rpcn::NotificationType::UserKickedGUI: notif_user_kicked_gui(notif.second); break; - case rpcn::NotificationType::QuickMatchCompleteGUI: notif_quickmatch_complete_gui(notif.second); break; + case rpcn::NotificationType::UserJoinedRoom: notif_user_joined_room(noti_data); break; + case rpcn::NotificationType::UserLeftRoom: notif_user_left_room(noti_data); break; + case rpcn::NotificationType::RoomDestroyed: notif_room_destroyed(noti_data); break; + case rpcn::NotificationType::UpdatedRoomDataInternal: notif_updated_room_data_internal(noti_data); break; + case rpcn::NotificationType::UpdatedRoomMemberDataInternal: notif_updated_room_member_data_internal(noti_data); break; + case rpcn::NotificationType::RoomMessageReceived: notif_room_message_received(noti_data); break; + case rpcn::NotificationType::SignalingHelper: notif_signaling_helper(noti_data); break; + case rpcn::NotificationType::MemberJoinedRoomGUI: notif_member_joined_room_gui(noti_data); break; + case rpcn::NotificationType::MemberLeftRoomGUI: notif_member_left_room_gui(noti_data); break; + case rpcn::NotificationType::RoomDisappearedGUI: notif_room_disappeared_gui(noti_data); break; + case rpcn::NotificationType::RoomOwnerChangedGUI: notif_room_owner_changed_gui(noti_data); break; + case rpcn::NotificationType::UserKickedGUI: notif_user_kicked_gui(noti_data); break; + case rpcn::NotificationType::QuickMatchCompleteGUI: notif_quickmatch_complete_gui(noti_data); break; default: fmt::throw_exception("Unknown notification(%d) received!", notif.first); break; } } diff --git a/rpcs3/Emu/NP/np_handler.h b/rpcs3/Emu/NP/np_handler.h index 4e0352c332..ab38eb6f3c 100644 --- a/rpcs3/Emu/NP/np_handler.h +++ b/rpcs3/Emu/NP/np_handler.h @@ -293,22 +293,22 @@ namespace np bool error_and_disconnect(const std::string& error_msg); // Notification handlers - void notif_user_joined_room(std::vector& data); - void notif_user_left_room(std::vector& data); - void notif_room_destroyed(std::vector& data); - void notif_updated_room_data_internal(std::vector& data); - void notif_updated_room_member_data_internal(std::vector& data); - void notif_signaling_helper(std::vector& data); - void notif_room_message_received(std::vector& data); + void notif_user_joined_room(vec_stream& noti); + void notif_user_left_room(vec_stream& noti); + void notif_room_destroyed(vec_stream& noti); + void notif_updated_room_data_internal(vec_stream& noti); + void notif_updated_room_member_data_internal(vec_stream& noti); + void notif_signaling_helper(vec_stream& noti); + void notif_room_message_received(vec_stream& noti); - void generic_gui_notification_handler(std::vector& 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& data); - void notif_member_left_room_gui(std::vector& data); - void notif_room_disappeared_gui(std::vector& data); - void notif_room_owner_changed_gui(std::vector& data); - void notif_user_kicked_gui(std::vector& data); - void notif_quickmatch_complete_gui(std::vector& data); + void notif_member_joined_room_gui(vec_stream& noti); + void notif_member_left_room_gui(vec_stream& noti); + void notif_room_disappeared_gui(vec_stream& noti); + void notif_room_owner_changed_gui(vec_stream& noti); + void notif_user_kicked_gui(vec_stream& noti); + void notif_quickmatch_complete_gui(vec_stream& noti); // Reply handlers void reply_get_world_list(u32 req_id, rpcn::ErrorType error, vec_stream& reply); diff --git a/rpcs3/Emu/NP/np_notifications.cpp b/rpcs3/Emu/NP/np_notifications.cpp index e051c64d65..55b74ec761 100644 --- a/rpcs3/Emu/NP/np_notifications.cpp +++ b/rpcs3/Emu/NP/np_notifications.cpp @@ -13,9 +13,8 @@ LOG_CHANNEL(rpcn_log, "rpcn"); namespace np { - void np_handler::notif_user_joined_room(std::vector& data) + void np_handler::notif_user_joined_room(vec_stream& noti) { - vec_stream noti(data); const auto* notification = noti.get_flatbuffer(); if (noti.is_error()) @@ -72,9 +71,8 @@ namespace np } } - void np_handler::notif_user_left_room(std::vector& data) + void np_handler::notif_user_left_room(vec_stream& noti) { - vec_stream noti(data); u64 room_id = noti.get(); const auto* update_info = noti.get_flatbuffer(); @@ -112,9 +110,8 @@ namespace np } } - void np_handler::notif_room_destroyed(std::vector& data) + void np_handler::notif_room_destroyed(vec_stream& noti) { - vec_stream noti(data); u64 room_id = noti.get(); const auto* update_info = noti.get_flatbuffer(); @@ -146,9 +143,8 @@ namespace np } } - void np_handler::notif_updated_room_data_internal(std::vector& data) + void np_handler::notif_updated_room_data_internal(vec_stream& noti) { - vec_stream noti(data); SceNpMatching2RoomId room_id = noti.get(); const auto* update_info = noti.get_flatbuffer(); @@ -182,9 +178,8 @@ namespace np } } - void np_handler::notif_updated_room_member_data_internal(std::vector& data) + void np_handler::notif_updated_room_member_data_internal(vec_stream& noti) { - vec_stream noti(data); SceNpMatching2RoomId room_id = noti.get(); const auto* update_info = noti.get_flatbuffer(); @@ -221,9 +216,8 @@ namespace np } } - void np_handler::notif_room_message_received(std::vector& data) + void np_handler::notif_room_message_received(vec_stream& noti) { - vec_stream noti(data); u64 room_id = noti.get(); u16 member_id = noti.get(); const auto* message_info = noti.get_flatbuffer(); @@ -254,29 +248,28 @@ namespace np } } - void np_handler::notif_signaling_helper(std::vector& data) + void np_handler::notif_signaling_helper(vec_stream& noti) { - vec_stream noti(data); - const u32 addr_p2p = noti.get(); - const u32 port_p2p = noti.get(); - const std::string str_npid = noti.get_string(false); + const auto* matching_info = noti.get_flatbuffer(); - 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"); return; } 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>(); sigh.send_information_packets(addr_p2p, port_p2p, npid_p2p); } - void np_handler::generic_gui_notification_handler(std::vector& 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(); if (noti.is_error()) @@ -329,36 +322,35 @@ namespace np ctx->queue_callback(req_id, notification_type, 0); } - void np_handler::notif_member_joined_room_gui(std::vector& 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& 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& 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& 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& 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& ctx); - void np_handler::notif_quickmatch_complete_gui(std::vector& data) + void np_handler::notif_quickmatch_complete_gui(vec_stream& noti) { - vec_stream noti(data); const auto* update_info = noti.get_flatbuffer(); if (noti.is_error())