Skip to content
Permalink
Browse files

Follow redirects and fix save loading by ptsave parameter

  • Loading branch information...
LBPHacker authored and jacob1 committed Mar 15, 2019
1 parent 341e75c commit 296b758193f357059c48584c4f2e17c1fbbef286
Showing with 12 additions and 24 deletions.
  1. +3 −19 src/client/Client.cpp
  2. +0 −1 src/client/Client.h
  3. +8 −4 src/client/http/Request.cpp
  4. +1 −0 src/client/http/RequestManager.cpp
@@ -1187,12 +1187,11 @@ RequestStatus Client::ExecVote(int saveID, int direction)
return ret;
}

unsigned char * Client::GetSaveData(int saveID, int saveDate, int & dataLength)
std::vector<unsigned char> Client::GetSaveData(int saveID, int saveDate)
{
lastError = "";
int dataStatus;
ByteString data;
dataLength = 0;
ByteString urlStr;
if (saveDate)
urlStr = ByteString::Build(STATICSCHEME, STATICSERVER, "/", saveID, "_", saveDate, ".cps");
@@ -1205,24 +1204,9 @@ unsigned char * Client::GetSaveData(int saveID, int saveDate, int & dataLength)
ParseServerReturn(data, dataStatus, false);
if (data.size() && dataStatus == 200)
{
unsigned char *data_out = (unsigned char *)malloc(data.size());
std::copy(data_out, data_out + data.size(), data.begin());
dataLength = (int)data.size();
return data_out;
return std::vector<unsigned char>(data.begin(), data.end());
}
return NULL;
}

std::vector<unsigned char> Client::GetSaveData(int saveID, int saveDate)
{
int dataSize;
unsigned char * data = GetSaveData(saveID, saveDate, dataSize);
if (!data)
return std::vector<unsigned char>();

std::vector<unsigned char> saveData(data, data+dataSize);
delete[] data;
return saveData;
return std::vector<unsigned char>();
}

LoginStatus Client::Login(ByteString username, ByteString password, User & user)
@@ -144,7 +144,6 @@ class Client: public Singleton<Client> {

RequestStatus AddComment(int saveID, String comment);

unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
std::vector<unsigned char> GetSaveData(int saveID, int saveDate);

LoginStatus Login(ByteString username, ByteString password, User & user);
@@ -101,9 +101,12 @@ namespace http
}
else
{
curl_easy_setopt(easy, CURLOPT_HTTPGET, 1);
curl_easy_setopt(easy, CURLOPT_HTTPGET, 1L);
}

curl_easy_setopt(easy, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(easy, CURLOPT_MAXREDIRS, 10L);

curl_easy_setopt(easy, CURLOPT_TIMEOUT, timeout);
curl_easy_setopt(easy, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(easy, CURLOPT_URL, uri.c_str());
@@ -113,11 +116,11 @@ namespace http
curl_easy_setopt(easy, CURLOPT_PROXY, proxy.c_str());
}

curl_easy_setopt(easy, CURLOPT_PRIVATE, this);
curl_easy_setopt(easy, CURLOPT_PRIVATE, (void *)this);
curl_easy_setopt(easy, CURLOPT_USERAGENT, user_agent.c_str());
curl_easy_setopt(easy, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(easy, CURLOPT_NOSIGNAL, 1L);

curl_easy_setopt(easy, CURLOPT_WRITEDATA, this);
curl_easy_setopt(easy, CURLOPT_WRITEDATA, (void *)this);
curl_easy_setopt(easy, CURLOPT_WRITEFUNCTION, (size_t (*)(char *ptr, size_t size, size_t count, void *userdata))([](char *ptr, size_t size, size_t count, void *userdata) -> size_t {
Request *req = (Request *)userdata;
auto actual_size = size * count;
@@ -296,6 +299,7 @@ namespace http
case 608: return "Proxy Server Not Found";
case 609: return "SSL Failure";
case 610: return "Cancelled by Shutdown";
case 611: return "Too Many Redirects";
default: return "Unknown Status Code";
}
}
@@ -119,6 +119,7 @@ namespace http
case CURLE_URL_MALFORMAT: finish_with = 606; break;
case CURLE_COULDNT_CONNECT: finish_with = 607; break;
case CURLE_COULDNT_RESOLVE_PROXY: finish_with = 608; break;
case CURLE_TOO_MANY_REDIRECTS: finish_with = 611; break;

case CURLE_SSL_CONNECT_ERROR:
case CURLE_SSL_ENGINE_NOTFOUND:

0 comments on commit 296b758

Please sign in to comment.
You can’t perform that action at this time.