Skip to content
This repository has been archived by the owner on Aug 26, 2020. It is now read-only.

Commit

Permalink
Red-by-last checking added to KOS checker.
Browse files Browse the repository at this point in the history
More-sane default font sizes.
  • Loading branch information
3vi1 committed Mar 11, 2017
1 parent f7b3896 commit a6e06e2
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 50 deletions.
5 changes: 5 additions & 0 deletions docs/RELEASES
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
0.7.0 - Added red-by-last KOS checking.

Changed default font sizes to be not customized for my weird 150% in a VM on a
4k screen size.

0.6.3 - Add the ability to kos-check people by right-click/Copy of links pasted into
chat.

Expand Down
207 changes: 186 additions & 21 deletions src/asyncinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,29 +44,40 @@ void AsyncInfo::cacheAvatar(const QString& name)
pilot = new PilotEntry;
pilot->name = name;

requestId(name, SLOT(idRetrieved()));

// Request the Pilot ID
// Resumes asynchronously in idRetrieved()
}

void AsyncInfo::requestId(const QString &name, const char* slot)
{
qDebug() << "AsyncInfo::requestId() - " << name;

// Request the Pilot ID
QUrl url("https://api.eveonline.com/eve/CharacterID.xml.aspx");
QUrlQuery query;
query.addQueryItem("names", pilot->name);
query.addQueryItem("names", name);
url.setQuery(query);

//qDebug() << "AsyncInfo::requestId() - after query";

QNetworkRequest request(url);
request.setRawHeader("User-Agent", meta.agentString.toUtf8());
reply = manager->get(request);
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
QNetworkReply* idReply = manager->get(request);
connect(idReply, SIGNAL(finished()),
this, slot);
connect(idReply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(error(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(finished()),
this, SLOT(idRetrieved()));

// Resumes asynchronously in idRetrieved()
}

void AsyncInfo::idRetrieved()
{
QByteArray b = reply->readAll();
reply->deleteLater();
QNetworkReply* idReply = qobject_cast<QNetworkReply*>(sender());
if (!idReply)
return;

QByteArray b = idReply->readAll();
idReply->deleteLater();

QXmlQuery query;
query.setFocus(b);
Expand All @@ -81,19 +92,23 @@ void AsyncInfo::idRetrieved()
"_64.jpg");
QNetworkRequest request(imageUrl);
request.setRawHeader("User-Agent", meta.agentString.toUtf8());
reply = manager->get(request);
connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
QNetworkReply* pixmapReply = manager->get(request);
connect(pixmapReply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(error(QNetworkReply::NetworkError)));
connect(reply, SIGNAL(finished()),
connect(pixmapReply, SIGNAL(finished()),
this, SLOT(pixmapRetrieved()));

// Resumes Asynchronously in pixmapRetrieved()
}

void AsyncInfo::pixmapRetrieved()
{
QByteArray b = reply->readAll();
reply->deleteLater();
QNetworkReply *pixmapReply = qobject_cast<QNetworkReply*>(sender());
if (!pixmapReply)
return;

QByteArray b = pixmapReply->readAll();
pixmapReply->deleteLater();

pilot->avatar.loadFromData(b);

Expand All @@ -108,10 +123,18 @@ void AsyncInfo::error(QNetworkReply::NetworkError err)
{
// Manage error here.
qDebug() << "*** In AsyncInfo::error: " << err;
this->deleteLater();
//this->deleteLater();
}

void AsyncInfo::kosCheck(const QString &reqNames)
{
checkNames = reqNames;
kosCheck(reqNames, SLOT(gotKosCheckReply()));
}

void AsyncInfo::kosCheck(const QString &reqNames,
const char* slot,
QString queryType)
{
QString names = reqNames;
names.replace('\n',',');
Expand All @@ -120,25 +143,28 @@ void AsyncInfo::kosCheck(const QString &reqNames)
QUrl url("http://kos.cva-eve.org/api/");
QUrlQuery query;
query.addQueryItem("c", "json");
query.addQueryItem("type", "multi");
query.addQueryItem("type", queryType);
query.addQueryItem("q", names);
url.setQuery(query);

qDebug() << "Query = " << url.query();

QNetworkRequest request(url);
request.setRawHeader("User-Agent", meta.agentString.toUtf8());
kosReply = manager->get(request);
/*connect(kosReply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(error(QNetworkReply::NetworkError)));*/
connect(kosReply, SIGNAL(finished()),
this, SLOT(kosCheckReply()));
this, slot);

}

void AsyncInfo::kosCheckReply()
void AsyncInfo::gotKosCheckReply()
{
QByteArray b = kosReply->readAll();
kosReply->deleteLater();

qDebug() << "kosCheckReply = " << b;
qDebug() << "gotKosCheckReply = " << b;

QList<KosEntry> entries;
QJsonDocument jsonResponse = QJsonDocument::fromJson(b);
Expand Down Expand Up @@ -174,6 +200,145 @@ void AsyncInfo::kosCheckReply()
entries.append(KosEntry);
}

emit kosResultReady(entries);
emit kosResultReady(checkNames, entries);
this->deleteLater();
}

void AsyncInfo::rblCheck(const QString& name, int id)
{
checkNames = name;

if(id == 0)
{
// We don't have the person's ID, so we need to get it.
requestId(name, SLOT(rblIdRetrieved()));
}
else
{
rblCheck(id);
}
}

void AsyncInfo::rblCheck(int id)
{
qDebug() << "AsyncInfo::rblCheck() - " << id;

// Request the Character Information
QUrl url("https://api.eveonline.com/eve/CharacterInfo.xml.aspx");
QUrlQuery query;
query.addQueryItem("characterID", QString::number(id));
url.setQuery(query);

QNetworkRequest request(url);
request.setRawHeader("User-Agent", meta.agentString.toUtf8());
QNetworkReply* infoReply = manager->get(request);
connect(infoReply, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(error(QNetworkReply::NetworkError)));
connect(infoReply, SIGNAL(finished()),
this, SLOT(rblInfoRetrieved()));
}

void AsyncInfo::rblIdRetrieved()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
if (!reply)
return;

QByteArray b = reply->readAll();
reply->deleteLater();

QXmlQuery query;
query.setFocus(b);
query.setQuery("//*:row/@characterID/string()");
QString results;
query.evaluateTo(&results);

int id = results.toInt();

rblCheck(id);
}

