From fa7a7d52d0d4084e2ee2c46a0cac07f4962ab71c Mon Sep 17 00:00:00 2001 From: kb1000 Date: Fri, 5 Jun 2020 14:41:25 +0200 Subject: [PATCH] Remove broken Mojang services status --- buildconfig/BuildConfig.h | 1 - launcher/CMakeLists.txt | 10 -- launcher/MainWindow.cpp | 3 - launcher/MainWindow.h | 2 - launcher/status/StatusChecker.cpp | 148 ------------------------ launcher/status/StatusChecker.h | 58 ---------- launcher/widgets/ServerStatus.cpp | 179 ------------------------------ launcher/widgets/ServerStatus.h | 40 ------- 8 files changed, 441 deletions(-) delete mode 100644 launcher/status/StatusChecker.cpp delete mode 100644 launcher/status/StatusChecker.h delete mode 100644 launcher/widgets/ServerStatus.cpp delete mode 100644 launcher/widgets/ServerStatus.h diff --git a/buildconfig/BuildConfig.h b/buildconfig/BuildConfig.h index 6a35d1b3..95f3ef22 100644 --- a/buildconfig/BuildConfig.h +++ b/buildconfig/BuildConfig.h @@ -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/"; diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 14704905..4ec6a7d1 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -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 diff --git a/launcher/MainWindow.cpp b/launcher/MainWindow.cpp index 182b22e9..67590946 100644 --- a/launcher/MainWindow.cpp +++ b/launcher/MainWindow.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(); diff --git a/launcher/MainWindow.h b/launcher/MainWindow.h index 67dec8cf..38e5b4b5 100644 --- a/launcher/MainWindow.h +++ b/launcher/MainWindow.h @@ -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; diff --git a/launcher/status/StatusChecker.cpp b/launcher/status/StatusChecker.cpp deleted file mode 100644 index 38fc2163..00000000 --- a/launcher/status/StatusChecker.cpp +++ /dev/null @@ -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 - -#include - -#include - -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 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); -} - diff --git a/launcher/status/StatusChecker.h b/launcher/status/StatusChecker.h deleted file mode 100644 index 06b3f576..00000000 --- a/launcher/status/StatusChecker.h +++ /dev/null @@ -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 -#include -#include - -#include - -class StatusChecker : public QObject -{ - Q_OBJECT -public: /* con/des */ - StatusChecker(); - -public: /* methods */ - QString getLastLoadErrorMsg() const; - bool isLoadingStatus() const; - QMap getStatusEntries() const; - -signals: - void statusLoading(bool loading); - void statusChanged(QMap 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 m_prevEntries; - QMap m_statusEntries; - NetJobPtr m_statusNetJob; - QString m_lastLoadError; - QByteArray dataSink; -}; - diff --git a/launcher/widgets/ServerStatus.cpp b/launcher/widgets/ServerStatus.cpp deleted file mode 100644 index 87c34f70..00000000 --- a/launcher/widgets/ServerStatus.cpp +++ /dev/null @@ -1,179 +0,0 @@ -#include "ServerStatus.h" -#include "LineSeparator.h" -#include "IconLabel.h" -#include "status/StatusChecker.h" -#include - -#include "MultiMC.h" - -#include -#include -#include -#include -#include -#include - -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 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" diff --git a/launcher/widgets/ServerStatus.h b/launcher/widgets/ServerStatus.h deleted file mode 100644 index e1e70dfb..00000000 --- a/launcher/widgets/ServerStatus.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include - -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 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 serverLabels; - QIcon goodIcon; - QIcon yellowIcon; - QIcon badIcon; - std::shared_ptr m_statusChecker; -};