Merge pull request #3185 from kb-1000/remove-status
GH-4157 Remove broken Mojang services status
This commit is contained in:
commit
0c798b8fc7
@ -82,7 +82,6 @@ public:
|
||||
QString RESOURCE_BASE = "https://resources.download.minecraft.net/";
|
||||
QString LIBRARY_BASE = "https://libraries.minecraft.net/";
|
||||
QString AUTH_BASE = "https://authserver.mojang.com/";
|
||||
QString MOJANG_STATUS_URL = "https://status.mojang.com/check";
|
||||
QString IMGUR_BASE_URL = "https://api.imgur.com/3/";
|
||||
QString FMLLIBS_BASE_URL = "https://files.multimc.org/fmllibs/";
|
||||
QString TRANSLATIONS_BASE_URL = "https://files.multimc.org/translations/";
|
||||
|
@ -193,13 +193,6 @@ set(ICONS_SOURCES
|
||||
icons/IconUtils.cpp
|
||||
)
|
||||
|
||||
# Minecraft services status checker
|
||||
set(STATUS_SOURCES
|
||||
# Status system
|
||||
status/StatusChecker.h
|
||||
status/StatusChecker.cpp
|
||||
)
|
||||
|
||||
# Support for Minecraft instances and launch
|
||||
set(MINECRAFT_SOURCES
|
||||
# Minecraft support
|
||||
@ -546,7 +539,6 @@ set(LOGIC_SOURCES
|
||||
${UPDATE_SOURCES}
|
||||
${NOTIFICATIONS_SOURCES}
|
||||
${NEWS_SOURCES}
|
||||
${STATUS_SOURCES}
|
||||
${MINECRAFT_SOURCES}
|
||||
${SCREENSHOTS_SOURCES}
|
||||
${TASKS_SOURCES}
|
||||
@ -796,8 +788,6 @@ SET(MULTIMC_SOURCES
|
||||
widgets/PageContainer.cpp
|
||||
widgets/PageContainer.h
|
||||
widgets/PageContainer_p.h
|
||||
widgets/ServerStatus.cpp
|
||||
widgets/ServerStatus.h
|
||||
widgets/VersionListView.cpp
|
||||
widgets/VersionListView.h
|
||||
widgets/VersionSelectWidget.cpp
|
||||
|
@ -73,7 +73,6 @@
|
||||
#include "groupview/GroupView.h"
|
||||
#include "groupview/InstanceDelegate.h"
|
||||
#include "widgets/LabeledToolButton.h"
|
||||
#include "widgets/ServerStatus.h"
|
||||
#include "dialogs/NewInstanceDialog.h"
|
||||
#include "dialogs/ProgressDialog.h"
|
||||
#include "dialogs/AboutDialog.h"
|
||||
@ -739,10 +738,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new MainWindow
|
||||
|
||||
m_statusLeft = new QLabel(tr("No instance selected"), this);
|
||||
m_statusCenter = new QLabel(tr("Total playtime: 0s."), this);
|
||||
m_statusRight = new ServerStatus(this);
|
||||
statusBar()->addPermanentWidget(m_statusLeft, 1);
|
||||
statusBar()->addPermanentWidget(m_statusCenter, 1);
|
||||
statusBar()->addPermanentWidget(m_statusRight, 0);
|
||||
|
||||
// Add "manage accounts" button, right align
|
||||
QWidget *spacer = new QWidget();
|
||||
|
@ -36,7 +36,6 @@ class QLabel;
|
||||
class MinecraftLauncher;
|
||||
class BaseProfilerFactory;
|
||||
class GroupView;
|
||||
class ServerStatus;
|
||||
class KonamiCode;
|
||||
class InstanceTask;
|
||||
|
||||
@ -207,7 +206,6 @@ private:
|
||||
QToolButton *newsLabel = nullptr;
|
||||
QLabel *m_statusLeft = nullptr;
|
||||
QLabel *m_statusCenter = nullptr;
|
||||
ServerStatus *m_statusRight = nullptr;
|
||||
QMenu *accountMenu = nullptr;
|
||||
QToolButton *accountMenuButton = nullptr;
|
||||
KonamiCode * secretEventFilter = nullptr;
|
||||
|
@ -1,148 +0,0 @@
|
||||
/* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "StatusChecker.h"
|
||||
|
||||
#include <QByteArray>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include <BuildConfig.h>
|
||||
|
||||
StatusChecker::StatusChecker()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void StatusChecker::timerEvent(QTimerEvent *e)
|
||||
{
|
||||
QObject::timerEvent(e);
|
||||
reloadStatus();
|
||||
}
|
||||
|
||||
void StatusChecker::reloadStatus()
|
||||
{
|
||||
if (isLoadingStatus())
|
||||
{
|
||||
// qDebug() << "Ignored request to reload status. Currently reloading already.";
|
||||
return;
|
||||
}
|
||||
|
||||
// qDebug() << "Reloading status.";
|
||||
|
||||
NetJob* job = new NetJob("Status JSON");
|
||||
job->addNetAction(Net::Download::makeByteArray(BuildConfig.MOJANG_STATUS_URL, &dataSink));
|
||||
QObject::connect(job, &NetJob::succeeded, this, &StatusChecker::statusDownloadFinished);
|
||||
QObject::connect(job, &NetJob::failed, this, &StatusChecker::statusDownloadFailed);
|
||||
m_statusNetJob.reset(job);
|
||||
emit statusLoading(true);
|
||||
job->start();
|
||||
}
|
||||
|
||||
void StatusChecker::statusDownloadFinished()
|
||||
{
|
||||
qDebug() << "Finished loading status JSON.";
|
||||
m_statusEntries.clear();
|
||||
m_statusNetJob.reset();
|
||||
|
||||
QJsonParseError jsonError;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(dataSink, &jsonError);
|
||||
|
||||
if (jsonError.error != QJsonParseError::NoError)
|
||||
{
|
||||
fail("Error parsing status JSON:" + jsonError.errorString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!jsonDoc.isArray())
|
||||
{
|
||||
fail("Error parsing status JSON: JSON root is not an array");
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonArray root = jsonDoc.array();
|
||||
|
||||
for(auto status = root.begin(); status != root.end(); ++status)
|
||||
{
|
||||
QVariantMap map = (*status).toObject().toVariantMap();
|
||||
|
||||
for (QVariantMap::const_iterator iter = map.begin(); iter != map.end(); ++iter)
|
||||
{
|
||||
QString key = iter.key();
|
||||
QVariant value = iter.value();
|
||||
|
||||
if(value.type() == QVariant::Type::String)
|
||||
{
|
||||
m_statusEntries.insert(key, value.toString());
|
||||
//qDebug() << "Status JSON object: " << key << m_statusEntries[key];
|
||||
}
|
||||
else
|
||||
{
|
||||
fail("Malformed status JSON: expected status type to be a string.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
succeed();
|
||||
}
|
||||
|
||||
void StatusChecker::statusDownloadFailed(QString reason)
|
||||
{
|
||||
fail(tr("Failed to load status JSON:\n%1").arg(reason));
|
||||
}
|
||||
|
||||
|
||||
QMap<QString, QString> StatusChecker::getStatusEntries() const
|
||||
{
|
||||
return m_statusEntries;
|
||||
}
|
||||
|
||||
bool StatusChecker::isLoadingStatus() const
|
||||
{
|
||||
return m_statusNetJob.get() != nullptr;
|
||||
}
|
||||
|
||||
QString StatusChecker::getLastLoadErrorMsg() const
|
||||
{
|
||||
return m_lastLoadError;
|
||||
}
|
||||
|
||||
void StatusChecker::succeed()
|
||||
{
|
||||
if(m_prevEntries != m_statusEntries)
|
||||
{
|
||||
emit statusChanged(m_statusEntries);
|
||||
m_prevEntries = m_statusEntries;
|
||||
}
|
||||
m_lastLoadError = "";
|
||||
qDebug() << "Status loading succeeded.";
|
||||
m_statusNetJob.reset();
|
||||
emit statusLoading(false);
|
||||
}
|
||||
|
||||
void StatusChecker::fail(const QString& errorMsg)
|
||||
{
|
||||
if(m_prevEntries != m_statusEntries)
|
||||
{
|
||||
emit statusChanged(m_statusEntries);
|
||||
m_prevEntries = m_statusEntries;
|
||||
}
|
||||
m_lastLoadError = errorMsg;
|
||||
qDebug() << "Failed to load status:" << errorMsg;
|
||||
m_statusNetJob.reset();
|
||||
emit statusLoading(false);
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
/* Copyright 2013-2021 MultiMC Contributors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
|
||||
#include <net/NetJob.h>
|
||||
|
||||
class StatusChecker : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public: /* con/des */
|
||||
StatusChecker();
|
||||
|
||||
public: /* methods */
|
||||
QString getLastLoadErrorMsg() const;
|
||||
bool isLoadingStatus() const;
|
||||
QMap<QString, QString> getStatusEntries() const;
|
||||
|
||||
signals:
|
||||
void statusLoading(bool loading);
|
||||
void statusChanged(QMap<QString, QString> newStatus);
|
||||
|
||||
public slots:
|
||||
void reloadStatus();
|
||||
|
||||
protected: /* methods */
|
||||
virtual void timerEvent(QTimerEvent *);
|
||||
|
||||
protected slots:
|
||||
void statusDownloadFinished();
|
||||
void statusDownloadFailed(QString reason);
|
||||
void succeed();
|
||||
void fail(const QString& errorMsg);
|
||||
|
||||
protected: /* data */
|
||||
QMap<QString, QString> m_prevEntries;
|
||||
QMap<QString, QString> m_statusEntries;
|
||||
NetJobPtr m_statusNetJob;
|
||||
QString m_lastLoadError;
|
||||
QByteArray dataSink;
|
||||
};
|
||||
|
@ -1,179 +0,0 @@
|
||||
#include "ServerStatus.h"
|
||||
#include "LineSeparator.h"
|
||||
#include "IconLabel.h"
|
||||
#include "status/StatusChecker.h"
|
||||
#include <DesktopServices.h>
|
||||
|
||||
#include "MultiMC.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QFrame>
|
||||
#include <QLabel>
|
||||
#include <QMap>
|
||||
#include <QToolButton>
|
||||
#include <QAction>
|
||||
|
||||
class ClickableLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ClickableLabel(QWidget *parent) : QLabel(parent)
|
||||
{
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
}
|
||||
|
||||
~ClickableLabel(){};
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
emit clicked();
|
||||
}
|
||||
};
|
||||
|
||||
class ClickableIconLabel : public IconLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ClickableIconLabel(QWidget *parent, QIcon icon, QSize size) : IconLabel(parent, icon, size)
|
||||
{
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
}
|
||||
|
||||
~ClickableIconLabel(){};
|
||||
|
||||
signals:
|
||||
void clicked();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *event)
|
||||
{
|
||||
emit clicked();
|
||||
}
|
||||
};
|
||||
|
||||
ServerStatus::ServerStatus(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
|
||||
{
|
||||
layout = new QHBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
goodIcon = MMC->getThemedIcon("status-good");
|
||||
yellowIcon = MMC->getThemedIcon("status-yellow");
|
||||
badIcon = MMC->getThemedIcon("status-bad");
|
||||
|
||||
addStatus("authserver.mojang.com", tr("Auth"));
|
||||
addLine();
|
||||
addStatus("session.minecraft.net", tr("Session"));
|
||||
addLine();
|
||||
addStatus("textures.minecraft.net", tr("Skins"));
|
||||
addLine();
|
||||
addStatus("api.mojang.com", tr("API"));
|
||||
|
||||
m_statusRefresh = new QToolButton(this);
|
||||
m_statusRefresh->setCheckable(true);
|
||||
m_statusRefresh->setToolButtonStyle(Qt::ToolButtonIconOnly);
|
||||
m_statusRefresh->setIcon(MMC->getThemedIcon("refresh"));
|
||||
layout->addWidget(m_statusRefresh);
|
||||
|
||||
setLayout(layout);
|
||||
|
||||
// Start status checker
|
||||
m_statusChecker.reset(new StatusChecker());
|
||||
{
|
||||
auto reloader = m_statusChecker.get();
|
||||
connect(reloader, &StatusChecker::statusChanged, this, &ServerStatus::StatusChanged);
|
||||
connect(reloader, &StatusChecker::statusLoading, this, &ServerStatus::StatusReloading);
|
||||
connect(m_statusRefresh, &QAbstractButton::clicked, this, &ServerStatus::reloadStatus);
|
||||
m_statusChecker->startTimer(60000);
|
||||
reloadStatus();
|
||||
}
|
||||
}
|
||||
|
||||
ServerStatus::~ServerStatus()
|
||||
{
|
||||
}
|
||||
|
||||
void ServerStatus::reloadStatus()
|
||||
{
|
||||
m_statusChecker->reloadStatus();
|
||||
}
|
||||
|
||||
void ServerStatus::addLine()
|
||||
{
|
||||
layout->addWidget(new LineSeparator(this, Qt::Vertical));
|
||||
}
|
||||
|
||||
void ServerStatus::addStatus(QString key, QString name)
|
||||
{
|
||||
{
|
||||
auto label = new ClickableIconLabel(this, badIcon, QSize(16, 16));
|
||||
label->setToolTip(key);
|
||||
serverLabels[key] = label;
|
||||
layout->addWidget(label);
|
||||
connect(label,SIGNAL(clicked()),SLOT(clicked()));
|
||||
}
|
||||
{
|
||||
auto label = new ClickableLabel(this);
|
||||
label->setText(name);
|
||||
label->setToolTip(key);
|
||||
layout->addWidget(label);
|
||||
connect(label,SIGNAL(clicked()),SLOT(clicked()));
|
||||
}
|
||||
}
|
||||
|
||||
void ServerStatus::clicked()
|
||||
{
|
||||
DesktopServices::openUrl(QUrl("https://github.com/MultiMC/MultiMC5/wiki/Mojang-Services-Status"));
|
||||
}
|
||||
|
||||
void ServerStatus::setStatus(QString key, int value)
|
||||
{
|
||||
if (!serverLabels.contains(key))
|
||||
return;
|
||||
IconLabel *label = serverLabels[key];
|
||||
switch(value)
|
||||
{
|
||||
case 0:
|
||||
label->setIcon(goodIcon);
|
||||
break;
|
||||
case 1:
|
||||
label->setIcon(yellowIcon);
|
||||
break;
|
||||
default:
|
||||
case 2:
|
||||
label->setIcon(badIcon);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ServerStatus::StatusChanged(const QMap<QString, QString> statusEntries)
|
||||
{
|
||||
auto convertStatus = [&](QString status)->int
|
||||
{
|
||||
if (status == "green")
|
||||
return 0;
|
||||
else if (status == "yellow")
|
||||
return 1;
|
||||
else if (status == "red")
|
||||
return 2;
|
||||
return 2;
|
||||
}
|
||||
;
|
||||
auto iter = statusEntries.begin();
|
||||
while (iter != statusEntries.end())
|
||||
{
|
||||
QString key = iter.key();
|
||||
auto value = convertStatus(iter.value());
|
||||
setStatus(key, value);
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
|
||||
void ServerStatus::StatusReloading(bool is_reloading)
|
||||
{
|
||||
m_statusRefresh->setChecked(is_reloading);
|
||||
}
|
||||
|
||||
#include "ServerStatus.moc"
|
@ -1,40 +0,0 @@
|
||||
#pragma once
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include <QMap>
|
||||
#include <QIcon>
|
||||
#include <memory>
|
||||
|
||||
class IconLabel;
|
||||
class QToolButton;
|
||||
class QHBoxLayout;
|
||||
class StatusChecker;
|
||||
|
||||
class ServerStatus: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ServerStatus(QWidget *parent = nullptr, Qt::WindowFlags f = 0);
|
||||
virtual ~ServerStatus();
|
||||
|
||||
public slots:
|
||||
void reloadStatus();
|
||||
void StatusChanged(const QMap<QString, QString> statuses);
|
||||
void StatusReloading(bool is_reloading);
|
||||
|
||||
private slots:
|
||||
void clicked();
|
||||
|
||||
private: /* methods */
|
||||
void addLine();
|
||||
void addStatus(QString key, QString name);
|
||||
void setStatus(QString key, int value);
|
||||
private: /* data */
|
||||
QHBoxLayout * layout = nullptr;
|
||||
QToolButton *m_statusRefresh = nullptr;
|
||||
QMap<QString, IconLabel *> serverLabels;
|
||||
QIcon goodIcon;
|
||||
QIcon yellowIcon;
|
||||
QIcon badIcon;
|
||||
std::shared_ptr<StatusChecker> m_statusChecker;
|
||||
};
|
Loading…
Reference in New Issue
Block a user