* special function for the overlay Steam_Friends::get_friend_rich_presence_silent to avoid spamming the debug log

* refactor private method name
This commit is contained in:
otavepto 2024-05-06 21:29:59 +03:00
parent f660b29100
commit 6fbc37630b
3 changed files with 24 additions and 11 deletions

View File

@ -67,7 +67,7 @@ public ISteamFriends
void rich_presence_updated(CSteamID id, AppId_t appid); void rich_presence_updated(CSteamID id, AppId_t appid);
bool isAppIdCompatible(Friend *f); bool is_appid_compatible(Friend *f);
struct Avatar_Numbers add_friend_avatars(CSteamID id); struct Avatar_Numbers add_friend_avatars(CSteamID id);
@ -315,6 +315,9 @@ public:
void ClearRichPresence(); void ClearRichPresence();
// the overlay will keep calling GetFriendRichPresence() and spam the debug log, hence this function
const char *get_friend_rich_presence_silent( CSteamID steamIDFriend, const char *pchKey );
const char *GetFriendRichPresence( CSteamID steamIDFriend, const char *pchKey ); const char *GetFriendRichPresence( CSteamID steamIDFriend, const char *pchKey );
int GetFriendRichPresenceKeyCount( CSteamID steamIDFriend ); int GetFriendRichPresenceKeyCount( CSteamID steamIDFriend );

View File

@ -45,7 +45,7 @@ void Steam_Friends::rich_presence_updated(CSteamID id, AppId_t appid)
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
} }
bool Steam_Friends::isAppIdCompatible(Friend *f) bool Steam_Friends::is_appid_compatible(Friend *f)
{ {
if (settings->is_lobby_connect) return true; if (settings->is_lobby_connect) return true;
if (f == &us) return true; if (f == &us) return true;
@ -826,9 +826,9 @@ void Steam_Friends::ClearRichPresence()
} }
const char* Steam_Friends::GetFriendRichPresence( CSteamID steamIDFriend, const char *pchKey ) // the overlay will keep calling GetFriendRichPresence() and spam the debug log, hence this function
const char* Steam_Friends::get_friend_rich_presence_silent( CSteamID steamIDFriend, const char *pchKey )
{ {
PRINT_DEBUG("%llu '%s'", steamIDFriend.ConvertToUint64(), pchKey);
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
const char *value = ""; const char *value = "";
@ -839,11 +839,21 @@ const char* Steam_Friends::GetFriendRichPresence( CSteamID steamIDFriend, const
f = find_friend(steamIDFriend); f = find_friend(steamIDFriend);
} }
if (f && isAppIdCompatible(f)) { if (f && is_appid_compatible(f)) {
auto result = f->rich_presence().find(pchKey); auto result = f->rich_presence().find(pchKey);
if (result != f->rich_presence().end()) value = result->second.c_str(); if (result != f->rich_presence().end()) value = result->second.c_str();
} }
return value;
}
const char* Steam_Friends::GetFriendRichPresence( CSteamID steamIDFriend, const char *pchKey )
{
PRINT_DEBUG("%llu '%s'", steamIDFriend.ConvertToUint64(), pchKey);
std::lock_guard<std::recursive_mutex> lock(global_mutex);
const char *value = get_friend_rich_presence_silent(steamIDFriend, pchKey);
PRINT_DEBUG("returned '%s'", value); PRINT_DEBUG("returned '%s'", value);
return value; return value;
} }
@ -861,7 +871,7 @@ int Steam_Friends::GetFriendRichPresenceKeyCount( CSteamID steamIDFriend )
f = find_friend(steamIDFriend); f = find_friend(steamIDFriend);
} }
if (f && isAppIdCompatible(f)) num = f->rich_presence().size(); if (f && is_appid_compatible(f)) num = f->rich_presence().size();
return num; return num;
} }
@ -879,7 +889,7 @@ const char* Steam_Friends::GetFriendRichPresenceKeyByIndex( CSteamID steamIDFrie
f = find_friend(steamIDFriend); f = find_friend(steamIDFriend);
} }
if (f && isAppIdCompatible(f) && f->rich_presence().size() > iKey && iKey >= 0) { if (f && is_appid_compatible(f) && f->rich_presence().size() > iKey && iKey >= 0) {
auto friend_data = f->rich_presence().begin(); auto friend_data = f->rich_presence().begin();
for (int i = 0; i < iKey; ++i) ++friend_data; for (int i = 0; i < iKey; ++i) ++friend_data;
key = friend_data->first.c_str(); key = friend_data->first.c_str();
@ -1234,7 +1244,7 @@ void Steam_Friends::Callback(Common_Message *msg)
if (map1 != map2) { if (map1 != map2) {
//The App ID of the game. This should always be the current game. //The App ID of the game. This should always be the current game.
if (isAppIdCompatible(f)) { if (is_appid_compatible(f)) {
rich_presence_updated((uint64)msg->friend_().id(), (uint64)msg->friend_().appid()); rich_presence_updated((uint64)msg->friend_().id(), (uint64)msg->friend_().appid());
} }
} }

View File

@ -652,7 +652,7 @@ bool Steam_Overlay::is_friend_joinable(std::pair<const Friend, friend_window_sta
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
Steam_Friends* steamFriends = get_steam_client()->steam_friends; Steam_Friends* steamFriends = get_steam_client()->steam_friends;
if (std::string(steamFriends->GetFriendRichPresence((uint64)f.first.id(), "connect")).length() > 0 ) { if (std::string(steamFriends->get_friend_rich_presence_silent((uint64)f.first.id(), "connect")).length() > 0 ) {
PRINT_DEBUG("%" PRIu64 " true (connect string)", f.first.id()); PRINT_DEBUG("%" PRIu64 " true (connect string)", f.first.id());
return true; return true;
} }
@ -672,7 +672,7 @@ bool Steam_Overlay::got_lobby()
{ {
std::lock_guard<std::recursive_mutex> lock(global_mutex); std::lock_guard<std::recursive_mutex> lock(global_mutex);
Steam_Friends* steamFriends = get_steam_client()->steam_friends; Steam_Friends* steamFriends = get_steam_client()->steam_friends;
if (std::string(steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect")).length() > 0) if (std::string(steamFriends->get_friend_rich_presence_silent(settings->get_local_steam_id(), "connect")).length() > 0)
return true; return true;
if (settings->get_lobby().IsValid()) if (settings->get_lobby().IsValid())
@ -1152,7 +1152,7 @@ void Steam_Overlay::post_achievement_notification(Overlay_Achievement &ach)
void Steam_Overlay::invite_friend(uint64 friend_id, class Steam_Friends* steamFriends, class Steam_Matchmaking* steamMatchmaking) void Steam_Overlay::invite_friend(uint64 friend_id, class Steam_Friends* steamFriends, class Steam_Matchmaking* steamMatchmaking)
{ {
std::string connect_str = steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect"); std::string connect_str = steamFriends->get_friend_rich_presence_silent(settings->get_local_steam_id(), "connect");
if (connect_str.length() > 0) { if (connect_str.length() > 0) {
steamFriends->InviteUserToGame(friend_id, connect_str.c_str()); steamFriends->InviteUserToGame(friend_id, connect_str.c_str());
PRINT_DEBUG("sent game invitation to friend with id = %llu", friend_id); PRINT_DEBUG("sent game invitation to friend with id = %llu", friend_id);