switch to QRegularExpression for client version validation

This commit is contained in:
in1tiate 2021-03-11 04:32:41 -06:00
parent 7157d5410e
commit bd471eda00
2 changed files with 7 additions and 7 deletions

View File

@ -28,7 +28,7 @@
#include <QHostAddress> #include <QHostAddress>
#include <QTcpSocket> #include <QTcpSocket>
#include <QDateTime> #include <QDateTime>
#include <QRegExp> #include <QRegularExpression>
#include <QtGlobal> #include <QtGlobal>
#if QT_VERSION > QT_VERSION_CHECK(5, 10, 0) #if QT_VERSION > QT_VERSION_CHECK(5, 10, 0)
#include <QRandomGenerator> #include <QRandomGenerator>

View File

@ -56,12 +56,12 @@ void AOClient::pktSoftwareId(AreaData* area, int argc, QStringList argv, AOPacke
version.string = argv[1]; version.string = argv[1];
QRegExp rx("\\b(\\d+)\\.(\\d+)\\.(\\d+)\\b"); // matches X.X.X (e.g. 2.9.0, 2.4.10, etc.) QRegularExpression rx("\\b(\\d+)\\.(\\d+)\\.(\\d+)\\b"); // matches X.X.X (e.g. 2.9.0, 2.4.10, etc.)
if (rx.indexIn(version.string) != -1) { QRegularExpressionMatch match = rx.match(version.string);
QStringList version_raw = rx.capturedTexts(); if (match.hasMatch()) {
version.release = version_raw[0].toInt(); version.release = match.captured(1).toInt();
version.major = version_raw[1].toInt(); version.major = match.captured(2).toInt();
version.minor = version_raw[2].toInt(); version.minor = match.captured(3).toInt();
} }
sendPacket("PN", {QString::number(server->player_count), max_players}); sendPacket("PN", {QString::number(server->player_count), max_players});