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