crew scan feature improved
This commit is contained in:
parent
d28bf999ae
commit
e0f9d9b1a1
2 changed files with 87 additions and 43 deletions
|
@ -32,21 +32,57 @@
|
|||
|
||||
DatabaseThread::DatabaseThread(CrewDatabase *crewDB, QObject *parent) : QThread(parent), crewDB(crewDB)
|
||||
{
|
||||
crewMaxPages = 83;
|
||||
}
|
||||
|
||||
void DatabaseThread::run()
|
||||
{
|
||||
QNetworkAccessManager *netManager = new QNetworkAccessManager();
|
||||
QEventLoop threadLoop;
|
||||
dbtBegin:
|
||||
|
||||
QStringList crewList = crewDB->getCrews();
|
||||
|
||||
// Quick time scan
|
||||
if (crewList.length() <= 3)
|
||||
{
|
||||
scanCrewMembersList(crewList, 3, 0);
|
||||
emit playerNameUpdated();
|
||||
}
|
||||
else if (crewList.length() <= 5)
|
||||
{
|
||||
scanCrewMembersList(crewList, 2, 0);
|
||||
emit playerNameUpdated();
|
||||
}
|
||||
|
||||
QEventLoop waitingLoop;
|
||||
QTimer::singleShot(5000, &waitingLoop, SLOT(quit()));
|
||||
waitingLoop.exec();
|
||||
|
||||
// Long time scan
|
||||
scanCrewMembersList(crewList, crewMaxPages, 10000);
|
||||
emit playerNameUpdated();
|
||||
|
||||
QTimer::singleShot(300000, &threadLoop, SLOT(quit()));
|
||||
threadLoop.exec();
|
||||
goto dbtBegin;
|
||||
}
|
||||
|
||||
void DatabaseThread::scanCrewMembersList(QStringList crewList, int maxPages, int requestDelay)
|
||||
{
|
||||
foreach (const QString &crewID, crewList)
|
||||
{
|
||||
QString memberListUrl = "http://socialclub.rockstargames.com/crewsapi/GetMembersList?crewId=" + crewID;
|
||||
|
||||
int currentPage = 0;
|
||||
int foundPlayers = 0;
|
||||
int totalPlayers = 1000;
|
||||
|
||||
while(foundPlayers < totalPlayers && currentPage < maxPages)
|
||||
{
|
||||
QNetworkAccessManager *netManager = new QNetworkAccessManager();
|
||||
|
||||
QString memberListUrl = "http://socialclub.rockstargames.com/crewsapi/GetMembersList?crewId=" + crewID + "&pageNumber=" + QString::number(currentPage);
|
||||
|
||||
QNetworkRequest netRequest(memberListUrl);
|
||||
netRequest.setRawHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0 gta5sync/1.0");
|
||||
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");
|
||||
|
@ -64,12 +100,16 @@ void DatabaseThread::run()
|
|||
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"))
|
||||
{
|
||||
QList<QVariant> memberList = crewMap["Members"].toList();
|
||||
foreach (const QVariant &memberVariant, memberList)
|
||||
{
|
||||
QMap<QString, QVariant> memberMap = memberVariant.toMap();
|
||||
foundPlayers++;
|
||||
if (memberMap.contains("RockstarId") && memberMap.contains("Name"))
|
||||
{
|
||||
int RockstarId = memberMap["RockstarId"].toInt();
|
||||
|
@ -81,12 +121,13 @@ void DatabaseThread::run()
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
emit playerNameUpdated();
|
||||
QEventLoop waitingLoop;
|
||||
QTimer::singleShot(requestDelay, &waitingLoop, SLOT(quit()));
|
||||
waitingLoop.exec();
|
||||
|
||||
QTimer::singleShot(300000, &threadLoop, SLOT(quit()));
|
||||
threadLoop.exec();
|
||||
goto dbtBegin;
|
||||
currentPage++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,9 @@ public:
|
|||
|
||||
private:
|
||||
CrewDatabase *crewDB;
|
||||
void scanCrewMembersList(QStringList crewList, int maxPages, int requestDelay);
|
||||
int crewMaxPages;
|
||||
int plyrPerReq;
|
||||
|
||||
protected:
|
||||
void run();
|
||||
|
|
Loading…
Reference in a new issue