# HG changeset patch # User Ondrej Skopek # Date 1355173794 -3600 # Node ID e4a0d980d1e20070b3360a4915b8341060423c30 # Parent 302a2521fe7ade8e1eca3b36fe83e6bcfaa8d55f Patched login dialog bugs, added retry dialogs diff -r 302a2521fe7a -r e4a0d980d1e2 QTfrontend/gameuiconfig.cpp --- a/QTfrontend/gameuiconfig.cpp Mon Dec 10 10:32:51 2012 -0500 +++ b/QTfrontend/gameuiconfig.cpp Mon Dec 10 22:09:54 2012 +0100 @@ -233,11 +233,16 @@ setValue("audio/volume", Form->ui.pageOptions->volumeBox->value()); setValue("net/nick", netNick()); - if (netPasswordIsValid() && Form->ui.pageOptions->CBSavePassword->isChecked()) + if ((netPasswordLength()==0)) { + setValue("net/passwordhash", ""); + setValue("net/passwordlength", 0); + } + else if (netPasswordIsValid() && Form->ui.pageOptions->CBSavePassword->isChecked()) { setValue("net/passwordhash", netPasswordHash()); setValue("net/passwordlength", netPasswordLength()); } + setValue("net/savepassword", Form->ui.pageOptions->CBSavePassword->isChecked()); setValue("net/ip", *netHost); setValue("net/port", netPort); diff -r 302a2521fe7a -r e4a0d980d1e2 QTfrontend/hwform.cpp --- a/QTfrontend/hwform.cpp Mon Dec 10 10:32:51 2012 -0500 +++ b/QTfrontend/hwform.cpp Mon Dec 10 22:09:54 2012 +0100 @@ -1057,9 +1057,53 @@ } //Remove temporary hash from config - QString key = "net/temppasswordhash"; - config->setValue(key, ""); - config->remove(key); + clearPasswordHashes(true, false); +} + +inline void HWForm::clearPasswordHashes(bool clearTempHash, bool clearHash) +{ + if (clearTempHash) { + QString key = "net/temppasswordhash"; + config->setValue(key, ""); + config->remove(key); + } + if (clearHash) { + config->setValue("net/passwordhash", ""); + config->setValue("net/passwordlength", 0); + } +} + +void HWForm::NetNickRegistered(const QString & nick) +{ + //Get hashes + QString hash = config->value("net/passwordhash", "").toString(); + QString temphash = config->value("net/temppasswordhash", "").toString(); + + if (hash.isEmpty()) { + if (temphash.isEmpty()) { //If the user enters a registered nick with no password + QString suppliedpass; + while (suppliedpass.isEmpty()) { + QInputDialog nickRegedDialog(this); + nickRegedDialog.setWindowModality(Qt::WindowModal); + nickRegedDialog.setInputMode(QInputDialog::TextInput); + nickRegedDialog.setWindowTitle(tr("Hedgewars - Nick registered")); + nickRegedDialog.setLabelText(tr("This nick is registered, and you haven't specified a password.\n\nIf this nick isn't yours, please register your own nick at www.hedgewars.org\n\nPassword:")); + nickRegedDialog.setTextEchoMode(QLineEdit::Password); + nickRegedDialog.exec(); + + suppliedpass = nickRegedDialog.textValue(); + + if (nickRegedDialog.result() == QDialog::Rejected) { + clearPasswordHashes(true, true); + GoBack(); + return; + } + temphash = QCryptographicHash::hash(suppliedpass.toUtf8(), QCryptographicHash::Md5).toHex(); + config->setValue("net/temppasswordhash", temphash); + } + } + } + NetPassword(nick); } void HWForm::NetNickTaken(const QString & nick) @@ -1069,7 +1113,12 @@ if (!ok || newNick.isEmpty()) { - ForcedDisconnect(tr("No nickname supplied.")); + //ForcedDisconnect(tr("No nickname supplied.")); + int retry = RetryDialog("Hedgewars - Empty nickname", "No nickname supplied."); + GoBack(); + if (retry) { + NetConnectOfficialServer(); + } return; } @@ -1084,8 +1133,37 @@ void HWForm::NetAuthFailed() { // Set the password blank if case the user tries to join and enter his password again - config->setValue("net/passwordlength", 0); - config->setNetPasswordLength(0); + clearPasswordHashes(false, true); + + //Try to login again + bool retry = RetryDialog("Hedgewars - Wrong password", "You entered a wrong password."); + GoBack(); + + if (retry) { + NetConnectOfficialServer(); + } +} + +bool HWForm::RetryDialog(const QString & title, const QString & label) +{ + QMessageBox retryMsg(this); + retryMsg.setIcon(QMessageBox::Warning); + retryMsg.setWindowTitle(title); + retryMsg.setText(label); + retryMsg.setWindowModality(Qt::WindowModal); + + retryMsg.addButton(QMessageBox::Cancel); + + QPushButton *retryButton = retryMsg.addButton(QMessageBox::Ok); + retryButton->setText("Try Again"); + retryButton->setFocus(); + + retryMsg.exec(); + + if (retryMsg.clickedButton() == retryButton) { + return true; + } + return false; } void HWForm::NetTeamAccepted(const QString & team) @@ -1138,7 +1216,7 @@ connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&)), Qt::QueuedConnection); connect(hwnet, SIGNAL(RemoveNetTeam(const HWTeam&)), this, SLOT(RemoveNetTeam(const HWTeam&)), Qt::QueuedConnection); connect(hwnet, SIGNAL(TeamAccepted(const QString&)), this, SLOT(NetTeamAccepted(const QString&)), Qt::QueuedConnection); - connect(hwnet, SIGNAL(AskForPassword(const QString&)), this, SLOT(NetPassword(const QString&)), Qt::QueuedConnection); + connect(hwnet, SIGNAL(NickRegistered(const QString&)), this, SLOT(NetNickRegistered(const QString&)), Qt::QueuedConnection); connect(hwnet, SIGNAL(NickTaken(const QString&)), this, SLOT(NetNickTaken(const QString&)), Qt::QueuedConnection); connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed()), Qt::QueuedConnection); //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom())); @@ -1262,8 +1340,7 @@ //nick and pass stuff //remove temppasswordhash just in case - config->value("net/temppasswordhash", ""); - config->remove("net/temppasswordhash"); + clearPasswordHashes(true, false); //initialize QString hash = config->value("net/passwordhash", "").toString(); @@ -1288,8 +1365,16 @@ //if dialog close, create an error message if (hpd->exec() != QDialog::Accepted) { - ForcedDisconnect(tr("Login info not supplied.")); - delete hpd; + /*//ForcedDisconnect(tr("Login info not supplied.")); + int retry = RetryDialog("Hedgewars - Empty login info", "Login info not supplied."); + GoBack(); + delete hpd; + if (retry) { + NetConnectOfficialServer(); + } + //delete hpd;*/ + delete hpd; + GoBack(); return; } @@ -1297,23 +1382,40 @@ nickname = hpd->leNickname->text(); password = hpd->lePassword->text(); - //calculate temphash and set it into config - temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex(); - config->setValue("net/temppasswordhash", temphash); - - //if user wants to save password - bool save = hpd->cbSave->isChecked(); - config->setValue("net/savepassword", save); - if (save) // user wants to save password - { - config->setValue("net/passwordhash", temphash); - config->setValue("net/passwordlength", password.size()); - config->setNetPasswordLength(password.size()); - } + //check the nickname variable + if (nickname.isEmpty()) { + //ForcedDisconnect(tr("No nickname supplied.")); + int retry = RetryDialog("Hedgewars - Empty nickname", "No nickname supplied."); + GoBack(); + delete hpd; + if (retry) { + NetConnectOfficialServer(); + } + //delete hpd; + return; + } + + if (!password.isEmpty()) { + //calculate temphash and set it into config + temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex(); + config->setValue("net/temppasswordhash", temphash); + + //if user wants to save password + bool save = hpd->cbSave->isChecked(); + config->setValue("net/savepassword", save); + if (save) // user wants to save password + { + config->setValue("net/passwordhash", temphash); + config->setValue("net/passwordlength", password.size()); + config->setNetPasswordLength(password.size()); + } + } + else { + config->setValue("net/temppasswordhash", "EMPTY"); + } delete hpd; - //update nickname config->setValue("net/nick", nickname); config->updNetNick(); @@ -1327,8 +1429,7 @@ //if pass is none (hash is generated anyway), remove the hash if (password.size() <= 0) { - config->setValue("net/temppasswordhash", ""); - config->remove("net/temppasswordhash"); + clearPasswordHashes(true, false); } } diff -r 302a2521fe7a -r e4a0d980d1e2 QTfrontend/hwform.h --- a/QTfrontend/hwform.h Mon Dec 10 10:32:51 2012 -0500 +++ b/QTfrontend/hwform.h Mon Dec 10 22:09:54 2012 +0100 @@ -105,8 +105,10 @@ void NetWarning(const QString & wrnmsg); void NetGameEnter(); void NetPassword(const QString & nick); + void NetNickRegistered(const QString & nick); void NetNickTaken(const QString & nick); void NetAuthFailed(); + bool RetryDialog(const QString & title, const QString & label); void NetTeamAccepted(const QString& team); void AddNetTeam(const HWTeam& team); void RemoveNetTeam(const HWTeam& team); @@ -148,6 +150,7 @@ void CustomizePalettes(); void resizeEvent(QResizeEvent * event); //void keyReleaseEvent(QKeyEvent *event); + inline void clearPasswordHashes(bool clearTempHash, bool clearHash); enum PageIDs { diff -r 302a2521fe7a -r e4a0d980d1e2 QTfrontend/net/newnetclient.cpp --- a/QTfrontend/net/newnetclient.cpp Mon Dec 10 10:32:51 2012 -0500 +++ b/QTfrontend/net/newnetclient.cpp Mon Dec 10 22:09:54 2012 +0100 @@ -538,7 +538,7 @@ if (lst[0] == "ASKPASSWORD") { - emit AskForPassword(mynick); + emit NickRegistered(mynick); return; } @@ -573,6 +573,10 @@ if (lst[1] == "Authentication failed") { emit AuthFailed(); + m_game_connected = false; + Disconnect(); + //omitted 'emit disconnected()', we don't want the error message + return; } m_game_connected = false; Disconnect(); diff -r 302a2521fe7a -r e4a0d980d1e2 QTfrontend/net/newnetclient.h --- a/QTfrontend/net/newnetclient.h Mon Dec 10 10:32:51 2012 -0500 +++ b/QTfrontend/net/newnetclient.h Mon Dec 10 22:09:54 2012 +0100 @@ -90,7 +90,7 @@ void disconnected(const QString & reason); void Error(const QString & errmsg); void Warning(const QString & wrnmsg); - void AskForPassword(const QString & nick); + void NickRegistered(const QString & nick); void NickTaken(const QString & nick); void AuthFailed(); void EnteredGame();