diff --git a/rpcs3/Emu/Cell/Modules/cellNetCtl.cpp b/rpcs3/Emu/Cell/Modules/cellNetCtl.cpp index 59e8e85c11..6433ef2667 100644 --- a/rpcs3/Emu/Cell/Modules/cellNetCtl.cpp +++ b/rpcs3/Emu/Cell/Modules/cellNetCtl.cpp @@ -11,6 +11,7 @@ #include "Utilities/StrUtil.h" #include "Emu/NP/np_handler.h" +#include "Emu/NP/np_helpers.h" LOG_CHANNEL(cellNetCtl); diff --git a/rpcs3/Emu/Cell/Modules/sceNp.cpp b/rpcs3/Emu/Cell/Modules/sceNp.cpp index 02ee3444c9..cc314b9bf4 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNp.cpp @@ -1267,12 +1267,20 @@ error_code sceNpBasicGetFriendListEntry(u32 index, vm::ptr npid) return SCE_NP_BASIC_ERROR_INVALID_ARGUMENT; } - // TODO: Find the correct test which returns SCE_NP_ERROR_ID_NOT_FOUND if (nph.get_psn_status() != SCE_NP_MANAGER_STATUS_ONLINE) { - return SCE_NP_ERROR_ID_NOT_FOUND; + return SCE_NP_BASIC_ERROR_BUSY; } + const auto [error, res_npid] = nph.get_friend_by_index(index); + + if (error) + { + return error; + } + + memcpy(npid.get_ptr(), &res_npid.value(), sizeof(SceNpId)); + return CELL_OK; } @@ -4250,7 +4258,7 @@ error_code sceNpScoreCensorCommentAsync(s32 transId, vm::cptr comment, s32 error_code sceNpScoreSanitizeComment(s32 transId, vm::cptr comment, vm::ptr sanitizedComment, vm::ptr option) { - sceNp.todo("sceNpScoreSanitizeComment(transId=%d, comment=%s, sanitizedComment=*0x%x, option=*0x%x)", transId, comment, sanitizedComment, option); + sceNp.warning("sceNpScoreSanitizeComment(transId=%d, comment=%s, sanitizedComment=*0x%x, option=*0x%x)", transId, comment, sanitizedComment, option); auto& nph = g_fxo->get>(); @@ -4264,9 +4272,10 @@ error_code sceNpScoreSanitizeComment(s32 transId, vm::cptr comment, vm::pt return SCE_NP_COMMUNITY_ERROR_INSUFFICIENT_ARGUMENT; } - if (strlen(comment.get_ptr()) > SCE_NP_SCORE_CENSOR_COMMENT_MAXLEN || option) // option check at least until fw 4.71 + const auto comment_len = strlen(comment.get_ptr()); + + if (comment_len > SCE_NP_SCORE_CENSOR_COMMENT_MAXLEN || option) // option check at least until fw 4.71 { - // TODO: is SCE_NP_SCORE_CENSOR_COMMENT_MAXLEN + 1 allowed ? return SCE_NP_COMMUNITY_ERROR_INVALID_ARGUMENT; } @@ -4275,6 +4284,9 @@ error_code sceNpScoreSanitizeComment(s32 transId, vm::cptr comment, vm::pt return SCE_NP_COMMUNITY_ERROR_INVALID_ONLINE_ID; } + // TODO: send to server and get sanitized version back + memcpy(sanitizedComment.get_ptr(), comment.get_ptr(), comment_len + 1); + return CELL_OK; } diff --git a/rpcs3/Emu/Cell/lv2/sys_net.cpp b/rpcs3/Emu/Cell/lv2/sys_net.cpp index fa2b2b9279..df1fd33318 100644 --- a/rpcs3/Emu/Cell/lv2/sys_net.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_net.cpp @@ -24,6 +24,7 @@ #endif #include "Emu/NP/np_handler.h" +#include "Emu/NP/np_helpers.h" #include "Emu/NP/np_dnshook.h" #include diff --git a/rpcs3/Emu/NP/np_cache.cpp b/rpcs3/Emu/NP/np_cache.cpp index 18fb2f7134..d57d1af302 100644 --- a/rpcs3/Emu/NP/np_cache.cpp +++ b/rpcs3/Emu/NP/np_cache.cpp @@ -1,8 +1,8 @@ #include "stdafx.h" #include -#include "np_allocator.h" -#include "np_cache.h" +#include "Emu/NP/np_allocator.h" +#include "Emu/NP/np_cache.h" namespace np { diff --git a/rpcs3/Emu/NP/np_dnshook.cpp b/rpcs3/Emu/NP/np_dnshook.cpp index b8ea108f5f..92e7ea3bfc 100644 --- a/rpcs3/Emu/NP/np_dnshook.cpp +++ b/rpcs3/Emu/NP/np_dnshook.cpp @@ -1,5 +1,5 @@ #include "stdafx.h" -#include "np_dnshook.h" +#include "Emu/NP/np_dnshook.h" #include "Emu/system_config.h" #include "Utilities/StrUtil.h" diff --git a/rpcs3/Emu/NP/np_handler.cpp b/rpcs3/Emu/NP/np_handler.cpp index 0d1dfd0151..a39c709a02 100644 --- a/rpcs3/Emu/NP/np_handler.cpp +++ b/rpcs3/Emu/NP/np_handler.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "Emu/system_config.h" -#include "np_handler.h" +#include "Emu/NP/np_handler.h" #include "Emu/Cell/PPUModule.h" #include "Emu/Cell/Modules/sceNp.h" #include "Emu/Cell/Modules/sceNp2.h" @@ -8,10 +8,11 @@ #include "Utilities/StrUtil.h" #include "Emu/Cell/Modules/cellSysutil.h" #include "Emu/IdManager.h" -#include "np_structs_extra.h" +#include "Emu/NP/np_structs_extra.h" #include "Emu/System.h" #include "Emu/NP/rpcn_config.h" #include "Emu/NP/np_contexts.h" +#include "Emu/NP/np_helpers.h" #ifdef _WIN32 #include @@ -603,6 +604,21 @@ namespace np return rpcn->get_num_blocks(); } + std::pair> np_handler::get_friend_by_index(u32 index) + { + auto str_friend = rpcn->get_friend_by_index(index); + + if (!str_friend) + { + return {SCE_NP_ERROR_ID_NOT_FOUND, {}}; + } + + SceNpId npid_friend; + string_to_npid(str_friend.value(), &npid_friend); + + return {CELL_OK, npid_friend}; + } + std::pair> np_handler::local_get_room_password(SceNpMatching2RoomId room_id) { return np_cache.get_password(room_id); diff --git a/rpcs3/Emu/NP/np_handler.h b/rpcs3/Emu/NP/np_handler.h index f4d1d7f001..e73c600feb 100644 --- a/rpcs3/Emu/NP/np_handler.h +++ b/rpcs3/Emu/NP/np_handler.h @@ -9,11 +9,11 @@ #include "Emu/Cell/Modules/sceNp2.h" #include "Emu/NP/rpcn_client.h" -#include "generated/np2_structs_generated.h" -#include "signaling_handler.h" -#include "np_allocator.h" -#include "np_cache.h" -#include "np_event_data.h" +#include "Emu/NP/generated/np2_structs_generated.h" +#include "Emu/NP/signaling_handler.h" +#include "Emu/NP/np_allocator.h" +#include "Emu/NP/np_cache.h" +#include "Emu/NP/np_event_data.h" namespace np { @@ -24,15 +24,6 @@ namespace np std::vector data; }; - // Helper functions - std::string ip_to_string(u32 addr); - std::string ether_to_string(std::array& ether); - - void string_to_npid(const std::string& str, SceNpId* npid); - void string_to_online_name(const std::string& str, SceNpOnlineName* online_name); - void string_to_avatar_url(const std::string& str, SceNpAvatarUrl* avatar_url); - void string_to_communication_id(const std::string& str, SceNpCommunicationId* comm_id); - class np_handler { public: @@ -125,6 +116,7 @@ namespace np // Friend stuff u32 get_num_friends(); u32 get_num_blocks(); + std::pair> get_friend_by_index(u32 index); // Misc stuff void req_ticket(u32 version, const SceNpId* npid, const char* service_id, const u8* cookie, u32 cookie_size, const char* entitlement_id, u32 consumed_count); diff --git a/rpcs3/Emu/NP/np_helpers.h b/rpcs3/Emu/NP/np_helpers.h new file mode 100644 index 0000000000..3da4a835c0 --- /dev/null +++ b/rpcs3/Emu/NP/np_helpers.h @@ -0,0 +1,14 @@ +#include "util/types.hpp" +#include "Emu/Cell/Modules/sceNp.h" +#include "Emu/Cell/Modules/sceNp2.h" + +namespace np +{ + std::string ip_to_string(u32 addr); + std::string ether_to_string(std::array& ether); + + void string_to_npid(const std::string& str, SceNpId* npid); + void string_to_online_name(const std::string& str, SceNpOnlineName* online_name); + void string_to_avatar_url(const std::string& str, SceNpAvatarUrl* avatar_url); + void string_to_communication_id(const std::string& str, SceNpCommunicationId* comm_id); +} diff --git a/rpcs3/Emu/NP/np_notifications.cpp b/rpcs3/Emu/NP/np_notifications.cpp index 9a4bf0305c..f96eb4d061 100644 --- a/rpcs3/Emu/NP/np_notifications.cpp +++ b/rpcs3/Emu/NP/np_notifications.cpp @@ -2,8 +2,9 @@ #include "Emu/Cell/PPUModule.h" #include "Emu/Cell/Modules/cellSysutil.h" #include "Emu/IdManager.h" -#include "np_handler.h" -#include "np_structs_extra.h" +#include "Emu/NP/np_handler.h" +#include "Emu/NP/np_helpers.h" +#include "Emu/NP/np_structs_extra.h" LOG_CHANNEL(rpcn_log, "rpcn"); diff --git a/rpcs3/Emu/NP/rpcn_client.cpp b/rpcs3/Emu/NP/rpcn_client.cpp index 6ea5152333..427aedd7ea 100644 --- a/rpcs3/Emu/NP/rpcn_client.cpp +++ b/rpcs3/Emu/NP/rpcn_client.cpp @@ -11,6 +11,7 @@ #include "Emu/IdManager.h" #include "Emu/System.h" #include "Emu/NP/rpcn_config.h" +#include "Emu/NP/np_helpers.h" #include "util/asm.hpp" @@ -774,10 +775,14 @@ namespace rpcn } }; - get_usernames_and_status(reply, friend_infos.friends); - get_usernames(reply, friend_infos.requests_sent); - get_usernames(reply, friend_infos.requests_received); - get_usernames(reply, friend_infos.blocked); + { + std::lock_guard lock(mutex_friends); + + get_usernames_and_status(reply, friend_infos.friends); + get_usernames(reply, friend_infos.requests_sent); + get_usernames(reply, friend_infos.requests_received); + get_usernames(reply, friend_infos.blocked); + } if (is_error(error)) { @@ -1736,6 +1741,7 @@ namespace rpcn void rpcn_client::get_friends_and_register_cb(friend_data& friend_infos, friend_cb_func cb_func, void* cb_param) { std::lock_guard lock(mutex_friends); + friend_infos = this->friend_infos; friend_cbs.insert(std::make_pair(cb_func, cb_param)); } @@ -1743,6 +1749,7 @@ namespace rpcn void rpcn_client::remove_friend_cb(friend_cb_func cb_func, void* cb_param) { std::lock_guard lock(mutex_friends); + for (const auto& friend_cb : friend_cbs) { if (friend_cb.first == cb_func && friend_cb.second == cb_param) @@ -1933,6 +1940,7 @@ namespace rpcn void rpcn_client::remove_message_cb(message_cb_func cb_func, void* cb_param) { std::lock_guard lock(mutex_messages); + for (const auto& message_cb : message_cbs) { if (message_cb.cb_func == cb_func && message_cb.cb_param == cb_param) @@ -1946,17 +1954,40 @@ namespace rpcn void rpcn_client::discard_active_message(u64 id) { std::lock_guard lock(mutex_messages); + active_messages.erase(id); } - u32 rpcn_client::get_num_friends() const + u32 rpcn_client::get_num_friends() { + std::lock_guard lock(mutex_friends); + return friend_infos.friends.size(); } - u32 rpcn_client::get_num_blocks() const + u32 rpcn_client::get_num_blocks() { + std::lock_guard lock(mutex_friends); + return friend_infos.blocked.size(); } + std::optional rpcn_client::get_friend_by_index(u32 index) + { + std::lock_guard lock(mutex_friends); + + if (index >= friend_infos.friends.size()) + { + return {}; + } + + auto it = friend_infos.friends.begin(); + for (usz i = 0; i < index; i++) + { + it++; + } + + return it->first; + } + } // namespace rpcn diff --git a/rpcs3/Emu/NP/rpcn_client.h b/rpcs3/Emu/NP/rpcn_client.h index 70b210a572..9c3ed793d4 100644 --- a/rpcs3/Emu/NP/rpcn_client.h +++ b/rpcs3/Emu/NP/rpcn_client.h @@ -293,8 +293,9 @@ namespace rpcn bool add_friend(const std::string& friend_username); bool remove_friend(const std::string& friend_username); - u32 get_num_friends() const; - u32 get_num_blocks() const; + u32 get_num_friends(); + u32 get_num_blocks(); + std::optional get_friend_by_index(u32 index); std::vector>> get_notifications(); std::unordered_map>> get_replies(); diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index e3fa6f4de6..f967666902 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -471,6 +471,7 @@ +