-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRockstarStatus.cpp
70 lines (66 loc) · 2.4 KB
/
RockstarStatus.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "RockstarStatus.h"
RockstarStatus::RockstarStatus()
: QObject()
{
}
RockstarStatus::~RockstarStatus()
{
}
void RockstarStatus::doget()
{
QNetworkReply *rep = accessmanager.get(QNetworkRequest(QUrl("https://support.rockstargames.com/services/status.json?tz=Asia/Shanghai")));
if (rep->error() == QNetworkReply::NoError)
{
connect(&accessmanager, SIGNAL(finished(QNetworkReply*)), this, SLOT(on_get_finished(QNetworkReply*)));
}
else
{
emit reporterr(QString::fromWCharArray(L"Rockstar服务器状态获取失败!可能被墙了,请开梯子试试。"));
}
return;
}
void RockstarStatus::on_get_finished(QNetworkReply *rep)
{
QString result;
QString respstr = rep->readAll();
rep->deleteLater();
QJsonDocument respjson = QJsonDocument::fromJson(respstr.toUtf8().data());
if (respjson.isNull() || respjson.isEmpty())
{
emit reporterr(QString::fromWCharArray(L"Rockstar服务器状态获取失败!Rockstar服务器回传的信息格式错误。"));
}
else
{
result.append(QString::fromWCharArray(L"根据Rockstar官方通报,目前GTA Online各平台服务器状态如下:\n"));
QJsonObject obj = respjson.object();
QJsonArray statuses = obj.value("statuses").toArray();
QJsonArray::iterator i = statuses.begin();
while (i != statuses.end())
{
if ((*i).toObject().value("tag").toString() == "gtao")
{
QJsonArray platforms = (*i).toObject().value("services_platforms").toArray();
QJsonArray::iterator j = platforms.begin();
while (j != platforms.end())
{
QJsonObject platform = (*j).toObject();
int platformstatus = platform.value("service_status_id").toInt();
result.append(platform.value("name").toString());
result.append(QString::fromWCharArray(L"平台:"));
result.append(platformstatus == 1 ? QString::fromWCharArray(L"服务正常\n") : QString::fromWCharArray(L"服务不正常,内部错误代码为:%1\n").arg(platformstatus));
j++;
}
}
else if ((*i).toObject().value("tag").toString() == "sc")
{
int scstatus = (*i).toObject().value("services_platforms").toArray()[0].toObject().value("service_status_id").toInt();
result.append(QString::fromWCharArray(L"Rockstar Social Club 服务状态:"));
result.append(scstatus == 1 ? QString::fromWCharArray(L"服务正常") : QString::fromWCharArray(L"服务不正常,内部错误代码为:%1").arg(scstatus));
}
i++;
}
}
disconnect(&accessmanager, SIGNAL(finished(QNetworkReply*)), this, SLOT(on_get_finished(QNetworkReply*)));
emit finishget(result);
return;
}