Skip to content

Commit

Permalink
Only fetch MAD manifesto on server join (R2Northstar#751)
Browse files Browse the repository at this point in the history
Previously, the verified mods manifesto was fetched on game start without checking if the verified mod feature is enabled Squirrel-side; with this, the manifesto is only fetched when the user wants to download a mod (meaning they enabled the feature beforehand).
  • Loading branch information
Alystrasz authored and wolf109909 committed Jul 30, 2024
1 parent 1df1de1 commit 73d6bca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 16 additions & 1 deletion primedev/mods/autodownload/moddownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ size_t WriteToString(void* ptr, size_t size, size_t count, void* stream)

void ModDownloader::FetchModsListFromAPI()
{
modState.state = MANIFESTO_FETCHING;

std::thread requestThread(
[this]()
{
Expand All @@ -66,6 +68,9 @@ void ModDownloader::FetchModsListFromAPI()
rapidjson::Document verifiedModsJson;
std::string url = modsListUrl;

// Empty verified mods manifesto
verifiedMods = {};

curl_global_init(CURL_GLOBAL_ALL);
easyhandle = curl_easy_init();
std::string readBuffer;
Expand All @@ -78,7 +83,12 @@ void ModDownloader::FetchModsListFromAPI()
curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, WriteToString);
result = curl_easy_perform(easyhandle);
ScopeGuard cleanup([&] { curl_easy_cleanup(easyhandle); });
ScopeGuard cleanup(
[&]
{
curl_easy_cleanup(easyhandle);
modState.state = DOWNLOADING;
});

if (result == CURLcode::CURLE_OK)
{
Expand Down Expand Up @@ -643,7 +653,12 @@ void ModDownloader::DownloadMod(std::string modName, std::string modVersion)
ON_DLL_LOAD_RELIESON("engine.dll", ModDownloader, (ConCommand), (CModule module))
{
g_pModDownloader = new ModDownloader();
}

ADD_SQFUNC("void", NSFetchVerifiedModsManifesto, "", "", ScriptContext::SERVER | ScriptContext::CLIENT | ScriptContext::UI)
{
g_pModDownloader->FetchModsListFromAPI();
return SQRESULT_NULL;
}

ADD_SQFUNC(
Expand Down
2 changes: 2 additions & 0 deletions primedev/mods/autodownload/moddownloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class ModDownloader
{
// Indicate UI to not immediately return false
IDLE,
MANIFESTO_FETCHING,

// Normal installation process
DOWNLOADING,
CHECKSUMING,
Expand Down

0 comments on commit 73d6bca

Please sign in to comment.