void AsyncInfo::rblInfoRetrieved()
{
qDebug() << "AsyncInfo::rblInfoRetrieved() - Entered...";

QNetworkReply* infoReply = qobject_cast<QNetworkReply*>(sender());
if (!infoReply)
return;

QByteArray b = infoReply->readAll();
infoReply->deleteLater();

qDebug() << "AsyncInfo::rblInfoRetrieved() - " << b;

if(b.length() > 0)
{
QXmlQuery query;
query.setFocus(b);
/* query.setQuery("//[REMOVE_ME]*:characterName/string()");
QString name;
query.evaluateTo(&name);
name = name.trimmed();
*/
query.setQuery("//*:row/concat(@corporationID,',',@corporationName/string())");
QStringList results;
query.evaluateTo(&results);

foreach(QString result, results)
{
QStringList entry = result.split(',');
if(entry[0].toInt() > 2000000)
{
// Found last NPC corp
//entry[1].replace(' ','+');
kosCheck(entry[1], SLOT(gotKosCheckCorpReply()), "corp");
return;
}
}
}

emit rblResultReady(checkNames, false);
this->deleteLater();
}

void AsyncInfo::gotKosCheckCorpReply()
{
QNetworkReply* rblReply = qobject_cast<QNetworkReply*>(sender());
if (!rblReply)
return;

QByteArray b = rblReply->readAll();
rblReply->deleteLater();

qDebug() << "AsyncInfo::gotKosCheckCorpReply - b = " << b;

QJsonDocument jsonResponse = QJsonDocument::fromJson(b);
QJsonObject jsonObject = jsonResponse.object();
QJsonArray jsonArray = jsonObject["results"].toArray();

KosEntry kosEntry;
foreach (const QJsonValue& value, jsonArray) {
QJsonObject obj = value.toObject();

// Most of these are unused right now, but I've got plans

kosEntry.corp.eveId = obj["eveid"].toInt();
kosEntry.corp.icon = obj["icon"].toString();
kosEntry.corp.id = obj["id"].toInt();
kosEntry.corp.kos = obj["kos"].toBool();
kosEntry.corp.name = obj["label"].toString();
kosEntry.corp.npc = obj["npc"].toBool();
kosEntry.corp.ticker = obj["ticker"].toString();

QJsonObject allianceObj = obj["alliance"].toObject();
kosEntry.alliance.eveId = allianceObj["eveid"].toInt();
kosEntry.alliance.icon = allianceObj["icon"].toString();
kosEntry.alliance.id = allianceObj["id"].toInt();
kosEntry.alliance.kos = allianceObj["kos"].toBool();
kosEntry.alliance.name = allianceObj["label"].toString();
kosEntry.alliance.ticker = allianceObj["ticker"].toString();
}

emit rblResultReady(checkNames, kosEntry.corp.kos | kosEntry.alliance.kos);
this->deleteLater();
}
21 changes: 18 additions & 3 deletions src/asyncinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,23 @@ struct PilotEntry
QString name;
int id;
QPixmap avatar;
//QVector<QPair<int,QString>> employmentHistory;
QDateTime cacheUntil;

