--- a/QTfrontend/gameuiconfig.cpp Fri Dec 14 09:58:26 2012 -0500
+++ b/QTfrontend/gameuiconfig.cpp Fri Dec 14 18:57:31 2012 +0100
@@ -233,11 +233,13 @@
setValue("audio/volume", Form->ui.pageOptions->volumeBox->value());
setValue("net/nick", netNick());
- if (netPasswordIsValid() && Form->ui.pageOptions->CBSavePassword->isChecked())
- {
- setValue("net/passwordhash", netPasswordHash());
- setValue("net/passwordlength", netPasswordLength());
+ if (netPasswordIsValid() && Form->ui.pageOptions->CBSavePassword->isChecked()) {
+ setPasswordHash(netPasswordHash());
}
+ else if(!Form->ui.pageOptions->CBSavePassword->isChecked()) {
+ clearPasswordHash();
+ }
+
setValue("net/savepassword", Form->ui.pageOptions->CBSavePassword->isChecked());
setValue("net/ip", *netHost);
setValue("net/port", netPort);
@@ -477,6 +479,38 @@
return (netPasswordLength() == 0 || Form->ui.pageOptions->editNetPassword->text() != QString(netPasswordLength(), '*'));
}
+void GameUIConfig::clearPasswordHash()
+{
+ setValue("net/passwordhash", QString());
+ setValue("net/passwordlength", 0);
+}
+
+void GameUIConfig::setPasswordHash(const QString & passwordhash)
+{
+ setValue("net/passwordhash", passwordhash);
+ setValue("net/passwordlength", passwordhash.size()/4);
+ setNetPasswordLength(passwordhash.size()/4); //the hash.size() is divided by 4 let PAGE_SETUP use a reasonable number of stars to display the PW
+}
+
+QString GameUIConfig::passwordHash()
+{
+ return value("net/passwordhash").toString();
+}
+
+void GameUIConfig::clearTempHash()
+{
+ setTempHash(QString());
+}
+
+void GameUIConfig::setTempHash(const QString & temphash)
+{
+ this->temphash = temphash;
+}
+
+QString GameUIConfig::tempHash() {
+ return this->temphash;
+}
+
// When hedgewars launches, the password field is set with null characters. If the user tries to edit the field and there are such characters, then clear the field
bool GameUIConfig::eventFilter(QObject *object, QEvent *event)
{
--- a/QTfrontend/gameuiconfig.h Fri Dec 14 09:58:26 2012 -0500
+++ b/QTfrontend/gameuiconfig.h Fri Dec 14 18:57:31 2012 +0100
@@ -52,6 +52,12 @@
QString netNick();
QByteArray netPasswordHash();
int netPasswordLength();
+ void clearPasswordHash();
+ void setPasswordHash(const QString & passwordhash);
+ QString passwordHash();
+ void clearTempHash();
+ void setTempHash(const QString & temphash);
+ QString tempHash();
void setNetPasswordLength(int passwordLength);
bool isReducedQuality() const;
bool isFrontendEffects() const;
@@ -87,6 +93,7 @@
bool netPasswordIsValid();
bool eventFilter(QObject *object, QEvent *event);
quint8 depth;
+ QString temphash;
};
#endif
--- a/QTfrontend/hwform.cpp Fri Dec 14 09:58:26 2012 -0500
+++ b/QTfrontend/hwform.cpp Fri Dec 14 18:57:31 2012 +0100
@@ -1041,8 +1041,8 @@
void HWForm::NetPassword(const QString & nick)
{
//Get hashes
- QString hash = config->value("net/passwordhash", "").toString();
- QString temphash = config->value("net/temppasswordhash", "").toString();
+ QString hash = config->passwordHash();
+ QString temphash = config->tempHash();
//Check them
@@ -1057,9 +1057,41 @@
}
//Remove temporary hash from config
- QString key = "net/temppasswordhash";
- config->setValue(key, "");
- config->remove(key);
+ config->clearTempHash();
+}
+
+void HWForm::NetNickRegistered(const QString & nick)
+{
+ //Get hashes
+ QString hash = config->passwordHash();
+ QString temphash = config->tempHash();
+
+ 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) {
+ config->clearPasswordHash();
+ config->clearTempHash();
+ GoBack();
+ return;
+ }
+ temphash = QCryptographicHash::hash(suppliedpass.toUtf8(), QCryptographicHash::Md5).toHex();
+ config->setTempHash(temphash);
+ }
+ }
+ }
+ NetPassword(nick);
}
void HWForm::NetNickTaken(const QString & nick)
@@ -1069,7 +1101,12 @@
if (!ok || newNick.isEmpty())
{
- ForcedDisconnect(tr("No nickname supplied."));
+ //ForcedDisconnect(tr("No nickname supplied."));
+ bool retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
+ GoBack();
+ if (retry) {
+ NetConnectOfficialServer();
+ }
return;
}
@@ -1084,8 +1121,39 @@
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);
+ config->clearTempHash();
+
+ //Try to login again
+ bool retry = RetryDialog(tr("Hedgewars - Wrong password"), tr("You entered a wrong password."));
+ GoBack();
+
+ config->clearPasswordHash();
+ config->clearTempHash();
+ 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(tr("Try Again"));
+ retryButton->setFocus();
+
+ retryMsg.exec();
+
+ if (retryMsg.clickedButton() == retryButton) {
+ return true;
+ }
+ return false;
}
void HWForm::NetTeamAccepted(const QString & team)
@@ -1138,7 +1206,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()));
@@ -1258,78 +1326,86 @@
connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
-
+
//nick and pass stuff
-
+
//remove temppasswordhash just in case
- config->value("net/temppasswordhash", "");
- config->remove("net/temppasswordhash");
-
+ config->clearTempHash();
+
//initialize
- QString hash = config->value("net/passwordhash", "").toString();
- QString temphash = config->value("net/temppasswordhash", "").toString();
+ QString hash = config->passwordHash();
+ QString temphash = config->tempHash();
QString nickname = config->value("net/nick", "").toString();
QString password;
-
+
if (nickname.isEmpty() || hash.isEmpty()) { //if something from login is missing, start dialog loop
-
- while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())) //while a nickname, or both hashes are missing
- {
- //open dialog
- HWPasswordDialog * hpd = new HWPasswordDialog(this);
- hpd->cbSave->setChecked(config->value("net/savepassword", true).toBool());
+
+ while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())) //while a nickname, or both hashes are missing
+ {
+ //open dialog
+ HWPasswordDialog * pwDialog = new HWPasswordDialog(this);
+ pwDialog->cbSave->setChecked(config->value("net/savepassword", true).toBool());
- //if nickname is present, put it into the field
- if (!nickname.isEmpty()) {
- hpd->leNickname->setText(nickname);
- hpd->lePassword->setFocus();
- }
+ //if nickname is present, put it into the field
+ if (!nickname.isEmpty()) {
+ pwDialog->leNickname->setText(nickname);
+ pwDialog->lePassword->setFocus();
+ }
- //if dialog close, create an error message
- if (hpd->exec() != QDialog::Accepted)
- {
- ForcedDisconnect(tr("Login info not supplied."));
- delete hpd;
+ //if dialog close, create an error message
+ if (pwDialog->exec() != QDialog::Accepted) {
+ delete pwDialog;
+ GoBack();
return;
}
- //set nick and pass from the dialog
- 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);
+ //set nick and pass from the dialog
+ nickname = pwDialog->leNickname->text();
+ password = pwDialog->lePassword->text();
- //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()) {
+ int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
+ GoBack();
+ delete pwDialog;
+ if (retry) {
+ NetConnectOfficialServer();
+ }
+ return;
}
- delete hpd;
+ if (!password.isEmpty()) {
+ //calculate temphash and set it into config
+ temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
+ config->setTempHash(temphash);
+ //if user wants to save password
+ bool save = pwDialog->cbSave->isChecked();
+ config->setValue("net/savepassword", save);
+ if (save) // user wants to save password
+ {
+ config->setPasswordHash(temphash);
+ }
+ }
+ else {
+ delete pwDialog;
+ config->setValue("net/nick", nickname);
+ config->updNetNick();
+ config->clearPasswordHash();
+ break;
+ }
- //update nickname
+ delete pwDialog;
+
+ //update nickname
config->setValue("net/nick", nickname);
config->updNetNick();
-
- //and all the variables
- hash = config->value("net/passwordhash", "").toString();
- temphash = config->value("net/temppasswordhash", "").toString();
- nickname = config->value("net/nick", "").toString();
- }
-
-
- //if pass is none (hash is generated anyway), remove the hash
- if (password.size() <= 0) {
- config->setValue("net/temppasswordhash", "");
- config->remove("net/temppasswordhash");
- }
+
+ //and all the variables
+ hash = config->passwordHash();
+ temphash = config->tempHash();
+ nickname = config->value("net/nick", "").toString();
+ }
}
ui.pageRoomsList->setUser(nickname);
@@ -1404,6 +1480,21 @@
void HWForm::ForcedDisconnect(const QString & reason)
{
+ if (reason == "Reconnected too fast") { //TODO: this is a hack, which should be remade
+ bool retry = RetryDialog(tr("Hedgewars - Connection error"), tr("You reconnected too fast.\nPlease wait a few seconds and try again."));
+ if (retry) {
+ NetConnectOfficialServer();
+ }
+ else {
+ while (ui.Pages->currentIndex() != ID_PAGE_NET
+ && ui.Pages->currentIndex() != ID_PAGE_NETTYPE
+ && ui.Pages->currentIndex() != ID_PAGE_MAIN)
+ {
+ GoBack();
+ }
+ }
+ return;
+ }
if (pnetserver)
return; // we have server - let it care of all things
if (hwnet)
--- a/QTfrontend/hwform.h Fri Dec 14 09:58:26 2012 -0500
+++ b/QTfrontend/hwform.h Fri Dec 14 18:57:31 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);
--- a/QTfrontend/net/newnetclient.cpp Fri Dec 14 09:58:26 2012 -0500
+++ b/QTfrontend/net/newnetclient.cpp Fri Dec 14 18:57:31 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();
--- a/QTfrontend/net/newnetclient.h Fri Dec 14 09:58:26 2012 -0500
+++ b/QTfrontend/net/newnetclient.h Fri Dec 14 18:57:31 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();