CrewID 0 can't be scanned, so don't even try it

This commit is contained in:
Rafael 2016-04-07 17:28:27 +02:00
parent d42d8b9900
commit b06706a895

View file

@ -72,69 +72,72 @@ void DatabaseThread::scanCrewMembersList(QStringList crewList, int maxPages, int
{ {
foreach (const QString &crewID, crewList) foreach (const QString &crewID, crewList)
{ {
if (crewID != "0")
int currentPage = 0;
int foundPlayers = 0;
int totalPlayers = 1000;
while(foundPlayers < totalPlayers && currentPage < maxPages)
{ {
QNetworkAccessManager *netManager = new QNetworkAccessManager(); int currentPage = 0;
int foundPlayers = 0;
int totalPlayers = 1000;
QString memberListUrl = "https://socialclub.rockstargames.com/crewsapi/GetMembersList?crewId=" + crewID + "&pageNumber=" + QString::number(currentPage); while(foundPlayers < totalPlayers && currentPage < maxPages)
QNetworkRequest netRequest(memberListUrl);
netRequest.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0 gta5sync/1.0");
netRequest.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
netRequest.setRawHeader("Accept-Language", "en-US;q=0.5,en;q=0.3");
netRequest.setRawHeader("Connection", "keep-alive");
QNetworkReply *netReply = netManager->get(netRequest);
QEventLoop downloadLoop;
QObject::connect(netReply, SIGNAL(finished()), &downloadLoop, SLOT(quit()));
QTimer::singleShot(30000, &downloadLoop, SLOT(quit()));
downloadLoop.exec();
if (netReply->isFinished())
{ {
QByteArray crewJson = netReply->readAll(); QNetworkAccessManager *netManager = new QNetworkAccessManager();
QJsonDocument crewDocument = QJsonDocument::fromJson(crewJson);
QJsonObject crewObject = crewDocument.object();
QVariantMap crewMap = crewObject.toVariantMap();
if (crewMap.contains("Total")) { totalPlayers = crewMap["Total"].toInt(); } QString memberListUrl = "https://socialclub.rockstargames.com/crewsapi/GetMembersList?crewId=" + crewID + "&pageNumber=" + QString::number(currentPage);
if (crewMap.contains("Members")) QNetworkRequest netRequest(memberListUrl);
netRequest.setRawHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Firefox/45.0 gta5sync/1.0");
netRequest.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
netRequest.setRawHeader("Accept-Language", "en-US;q=0.5,en;q=0.3");
netRequest.setRawHeader("Connection", "keep-alive");
QNetworkReply *netReply = netManager->get(netRequest);
QEventLoop downloadLoop;
QObject::connect(netReply, SIGNAL(finished()), &downloadLoop, SLOT(quit()));
QTimer::singleShot(30000, &downloadLoop, SLOT(quit()));
downloadLoop.exec();
if (netReply->isFinished())
{ {
QList<QVariant> memberList = crewMap["Members"].toList(); QByteArray crewJson = netReply->readAll();
foreach (const QVariant &memberVariant, memberList) qDebug() << crewJson;
QJsonDocument crewDocument = QJsonDocument::fromJson(crewJson);
QJsonObject crewObject = crewDocument.object();
QVariantMap crewMap = crewObject.toVariantMap();
if (crewMap.contains("Total")) { totalPlayers = crewMap["Total"].toInt(); }
if (crewMap.contains("Members"))
{ {
QMap<QString, QVariant> memberMap = memberVariant.toMap(); QList<QVariant> memberList = crewMap["Members"].toList();
foundPlayers++; foreach (const QVariant &memberVariant, memberList)
if (memberMap.contains("RockstarId") && memberMap.contains("Name"))
{ {
int RockstarId = memberMap["RockstarId"].toInt(); QMap<QString, QVariant> memberMap = memberVariant.toMap();
QString memberName = memberMap["Name"].toString(); foundPlayers++;
if (memberName != "" && RockstarId != 0) if (memberMap.contains("RockstarId") && memberMap.contains("Name"))
{ {
emit playerNameFound(RockstarId, memberName); int RockstarId = memberMap["RockstarId"].toInt();
QString memberName = memberMap["Name"].toString();
if (memberName != "" && RockstarId != 0)
{
emit playerNameFound(RockstarId, memberName);
}
} }
} }
} }
QEventLoop waitingLoop;
QTimer::singleShot(requestDelay, &waitingLoop, SLOT(quit()));
waitingLoop.exec();
currentPage++;
} }
QEventLoop waitingLoop; netReply->deleteLater();
QTimer::singleShot(requestDelay, &waitingLoop, SLOT(quit())); delete netReply;
waitingLoop.exec(); netManager->deleteLater();
delete netManager;
currentPage++;
} }
netReply->deleteLater();
delete netReply;
netManager->deleteLater();
delete netManager;
} }
} }
} }