diff --git a/launcher/ui/pages/instance/McClient.hpp b/launcher/ui/pages/instance/McClient.hpp index f85d7fd21..992328504 100644 --- a/launcher/ui/pages/instance/McClient.hpp +++ b/launcher/ui/pages/instance/McClient.hpp @@ -3,6 +3,8 @@ #include #include +#include + #define SEGMENT_BITS 0x7F #define CONTINUE_BIT 0x80 @@ -23,13 +25,13 @@ public: socket.connectToHost(ip, port); if (!socket.waitForConnected(3000)) { - throw std::runtime_error("Failed to connect to socket"); + throw Exception("Failed to connect to socket"); } qDebug() << "Connected to socket successfully"; sendRequest(); if (!socket.waitForReadyRead(3000)) { - throw std::runtime_error("Socket didn't send anything to read"); + throw Exception("Socket didn't send anything to read"); } return readResponse(); } @@ -59,7 +61,7 @@ public: while (bytesToRead > 0) { qDebug() << bytesToRead << " bytes left to read"; if (!socket.waitForReadyRead()) { - throw std::runtime_error("Read timeout or error"); + throw Exception("Read timeout or error"); } QByteArray chunk = socket.read(qMin(bytesToRead, socket.bytesAvailable())); @@ -82,9 +84,9 @@ public: int packetID = readVarInt(resp); if (packetID != 0x00) { - throw std::runtime_error( + throw Exception( QString("Packet ID doesn't match expected value (0x00 vs 0x%1)") - .arg(packetID, 0, 16).toStdString() + .arg(packetID, 0, 16) ); } @@ -125,7 +127,7 @@ private: position += 7; - if (position >= 32) throw std::runtime_error("VarInt is too big"); + if (position >= 32) throw Exception("VarInt is too big"); } return value; @@ -133,7 +135,7 @@ private: char readByte(QByteArray &data) { if (data.isEmpty()) { - throw std::runtime_error("No more bytes to read"); + throw Exception("No more bytes to read"); } char byte = data.at(0); diff --git a/launcher/ui/pages/instance/ServersPage.cpp b/launcher/ui/pages/instance/ServersPage.cpp index 1a973580d..5f3babcf2 100644 --- a/launcher/ui/pages/instance/ServersPage.cpp +++ b/launcher/ui/pages/instance/ServersPage.cpp @@ -145,9 +145,14 @@ class ServerPingTask : public Task { resolver->deleteLater(); qDebug() << "Resolved Addresse for" << domain << ": " << ip << ":" << port; McClient client(nullptr, domain, ip, port); - int online = client.getOnlinePlayers(); - qDebug() << "Online players: " << online; - m_server.m_currentPlayers = online; + + try { + int online = client.getOnlinePlayers(); + qDebug() << "Online players: " << online; + m_server.m_currentPlayers = online; + } catch(const Exception& e) { + qDebug() << "Failed to get online players: " << e.cause(); + } }); resolver->ping(); }