rpcn: throw exception when using rpcn features without a proper config

This commit is contained in:
Megamouse 2023-03-03 10:45:29 +01:00
parent 14c0289542
commit 1d7a00666e
7 changed files with 47 additions and 30 deletions

View File

@ -441,6 +441,16 @@ namespace np
}
}
std::shared_ptr<rpcn::rpcn_client> 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<std::shared_ptr<std::pair<std::string, message_data>>> 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<error_code, std::optional<SceNpId>> 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)
{

View File

@ -350,6 +350,7 @@ namespace np
// RPCN
shared_mutex mutex_rpcn;
std::shared_ptr<rpcn::rpcn_client> rpcn;
std::shared_ptr<rpcn::rpcn_client> get_rpcn();
// UPNP
upnp_handler upnp;

View File

@ -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);
}

View File

@ -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> rpcn_client::get_instance()
std::shared_ptr<rpcn_client> 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<rpcn_client> sptr;
std::lock_guard lock(inst_mutex);

View File

@ -335,7 +335,7 @@ namespace rpcn
~rpcn_client();
rpcn_client(rpcn_client& other) = delete;
void operator=(const rpcn_client&) = delete;
static std::shared_ptr<rpcn_client> get_instance();
static std::shared_ptr<rpcn_client> get_instance(bool check_config = false);
rpcn_state wait_for_connection();
rpcn_state wait_for_authentified();

View File

@ -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();

View File

@ -35,7 +35,7 @@ bool sendmessage_dialog_frame::Exec(message_data& msg_data, std::set<std::string
m_dialog->setWindowTitle(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();