diff --git a/src/server/server.cpp b/src/server/server.cpp index f28ff971..3f0e6618 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -193,30 +193,13 @@ void Server::processRequest(const QByteArray &msg) { QJsonArray arr = String2Json(doc[3].toString()).array(); - if (md5 != arr[2].toString()) { - QJsonArray body; - body << -2; - body << (Router::TYPE_NOTIFICATION | Router::SRC_SERVER | - Router::DEST_CLIENT); - body << "ErrorMsg"; - body << "MD5 check failed!"; - client->send(JsonArray2Bytes(body)); - - body.removeLast(); - body.removeLast(); - body << "UpdatePackage"; - body << Pacman->getPackSummary(); - client->send(JsonArray2Bytes(body)); - - client->disconnectFromHost(); - return; - } - - handleNameAndPassword(client, arr[0].toString(), arr[1].toString()); + handleNameAndPassword(client, arr[0].toString(), arr[1].toString(), + arr[2].toString()); } void Server::handleNameAndPassword(ClientSocket *client, const QString &name, - const QString &password) { + const QString &password, + const QString &md5_str) { // First check the name and password // Matches a string that does not contain special characters static QRegularExpression nameExp("['\";#]+|(--)|(/\\*)|(\\*/)|(--\\+)"); @@ -236,6 +219,25 @@ void Server::handleNameAndPassword(ClientSocket *client, const QString &name, decrypted_pw = "\xFF"; } + if (md5 != md5_str) { + QJsonArray body; + body << -2; + body << (Router::TYPE_NOTIFICATION | Router::SRC_SERVER | + Router::DEST_CLIENT); + body << "ErrorMsg"; + body << "MD5 check failed!"; + client->send(JsonArray2Bytes(body)); + + body.removeLast(); + body.removeLast(); + body << "UpdatePackage"; + body << Pacman->getPackSummary(); + client->send(JsonArray2Bytes(body)); + + client->disconnectFromHost(); + return; + } + bool passed = false; QString error_msg; QJsonArray result; diff --git a/src/server/server.h b/src/server/server.h index 623c892f..89c9cecf 100644 --- a/src/server/server.h +++ b/src/server/server.h @@ -19,8 +19,8 @@ public: bool listen(const QHostAddress &address = QHostAddress::Any, ushort port = 9527u); - void createRoom(ServerPlayer *owner, const QString &name, - int capacity, const QByteArray &settings = "{}"); + void createRoom(ServerPlayer *owner, const QString &name, int capacity, + const QByteArray &settings = "{}"); Room *findRoom(int id) const; Room *lobby() const; @@ -61,8 +61,8 @@ private: sqlite3 *db; QString md5; - void handleNameAndPassword(ClientSocket *client, - const QString &name, const QString &password); + void handleNameAndPassword(ClientSocket *client, const QString &name, + const QString &password, const QString &md5_str); }; extern Server *ServerInstance;