Skip to content

Commit

Permalink
overlays: add friends list to home menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Megamouse committed Oct 6, 2024
1 parent 73fe420 commit 0a57c45
Show file tree
Hide file tree
Showing 17 changed files with 858 additions and 29 deletions.
1 change: 1 addition & 0 deletions rpcs3/Emu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ target_sources(rpcs3_emu PRIVATE
RSX/NV47/HW/nv308a.cpp
RSX/NV47/HW/nv406e.cpp
RSX/NV47/HW/nv4097.cpp
RSX/Overlays/FriendsList/overlay_friends_list_dialog.cpp
RSX/Overlays/HomeMenu/overlay_home_menu.cpp
RSX/Overlays/HomeMenu/overlay_home_menu_components.cpp
RSX/Overlays/HomeMenu/overlay_home_menu_main_menu.cpp
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/NP/np_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ namespace np
if (g_cfg.net.psn_status >= np_psn_status::psn_fake)
{
g_cfg_rpcn.load(); // Ensures config is loaded even if rpcn is not running for simulated
std::string s_npid = g_cfg_rpcn.get_npid();
const std::string s_npid = g_cfg_rpcn.get_npid();
ensure(!s_npid.empty()); // It should have been generated before this

string_to_npid(s_npid, npid);
Expand Down
32 changes: 21 additions & 11 deletions rpcs3/Emu/NP/rpcn_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace rpcn
}
}

void overlay_friend_callback(void* param, rpcn::NotificationType ntype, const std::string& username, bool status)
void overlay_friend_callback(void* /*param*/, rpcn::NotificationType ntype, const std::string& username, bool status)
{
if (!g_cfg.misc.show_rpcn_popups)
return;
Expand All @@ -88,6 +88,7 @@ namespace rpcn
case rpcn::NotificationType::FriendNew: loc_id = localized_string_id::RPCN_FRIEND_ADDED; break;
case rpcn::NotificationType::FriendLost: loc_id = localized_string_id::RPCN_FRIEND_LOST; break;
case rpcn::NotificationType::FriendStatus: loc_id = status ? localized_string_id::RPCN_FRIEND_LOGGED_IN : localized_string_id::RPCN_FRIEND_LOGGED_OUT; break;
case rpcn::NotificationType::FriendPresenceChanged: return;
default: rpcn_log.fatal("An unhandled notification type was received by the overlay friend callback!"); break;
}

Expand Down Expand Up @@ -2572,6 +2573,12 @@ namespace rpcn
return state;
}

void rpcn_client::get_friends(friend_data& friend_infos)
{
std::lock_guard lock(mutex_friends);
friend_infos = this->friend_infos;
}

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);
Expand Down Expand Up @@ -2619,7 +2626,7 @@ namespace rpcn
{
case NotificationType::FriendQuery: // Other user sent a friend request
{
std::string username = vdata.get_string(false);
const std::string username = vdata.get_string(false);
if (vdata.is_error())
{
rpcn_log.error("Error parsing FriendQuery notification");
Expand All @@ -2632,8 +2639,8 @@ namespace rpcn
}
case NotificationType::FriendNew: // Add a friend to the friendlist(either accepted a friend request or friend accepted it)
{
bool online = !!vdata.get<u8>();
std::string username = vdata.get_string(false);
const bool online = !!vdata.get<u8>();
const std::string username = vdata.get_string(false);
if (vdata.is_error())
{
rpcn_log.error("Error parsing FriendNew notification");
Expand All @@ -2649,22 +2656,24 @@ namespace rpcn
}
case NotificationType::FriendLost: // Remove friend from the friendlist(user removed friend or friend removed friend)
{
std::string username = vdata.get_string(false);
const std::string username = vdata.get_string(false);
if (vdata.is_error())
{
rpcn_log.error("Error parsing FriendLost notification");
break;
}

friend_infos.requests_received.erase(username);
friend_infos.requests_sent.erase(username);
friend_infos.friends.erase(username);
call_callbacks(ntype, username, false);
break;
}
case NotificationType::FriendStatus: // Set status of friend to Offline or Online
{
bool online = !!vdata.get<u8>();
u64 timestamp = vdata.get<u64>();
std::string username = vdata.get_string(false);
const bool online = !!vdata.get<u8>();
const u64 timestamp = vdata.get<u64>();
const std::string username = vdata.get_string(false);
if (vdata.is_error())
{
rpcn_log.error("Error parsing FriendStatus notification");
Expand Down Expand Up @@ -2692,7 +2701,7 @@ namespace rpcn
}
case NotificationType::FriendPresenceChanged:
{
std::string npid = vdata.get_string(true);
const std::string username = vdata.get_string(true);
SceNpCommunicationId pr_com_id = vdata.get_com_id();
std::string pr_title = fmt::truncate(vdata.get_string(true), SCE_NP_BASIC_PRESENCE_TITLE_SIZE_MAX - 1);
std::string pr_status = fmt::truncate(vdata.get_string(true), SCE_NP_BASIC_PRESENCE_EXTENDED_STATUS_SIZE_MAX - 1);
Expand All @@ -2709,7 +2718,7 @@ namespace rpcn
break;
}

if (auto u = friend_infos.friends.find(npid); u != friend_infos.friends.end())
if (auto u = friend_infos.friends.find(username); u != friend_infos.friends.end())
{
u->second.pr_com_id = std::move(pr_com_id);
u->second.pr_title = std::move(pr_title);
Expand All @@ -2718,9 +2727,10 @@ namespace rpcn
u->second.pr_data = std::move(pr_data);

std::lock_guard lock(mutex_presence_updates);
presence_updates.insert_or_assign(std::move(npid), u->second);
presence_updates.insert_or_assign(username, u->second);
}

call_callbacks(ntype, username, false);
break;
}
default:
Expand Down
1 change: 1 addition & 0 deletions rpcs3/Emu/NP/rpcn_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ namespace rpcn
rpcn_state wait_for_authentified();
bool terminate_connection();

void get_friends(friend_data& friend_infos);
void get_friends_and_register_cb(friend_data& friend_infos, friend_cb_func cb_func, void* cb_param);
void register_friend_cb(friend_cb_func, void* cb_param);
void remove_friend_cb(friend_cb_func, void* cb_param);
Expand Down
Loading

0 comments on commit 0a57c45

Please sign in to comment.