Follow redirects and fix save loading by ptsave parameter
This commit is contained in:
parent
341e75cdfe
commit
296b758193
@ -1187,12 +1187,11 @@ RequestStatus Client::ExecVote(int saveID, int direction)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char * Client::GetSaveData(int saveID, int saveDate, int & dataLength)
|
std::vector<unsigned char> Client::GetSaveData(int saveID, int saveDate)
|
||||||
{
|
{
|
||||||
lastError = "";
|
lastError = "";
|
||||||
int dataStatus;
|
int dataStatus;
|
||||||
ByteString data;
|
ByteString data;
|
||||||
dataLength = 0;
|
|
||||||
ByteString urlStr;
|
ByteString urlStr;
|
||||||
if (saveDate)
|
if (saveDate)
|
||||||
urlStr = ByteString::Build(STATICSCHEME, STATICSERVER, "/", saveID, "_", saveDate, ".cps");
|
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);
|
ParseServerReturn(data, dataStatus, false);
|
||||||
if (data.size() && dataStatus == 200)
|
if (data.size() && dataStatus == 200)
|
||||||
{
|
{
|
||||||
unsigned char *data_out = (unsigned char *)malloc(data.size());
|
return std::vector<unsigned char>(data.begin(), data.end());
|
||||||
std::copy(data_out, data_out + data.size(), data.begin());
|
|
||||||
dataLength = (int)data.size();
|
|
||||||
return data_out;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return std::vector<unsigned char>();
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginStatus Client::Login(ByteString username, ByteString password, User & user)
|
LoginStatus Client::Login(ByteString username, ByteString password, User & user)
|
||||||
|
@ -144,7 +144,6 @@ public:
|
|||||||
|
|
||||||
RequestStatus AddComment(int saveID, String comment);
|
RequestStatus AddComment(int saveID, String comment);
|
||||||
|
|
||||||
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
|
||||||
std::vector<unsigned char> GetSaveData(int saveID, int saveDate);
|
std::vector<unsigned char> GetSaveData(int saveID, int saveDate);
|
||||||
|
|
||||||
LoginStatus Login(ByteString username, ByteString password, User & user);
|
LoginStatus Login(ByteString username, ByteString password, User & user);
|
||||||
|
@ -101,9 +101,12 @@ namespace http
|
|||||||
}
|
}
|
||||||
else
|
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_TIMEOUT, timeout);
|
||||||
curl_easy_setopt(easy, CURLOPT_HTTPHEADER, headers);
|
curl_easy_setopt(easy, CURLOPT_HTTPHEADER, headers);
|
||||||
curl_easy_setopt(easy, CURLOPT_URL, uri.c_str());
|
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_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_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 {
|
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;
|
Request *req = (Request *)userdata;
|
||||||
auto actual_size = size * count;
|
auto actual_size = size * count;
|
||||||
@ -296,6 +299,7 @@ namespace http
|
|||||||
case 608: return "Proxy Server Not Found";
|
case 608: return "Proxy Server Not Found";
|
||||||
case 609: return "SSL Failure";
|
case 609: return "SSL Failure";
|
||||||
case 610: return "Cancelled by Shutdown";
|
case 610: return "Cancelled by Shutdown";
|
||||||
|
case 611: return "Too Many Redirects";
|
||||||
default: return "Unknown Status Code";
|
default: return "Unknown Status Code";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,6 +119,7 @@ namespace http
|
|||||||
case CURLE_URL_MALFORMAT: finish_with = 606; break;
|
case CURLE_URL_MALFORMAT: finish_with = 606; break;
|
||||||
case CURLE_COULDNT_CONNECT: finish_with = 607; break;
|
case CURLE_COULDNT_CONNECT: finish_with = 607; break;
|
||||||
case CURLE_COULDNT_RESOLVE_PROXY: finish_with = 608; 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_CONNECT_ERROR:
|
||||||
case CURLE_SSL_ENGINE_NOTFOUND:
|
case CURLE_SSL_ENGINE_NOTFOUND:
|
||||||
|
Reference in New Issue
Block a user