--- a/QTfrontend/gameuiconfig.cpp Tue Dec 11 15:45:20 2012 +0100
+++ b/QTfrontend/gameuiconfig.cpp Wed Dec 12 15:57:01 2012 +0100
@@ -237,10 +237,9 @@
setValue("net/passwordhash", "");
setValue("net/passwordlength", 0);
}
- else if (netPasswordIsValid() && Form->ui.pageOptions->CBSavePassword->isChecked())
- {
- setValue("net/passwordhash", netPasswordHash());
- setValue("net/passwordlength", netPasswordLength());
+ else if (netPasswordIsValid() && Form->ui.pageOptions->CBSavePassword->isChecked()) {
+ setValue("net/passwordhash", "");
+ setValue("net/passwordlength", 0);
}
setValue("net/savepassword", Form->ui.pageOptions->CBSavePassword->isChecked());
@@ -482,6 +481,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());
+ netPasswordLength();
+}
+
+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 Tue Dec 11 15:45:20 2012 +0100
+++ b/QTfrontend/gameuiconfig.h Wed Dec 12 15:57:01 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 Tue Dec 11 15:45:20 2012 +0100
+++ b/QTfrontend/hwform.cpp Wed Dec 12 15:57:01 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,52 +1057,42 @@
}
//Remove temporary hash from config
- 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);
- }
+ config->clearPasswordHash();
}
void HWForm::NetNickRegistered(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();
+ qDebug("NETNICKREGISTERED");
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();
+ qDebug("NNR - HASH EMPTY");
+ if (temphash.isEmpty()) { //If the user enters a registered nick with no password
+ qDebug("NNR - TEMPHASH EMTPY");
+ 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();
- if (nickRegedDialog.result() == QDialog::Rejected) {
- clearPasswordHashes(true, true);
- GoBack();
- return;
- }
- temphash = QCryptographicHash::hash(suppliedpass.toUtf8(), QCryptographicHash::Md5).toHex();
- config->setValue("net/temppasswordhash", temphash);
- }
- }
- }
+ 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);
}
@@ -1133,8 +1123,8 @@
void HWForm::NetAuthFailed()
{
// Set the password blank if case the user tries to join and enter his password again
- clearPasswordHashes(false, true);
-
+ config->clearTempHash();
+
//Try to login again
bool retry = RetryDialog("Hedgewars - Wrong password", "You entered a wrong password.");
GoBack();
@@ -1336,93 +1326,87 @@
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
- clearPasswordHashes(true, false);
-
+ 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)
- {
- delete hpd;
- GoBack();
+ //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();
+ //set nick and pass from the dialog
+ nickname = pwDialog->leNickname->text();
+ password = pwDialog->lePassword->text();
- //check the nickname variable
- if (nickname.isEmpty()) {
- //ForcedDisconnect(tr("No nickname supplied."));
- int retry = RetryDialog("Hedgewars - Empty nickname", "No nickname supplied.");
- GoBack();
- delete hpd;
+ //check the nickname variable
+ if (nickname.isEmpty()) {
+ int retry = RetryDialog("Hedgewars - Empty nickname", "No nickname supplied.");
+ GoBack();
+ delete pwDialog;
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");
- }
+ return;
+ }
+
+ if (!password.isEmpty()) {
+ //calculate temphash and set it into config
+ temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
+ config->setTempHash(temphash);
- delete hpd;
+ //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);
+ config->setNetPasswordLength(password.size());
+ }
+ }
+ 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) {
- clearPasswordHashes(true, false);
- }
+
+ //and all the variables
+ hash = config->passwordHash();
+ temphash = config->tempHash();
+ nickname = config->value("net/nick", "").toString();
+ }
}
ui.pageRoomsList->setUser(nickname);
--- a/QTfrontend/hwform.h Tue Dec 11 15:45:20 2012 +0100
+++ b/QTfrontend/hwform.h Wed Dec 12 15:57:01 2012 +0100
@@ -150,7 +150,6 @@
void CustomizePalettes();
void resizeEvent(QResizeEvent * event);
//void keyReleaseEvent(QKeyEvent *event);
- inline void clearPasswordHashes(bool clearTempHash, bool clearHash);
enum PageIDs
{