diff options
| author | Darkelarious <github@333networks.com> | 2025-03-08 15:37:38 +0100 |
|---|---|---|
| committer | Darkelarious <github@333networks.com> | 2025-03-08 15:37:38 +0100 |
| commit | c4bb33bf7242607d173cd61bf2cb7f6e560c8dc7 (patch) | |
| tree | a2209667fc5fe503857b2361fe87ff7dc06dad79 /src/UdpTasks | |
| parent | ee9c0c04bdcd8b7223dd0f6f313592e8a91994dc (diff) | |
| download | Masterserver-Qt5-c4bb33bf7242607d173cd61bf2cb7f6e560c8dc7.tar.gz Masterserver-Qt5-c4bb33bf7242607d173cd61bf2cb7f6e560c8dc7.zip | |
hotfix 4
Parse players differently to handle gaps in data. SQL query optimisation for stats.
Diffstat (limited to 'src/UdpTasks')
| -rw-r--r-- | src/UdpTasks/StatusChecker/playerinfoinsert.cpp | 58 | ||||
| -rw-r--r-- | src/UdpTasks/StatusChecker/statuschecker.h | 1 |
2 files changed, 37 insertions, 22 deletions
diff --git a/src/UdpTasks/StatusChecker/playerinfoinsert.cpp b/src/UdpTasks/StatusChecker/playerinfoinsert.cpp index ce21422..c98b8b4 100644 --- a/src/UdpTasks/StatusChecker/playerinfoinsert.cpp +++ b/src/UdpTasks/StatusChecker/playerinfoinsert.cpp @@ -31,29 +31,43 @@ bool StatusChecker::insertPlayerInfo(const QString &serverAddres if ( ! q.exec() ) return reportQuery(q); - // iterate through serverInfo player data - int playerIndex = 0; - while ( serverInfo.contains( QStringLiteral("player_%1").arg(playerIndex) ) ) + // hotfix 4: some player data may be missing intermittently (e.g player 1, 2, 4, 5 ) + + // regex to find player_%d + static QRegularExpression p_regex("player_(\\d+)"); + + // iterate all serverinfo fields for player_%d + QHashIterator<QString, QString> infoIterator(serverInfo); + while ( infoIterator.hasNext() ) { - QString insertString = "INSERT INTO playerinfo " - "(sid, name, team, frags, mesh, skin, face, ping, misc, dt_player) " - "VALUES (:sid, :name, :team, :frags, :mesh, :skin, :face, :ping, :misc, :dt_player)"; - q.prepare(insertString); - q.bindValue(":sid", serverID); - q.bindValue(":name", serverInfo.value(QStringLiteral("player_%1").arg(playerIndex), "Player")); - q.bindValue(":team", serverInfo.value(QStringLiteral( "team_%1").arg(playerIndex), "0")); - q.bindValue(":frags", serverInfo.value(QStringLiteral( "frags_%1").arg(playerIndex), "0")); - q.bindValue(":mesh", serverInfo.value(QStringLiteral( "mesh_%1").arg(playerIndex), "default")); - q.bindValue(":skin", serverInfo.value(QStringLiteral( "skin_%1").arg(playerIndex), "default")); - q.bindValue(":face", serverInfo.value(QStringLiteral( "face_%1").arg(playerIndex), "default")); - q.bindValue(":ping", serverInfo.value(QStringLiteral( "ping_%1").arg(playerIndex), "0")); - q.bindValue(":misc", ""); // reserved for additional query info - q.bindValue(":dt_player", QDateTime::currentSecsSinceEpoch() ); - if ( ! q.exec() ) - return reportQuery(q); - - // successfull insert, increase player index - playerIndex++; + infoIterator.next(); + + // match player id in player_%d + QRegularExpressionMatch p_match = p_regex.match( infoIterator.key() ); + if ( p_match.hasMatch() ) + { + // extract the player_id from matched string + QString playerIndexString = p_match.captured(0); + int playerIndex = playerIndexString.remove("player_").toInt(); + + // and insert the whole player dataset into the db (no sanity check needed, to defaults) + QString insertString = "INSERT INTO playerinfo " + "(sid, name, team, frags, mesh, skin, face, ping, misc, dt_player) " + "VALUES (:sid, :name, :team, :frags, :mesh, :skin, :face, :ping, :misc, :dt_player)"; + q.prepare(insertString); + q.bindValue(":sid", serverID); + q.bindValue(":name", serverInfo.value(QStringLiteral("player_%1").arg(playerIndex), "Player")); + q.bindValue(":team", serverInfo.value(QStringLiteral( "team_%1").arg(playerIndex), "0")); + q.bindValue(":frags", serverInfo.value(QStringLiteral( "frags_%1").arg(playerIndex), "0")); + q.bindValue(":mesh", serverInfo.value(QStringLiteral( "mesh_%1").arg(playerIndex), "default")); + q.bindValue(":skin", serverInfo.value(QStringLiteral( "skin_%1").arg(playerIndex), "default")); + q.bindValue(":face", serverInfo.value(QStringLiteral( "face_%1").arg(playerIndex), "default")); + q.bindValue(":ping", serverInfo.value(QStringLiteral( "ping_%1").arg(playerIndex), "0")); + q.bindValue(":misc", ""); // reserved for additional query info + q.bindValue(":dt_player", QDateTime::currentSecsSinceEpoch() ); + if ( ! q.exec() ) + return reportQuery(q); + } // hasMatch } return true; diff --git a/src/UdpTasks/StatusChecker/statuschecker.h b/src/UdpTasks/StatusChecker/statuschecker.h index bf3c4c2..907c8ae 100644 --- a/src/UdpTasks/StatusChecker/statuschecker.h +++ b/src/UdpTasks/StatusChecker/statuschecker.h @@ -4,6 +4,7 @@ #include <QTimer> #include <QUdpSocket> #include <QNetworkDatagram> +#include <QRegularExpression> #include "Core/CoreObject/coreobject.h" #include "Database/Common/commonactions.h" |
