mirror of
https://github.com/RPCS3/rpcs3.git
synced 2026-01-31 01:25:18 +01:00
Improve Message ComId handling
This commit is contained in:
@@ -1345,7 +1345,7 @@ error_code sceNpMatching2CreateContext(
|
||||
|
||||
error_code sceNpMatching2GetSignalingOptParamLocal(SceNpMatching2ContextId ctxId, SceNpMatching2RoomId roomId, vm::ptr<SceNpMatching2SignalingOptParam> 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<named_thread<np::np_handler>>();
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <WS2tcpip.h>
|
||||
#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<SceNpCommunicationId> 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; } )
|
||||
|
||||
@@ -10,11 +10,11 @@ namespace np
|
||||
std::string ether_to_string(std::array<u8, 6>& ether);
|
||||
bool validate_communication_id(const SceNpCommunicationId& com_id);
|
||||
std::string communication_id_to_string(const SceNpCommunicationId& communicationId);
|
||||
std::optional<SceNpCommunicationId> 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 <typename T>
|
||||
|
||||
@@ -2171,7 +2171,7 @@ namespace rpcn
|
||||
bool rpcn_client::send_message(const message_data& msg_data, const std::set<std::string>& npids)
|
||||
{
|
||||
np2_structs::MessageDetails pb_message;
|
||||
pb_message.set_communicationid(static_cast<const char*>(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);
|
||||
|
||||
Reference in New Issue
Block a user