From cf9ee07b8e31d3fa2e89a59357effe5002baaec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 9 Mar 2026 00:41:30 +0100 Subject: [PATCH] Adhoc: Forgot that we have to load the server list in-game to check the connection mode --- Core/HLE/sceNetAdhoc.cpp | 26 ++++++++++++++++++++++---- Core/HLE/sceNetAdhoc.h | 4 ++-- UI/PauseScreen.cpp | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Core/HLE/sceNetAdhoc.cpp b/Core/HLE/sceNetAdhoc.cpp index dc2fe0e7f7..04c8d648e2 100644 --- a/Core/HLE/sceNetAdhoc.cpp +++ b/Core/HLE/sceNetAdhoc.cpp @@ -95,6 +95,7 @@ std::chrono::time_point relayLastFailure; bool trackingRelayFailure = false; bool relayDisabled = false; bool relayFirstConnect = true; +bool g_serverListLoaded = false; int gameModeNotifyEvent = -1; @@ -174,9 +175,10 @@ static void LoadFallbackServerList() { return; } ParseServerListEntriesJSON(std::string_view((char*)jsonStr.get(), jsonSize)); + g_serverListLoaded = true; } -void AdhocLoadServerList() { +void AdhocLoadServerList(bool sync) { { std::lock_guard guard(g_proAdhocServerListMutex); if (!g_proAdhocServerList.empty()) { @@ -189,7 +191,7 @@ void AdhocLoadServerList() { if (startsWith(g_Config.sAdhocServerListUrl, "http")) { // Download the list. - g_DownloadManager.StartDownload(g_Config.sAdhocServerListUrl, Path(), http::RequestFlags::Cached24H, nullptr, "adhoc-servers", [url = g_Config.sAdhocServerListUrl](http::Request &request) { + auto dl = g_DownloadManager.StartDownload(g_Config.sAdhocServerListUrl, Path(), http::RequestFlags::Cached24H, nullptr, "adhoc-servers", [url = g_Config.sAdhocServerListUrl](http::Request &request) { if (request.Failed()) { ERROR_LOG(Log::sceNet, "Failed to download adhoc server list from %s, falling back.", url.c_str()); LoadFallbackServerList(); @@ -202,8 +204,18 @@ void AdhocLoadServerList() { request.buffer().TakeAll(&json); if (!ParseServerListEntriesJSON(std::string_view(json.data(), json.size()))) { LoadFallbackServerList(); + return; } }); + + if (sync) { + // Unfortunate. + do { + sleep_ms(10, "waiting-for-adhoc-server-list"); + g_DownloadManager.Update(); + } while (!dl->Done()); + } + g_serverListLoaded = true; } else if (!g_Config.sAdhocServerListUrl.empty()) { // Try to read local file. std::string json; @@ -221,13 +233,19 @@ void AdhocLoadServerList() { } } -std::vector AdhocGetServerList() { +std::vector AdhocGetServerList(bool sync) { + if (!g_serverListLoaded) { + // In-game - unfortunately we have to do a synchronous load here. + // If cached it will be fast though. + AdhocLoadServerList(sync); + } + std::lock_guard guard(g_proAdhocServerListMutex); return g_proAdhocServerList; } static AdhocDataMode AdhocGetServerDataMode(std::string_view server) { - std::vector list = AdhocGetServerList(); + std::vector list = AdhocGetServerList(true); for (const auto &item : list) { if (equals(server, item.host)) { INFO_LOG(Log::sceNet, "server %.*s is in known list, using data mode %s", STR_VIEW(server), AdhocDataModeToString(item.mode)); diff --git a/Core/HLE/sceNetAdhoc.h b/Core/HLE/sceNetAdhoc.h index 17b093bdbd..29a5178b59 100644 --- a/Core/HLE/sceNetAdhoc.h +++ b/Core/HLE/sceNetAdhoc.h @@ -114,8 +114,8 @@ struct AdhocServerListEntry { AdhocDataMode mode = AdhocDataMode::P2P; }; -void AdhocLoadServerList(); -std::vector AdhocGetServerList(); +void AdhocLoadServerList(bool sync = false); +std::vector AdhocGetServerList(bool sync = false); class PointerWrap; diff --git a/UI/PauseScreen.cpp b/UI/PauseScreen.cpp index be63b1d2de..1d737e0135 100644 --- a/UI/PauseScreen.cpp +++ b/UI/PauseScreen.cpp @@ -546,6 +546,7 @@ void GamePauseScreen::CreateViews() { if (NetAdhocctl_GetState() >= ADHOCCTL_STATE_CONNECTED) { // Awkwardly re-using a string here saveDataScrollItems->Add(new TextView(ApplySafeSubstitutions("%1: %2 (%3)", nw->T("AdHoc server"), nw->T("Connected"), g_Config.sProAdhocServer))); + // TODO: Add more metadata about the connected ad-hoc server here. } }