Code:
void getBaseInfo(std::string& url)
{
net::HTTPRequest req("GET", Poco::URI(url).getPathEtc());
sess_.sendRequest(req);
net::HTTPResponse resp;
std::istream& resp_body_strm = sess_.receiveResponse(resp) >> std::noskipws;
std::string resp_body = std::string(std::istream_iterator<char>(resp_body_strm), std::istream_iterator<char>());
resp.getCookies(cookies_);
if (resp.has("Location"))
{
sess_.sendRequest(*makeRequest("GET", "/indexInternal.es?action=internalMapRevolution"));
net::HTTPResponse resp2;
resp_body = std::string(std::istream_iterator<char>(sess_.receiveResponse(resp2) >> std::noskipws), std::istream_iterator<char>());
}
if (!Util::getBetween(resp_body, std::string("ionID\": \""), std::string("\","), SID_))
{
error_ = true;
#ifdef _DEBUG
std::ofstream f("getBaseInfo.html", std::ios::binary);
f << resp_body;
#endif
return;
}
std::string uid_str;
if (!Util::getBetween(resp_body, std::string("erID\": \""), std::string("\","), uid_str))
{
error_ = true;
#ifdef _DEBUG
std::ofstream f("getBaseInfo.html", std::ios::binary);
f << resp_body;
#endif
return;
}
UID_ = UID(uid_str);
std::string mapid_str;
if (!Util::getBetween(resp_body, std::string("apID\": \""), std::string("\","), mapid_str))
{
error_ = true;
#ifdef _DEBUG
std::ofstream f("getBaseInfo.html", std::ios::binary);
f << resp_body;
#endif
return;
}
mapID_ = atoi(mapid_str.c_str());
std::string game_id;
if (!Util::getBetween(resp_body, "\"pid\": \"", "\",", game_id))
{
error_ = true;
#ifdef _DEBUG
std::ofstream f("getBaseInfo.html", std::ios::binary);
f << resp_body;
#endif
return;
}
gameID_ = atoi(game_id.c_str());
}
This is what I use to get needed information for the gameclient login. It takes the URL that you get for an active instance login.
To get this URL I do this:
Code:
bool Authenticate(const std::string& username, const std::string& pw)
{
std::string username_enc, pw_enc; // Encode username & pw
Poco::URI::encode(username, "=&+;", username_enc);
Poco::URI::encode(pw, "=&+;", pw_enc);
std::ostringstream req_body_content_strm; // prepare post body
req_body_content_strm << "loginForm_default_username=" << username_enc << "&loginForm_default_password=" << pw_enc << "&loginForm_default_login_submit=Login";
std::string req_body_content = req_body_content_strm.str();
net::HTTPRequest req("POST", "/?locale=en&aid=0"); // send request
req.setContentType("application/x-www-form-urlencoded");
req.setContentLength(req_body_content.length());
sess_.sendRequest(req) << req_body_content;
net::HTTPResponse resp; // receive response
std::istream& resp_body_strm = sess_.receiveResponse(resp);
resp_body_strm >> std::noskipws;
std::string resp_body = std::string(std::istream_iterator<char>(resp_body_strm), std::istream_iterator<char>());
if ((int)resp_body.find("serverSelection_ini ini_active", 0) < 1) // are we logged in?
{
/*std::ofstream f("login.html", std::ios::binary);
f << resp_body;*/
return false;
}
authenticated_ = true;
int off = 0; // parse response body
int found = 0;
while((found = resp_body.find("serverSelection_ini ini_active", off)) > 0)
{
off += found + 2;
std::string::size_type link_begin_pos = resp_body.find("target=\"", found) + 8;
std::string::size_type link_end_pos = resp_body.find("\" onclick=", link_begin_pos);
std::string link = resp_body.substr(link_begin_pos, link_end_pos - link_begin_pos);
std::string servername = link.substr(7, link.find(".", 0) - 7);
map_[servername] = link;
}
return true;
}
This is all C++ using the awesome Poco libraries.
This code is not worth copy pasting, to anyone who thinks of doing that, believe me. But you can see how it basically works.
Also note, that this worked a few days ago. I don't know if it still does with the new update.
Also note that this might not be secure in terms of banning. This is optimized to reduce traffic, not for security.
Hope it helps.