From bd471eda00e7b51da92de341da910c55f4fb9e69 Mon Sep 17 00:00:00 2001 From: in1tiate Date: Thu, 11 Mar 2021 04:32:41 -0600 Subject: [PATCH] switch to QRegularExpression for client version validation --- include/aoclient.h | 2 +- src/packets.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/aoclient.h b/include/aoclient.h index 4b33f53..7b97907 100644 --- a/include/aoclient.h +++ b/include/aoclient.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #if QT_VERSION > QT_VERSION_CHECK(5, 10, 0) #include diff --git a/src/packets.cpp b/src/packets.cpp index 53a7962..66f32ac 100644 --- a/src/packets.cpp +++ b/src/packets.cpp @@ -56,12 +56,12 @@ void AOClient::pktSoftwareId(AreaData* area, int argc, QStringList argv, AOPacke version.string = argv[1]; - QRegExp 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) { - QStringList version_raw = rx.capturedTexts(); - version.release = version_raw[0].toInt(); - version.major = version_raw[1].toInt(); - version.minor = version_raw[2].toInt(); + QRegularExpression rx("\\b(\\d+)\\.(\\d+)\\.(\\d+)\\b"); // matches X.X.X (e.g. 2.9.0, 2.4.10, etc.) + QRegularExpressionMatch match = rx.match(version.string); + if (match.hasMatch()) { + version.release = match.captured(1).toInt(); + version.major = match.captured(2).toInt(); + version.minor = match.captured(3).toInt(); } sendPacket("PN", {QString::number(server->player_count), max_players});