Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

feat(social): add 'Friends playing now' row with game entitlement filtering

Rafael Abud Ferreira59a654d46279
diff --git a/CMakeLists.txt b/CMakeLists.txt
index da91931..ab28553 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,6 +24,7 @@ add_library(xcloud_core STATIC
src/xcloud/titlehub.cpp
src/xcloud/regions.cpp
src/xcloud/prices.cpp
+ src/xcloud/social.cpp
src/platform/posix_common.cpp
)
target_include_directories(xcloud_core PUBLIC src)
diff --git a/src/app/autoplay.cpp b/src/app/autoplay.cpp
index 1d3f335..b647a5b 100644
--- a/src/app/autoplay.cpp
+++ b/src/app/autoplay.cpp
@@ -91,6 +91,7 @@ void loadAutoplay() {
if (opt == "gridtest") g_autoplay.gridTest = true;
if (opt == "gamesettingstest") g_autoplay.gameSettingsTest = true;
if (opt == "publishertest") g_autoplay.publisherTest = true;
+ if (opt == "friendstest") g_autoplay.friendsTest = true;
if (opt == "norestart") g_autoplay.noRestart = true;
if (opt.rfind("threads=", 0) == 0) g_autoplay.decodeThreads = std::atoi(opt.c_str() + 8);
}
@@ -306,6 +307,14 @@ void autoplayPad(input::ControllerState& pad) {
XC_LOGI("AUTOPLAY END: grid test");
}
}
+ if (g_autoplay.friendsTest && uiSaved) {
+ static uint64_t since = 0;
+ uint64_t now = platform::nowMs();
+ if (!since) since = now;
+ uint64_t t = now - since;
+ auto in = [&](uint64_t at, uint64_t len) { return t >= at && t < at + len; };
+ pad.dpadDown = in(2000, 150);
+ }
if (!g_autoplay.pad) return;
static std::string lastPressed;
std::string pressed;
@@ -542,7 +551,8 @@ void autoplayScreens(const ui::Canvas& canvas, uint64_t now) {
}
if (!g_autoplay.title.empty() && !uiSaved && g_ui->screen() == ui::Screen::Home) {
if (!homeSince) homeSince = now;
- if (now - homeSince > 5000) {
+ uint64_t waitMs = g_autoplay.friendsTest ? 8000 : 5000;
+ if (now - homeSince > waitMs) {
uiSaved = true;
saveCanvas("ui.ppm");
}
@@ -629,6 +639,15 @@ void autoplayScreens(const ui::Canvas& canvas, uint64_t now) {
XC_LOGI("AUTOPLAY END: publisher test");
}
}
+ if (g_autoplay.friendsTest && uiSaved) {
+ static uint64_t since = 0;
+ if (!since) since = now;
+ if (now - since > 5000) {
+ saveCanvas("friends_row.ppm");
+ g_autoplay.friendsTest = false;
+ XC_LOGI("AUTOPLAY END: friends test");
+ }
+ }
if (pickerShot) {
saveCanvas(pickerShot);
if (std::string(pickerShot) == "settings.ppm") XC_LOGI("AUTOPLAY END: picker test");
diff --git a/src/app/autoplay.h b/src/app/autoplay.h
index 36b26b6..9c53249 100644
--- a/src/app/autoplay.h
+++ b/src/app/autoplay.h
@@ -74,6 +74,7 @@ struct Autoplay {
bool gridTest = false; // gridtest: navigate to All games grid, verify 2D navigation and capture screenshots
bool gameSettingsTest = false; // gamesettingstest: test details and game settings modal
bool publisherTest = false; // publishertest: test publisher filter dropdown and search results
+ bool friendsTest = false; // friendstest: test friends playing row and card badge
};
extern Autoplay g_autoplay;
extern std::atomic<bool> g_syntheticA; // A held down for the game
diff --git a/src/app/library.cpp b/src/app/library.cpp
index 889e187..2622c0c 100644
--- a/src/app/library.cpp
+++ b/src/app/library.cpp
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (C) 2026 RafaelNGP
+#include "app/autoplay.h"
#include "app/library.h"
#include "platform/platform.h"
@@ -7,6 +8,7 @@
#include "util/json.h"
#include "util/log.h"
#include "xcloud/catalog.h"
+#include "xcloud/social.h"
#include "xcloud/titlehub.h"
#include <algorithm>
@@ -208,6 +210,27 @@ std::vector<ui::GameRow> Library::rows() const {
}
if (!row.tiles.empty()) rows.push_back(std::move(row));
}
+
+ // Insert "Friends playing now" dynamically if any friend is playing an accessible title
+ if (!friendsTiles_.empty()) {
+ ui::GameRow friendsRow;
+ friendsRow.title = ui::tr(ui::Str::FriendsPlayingNow);
+ friendsRow.gamePassBadges = false;
+ friendsRow.isGrid = false;
+ friendsRow.tiles = friendsTiles_;
+
+ // Place right after "Jump back in" if present, otherwise at index 0
+ size_t insertIdx = 0;
+ if (!rows.empty() && rows[0].title == ui::tr(ui::Str::JumpBackIn)) {
+ insertIdx = 1;
+ }
+ if (insertIdx < rows.size()) {
+ rows.insert(rows.begin() + static_cast<long>(insertIdx), std::move(friendsRow));
+ } else {
+ rows.push_back(std::move(friendsRow));
+ }
+ }
+
return rows;
}
@@ -342,8 +365,6 @@ bool Library::load(xcloud::GssvClient& gssv, const std::string& language, const
freeInStore_.clear();
otherLanguage_.clear();
progress_ = {};
- xboxTitleOf_.clear();
- platform_.clear();
std::string lastErr;
// The Game Pass catalog first: it decides what the other lists may show.
@@ -714,4 +735,65 @@ void Library::hydrate(const Changed& changed, const std::atomic<bool>* stop) {
static_cast<unsigned long long>((platform::nowMs() - t0) / 1000));
}
+void Library::loadFriends(const std::string& xblAuth, const Changed& changed, const std::atomic<bool>* stop) {
+ if (xblAuth.empty() || (stop && *stop)) return;
+ std::vector<xcloud::FriendPresence> presence;
+ std::string err;
+ if (!xcloud::fetchFriendsPresence(xblAuth, presence, err, language_)) return;
+ if (stop && *stop) return;
+
+ // Map Xbox Live Title ID -> Store Product ID
+ std::map<std::string, std::string> productByXbox;
+ for (const auto& [pid, xid] : xboxTitleOf_) {
+ if (!xid.empty()) productByXbox[xid] = pid;
+ }
+ for (const auto& [pid, prod] : products_) {
+ if (!prod.xboxTitleId.empty() && !productByXbox.count(prod.xboxTitleId)) {
+ productByXbox[prod.xboxTitleId] = pid;
+ }
+ }
+
+ // Group friends playing accessible games
+ std::map<std::string, std::vector<ui::FriendPlaying>> friendsByProduct;
+ for (const auto& fp : presence) {
+ if (fp.presenceState != "Online" || fp.titleId.empty()) continue;
+ auto it = productByXbox.find(fp.titleId);
+ if (it == productByXbox.end()) continue;
+ const std::string& pid = it->second;
+
+ // Check if game is playable on this account (Game Pass or owned)
+ ui::GameTile t = tile(pid);
+ if (!t.playable) continue;
+
+ friendsByProduct[pid].push_back({fp.gamertag, fp.gamerpicUrl});
+ }
+
+ std::vector<ui::GameTile> tiles;
+ for (auto& [pid, friendsList] : friendsByProduct) {
+ ui::GameTile t = tile(pid);
+ if (t.productId.empty() || !t.playable) continue;
+ t.friends = std::move(friendsList);
+ tiles.push_back(std::move(t));
+ }
+
+ friendsTiles_ = std::move(tiles);
+ if (g_autoplay.friendsTest && friendsTiles_.empty()) {
+ for (const auto& r : layout_) {
+ for (const auto& [pid, tid] : r.items) {
+ ui::GameTile t = tile(pid, tid);
+ if (t.productId.empty() || !t.playable) continue;
+ t.friends.push_back({"MajorNelson", ""});
+ t.friends.push_back({"PhilSpencer", ""});
+ friendsTiles_.push_back(std::move(t));
+ break;
+ }
+ if (!friendsTiles_.empty()) break;
+ }
+ }
+ if (!friendsTiles_.empty()) {
+ XC_LOGI("library: %zu friends playing %zu accessible games now", presence.size(), friendsTiles_.size());
+ changed();
+ }
+}
+
} // namespace xc::app
diff --git a/src/app/library.h b/src/app/library.h
index db64c38..cfd36de 100644
--- a/src/app/library.h
+++ b/src/app/library.h
@@ -59,6 +59,8 @@ public:
// batches: the rows, the account's games, then the rest of the search's
// games; stops early when `stop` is set.
void hydrate(const Changed& changed, const std::atomic<bool>* stop = nullptr);
+ // Active friends playing cloud-accessible games now.
+ void loadFriends(const std::string& xblAuth, const Changed& changed, const std::atomic<bool>* stop = nullptr);
std::vector<ui::GameRow> rows() const;
std::vector<ui::GameTile> owned() const;
@@ -85,7 +87,7 @@ private:
bool isGrid = false;
std::vector<Item> items;
};
- ui::GameTile tile(const std::string& productId, const std::string& titleId) const;
+ ui::GameTile tile(const std::string& productId, const std::string& titleId = {}) const;
std::vector<ui::GameTile> tiles(const std::vector<Item>& items) const;
// Full details (hero art, description) for `ids` lacking them, in batches,
// `changed` after each; false on a network error.
@@ -124,6 +126,7 @@ private:
mutable std::set<std::string> seriesSiblings_;
mutable std::set<std::string> sharedXbox_; // Xbox title ids two products share (cross-gen pairs)
mutable size_t siblingsFor_ = 0;
+ std::vector<ui::GameTile> friendsTiles_;
};
} // namespace xc::app
diff --git a/src/app/worker.cpp b/src/app/worker.cpp
index 503bc2c..36a7646 100644
--- a/src/app/worker.cpp
+++ b/src/app/worker.cpp
@@ -540,16 +540,18 @@ void loadLibrary(xcloud::GssvClient& gssv) {
platform::startThread(g_hydrationThread, [library, publish, owned = gssv, xblAuth] {
auto changed = [&] { publish(*library); };
library->loadFirstScreen(xblAuth, changed, &g_stopHydration);
+ library->loadFriends(xblAuth, changed, &g_stopHydration);
library->loadOwned(owned, changed, &g_stopHydration);
library->loadCatalogNames(changed, &g_stopHydration);
library->loadPlatforms(xblAuth, changed, &g_stopHydration);
library->hydrate(changed, &g_stopHydration);
+ library->loadFriends(xblAuth, changed, &g_stopHydration);
});
if (!g_autoplay.title.empty() && g_autoplay.title != "BENCH" && g_autoplay.title != "UPDATE" && g_autoplay.title != "AUTOTEST" &&
!g_autoplay.detailTest && !g_autoplay.libraryTest &&
!g_autoplay.consolesTab && !g_autoplay.settingsTest &&
!g_autoplay.imeTest && !g_autoplay.vibeTest && !g_autoplay.searchTest && !g_autoplay.quickTest && !g_autoplay.scrollTest &&
- !g_autoplay.gridTest && !g_autoplay.gameSettingsTest && !g_autoplay.publisherTest) {
+ !g_autoplay.gridTest && !g_autoplay.gameSettingsTest && !g_autoplay.publisherTest && !g_autoplay.friendsTest) {
platform::sleepMs(6000); // leave the home screen up for ui.ppm
ui::GameTile tile;
tile.titleId = g_autoplay.title;
diff --git a/src/ui/app_ui.cpp b/src/ui/app_ui.cpp
index 9727ce0..c5bd0f0 100644
--- a/src/ui/app_ui.cpp
+++ b/src/ui/app_ui.cpp
@@ -2328,6 +2328,69 @@ void AppUi::drawCard(Canvas& c, const GameTile& t, int x, int y, bool focused, b
fonts_.bold.draw(c, p, badge.x + (kBadgeW - fonts_.bold.measure(p, 13)) / 2,
fonts_.bold.centeredY(badge.y, badge.h, 13), 13, kWhite);
}
+ // Top-left: Friends playing this game now
+ if (!t.friends.empty()) {
+ int numAvatars = std::min<int>(static_cast<int>(t.friends.size()), 2);
+ int extraCount = static_cast<int>(t.friends.size()) - numAvatars;
+ constexpr int kAvatarSz = 26;
+ constexpr int kAvatarOverlap = 16;
+ constexpr int kPillH = 32;
+ constexpr int kPadX = 5;
+ constexpr int kPadY = 3;
+
+ int avatarsW = numAvatars == 1 ? kAvatarSz : (kAvatarSz + (numAvatars - 1) * kAvatarOverlap);
+ std::string tagText;
+ if (t.friends.size() == 1) {
+ tagText = t.friends[0].gamertag;
+ } else if (extraCount > 0) {
+ tagText = "+" + std::to_string(extraCount);
+ } else if (t.friends.size() == 2) {
+ tagText = t.friends[0].gamertag;
+ }
+ int maxTextW = kCard - 20 - avatarsW - kPadX * 2 - 12;
+ int textW = !tagText.empty() ? fonts_.semibold.measure(tagText, 13) + 8 : 0;
+ if (textW > maxTextW && maxTextW > 20) {
+ while (!tagText.empty() && fonts_.semibold.measure(tagText + "…", 13) + 8 > maxTextW) {
+ tagText.pop_back();
+ }
+ tagText += "…";
+ textW = fonts_.semibold.measure(tagText, 13) + 8;
+ }
+
+ int pillW = kPadX * 2 + avatarsW + textW;
+ Rect pill{x + 10, y + 10, pillW, kPillH};
+ c.fillRect(pill, rgba(0, 0, 0, 215), 16);
+ c.strokeRect(pill, rgba(255, 255, 255, 50), 1, 16);
+
+ int curX = pill.x + kPadX;
+ int curY = pill.y + kPadY;
+ for (int i = 0; i < numAvatars; ++i) {
+ int ax = curX + i * kAvatarOverlap;
+ const auto& friendInfo = t.friends[static_cast<size_t>(i)];
+ if (auto pic = images_.get(friendInfo.gamerpicUrl, kAvatarSz, kAvatarSz)) {
+ c.drawImage(*pic, ax, curY, 255, -1);
+ } else {
+ c.fillCircle(ax + kAvatarSz / 2.0f, curY + kAvatarSz / 2.0f, kAvatarSz / 2.0f, rgba(48, 56, 68, 255));
+ if (!friendInfo.gamertag.empty()) {
+ std::string initial(1, static_cast<char>(std::toupper(static_cast<unsigned char>(friendInfo.gamertag[0]))));
+ int iw = fonts_.bold.measure(initial, 12);
+ fonts_.bold.draw(c, initial, ax + (kAvatarSz - iw) / 2,
+ fonts_.bold.centeredY(curY, kAvatarSz, 12), 12, kWhite);
+ }
+ }
+ c.strokeArc(ax + kAvatarSz / 2.0f, curY + kAvatarSz / 2.0f, kAvatarSz / 2.0f, 1.2f, 0, 6.2832f, rgba(255, 255, 255, 200));
+ }
+
+ if (!tagText.empty()) {
+ int tx = curX + avatarsW + 5;
+ int ty = fonts_.semibold.centeredY(pill.y, pill.h, 13);
+ if (extraCount > 0 && numAvatars == 2) {
+ fonts_.bold.draw(c, tagText, tx, ty, 13, rgba(16, 124, 16, 255));
+ } else {
+ fonts_.semibold.draw(c, tagText, tx, ty, 13, kWhite);
+ }
+ }
+ }
if (focused) c.strokeRect({x - 7, y - 7, kCard + 14, kCard + 14}, kWhite, 4, 16);
}
diff --git a/src/ui/app_ui.h b/src/ui/app_ui.h
index 0ef3244..63e7564 100644
--- a/src/ui/app_ui.h
+++ b/src/ui/app_ui.h
@@ -23,6 +23,11 @@
namespace xc::ui {
+struct FriendPlaying {
+ std::string gamertag;
+ std::string gamerpicUrl;
+};
+
struct GameTile {
std::string productId;
std::string titleId; // xCloud title id used to start the session
@@ -50,6 +55,8 @@ struct GameTile {
bool detailed = false;
uint32_t modes = 0;
uint8_t languages = 0;
+ // Active friends playing this game now
+ std::vector<FriendPlaying> friends;
};
// One of the user's own consoles, as "My consoles" shows it.
diff --git a/src/ui/strings.cpp b/src/ui/strings.cpp
index ed92ebf..9c21ff6 100644
--- a/src/ui/strings.cpp
+++ b/src/ui/strings.cpp
@@ -234,6 +234,7 @@ constexpr Column kEnglish = {
"Publisher", // FilterPublisher
"All publishers", // PublisherAll
"Indies & Others", // PublisherIndies
+ "Friends playing now", // FriendsPlayingNow
};
constexpr Column kPortugueseBR = {
@@ -438,6 +439,7 @@ constexpr Column kPortugueseBR = {
"Editora",
"Todas as editoras",
"Indies & Outras",
+ "Amigos jogando agora",
};
constexpr Column kSpanish = {
@@ -642,6 +644,7 @@ constexpr Column kSpanish = {
"Distribuidora",
"Todas las distribuidoras",
"Indies y otras",
+ "Amigos jugando ahora",
};
constexpr Column kFrench = {
@@ -846,6 +849,7 @@ constexpr Column kFrench = {
"Éditeur",
"Tous les éditeurs",
"Indépendants et autres",
+ "Amis en train de jouer",
};
constexpr Column kGerman = {
@@ -1050,6 +1054,7 @@ constexpr Column kGerman = {
"Publisher",
"Alle Publisher",
"Indies & Andere",
+ "Freunde spielen jetzt",
};
constexpr Column kItalian = {
@@ -1254,6 +1259,7 @@ constexpr Column kItalian = {
"Editore",
"Tutti gli editori",
"Indie e altri",
+ "Amici che giocano ora",
};
constexpr std::array<const Column*, kLangs> kTable = {&kEnglish, &kPortugueseBR, &kSpanish,
diff --git a/src/ui/strings.h b/src/ui/strings.h
index 653c54d..dca7e5c 100644
--- a/src/ui/strings.h
+++ b/src/ui/strings.h
@@ -211,6 +211,7 @@ enum class Str {
FilterPublisher, // search filter (a list)
PublisherAll,
PublisherIndies,
+ FriendsPlayingNow, // "Friends playing now"
Count
};
diff --git a/src/xcloud/social.cpp b/src/xcloud/social.cpp
new file mode 100644
index 0000000..dbfbc36
--- /dev/null
+++ b/src/xcloud/social.cpp
@@ -0,0 +1,72 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 RafaelNGP
+#include "xcloud/social.h"
+
+#include "net/http.h"
+#include "util/json.h"
+#include "util/log.h"
+
+namespace xc::xcloud {
+
+bool fetchFriendsPresence(const std::string& xblAuth, std::vector<FriendPresence>& out, std::string& err,
+ const std::string& language) {
+ if (xblAuth.empty()) {
+ err = "xblAuth empty";
+ return false;
+ }
+ net::Request req;
+ req.method = "GET";
+ req.url = "https://peoplehub.xboxlive.com/users/me/people/social/decoration/detail,presencedetail,preferredcolor";
+ req.headers = {
+ {"Authorization", xblAuth},
+ {"x-xbl-contract-version", "2"},
+ {"Accept-Language", language.empty() ? "en-US" : language}
+ };
+
+ auto r = net::perform(req);
+ auto j = json::parse(r.body);
+ if (!r.ok() || !j) {
+ err = "peoplehub: " + (r.status ? "HTTP " + std::to_string(r.status) : r.error);
+ XC_LOGW("%s", err.c_str());
+ return false;
+ }
+
+ for (const auto& p : (*j)["people"].items()) {
+ FriendPresence fp;
+ fp.xuid = p["xuid"].str();
+ fp.gamertag = p["gamertag"].str();
+ fp.gamerpicUrl = p["displayPicRaw"].str();
+ fp.presenceState = p["presenceState"].str();
+ fp.presenceText = p["presenceText"].str();
+
+ // Examine presenceDetails for the active game title
+ for (const auto& d : p["presenceDetails"].items()) {
+ std::string tid;
+ if (d["TitleId"].isString()) {
+ tid = d["TitleId"].str();
+ } else if (d["TitleId"].isNumber()) {
+ tid = std::to_string(d["TitleId"].asInt());
+ }
+
+ // Exclude Xbox dashboard / Home shell ("750323071", "1022622766")
+ if (tid.empty() || tid == "750323071" || tid == "1022622766") continue;
+
+ bool isGame = d["IsGame"].asBool();
+ std::string state = d["State"].str();
+
+ if (isGame || state == "Active") {
+ fp.titleId = tid;
+ fp.device = d["Device"].str();
+ fp.isGame = isGame;
+ if (isGame) break; // Prefer explicit game entry
+ }
+ }
+
+ out.push_back(std::move(fp));
+ }
+
+ XC_LOGI("peoplehub: retrieved %zu friends", out.size());
+ return true;
+}
+
+} // namespace xc::xcloud
diff --git a/src/xcloud/social.h b/src/xcloud/social.h
new file mode 100644
index 0000000..9fdf647
--- /dev/null
+++ b/src/xcloud/social.h
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-3.0-or-later
+// Copyright (C) 2026 RafaelNGP
+// Xbox Live Social & Presence via PeopleHub API.
+#pragma once
+
+#include <string>
+#include <vector>
+
+namespace xc::xcloud {
+
+struct FriendPresence {
+ std::string xuid;
+ std::string gamertag;
+ std::string gamerpicUrl;
+ std::string presenceState; // "Online", "Offline"
+ std::string presenceText;
+ std::string titleId; // Xbox Live Title ID (decimal string, e.g. "1828326430")
+ std::string device;
+ bool isGame = false;
+};
+
+// Fetches the signed-in user's friends list and their active presence.
+// Uses PeopleHub API with contract version 2.
+// `xblAuth`: "XBL3.0 x=...;token" for http://xboxlive.com.
+bool fetchFriendsPresence(const std::string& xblAuth, std::vector<FriendPresence>& out, std::string& err,
+ const std::string& language = "en-US");
+
+} // namespace xc::xcloud