Skip to content

Commit

Permalink
remove replay update functions as they _should_ be obsolete now
Browse files Browse the repository at this point in the history
  • Loading branch information
MinaciousGrace committed Apr 17, 2020
1 parent c92460b commit 0f6081b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 122 deletions.
115 changes: 0 additions & 115 deletions src/Etterna/Singletons/DownloadManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1216,121 +1216,6 @@ DownloadManager::UploadScoreWithReplayDataFromDisk(const string& sk,
HTTPRequests.push_back(req);
return;
}

// only appends replaydata to an existing eo score without altering it
void
DownloadManager::UpdateOnlineScoreReplayData(const string& sk,
function<void()> callback)
{
if (!LoggedIn())
return;

auto* hs = SCOREMAN->GetScoresByKey().at(sk);
CURL* curlHandle = initCURLHandle(true);
string url = serverURL.Get() + "/updateReplayData";
curl_httppost* form = nullptr;
curl_httppost* lastPtr = nullptr;
SetCURLFormPostField(
curlHandle, form, lastPtr, "scorekey", hs->GetScoreKey());
string toSend = "[";
if (!hs->LoadReplayData())
return;
auto& rows = hs->GetNoteRowVector();
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*) {
long response_code;
curl_easy_getinfo(req.handle, CURLINFO_RESPONSE_CODE, &response_code);
Document d;
if (d.Parse(req.result.c_str()).HasParseError()) {
LOG->Trace(("Malformed request response: " + req.result).c_str());
return;
}
if (!d.HasMember("errors")) {
hs->AddUploadedServer(serverURL.Get());
} else {
auto onStatus = [hs](int status) {
if (status == 22) {
DLMAN->StartSession(
DLMAN->sessionUser,
DLMAN->sessionPass,
[hs](bool logged) {
if (logged) {
DLMAN->UpdateOnlineScoreReplayData(
hs->GetScoreKey());
}
});
} else if (status == 404 || status == 405 || status == 406) {
hs->AddUploadedServer(serverURL.Get());
}
};
if (d["errors"].IsArray()) {
for (auto& error : d["errors"].GetArray()) {
if (!error["status"].IsInt())
continue;
int status = error["status"].GetInt();
onStatus(status);
}
} else if (d["errors"].HasMember("status") &&
d["errors"]["status"].IsInt()) {
onStatus(d["errors"]["status"].GetInt());
}
}
if (callback)
callback();
};
auto fail = [callback](HTTPRequest& req, CURLMsg*) {
if (callback)
callback();
};
HTTPRequest* req = new HTTPRequest(curlHandle, done, form, fail);
SetCURLResultsString(curlHandle, &(req->result));
curl_multi_add_handle(mHTTPHandle, req->handle);
HTTPRequests.push_back(req);
LOG->Trace(("Updated EO replay data for" + hs->GetScoreKey()).c_str());
return;
}
void
UpdateReplayDataSequentially(deque<HighScore*> toUpload)
{
auto it = toUpload.begin();
if (it != toUpload.end()) {
toUpload.pop_front();
auto& hs = (*it);
DLMAN->UpdateOnlineScoreReplayData(hs->GetScoreKey(), [hs, toUpload]() {
hs->AddUploadedServer("nru");
UpdateReplayDataSequentially(toUpload);
});
}
return;
}
bool
DownloadManager::UpdateOnlineScoreReplayData()
{
if (!LoggedIn())
return false;
// we dont care if the chart is loaded for this function, only that there is
// a score that is already uploaded and already has replaydata, and that the
// source data is on disk to update it -mina
auto& scores = SCOREMAN->GetAllScores();
deque<HighScore*> toUpload;
for (auto& scorePtr : scores) {
auto ts = scorePtr->GetTopScore(); // still need to do this?
if ((ts == 1 || ts == 2)) {
if (scorePtr->HasReplayData() &&
scorePtr->IsUploadedToServer(serverURL.Get()) &&
!scorePtr->IsUploadedToServer("nru"))
toUpload.push_back(scorePtr);
}
}
UpdateReplayDataSequentially(toUpload);
return true;
}
void
uploadSequentially(deque<HighScore*> toUpload) // maybe this can set a progress
// bar for uploads? idk
Expand Down
9 changes: 2 additions & 7 deletions src/Etterna/Singletons/DownloadManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,8 @@ class DownloadManager
done); // Sends login request if not already logging in
void OnLogin();
bool UploadScores(); // Uploads all scores not yet uploaded to current
void ForceUploadScoresForChart(std::string ck); // forced upload wrapper for charts
void ForceUploadScoresForPack(std::string pack);// forced upload wrapper for packs
bool UpdateOnlineScoreReplayData(); // attempts updates existing replaydata
// server (Async, 1 request per score)
void ForceUploadScoresForChart(const std::string& ck, bool startnow); // forced upload wrapper for charts
void ForceUploadScoresForPack(const std::string& pack, bool startnow); // forced upload wrapper for packs
void RefreshPackList(const string& url);

void init();
Expand All @@ -251,9 +249,6 @@ class DownloadManager
void UploadScoreWithReplayDataFromDisk(
const string& sk,
function<void()> callback = function<void()>());
void UpdateOnlineScoreReplayData(
const string& sk,
function<void()> callback = function<void()>());
void UploadScore(HighScore* hs);

bool ShouldUploadScores();
Expand Down

0 comments on commit 0f6081b

Please sign in to comment.