diff --git a/src/DownloadManager.cpp b/src/DownloadManager.cpp index b4f5ac6528..f7cb49056b 100644 --- a/src/DownloadManager.cpp +++ b/src/DownloadManager.cpp @@ -1076,7 +1076,6 @@ DownloadManager::UploadScoreWithReplayDataFromDisk(string sk, if (hs->GetReplayType() == 2) { replayString += to_string(columns[i]) + ","; replayString += to_string(types[i]) + ","; - } replayString += to_string(rows[i]); replayString += "],"; @@ -1144,51 +1143,26 @@ DownloadManager::UploadScoreWithReplayDataFromDisk(string sk, } void // for online replay viewing accuracy -mina DownloadManager::UpdateOnlineScoreReplayData(string& sk, - function callback) + function callback) { if (!LoggedIn()) return; auto hs = SCOREMAN->GetScoresByKey().at(sk); CURL* curlHandle = initCURLHandle(true); - string url = serverURL.Get() + "/updatereplaydata"; + string url = serverURL.Get() + "/updatereplaydata/" + sk; curl_httppost* form = nullptr; curl_httppost* lastPtr = nullptr; SetCURLFormPostField( curlHandle, form, lastPtr, "scorekey", hs->GetScoreKey()); - string replayString; - vector offsets = hs->GetOffsetVector(); - vector columns = hs->GetTrackVector(); - vector types = hs->GetTapNoteTypeVector(); + string toSend = "["; auto& rows = hs->GetNoteRowVector(); - - if (!offsets.empty()) { - replayString = "["; - auto steps = SONGMAN->GetStepsByChartkey(hs->GetChartKey()); - if (steps == nullptr) - return; - vector timestamps = - steps->GetTimingData()->ConvertReplayNoteRowsToTimestamps( - rows, hs->GetMusicRate()); - for (size_t i = 0; i < offsets.size(); i++) { - replayString += "["; - replayString += to_string(timestamps[i]) + ","; - replayString += to_string(1000.f * offsets[i]) + ","; - if (hs->GetReplayType() == 2) { - replayString += to_string(columns[i]) + ","; - replayString += to_string(types[i]) + ","; - } - replayString += to_string(rows[i]); - replayString += "],"; - } - replayString = - replayString.substr(0, replayString.size() - 1); // remove "," - replayString += "]"; - hs->UnloadReplayData(); - } else - replayString = ""; - SetCURLFormPostField( - curlHandle, form, lastPtr, "replay_data", replayString); + for (auto& row : rows) { + toSend += to_string(row) + ","; + } + toSend = toSend.substr(0, toSend.size() - 1); // remove , + toSend += "]"; + SetCURLFormPostField(curlHandle, form, lastPtr, "replay", toSend); SetCURLPostToURL(curlHandle, url); curl_easy_setopt(curlHandle, CURLOPT_HTTPPOST, form); auto done = [this, hs, callback](HTTPRequest& req, CURLMsg*) { @@ -1198,45 +1172,41 @@ DownloadManager::UpdateOnlineScoreReplayData(string& sk, try { j = json::parse(req.result); bool delay = false; - try { - auto errors = j["errors"]; - for (auto error : errors) { - int status = error["status"]; - if (status == 22) { - delay = true; - DLMAN->StartSession( - DLMAN->sessionUser, - DLMAN->sessionPass, - [hs](bool logged) { - if (logged) { - DLMAN->UploadScoreWithReplayDataFromDisk( - hs->GetScoreKey()); - } - }); - } else if (status == 404 || status == 405 || - status == 406) { - hs->AddUploadedServer(serverURL.Get()); + if (j.find("errors") == j.end()) + hs->AddUploadedServer(serverURL.Get()); + else + try { + auto errors = j["errors"]; + for (auto error : errors) { + int status = error["status"]; + if (status == 22) { + delay = true; + DLMAN->StartSession( + DLMAN->sessionUser, + DLMAN->sessionPass, + [hs](bool logged) { + if (logged) { + DLMAN->UploadScoreWithReplayDataFromDisk( + hs->GetScoreKey()); + } + }); + } else if (status == 404 || status == 405 || + status == 406) { + hs->AddUploadedServer(serverURL.Get()); + } } + } catch (exception e) { } - } catch (exception e) { - } - if (!delay && j["data"]["type"] == "ssrResults") { - auto diffs = j["data"]["attributes"]["diff"]; - FOREACH_ENUM(Skillset, ss) - if (ss != Skill_Overall) - (DLMAN->sessionRatings)[ss] += - diffs.value(SkillsetToString(ss), 0.0); - (DLMAN->sessionRatings)[Skill_Overall] += - diffs.value("Rating", 0.0); - hs->AddUploadedServer(serverURL.Get()); - HTTPRunning = response_code; - } } catch (exception e) { } if (callback) callback(); }; - HTTPRequest* req = new HTTPRequest(curlHandle, done); + auto fail = [callback](HTTPRequest& req, CURLMsg*) { + if (callback) + callback(); + }; + HTTPRequest* req = new HTTPRequest(curlHandle, done, fail); SetCURLResultsString(curlHandle, &(req->result)); curl_multi_add_handle(mHTTPHandle, req->handle); HTTPRequests.push_back(req); @@ -1528,10 +1498,10 @@ DownloadManager::RequestReplayData(string scoreid, timestamps.emplace_back(note[0].get()); offsets.emplace_back(note[1].get() / 1000.f); - if (note.size() == 3) { // pre-0.6 with noterows + if (note.size() == 3) { // pre-0.6 with noterows rows.emplace_back(note[2].get()); } - if (note.size() > 3) { // 0.6 without noterows + if (note.size() > 3) { // 0.6 without noterows tracks.emplace_back(note[2].get()); types.emplace_back( static_cast(note[3].get())); @@ -1994,11 +1964,9 @@ UpdateReplayDataSequentially(deque toUpload) if (it != toUpload.end()) { toUpload.pop_front(); auto& hs = (*it); - DLMAN->UpdateOnlineScoreReplayData( - hs->GetScoreKey(), [hs, toUpload]() { - hs->AddUploadedServer(serverURL.Get()); - UpdateReplayDataSequentially(toUpload); - }); + DLMAN->UpdateOnlineScoreReplayData(hs->GetScoreKey(), [hs, toUpload]() { + UpdateReplayDataSequentially(toUpload); + }); } return; } @@ -2038,7 +2006,8 @@ uploadSequentially(deque toUpload) return; } bool -DownloadManager::UploadScores() // keeping in case we want to use this later -mina +DownloadManager::UploadScores() // keeping in case we want to use this later + // -mina { if (!LoggedIn()) return false; @@ -2049,7 +2018,8 @@ DownloadManager::UploadScores() // keeping in case we want to use this later -m auto ts = scorePtr->GetTopScore(); if ((ts == 1 || ts == 2) && !scorePtr->IsUploadedToServer(serverURL.Get())) { - if (scorePtr->HasReplayData()) // we should remove this check maybe -mina + if (scorePtr->HasReplayData()) // we should remove this check + // maybe -mina toUpload.emplace_back(scorePtr); } }