NP: Implement sceNpBasicGetFriendListEntry

This commit is contained in:
RipleyTom 2021-11-06 21:18:31 +01:00 committed by kd-11
parent d41e405420
commit c194804fec
12 changed files with 104 additions and 34 deletions

View file

@ -11,6 +11,7 @@
#include "Utilities/StrUtil.h"
#include "Emu/NP/np_handler.h"
#include "Emu/NP/np_helpers.h"
LOG_CHANNEL(cellNetCtl);

View file

@ -1267,12 +1267,20 @@ error_code sceNpBasicGetFriendListEntry(u32 index, vm::ptr<SceNpId> 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<char> comment, s32
error_code sceNpScoreSanitizeComment(s32 transId, vm::cptr<char> comment, vm::ptr<char> sanitizedComment, vm::ptr<void> 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<named_thread<np::np_handler>>();
@ -4264,9 +4272,10 @@ error_code sceNpScoreSanitizeComment(s32 transId, vm::cptr<char> 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<char> 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;
}

View file

@ -24,6 +24,7 @@
#endif
#include "Emu/NP/np_handler.h"
#include "Emu/NP/np_helpers.h"
#include "Emu/NP/np_dnshook.h"
#include <chrono>

View file

@ -1,8 +1,8 @@
#include "stdafx.h"
#include <bit>
#include "np_allocator.h"
#include "np_cache.h"
#include "Emu/NP/np_allocator.h"
#include "Emu/NP/np_cache.h"
namespace np
{

View file

@ -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"

View file

@ -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 <winsock2.h>
@ -603,6 +604,21 @@ namespace np
return 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);
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<error_code, std::optional<SceNpMatching2SessionPassword>> np_handler::local_get_room_password(SceNpMatching2RoomId room_id)
{
return np_cache.get_password(room_id);

View file

@ -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<u8> data;
};
// Helper functions
std::string ip_to_string(u32 addr);
std::string ether_to_string(std::array<u8, 6>& 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<error_code, std::optional<SceNpId>> 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);

14
rpcs3/Emu/NP/np_helpers.h Normal file
View file

@ -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<u8, 6>& 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);
}

View file

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

View file

@ -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<std::string> 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

View file

@ -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<std::string> get_friend_by_index(u32 index);
std::vector<std::pair<u16, std::vector<u8>>> get_notifications();
std::unordered_map<u32, std::pair<u16, std::vector<u8>>> get_replies();

View file

@ -471,6 +471,7 @@
<ClInclude Include="Emu\NP\np_cache.h" />
<ClInclude Include="Emu\NP\np_dnshook.h" />
<ClInclude Include="Emu\NP\np_event_data.h" />
<ClInclude Include="Emu\NP\np_helpers.h" />
<ClInclude Include="Emu\NP\np_structs_extra.h" />
<ClInclude Include="Emu\NP\rpcn_client.h" />
<ClInclude Include="Emu\NP\rpcn_config.h" />