QString ConnectionManager::GetResponse(void) const { QByteArray byteArray; byteArray = tcpSocket->readAll(); QString responseStr(byteArray); return responseStr; }
void ConnectionManager::HandleBannerData(int respType) { QString responseStr(GetResponse()); if(respType == EContinue) dataResponseStr += responseStr; else dataResponseStr = responseStr; { Parser bannerTokenRecognize(dataResponseStr, BANNER_TOKEN_SEP); int bannerToken = bannerTokenRecognize.GetResponseValue(Parser::ELeft).toInt(); if(bannerToken != BANNER_DATA) return; } Parser bannerRecognize(dataResponseStr); if(bannerRecognize.GetKeyValue(STATUS_KEY) != SUCCESS_VAL) { //handle an error here qWarning(ERROR_WARNING); return; } int type = EUnknown; QString dataStr = NULL; QString typeStr (bannerRecognize.GetKeyValue(TYPE_KEY)); if(bannerRecognize.IsCompleteDataReceived()) { if(typeStr != NULL) { type = typeStr.toInt(); if (type == EText) dataStr = bannerRecognize.GetKeyValue(TEXT_KEY); if (type == EImage) dataStr = bannerRecognize.GetKeyValue(CONTENT_BASE64_KEY); } actionCounter = ERedirect; } else type = EContinue; DisplayBanner(type, dataStr); }
void ConnectionManager::Redirection(void) { QString responseStr(GetResponse()); Parser result(responseStr); if(result.GetKeyValue(RESULT_KEY) == ERROR_VAL) { //handle an error here qWarning(ERROR_WARNING); return; } QString server(result.GetKeyValue(SERVER_KEY)); int port = result.GetKeyValue(PORT_KEY).toInt(); ++actionCounter; SetupConnection(server, port); }
void LoginTask::processNetReply(QNetworkReply *reply) { if(netReply != reply) return; // Check for errors. switch (reply->error()) { case QNetworkReply::NoError: { // Check the response code. int responseCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (responseCode == 200) { QString responseStr(reply->readAll()); QStringList strings = responseStr.split(":"); if (strings.count() >= 4) { bool parseSuccess; qint64 latestVersion = strings[0].toLongLong(&parseSuccess); if (parseSuccess) { // strings[1] is the download ticket. It isn't used anymore. QString username = strings[2]; QString sessionID = strings[3]; result = {username, sessionID, latestVersion}; emitSucceeded(); } else { emitFailed("Failed to parse Minecraft version string."); } } else { if (responseStr.toLower() == "bad login") emitFailed("Invalid username or password."); else if (responseStr.toLower() == "old version") emitFailed("Launcher outdated, please update."); else emitFailed("Login failed: " + responseStr); } } else if (responseCode == 503) { emitFailed("The login servers are currently unavailable. Check http://help.mojang.com/ for more info."); } else { emitFailed(QString("Login failed: Unknown HTTP error %1 occurred.").arg(QString::number(responseCode))); } break; } case QNetworkReply::OperationCanceledError: emitFailed("Login canceled."); break; default: emitFailed("Login failed: " + reply->errorString()); break; } }