diff --git a/rpcs3/Emu/Cell/Modules/sceNp2.cpp b/rpcs3/Emu/Cell/Modules/sceNp2.cpp index 98f2bf3883..fddc514bcc 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp2.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNp2.cpp @@ -1345,7 +1345,7 @@ error_code sceNpMatching2CreateContext( error_code sceNpMatching2GetSignalingOptParamLocal(SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, vm::ptr signalingOptParam) { - sceNp2.todo("sceNpMatching2GetSignalingOptParamLocal(ctxId=%d, roomId=%d, signalingOptParam=*0x%x)", ctxId, roomId, signalingOptParam); + sceNp2.warning("sceNpMatching2GetSignalingOptParamLocal(ctxId=%d, roomId=%d, signalingOptParam=*0x%x)", ctxId, roomId, signalingOptParam); auto& nph = g_fxo->get>(); diff --git a/rpcs3/Emu/NP/np_helpers.cpp b/rpcs3/Emu/NP/np_helpers.cpp index b6e49b97b2..839b33b614 100644 --- a/rpcs3/Emu/NP/np_helpers.cpp +++ b/rpcs3/Emu/NP/np_helpers.cpp @@ -8,6 +8,8 @@ #include #endif +LOG_CHANNEL(rpcn_log, "rpcn"); + namespace np { std::string ip_to_string(u32 ip_addr) @@ -34,6 +36,24 @@ namespace np return fmt::format("%s_%02d", com_id_data, communicationId.num); } + std::optional string_to_communication_id(std::string_view str) + { + SceNpCommunicationId id{}; + + const auto split_id = fmt::split_sv(str, {"_"}); + + if (split_id.size() != 2 || split_id[0].length() != 9 || split_id[1].length() != 2 || !std::isdigit(split_id[1][0]) || !std::isdigit(split_id[1][1])) + { + rpcn_log.error("Tried to parse an invalid communication_id!"); + return std::nullopt; + } + + strcpy_trunc(id.data, split_id); + id.num = std::stoi(std::string(split_id[1])); + + return id; + } + void strings_to_userinfo(std::string_view npid, std::string_view online_name, std::string_view avatar_url, SceNpUserInfo& user_info) { memset(&user_info, 0, sizeof(user_info)); @@ -81,12 +101,6 @@ namespace np strcpy_trunc(avatar_url.data, str); } - void string_to_communication_id(std::string_view str, SceNpCommunicationId& comm_id) - { - memset(&comm_id, 0, sizeof(comm_id)); - strcpy_trunc(comm_id.data, str); - } - bool is_valid_npid(const SceNpId& npid) { if (!std::all_of(npid.handle.data, npid.handle.data + 16, [](char c) { return std::isalnum(c) || c == '-' || c == '_' || c == 0; } ) diff --git a/rpcs3/Emu/NP/np_helpers.h b/rpcs3/Emu/NP/np_helpers.h index 054e45388d..c33b4ca001 100644 --- a/rpcs3/Emu/NP/np_helpers.h +++ b/rpcs3/Emu/NP/np_helpers.h @@ -10,11 +10,11 @@ namespace np std::string ether_to_string(std::array& ether); bool validate_communication_id(const SceNpCommunicationId& com_id); std::string communication_id_to_string(const SceNpCommunicationId& communicationId); + std::optional string_to_communication_id(std::string_view str); void string_to_npid(std::string_view str, SceNpId& npid); void string_to_online_name(std::string_view str, SceNpOnlineName& online_name); void string_to_avatar_url(std::string_view str, SceNpAvatarUrl& avatar_url); - void string_to_communication_id(std::string_view str, SceNpCommunicationId& comm_id); void strings_to_userinfo(std::string_view npid, std::string_view online_name, std::string_view avatar_url, SceNpUserInfo& user_info); template diff --git a/rpcs3/Emu/NP/rpcn_client.cpp b/rpcs3/Emu/NP/rpcn_client.cpp index 61ad839555..cce4fa397b 100644 --- a/rpcs3/Emu/NP/rpcn_client.cpp +++ b/rpcs3/Emu/NP/rpcn_client.cpp @@ -2171,7 +2171,7 @@ namespace rpcn bool rpcn_client::send_message(const message_data& msg_data, const std::set& npids) { np2_structs::MessageDetails pb_message; - pb_message.set_communicationid(static_cast(msg_data.commId.data)); + pb_message.set_communicationid(np::communication_id_to_string(msg_data.commId)); pb_message.set_msgid(msg_data.msgId); pb_message.mutable_maintype()->set_value(msg_data.mainType); pb_message.mutable_subtype()->set_value(msg_data.subType); @@ -3126,8 +3126,9 @@ namespace rpcn return; } - if (pb_mdata->communicationid().empty() || pb_mdata->communicationid().size() > 9 || - pb_mdata->subject().empty() || pb_mdata->body().empty()) + const auto communication_id = np::string_to_communication_id(pb_mdata->communicationid()); + + if (!communication_id) { rpcn_log.warning("Discarded invalid message!"); return; @@ -3141,7 +3142,7 @@ namespace rpcn .subject = pb_mdata->subject(), .body = pb_mdata->body()}; - strcpy_trunc(mdata.commId.data, pb_mdata->communicationid()); + mdata.commId = *communication_id; mdata.data.assign(pb_mdata->data().begin(), pb_mdata->data().end()); rpcn_log.notice("Received message from %s:", sender);