# HG changeset patch # User Zorg # Date 1307518614 14400 # Node ID 148d581b17ab98c010f655f3dbd14499d07ba96d # Parent b018f6117fc1f8bd77984f3d373b7c2e22f8cd75 Attempt to fix issue 125. The password pop-up doesn't appear every time when going into the official server anymore, now it only does it when the password is blank. If a user enters an invalid password, the password is set blank to avoid the user going back to the official server just to be rejected. When entering an invalid password, the unknown error dialog doesn't show up anymore, but the connection lost to server one still does. This fixes the bug where the user would be spammed with error messages. The user can also now change his password in the settings page. diff -r b018f6117fc1 -r 148d581b17ab QTfrontend/gameuiconfig.cpp --- a/QTfrontend/gameuiconfig.cpp Sat Jun 04 16:09:12 2011 -0400 +++ b/QTfrontend/gameuiconfig.cpp Wed Jun 08 03:36:54 2011 -0400 @@ -22,6 +22,7 @@ #include #include #include +#include #include "gameuiconfig.h" #include "hwform.h" @@ -66,6 +67,9 @@ QDir::home().dirName()); Form->ui.pageOptions->editNetNick->setText(netNick); + + int passLength = value("net/passwordlength", 0).toInt(); + setNetPasswordLength(passLength); delete netHost; netHost = new QString(value("net/ip", "").toString()); @@ -138,6 +142,11 @@ setValue("audio/volume", Form->ui.pageOptions->volumeBox->value()); setValue("net/nick", netNick()); + if (netPasswordIsValid()) + { + setValue("net/passwordhash", netPasswordHash()); + setValue("net/passwordlength", netPasswordLength()); + } setValue("net/ip", *netHost); setValue("net/port", netPort); setValue("net/servername", Form->ui.pageNetServer->leServerDescr->text()); @@ -145,7 +154,7 @@ setValue("fps/show", isShowFPSEnabled()); setValue("fps/limit", Form->ui.pageOptions->fpsedit->value()); - + setValue("misc/altdamage", isAltDamageEnabled()); setValue("misc/appendTimeToRecords", appendDateTimeToRecordName()); setValue("misc/locale", language()); @@ -296,6 +305,33 @@ return Form->ui.pageOptions->editNetNick->text(); } +QByteArray GameUIConfig::netPasswordHash() +{ + return QCryptographicHash::hash(Form->ui.pageOptions->editNetPassword->text().toLatin1(), QCryptographicHash::Md5).toHex(); +} + +int GameUIConfig::netPasswordLength() +{ + return Form->ui.pageOptions->editNetPassword->text().size(); +} + +bool GameUIConfig::netPasswordIsValid() +{ + return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '\0')); +} + +void GameUIConfig::setNetPasswordLength(int passwordLength) +{ + if (passwordLength > 0) + { + Form->ui.pageOptions->editNetPassword->setText(QString(passwordLength, '\0')); + } + else + { + Form->ui.pageOptions->editNetPassword->setText(""); + } +} + quint8 GameUIConfig::volume() { return Form->ui.pageOptions->volumeBox->value() * 128 / 100; diff -r b018f6117fc1 -r 148d581b17ab QTfrontend/gameuiconfig.h --- a/QTfrontend/gameuiconfig.h Sat Jun 04 16:09:12 2011 -0400 +++ b/QTfrontend/gameuiconfig.h Wed Jun 08 03:36:54 2011 -0400 @@ -49,6 +49,9 @@ quint8 timerInterval(); quint8 bitDepth(); QString netNick(); + QByteArray netPasswordHash(); + int netPasswordLength(); + void setNetPasswordLength(int passwordLength); bool isReducedQuality() const; bool isFrontendEffects() const; bool isFrontendFullscreen() const; @@ -68,6 +71,7 @@ void SaveOptions(); private: + bool netPasswordIsValid(); quint8 depth; }; diff -r b018f6117fc1 -r 148d581b17ab QTfrontend/newnetclient.cpp --- a/QTfrontend/newnetclient.cpp Sat Jun 04 16:09:12 2011 -0400 +++ b/QTfrontend/newnetclient.cpp Wed Jun 08 03:36:54 2011 -0400 @@ -486,23 +486,38 @@ emit AskForRunGame(); return; } + + if (lst[0] == "BYE") { + if (lst[1] == "Authentication failed") + { + // Set the password blank if case the user tries to join and enter his password again + config->setValue("net/passwordlength", 0); + config->setNetPasswordLength(0); + } + // return early so the user won't get an unknown error message dialog (the user already gets a server connection is lost one) + return; + } if (lst[0] == "ASKPASSWORD") { bool ok = false; int passLength = config->value("net/passwordlength", 0).toInt(); QString hash = config->value("net/passwordhash", "").toString(); - QString password = QInputDialog::getText(0, tr("Password"), tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(mynick), QLineEdit::Password, passLength==0?NULL:QString(passLength,'\0'), &ok); + + // If the password is blank, ask the user to enter one in + if (passLength == 0) + { + QString password = QInputDialog::getText(0, tr("Password"), tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(mynick), QLineEdit::Password, passLength==0?NULL:QString(passLength,'\0'), &ok); - if (!ok) { - Disconnect(); - emit Disconnected(); - return; - } - - if (!passLength || password!=QString(passLength, '\0')) { + if (!ok) { + Disconnect(); + emit Disconnected(); + return; + } + hash = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5).toHex(); config->setValue("net/passwordhash", hash); config->setValue("net/passwordlength", password.size()); + config->setNetPasswordLength(password.size()); } RawSendNet(QString("PASSWORD%1%2").arg(delimeter).arg(hash)); diff -r b018f6117fc1 -r 148d581b17ab QTfrontend/pageoptions.cpp --- a/QTfrontend/pageoptions.cpp Sat Jun 04 16:09:12 2011 -0400 +++ b/QTfrontend/pageoptions.cpp Wed Jun 08 03:36:54 2011 -0400 @@ -192,10 +192,18 @@ editNetNick->setText(QLineEdit::tr("unnamed")); connect(editNetNick, SIGNAL(editingFinished()), this, SLOT(trimNetNick())); MiscLayout->addWidget(editNetNick, 0, 1); + + labelNetPassword = new QLabel(groupMisc); + labelNetPassword->setText(QLabel::tr("Password")); + MiscLayout->addWidget(labelNetPassword, 1, 0); + + editNetPassword = new QLineEdit(groupMisc); + editNetPassword->setEchoMode(QLineEdit::Password); + MiscLayout->addWidget(editNetPassword, 1, 1); QLabel *labelLanguage = new QLabel(groupMisc); labelLanguage->setText(QLabel::tr("Locale") + " *"); - MiscLayout->addWidget(labelLanguage, 1, 0); + MiscLayout->addWidget(labelLanguage, 2, 0); CBLanguage = new QComboBox(groupMisc); QDir tmpdir; @@ -210,26 +218,26 @@ CBLanguage->addItem(QLocale::languageToString(loc.language()) + " (" + QLocale::countryToString(loc.country()) + ")", loc.name()); } - MiscLayout->addWidget(CBLanguage, 1, 1); + MiscLayout->addWidget(CBLanguage, 2, 1); CBAltDamage = new QCheckBox(groupMisc); CBAltDamage->setText(QCheckBox::tr("Alternative damage show")); - MiscLayout->addWidget(CBAltDamage, 2, 0, 1, 2); + MiscLayout->addWidget(CBAltDamage, 3, 0, 1, 2); CBNameWithDate = new QCheckBox(groupMisc); CBNameWithDate->setText(QCheckBox::tr("Append date and time to record file name")); - MiscLayout->addWidget(CBNameWithDate, 3, 0, 1, 2); + MiscLayout->addWidget(CBNameWithDate, 4, 0, 1, 2); #ifdef SPARKLE_ENABLED CBAutoUpdate = new QCheckBox(groupMisc); CBAutoUpdate->setText(QCheckBox::tr("Check for updates at startup")); - MiscLayout->addWidget(CBAutoUpdate, 4, 0, 1, 2); + MiscLayout->addWidget(CBAutoUpdate, 5, 0, 1, 2); #endif #ifndef __APPLE__ BtnAssociateFiles = new QPushButton(groupMisc); BtnAssociateFiles->setText(QPushButton::tr("Associate file extensions")); BtnAssociateFiles->setEnabled(!custom_data && !custom_config); - MiscLayout->addWidget(BtnAssociateFiles, 4, 0, 1, 2); + MiscLayout->addWidget(BtnAssociateFiles, 5, 0, 1, 2); #endif gbTBLayout->addWidget(groupMisc, 2, 0); } diff -r b018f6117fc1 -r 148d581b17ab QTfrontend/pageoptions.h --- a/QTfrontend/pageoptions.h Sat Jun 04 16:09:12 2011 -0400 +++ b/QTfrontend/pageoptions.h Wed Jun 08 03:36:54 2011 -0400 @@ -70,8 +70,10 @@ FPSEdit *fpsedit; QPushButton *BtnSaveOptions; QLabel *labelNN; + QLabel *labelNetPassword; QSpinBox * volumeBox; QLineEdit *editNetNick; + QLineEdit *editNetPassword; QSlider *SLQuality; QCheckBox *CBFrontendEffects;