From d5a1264bcbf47e2e1c11f6c2c24798c17e40f59c Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Thu, 16 Apr 2015 23:50:05 +0200 Subject: [PATCH 1/3] Updated server to support "." Now uses regex. Added "." Updated login message --- cockatrice/src/window_main.cpp | 4 ++-- .../src/servatrice_database_interface.cpp | 18 ++---------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/cockatrice/src/window_main.cpp b/cockatrice/src/window_main.cpp index f2268911..61c248c9 100644 --- a/cockatrice/src/window_main.cpp +++ b/cockatrice/src/window_main.cpp @@ -78,7 +78,7 @@ void MainWindow::processConnectionClosedEvent(const Event_ConnectionClosed &even break; } case Event_ConnectionClosed::SERVER_SHUTDOWN: reasonStr = tr("Scheduled server shutdown."); break; - case Event_ConnectionClosed::USERNAMEINVALID: reasonStr = tr("Invalid username.\nYou may only use A-Z, a-z, 0-9, _, and - in your username."); break; + case Event_ConnectionClosed::USERNAMEINVALID: reasonStr = tr("Invalid username.\nYou may only use A-Z, a-z, 0-9, _, ., and - in your username."); break; default: reasonStr = QString::fromStdString(event.reason_str()); } QMessageBox::critical(this, tr("Connection closed"), tr("The server has terminated your connection.\nReason: %1").arg(reasonStr)); @@ -261,7 +261,7 @@ void MainWindow::loginError(Response::ResponseCode r, QString reasonStr, quint32 break; } case Response::RespUsernameInvalid: - QMessageBox::critical(this, tr("Error"), tr("Invalid username.\nYou may only use A-Z, a-z, 0-9, _, and - in your username.")); + QMessageBox::critical(this, tr("Error"), tr("Invalid username.\nYou may only use A-Z, a-z, 0-9, _, ., and - in your username.")); break; case Response::RespRegistrationRequired: QMessageBox::critical(this, tr("Error"), tr("This server requires user registration.")); diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index fa52e09c..dd2b2261 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -98,22 +98,8 @@ bool Servatrice_DatabaseInterface::execSqlQuery(QSqlQuery *query) bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user) { - QString result; - result.reserve(user.size()); - foreach (const QChar& c, user) { - switch (c.category()) { - case QChar::Letter_Uppercase: //[A-Z] - case QChar::Letter_Lowercase: //[a-z] - case QChar::Number_DecimalDigit: //[0-9] - case QChar::Punctuation_Connector: //[_] - case QChar::Punctuation_Dash: //[-] - result += c; - default: - break; - } - } - result = result.trimmed(); - return (result.size() == user.size()); + static QRegExp re = QRegExp("^[a-zA-Z0-9_\-\.]+$"); + return re.exactMatch(user); } bool Servatrice_DatabaseInterface::getRequireRegistration() From bba9539229fe7105021d3c0b3c50f99d923b1368 Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Fri, 17 Apr 2015 00:17:03 +0200 Subject: [PATCH 2/3] Updated regex --- servatrice/src/servatrice_database_interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index dd2b2261..6fa9dfa3 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -98,7 +98,7 @@ bool Servatrice_DatabaseInterface::execSqlQuery(QSqlQuery *query) bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user) { - static QRegExp re = QRegExp("^[a-zA-Z0-9_\-\.]+$"); + static QRegExp re = QRegExp("[a-zA-Z0-9_\.-]+"); return re.exactMatch(user); } From 1f9b1d78bc60c8dd7941efc2e0116570aa43770a Mon Sep 17 00:00:00 2001 From: Matt Lowe Date: Fri, 17 Apr 2015 17:47:58 +0200 Subject: [PATCH 3/3] Double escaped "." --- servatrice/src/servatrice_database_interface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/servatrice/src/servatrice_database_interface.cpp b/servatrice/src/servatrice_database_interface.cpp index 6fa9dfa3..77f31156 100644 --- a/servatrice/src/servatrice_database_interface.cpp +++ b/servatrice/src/servatrice_database_interface.cpp @@ -98,7 +98,7 @@ bool Servatrice_DatabaseInterface::execSqlQuery(QSqlQuery *query) bool Servatrice_DatabaseInterface::usernameIsValid(const QString &user) { - static QRegExp re = QRegExp("[a-zA-Z0-9_\.-]+"); + static QRegExp re = QRegExp("[a-zA-Z0-9_\\.-]+"); return re.exactMatch(user); }