From c60268eb8eb0e2150d448f842d7d22bb1b5cba8f Mon Sep 17 00:00:00 2001 From: NSGolova Date: Sun, 7 Jul 2024 00:28:11 +0100 Subject: [PATCH] Version bump and fixed merge issues --- mod.json | 2 +- qpm.json | 6 +- src/Utils/PlaylistSynchronizer.cpp | 4 +- src/Utils/ReplayManager.cpp | 2 +- src/Utils/WebUtils.cpp | 89 ++++++++++++++++++++---------- 5 files changed, 67 insertions(+), 36 deletions(-) diff --git a/mod.json b/mod.json index be3920f..8ba2956 100644 --- a/mod.json +++ b/mod.json @@ -4,7 +4,7 @@ "id": "BeatLeader", "description": "beatleader.xyz | In-game leaderboards for custom and OST maps | Score replays | Clans, events, playlists and much more", "author": "NSGolova", - "version": "0.7.1", + "version": "0.8.1", "packageId": "com.beatgames.beatsaber", "packageVersion": "1.28.0_4124311467", "coverImage": "cover.png", diff --git a/qpm.json b/qpm.json index 6278df8..153cdc2 100644 --- a/qpm.json +++ b/qpm.json @@ -4,7 +4,7 @@ "info": { "name": "BeatLeader", "id": "BeatLeader", - "version": "0.7.1", + "version": "0.8.1", "url": null, "additionalData": { "overrideSoName": "libbl.so" @@ -47,7 +47,7 @@ }, { "id": "libcurl", - "versionRange": "*", + "versionRange": "=8.5.0", "additionalData": {} }, { @@ -67,7 +67,7 @@ }, { "id": "conditional-dependencies", - "versionRange": "*", + "versionRange": "=0.1.0", "additionalData": {} }, { diff --git a/src/Utils/PlaylistSynchronizer.cpp b/src/Utils/PlaylistSynchronizer.cpp index d6bd96f..fd0fbb4 100644 --- a/src/Utils/PlaylistSynchronizer.cpp +++ b/src/Utils/PlaylistSynchronizer.cpp @@ -101,8 +101,8 @@ void ActuallySyncPlaylist() { for (string playlist : parts) { DownloadPlaylist(WebUtils::API_URL + "playlist/" + playlist, playlist, true, [](auto songs) { - BSML::MainThreadScheduler::Schedule([] { - SongCore::API::Loading::RefreshLevelPacks(); + QuestUI::MainThreadScheduler::Schedule([] { + RuntimeSongLoader::API::RefreshPacks(true); }); }); } diff --git a/src/Utils/ReplayManager.cpp b/src/Utils/ReplayManager.cpp index 13ef45b..2e93570 100644 --- a/src/Utils/ReplayManager.cpp +++ b/src/Utils/ReplayManager.cpp @@ -57,7 +57,7 @@ void ReplayManager::TryPostReplay(string name, PlayEndData status, int tryIndex, WebUtils::PostFileAsync(WebUtils::API_URL + "replayoculus" + status.ToQueryString(), replayFile, (long)file_info.st_size, [name, tryIndex, finished, replayFile, replayPostStart, runCallback, status](long statusCode, string result, string headers) { fclose(replayFile); - if (statusCode >= 450 && tryIndex < 2) { + if ((statusCode >= 450 || statusCode < 200) && tryIndex < 2) { getLogger().info("%s", ("Retrying posting replay after " + to_string(statusCode) + " #" + to_string(tryIndex) + " " + std::string(result)).c_str()); if (statusCode == 100) { result = "Timed out"; diff --git a/src/Utils/WebUtils.cpp b/src/Utils/WebUtils.cpp index 97681ed..3fc65c3 100644 --- a/src/Utils/WebUtils.cpp +++ b/src/Utils/WebUtils.cpp @@ -2,6 +2,8 @@ #include "Utils/WebUtils.hpp" #include "Utils/ModConfig.hpp" +#include "UnityEngine/Application.hpp" + #include "libcurl/shared/curl.h" #include "libcurl/shared/easy.h" @@ -9,7 +11,7 @@ #include #define TIMEOUT 60 -#define USER_AGENT string(ID "/" VERSION " (BeatSaber/" + GameVersion + ") (Oculus)").c_str() + #define X_BSSB "X-BSSB: ✔" namespace WebUtils { @@ -17,6 +19,7 @@ namespace WebUtils { string API_URL = ""; string WEB_URL = ""; + string USER_AGENT = ""; void refresh_urls() { if (getModConfig().ServerType.GetValue() == "Test") { @@ -26,6 +29,7 @@ namespace WebUtils { API_URL = "https://api.beatleader.xyz/"; WEB_URL = "https://beatleader.xyz/"; } + USER_AGENT = "BeatLeader / " + modInfo.version + " (BeatSaber/" + (string)UnityEngine::Application::get_version() + ") (Oculus)"; } //https://stackoverflow.com/a/55660581 @@ -162,7 +166,7 @@ namespace WebUtils { long httpCode(0); curl_easy_setopt(curl, CURLOPT_WRITEDATA, reinterpret_cast(&val)); - curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); + curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT.c_str()); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); @@ -237,7 +241,7 @@ namespace WebUtils { long httpCode(0); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &val); - curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); + curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT.c_str()); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); @@ -245,11 +249,16 @@ namespace WebUtils { auto res = curl_easy_perform(curl); /* Check for errors */ if (res != CURLE_OK) { - getLogger().critical("curl_easy_perform() failed: %u: %s", res, curl_easy_strerror(res)); + long errorCode = static_cast(res); + string errorValue = curl_easy_strerror(res); + getLogger().critical("curl_easy_perform() failed: %u: %s", errorCode, errorValue.c_str()); + curl_easy_cleanup(curl); + finished(errorCode, errorValue); + } else { + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); + curl_easy_cleanup(curl); + finished(httpCode, val); } - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); - curl_easy_cleanup(curl); - finished(httpCode, val); } ); t.detach(); @@ -303,7 +312,7 @@ namespace WebUtils { if (val) { curl_easy_setopt(curl, CURLOPT_WRITEDATA, val); } - curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); + curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT.c_str()); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); @@ -311,7 +320,16 @@ namespace WebUtils { auto res = curl_easy_perform(curl); /* Check for errors */ if (res != CURLE_OK) { - getLogger().critical("curl_easy_perform() failed: %u: %s", res, curl_easy_strerror(res)); + long errorCode = static_cast(res); + string errorValue = curl_easy_strerror(res); + + getLogger().critical("curl_easy_perform() failed: %u: %s", errorCode, errorValue.c_str()); + if (val) { + fclose(val); + } + curl_easy_cleanup(curl); + finished(errorCode); + return; } curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); if (val) { @@ -368,7 +386,7 @@ namespace WebUtils { long httpCode(0); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &val); - curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); + curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT.c_str()); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); @@ -378,12 +396,16 @@ namespace WebUtils { CURLcode res = curl_easy_perform(curl); /* Check for errors */ if (res != CURLE_OK) { - getLogger().critical("curl_easy_perform() failed: %u: %s", res, curl_easy_strerror(res)); + long errorCode = static_cast(res); + string errorValue = curl_easy_strerror(res); + getLogger().critical("curl_easy_perform() failed: %u: %s", errorCode, errorValue.c_str()); + curl_easy_cleanup(curl); + finished(errorCode, errorValue); + } else { + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); + curl_easy_cleanup(curl); + finished(httpCode, val); } - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); - curl_easy_cleanup(curl); - //curl_mime_free(form); - finished(httpCode, val); } ); t.detach(); @@ -441,21 +463,26 @@ namespace WebUtils { long httpCode(0); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &val); - curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); + curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT.c_str()); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); CURLcode res = curl_easy_perform(curl); - /* Check for errors */ if (res != CURLE_OK) { - getLogger().critical("curl_easy_perform() failed: %u: %s", res, curl_easy_strerror(res)); + long errorCode = static_cast(res); + string errorValue = curl_easy_strerror(res); + getLogger().critical("curl_easy_perform() failed: %u: %s", errorCode, errorValue.c_str()); + curl_easy_cleanup(curl); + curl_formfree(formpost); + finished(errorCode, errorValue); + } else { + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); + curl_easy_cleanup(curl); + curl_formfree(formpost); + //curl_mime_free(form); + finished(httpCode, val); } - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); - curl_easy_cleanup(curl); - curl_formfree(formpost); - //curl_mime_free(form); - finished(httpCode, val); } ); t.detach(); @@ -538,7 +565,7 @@ namespace WebUtils { long httpCode(0); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &val); - curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT); + curl_easy_setopt(curl, CURLOPT_USERAGENT, USER_AGENT.c_str()); curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); @@ -556,12 +583,16 @@ namespace WebUtils { CURLcode res = curl_easy_perform(curl); /* Check for errors */ if (res != CURLE_OK) { - getLogger().critical("curl_easy_perform() failed: %u: %s", res, curl_easy_strerror(res)); + long errorCode = static_cast(res); + string errorValue = curl_easy_strerror(res); + getLogger().critical("curl_easy_perform() failed: %u: %s", errorCode, errorValue.c_str()); + curl_easy_cleanup(curl); + finished(errorCode, errorValue, ""); + } else { + curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); + curl_easy_cleanup(curl); + finished(httpCode, val, responseHeaders); } - curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode); - curl_easy_cleanup(curl); - //curl_mime_free(form); - finished(httpCode, val, responseHeaders); } ); t.detach();