friend QDataStream &operator<<(QDataStream &out, const PilotEntry& pilotEntry)
{
out << pilotEntry.name << pilotEntry.id <<
pilotEntry.avatar << pilotEntry.cacheUntil;
//pilotEntry.avatar << pilotEntry.employmentHistory << pilotEntry.cacheUntil;
return out;
}

friend QDataStream &operator>>(QDataStream &in, PilotEntry& pilotEntry)
{
in >> pilotEntry.name >> pilotEntry.id >>
pilotEntry.avatar >> pilotEntry.cacheUntil;
//pilotEntry.avatar >> pilotEntry.employmentHistory >>
pilotEntry.avatar >>
pilotEntry.cacheUntil;
return in;
}
};
Expand Down Expand Up @@ -98,22 +102,33 @@ class AsyncInfo : public QObject

void cacheAvatar(const QString& name);
void kosCheck(const QString& names);
void rblCheck(int id);
void rblCheck(const QString& name, int id = 0);

signals:
void resultReady(PilotEntry* pilotEntry);
void kosResultReady(const QList<KosEntry>& entries);
void kosResultReady(const QString& name, const QList<KosEntry>& entries);
void rblResultReady(const QString& name, bool kos);


public slots:
void idRetrieved();
void rblIdRetrieved();
void rblInfoRetrieved();
void pixmapRetrieved();
void error(QNetworkReply::NetworkError err);
void kosCheckReply();
void gotKosCheckReply();
void gotKosCheckCorpReply();

private:
QNetworkAccessManager* manager;
QNetworkReply* reply;
QNetworkReply* kosReply;

QString checkNames = "";

void requestId(const QString& name, const char* slot);
void kosCheck(const QString &reqNames, const char* slot, QString queryType = "unit");
};

#endif // ASYNCINFO_H
2 changes: 1 addition & 1 deletion src/imp.pro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = imp
TEMPLATE = app

VERSION = 0.6.3
VERSION = 0.7.0
QMAKE_TARGET_COMPANY = EternalDusk
QMAKE_TARGET_DESCRIPTION = Eve Online Intelligence Management Program
QMAKE_TARGET_COPYRIGHT = (c) Copyright 2016-2017 Jesse Litton
Expand Down
Loading

0 comments on commit a6e06e2

Please sign in to comment.