From 1d7a00666e4ace89ac985aa4effc4cc751e0fe2c Mon Sep 17 00:00:00 2001 From: Megamouse Date: Fri, 3 Mar 2023 10:45:29 +0100 Subject: [PATCH] rpcn: throw exception when using rpcn features without a proper config --- rpcs3/Emu/NP/np_handler.cpp | 18 +++++++-- rpcs3/Emu/NP/np_handler.h | 1 + rpcs3/Emu/NP/np_requests.cpp | 44 +++++++++++----------- rpcs3/Emu/NP/rpcn_client.cpp | 8 +++- rpcs3/Emu/NP/rpcn_client.h | 2 +- rpcs3/rpcs3qt/recvmessage_dialog_frame.cpp | 2 +- rpcs3/rpcs3qt/sendmessage_dialog_frame.cpp | 2 +- 7 files changed, 47 insertions(+), 30 deletions(-) diff --git a/rpcs3/Emu/NP/np_handler.cpp b/rpcs3/Emu/NP/np_handler.cpp index 6b4d1ee679..437c07eed2 100644 --- a/rpcs3/Emu/NP/np_handler.cpp +++ b/rpcs3/Emu/NP/np_handler.cpp @@ -441,6 +441,16 @@ namespace np } } + std::shared_ptr np_handler::get_rpcn() + { + if (!rpcn) [[unlikely]] + { + ensure(g_cfg.net.psn_status == np_psn_status::psn_fake); + fmt::throw_exception("RPCN is required to use PSN online features."); + } + return rpcn; + } + void np_handler::save(utils::serial& ar) { // TODO: See ctor @@ -812,7 +822,7 @@ namespace np std::optional>> np_handler::get_message(u64 id) { - return rpcn->get_message(id); + return get_rpcn()->get_message(id); } void np_handler::operator()() @@ -1025,17 +1035,17 @@ namespace np u32 np_handler::get_num_friends() { - return rpcn->get_num_friends(); + return get_rpcn()->get_num_friends(); } u32 np_handler::get_num_blocks() { - return rpcn->get_num_blocks(); + return get_rpcn()->get_num_blocks(); } std::pair> np_handler::get_friend_by_index(u32 index) { - auto str_friend = rpcn->get_friend_by_index(index); + auto str_friend = get_rpcn()->get_friend_by_index(index); if (!str_friend) { diff --git a/rpcs3/Emu/NP/np_handler.h b/rpcs3/Emu/NP/np_handler.h index 98456b8cf4..252dbeb0aa 100644 --- a/rpcs3/Emu/NP/np_handler.h +++ b/rpcs3/Emu/NP/np_handler.h @@ -350,6 +350,7 @@ namespace np // RPCN shared_mutex mutex_rpcn; std::shared_ptr rpcn; + std::shared_ptr get_rpcn(); // UPNP upnp_handler upnp; diff --git a/rpcs3/Emu/NP/np_requests.cpp b/rpcs3/Emu/NP/np_requests.cpp index 9fcdaa08a8..b8027700d8 100644 --- a/rpcs3/Emu/NP/np_requests.cpp +++ b/rpcs3/Emu/NP/np_requests.cpp @@ -23,7 +23,7 @@ namespace np return server_list; } - if (!rpcn->get_server_list(get_req_id(0), get_match2_context(ctx_id)->communicationId, server_list)) + if (!get_rpcn()->get_server_list(get_req_id(0), get_match2_context(ctx_id)->communicationId, server_list)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -77,7 +77,7 @@ namespace np { u32 req_id = generate_callback_info(ctx_id, optParam, SCE_NP_MATCHING2_REQUEST_EVENT_GetWorldInfoList); - if (!rpcn->get_world_list(req_id, get_match2_context(ctx_id)->communicationId, server_id)) + if (!get_rpcn()->get_world_list(req_id, get_match2_context(ctx_id)->communicationId, server_id)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -134,7 +134,7 @@ namespace np extra_nps::print_createjoinroom(req); - if (!rpcn->createjoin_room(req_id, get_match2_context(ctx_id)->communicationId, req)) + if (!get_rpcn()->createjoin_room(req_id, get_match2_context(ctx_id)->communicationId, req)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -183,7 +183,7 @@ namespace np extra_nps::print_joinroom(req); - if (!rpcn->join_room(req_id, get_match2_context(ctx_id)->communicationId, req)) + if (!get_rpcn()->join_room(req_id, get_match2_context(ctx_id)->communicationId, req)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -246,7 +246,7 @@ namespace np { u32 req_id = generate_callback_info(ctx_id, optParam, SCE_NP_MATCHING2_REQUEST_EVENT_LeaveRoom); - if (!rpcn->leave_room(req_id, get_match2_context(ctx_id)->communicationId, req)) + if (!get_rpcn()->leave_room(req_id, get_match2_context(ctx_id)->communicationId, req)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -281,7 +281,7 @@ namespace np extra_nps::print_search_room(req); - if (!rpcn->search_room(req_id, get_match2_context(ctx_id)->communicationId, req)) + if (!get_rpcn()->search_room(req_id, get_match2_context(ctx_id)->communicationId, req)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -322,7 +322,7 @@ namespace np extra_nps::print_get_roomdata_external_list_req(req); - if (!rpcn->get_roomdata_external_list(req_id, get_match2_context(ctx_id)->communicationId, req)) + if (!get_rpcn()->get_roomdata_external_list(req_id, get_match2_context(ctx_id)->communicationId, req)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -364,7 +364,7 @@ namespace np extra_nps::print_set_roomdata_ext_req(req); - if (!rpcn->set_roomdata_external(req_id, get_match2_context(ctx_id)->communicationId, req)) + if (!get_rpcn()->set_roomdata_external(req_id, get_match2_context(ctx_id)->communicationId, req)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -389,7 +389,7 @@ namespace np { u32 req_id = generate_callback_info(ctx_id, optParam, SCE_NP_MATCHING2_REQUEST_EVENT_GetRoomDataInternal); - if (!rpcn->get_roomdata_internal(req_id, get_match2_context(ctx_id)->communicationId, req)) + if (!get_rpcn()->get_roomdata_internal(req_id, get_match2_context(ctx_id)->communicationId, req)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -437,7 +437,7 @@ namespace np extra_nps::print_set_roomdata_int_req(req); - if (!rpcn->set_roomdata_internal(req_id, get_match2_context(ctx_id)->communicationId, req)) + if (!get_rpcn()->set_roomdata_internal(req_id, get_match2_context(ctx_id)->communicationId, req)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -464,7 +464,7 @@ namespace np extra_nps::print_set_roommemberdata_int_req(req); - if (!rpcn->set_roommemberdata_internal(req_id, get_match2_context(ctx_id)->communicationId, req)) + if (!get_rpcn()->set_roommemberdata_internal(req_id, get_match2_context(ctx_id)->communicationId, req)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -489,7 +489,7 @@ namespace np { u32 req_id = generate_callback_info(ctx_id, optParam, SCE_NP_MATCHING2_REQUEST_EVENT_SignalingGetPingInfo); - if (!rpcn->ping_room_owner(req_id, get_match2_context(ctx_id)->communicationId, req->roomId)) + if (!get_rpcn()->ping_room_owner(req_id, get_match2_context(ctx_id)->communicationId, req->roomId)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -527,7 +527,7 @@ namespace np { u32 req_id = generate_callback_info(ctx_id, optParam, SCE_NP_MATCHING2_REQUEST_EVENT_SendRoomMessage); - if (!rpcn->send_room_message(req_id, get_match2_context(ctx_id)->communicationId, req)) + if (!get_rpcn()->send_room_message(req_id, get_match2_context(ctx_id)->communicationId, req)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -556,7 +556,7 @@ namespace np pending_sign_infos_requests[req_id] = conn_id; } - if (!rpcn->req_sign_infos(req_id, npid)) + if (!get_rpcn()->req_sign_infos(req_id, npid)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -597,7 +597,7 @@ namespace np cookie_vec.assign(cookie, cookie + cookie_size); } - if (!rpcn->req_ticket(req_id, service_id_str, cookie_vec)) + if (!get_rpcn()->req_ticket(req_id, service_id_str, cookie_vec)) { rpcn_log.error("Disconnecting from RPCN!"); is_psn_active = false; @@ -679,7 +679,7 @@ namespace np u32 req_id = get_req_id(0x3334); trans_ctx->tdata = tdata_get_board_infos{.boardInfo = boardInfo}; - rpcn->get_board_infos(req_id, trans_ctx->communicationId, boardId); + get_rpcn()->get_board_infos(req_id, trans_ctx->communicationId, boardId); score_async_handler(std::move(lock), trans_ctx, req_id, async); } @@ -735,7 +735,7 @@ namespace np trans_ctx->tdata = tdata_record_score{.tmpRank = tmpRank}; - rpcn->record_score(req_id, trans_ctx->communicationId, boardId, trans_ctx->pcId, score, str_comment, vec_data); + get_rpcn()->record_score(req_id, trans_ctx->communicationId, boardId, trans_ctx->pcId, score, str_comment, vec_data); score_async_handler(std::move(lock), trans_ctx, req_id, async); } @@ -806,7 +806,7 @@ namespace np { trans_ctx->result = std::nullopt; u32 req_id = get_req_id(0x3334); - rpcn->record_score_data(req_id, trans_ctx->communicationId, trans_ctx->pcId, boardId, score, tdata->game_data); + get_rpcn()->record_score_data(req_id, trans_ctx->communicationId, trans_ctx->pcId, boardId, score, tdata->game_data); score_async_handler(std::move(lock), trans_ctx, req_id, async); } else @@ -858,7 +858,7 @@ namespace np trans_ctx->tdata = tdata_get_score_data{.totalSize = totalSize, .recvSize = recvSize, .score_data = score_data}; u32 req_id = get_req_id(0x3334); - rpcn->get_score_data(req_id, trans_ctx->communicationId, trans_ctx->pcId, boardId, npId); + get_rpcn()->get_score_data(req_id, trans_ctx->communicationId, trans_ctx->pcId, boardId, npId); score_async_handler(std::move(lock), trans_ctx, req_id, async); return; } @@ -943,7 +943,7 @@ namespace np bool with_comments = !!commentArray; bool with_gameinfo = !!infoArray; - rpcn->get_score_range(req_id, trans_ctx->communicationId, boardId, startSerialRank, arrayNum, with_comments, with_gameinfo); + get_rpcn()->get_score_range(req_id, trans_ctx->communicationId, boardId, startSerialRank, arrayNum, with_comments, with_gameinfo); score_async_handler(std::move(lock), trans_ctx, req_id, async); } @@ -1095,7 +1095,7 @@ namespace np bool with_comments = !!commentArray; bool with_gameinfo = !!infoArray; - rpcn->get_score_friend(req_id, trans_ctx->communicationId, boardId, include_self, with_comments, with_gameinfo, arrayNum); + get_rpcn()->get_score_friend(req_id, trans_ctx->communicationId, boardId, include_self, with_comments, with_gameinfo, arrayNum); score_async_handler(std::move(lock), trans_ctx, req_id, async); } @@ -1122,7 +1122,7 @@ namespace np bool with_comments = !!commentArray; bool with_gameinfo = !!infoArray; - rpcn->get_score_npid(req_id, trans_ctx->communicationId, boardId, npid_vec, with_comments, with_gameinfo); + get_rpcn()->get_score_npid(req_id, trans_ctx->communicationId, boardId, npid_vec, with_comments, with_gameinfo); score_async_handler(std::move(lock), trans_ctx, req_id, async); } diff --git a/rpcs3/Emu/NP/rpcn_client.cpp b/rpcs3/Emu/NP/rpcn_client.cpp index fc65514943..6f47b7c6a9 100644 --- a/rpcs3/Emu/NP/rpcn_client.cpp +++ b/rpcs3/Emu/NP/rpcn_client.cpp @@ -13,6 +13,7 @@ #include "Emu/NP/rpcn_config.h" #include "Emu/NP/np_helpers.h" #include "Emu/NP/vport0.h" +#include "Emu/system_config.h" #include "util/asm.hpp" @@ -148,8 +149,13 @@ namespace rpcn sem_authentified.release(); } - std::shared_ptr rpcn_client::get_instance() + std::shared_ptr rpcn_client::get_instance(bool check_config) { + if (check_config && g_cfg.net.psn_status != np_psn_status::psn_rpcn) + { + fmt::throw_exception("RPCN is required to use PSN online features."); + } + std::shared_ptr sptr; std::lock_guard lock(inst_mutex); diff --git a/rpcs3/Emu/NP/rpcn_client.h b/rpcs3/Emu/NP/rpcn_client.h index de73b6d35e..6f7d013c31 100644 --- a/rpcs3/Emu/NP/rpcn_client.h +++ b/rpcs3/Emu/NP/rpcn_client.h @@ -335,7 +335,7 @@ namespace rpcn ~rpcn_client(); rpcn_client(rpcn_client& other) = delete; void operator=(const rpcn_client&) = delete; - static std::shared_ptr get_instance(); + static std::shared_ptr get_instance(bool check_config = false); rpcn_state wait_for_connection(); rpcn_state wait_for_authentified(); diff --git a/rpcs3/rpcs3qt/recvmessage_dialog_frame.cpp b/rpcs3/rpcs3qt/recvmessage_dialog_frame.cpp index 8ab0e4709a..1d11610102 100644 --- a/rpcs3/rpcs3qt/recvmessage_dialog_frame.cpp +++ b/rpcs3/rpcs3qt/recvmessage_dialog_frame.cpp @@ -37,7 +37,7 @@ bool recvmessage_dialog_frame::Exec(SceNpBasicMessageMainType type, SceNpBasicMe m_dialog->setWindowTitle(tr("Choose message:")); - m_rpcn = rpcn::rpcn_client::get_instance(); + m_rpcn = rpcn::rpcn_client::get_instance(true); QVBoxLayout* vbox_global = new QVBoxLayout(); diff --git a/rpcs3/rpcs3qt/sendmessage_dialog_frame.cpp b/rpcs3/rpcs3qt/sendmessage_dialog_frame.cpp index afef0b125b..f3a479db6c 100644 --- a/rpcs3/rpcs3qt/sendmessage_dialog_frame.cpp +++ b/rpcs3/rpcs3qt/sendmessage_dialog_frame.cpp @@ -35,7 +35,7 @@ bool sendmessage_dialog_frame::Exec(message_data& msg_data, std::setsetWindowTitle(tr("Choose friend to message:")); - m_rpcn = rpcn::rpcn_client::get_instance(); + m_rpcn = rpcn::rpcn_client::get_instance(true); QVBoxLayout* vbox_global = new QVBoxLayout();