QTfrontend/hwform.cpp
changeset 8986 f7bb323a6934
parent 8982 0c0141cf851a
child 9033 b0ed8608303f
equal deleted inserted replaced
8985:fe8d1a476f0b 8986:f7bb323a6934
  1375     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
  1375     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
  1376     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
  1376     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
  1377     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1377     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1378 
  1378 
  1379     //nick and pass stuff
  1379     //nick and pass stuff
       
  1380     hwnet->m_private_game = !(hostName == NETGAME_DEFAULT_SERVER && port == NETGAME_DEFAULT_PORT);
       
  1381     if (hwnet->m_private_game == false && AskForNickAndPwd() != 0)
       
  1382         return;
       
  1383 
  1380     QString nickname = config->value("net/nick", "").toString();
  1384     QString nickname = config->value("net/nick", "").toString();
  1381 
       
  1382     hwnet->m_private_game = !(hostName == NETGAME_DEFAULT_SERVER && port == NETGAME_DEFAULT_PORT);
       
  1383     if (hwnet->m_private_game == false)
       
  1384         if (AskForNickAndPwd() != 0)
       
  1385             return;
       
  1386 
       
  1387     ui.pageRoomsList->setUser(nickname);
  1385     ui.pageRoomsList->setUser(nickname);
  1388     ui.pageNetGame->setUser(nickname);
  1386     ui.pageNetGame->setUser(nickname);
  1389 
  1387 
  1390     hwnet->Connect(hostName, port, nickname);
  1388     hwnet->Connect(hostName, port, nickname);
  1391 }
  1389 }
  1394 {
  1392 {
  1395     //remove temppasswordhash just in case
  1393     //remove temppasswordhash just in case
  1396     config->clearTempHash();
  1394     config->clearTempHash();
  1397 
  1395 
  1398     //initialize
  1396     //initialize
  1399     QString hash = config->passwordHash();
  1397     QString hash;
  1400     QString temphash = config->tempHash();
  1398     QString temphash;
  1401     QString nickname = config->value("net/nick", "").toString();
  1399     QString nickname;
  1402     QString password;
  1400     QString password;
  1403 
  1401 
  1404     //if something from login is missing, start dialog loop
  1402     do {
  1405     if (nickname.isEmpty() || hash.isEmpty())
  1403         nickname = config->value("net/nick", "").toString();
  1406     {
  1404         hash = config->passwordHash();
  1407         while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())) //while a nickname, or both hashes are missing
  1405         temphash = config->tempHash();
  1408         {
  1406 
       
  1407         //if something from login is missing, start dialog loop
       
  1408         if (nickname.isEmpty() || hash.isEmpty()) {
  1409             //open dialog
  1409             //open dialog
  1410             HWPasswordDialog * pwDialog = new HWPasswordDialog(this);
  1410             HWPasswordDialog * pwDialog = new HWPasswordDialog(this);
  1411             // make the "new account" button dialog open a browser with the registration page
  1411             // make the "new account" button dialog open a browser with the registration page
  1412             connect(pwDialog->pbNewAccount, SIGNAL(clicked()), this, SLOT(openRegistrationPage()));
  1412             connect(pwDialog->pbNewAccount, SIGNAL(clicked()), this, SLOT(openRegistrationPage()));
  1413             pwDialog->cbSave->setChecked(config->value("net/savepassword", true).toBool());
  1413             pwDialog->cbSave->setChecked(config->value("net/savepassword", true).toBool());
  1420 
  1420 
  1421             //if dialog close, create an error message
  1421             //if dialog close, create an error message
  1422             if (pwDialog->exec() != QDialog::Accepted) {
  1422             if (pwDialog->exec() != QDialog::Accepted) {
  1423                 delete pwDialog;
  1423                 delete pwDialog;
  1424                 GoBack();
  1424                 GoBack();
  1425                 return -1;
  1425                 break;
  1426             }
  1426             }
  1427 
  1427 
  1428             //set nick and pass from the dialog
  1428             //set nick and pass from the dialog
  1429             nickname = pwDialog->leNickname->text();
  1429             nickname = pwDialog->leNickname->text();
  1430             password = pwDialog->lePassword->text();
  1430             password = pwDialog->lePassword->text();
       
  1431             bool save = pwDialog->cbSave->isChecked();
       
  1432             //clean up
       
  1433             delete pwDialog;
  1431 
  1434 
  1432             //check the nickname variable
  1435             //check the nickname variable
  1433             if (nickname.isEmpty()) {
  1436             if (nickname.isEmpty()) {
  1434                 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
  1437                 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
  1435                 GoBack();
  1438                 GoBack();
  1436                 delete pwDialog;
       
  1437                 if (retry) {
  1439                 if (retry) {
  1438                     if (hwnet->m_private_game) {
  1440                     if (hwnet->m_private_game) {
  1439                         QStringList list = hwnet->getHost().split(":");
  1441                         QStringList list = hwnet->getHost().split(":");
  1440                         NetConnectServer(list.at(0), list.at(1).toShort());
  1442                         NetConnectServer(list.at(0), list.at(1).toShort());
  1441                     } else
  1443                     } else
  1442                         NetConnectOfficialServer();
  1444                         NetConnectOfficialServer();
  1443                     }
  1445                 }
  1444                 return -1;
  1446                 break; //loop restart
       
  1447             } else {
       
  1448                 //update nickname if it's fine
       
  1449                 config->setValue("net/nick", nickname);
       
  1450                 config->updNetNick();
  1445             }
  1451             }
  1446 
  1452 
  1447             if (!password.isEmpty()) {
  1453             //check the password variable
       
  1454             if (password.isEmpty()) {
       
  1455                 config->clearPasswordHash();
       
  1456                 break;
       
  1457             }  else {
  1448                 //calculate temphash and set it into config
  1458                 //calculate temphash and set it into config
  1449                 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
  1459                 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
  1450                 config->setTempHash(temphash);
  1460                 config->setTempHash(temphash);
  1451 
  1461 
  1452                 //if user wants to save password
  1462                 //if user wants to save password
  1453                 bool save = pwDialog->cbSave->isChecked();
       
  1454                 config->setValue("net/savepassword", save);
  1463                 config->setValue("net/savepassword", save);
  1455                 if (save) // user wants to save password
  1464                 if (save) {
  1456                 {
  1465                     // user wants to save password
  1457                     ui.pageOptions->CBSavePassword->setChecked(true);
  1466                     ui.pageOptions->CBSavePassword->setChecked(true);
  1458                     config->setPasswordHash(temphash);
  1467                     config->setPasswordHash(temphash);
  1459                 }
  1468                 }
  1460             }
  1469             }
  1461             else {
  1470         }
  1462                 delete pwDialog;
  1471     } while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())); //while a nickname, or both hashes are missing
  1463                 config->setValue("net/nick", nickname);
  1472 
  1464                 config->updNetNick();
       
  1465                 config->clearPasswordHash();
       
  1466                 break;
       
  1467             }
       
  1468 
       
  1469             delete pwDialog;
       
  1470 
       
  1471             //update nickname
       
  1472             config->setValue("net/nick", nickname);
       
  1473             config->updNetNick();
       
  1474 
       
  1475             //and all the variables
       
  1476             hash = config->passwordHash();
       
  1477             temphash = config->tempHash();
       
  1478             nickname = config->value("net/nick", "").toString();
       
  1479         }
       
  1480     }
       
  1481     return 0;
  1473     return 0;
  1482 }
  1474 }
  1483 
  1475 
  1484 void HWForm::NetConnect()
  1476 void HWForm::NetConnect()
  1485 {
  1477 {