QTfrontend/hwform.cpp
branch0.9.19
changeset 9081 7f04ad2cda54
parent 9063 5cab446e1341
child 9080 9b42757d7e71
equal deleted inserted replaced
8932:e095e3023682 9081:7f04ad2cda54
   151 
   151 
   152     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   152     ui.pageOptions->CBResolution->addItems(SDLInteraction::instance().getResolutions());
   153 
   153 
   154     config = new GameUIConfig(this, DataManager::instance().settingsFileName());
   154     config = new GameUIConfig(this, DataManager::instance().settingsFileName());
   155     frontendEffects = config->value("frontend/effects", true).toBool();
   155     frontendEffects = config->value("frontend/effects", true).toBool();
   156     playerHash = QString(QCryptographicHash::hash(config->value("net/nick","").toString().toUtf8(), QCryptographicHash::Md5).toHex());
   156     playerHash = QString(QCryptographicHash::hash(config->value("net/nick",tr("Guest")+QString("%1").arg(rand())).toString().toUtf8(), QCryptographicHash::Md5).toHex());
   157 
   157 
   158     ui.pageRoomsList->setSettings(config);
   158     ui.pageRoomsList->setSettings(config);
   159     ui.pageNetGame->setSettings(config);
   159     ui.pageNetGame->setSettings(config);
   160     ui.pageNetGame->chatWidget->setSettings(config);
   160     ui.pageNetGame->chatWidget->setSettings(config);
   161     ui.pageRoomsList->chatWidget->setSettings(config);
   161     ui.pageRoomsList->chatWidget->setSettings(config);
   316     //    this, SLOT(GoBack())); // executed third
   316     //    this, SLOT(GoBack())); // executed third
   317 
   317 
   318 
   318 
   319     connect(ui.pageMain->BtnNetLocal, SIGNAL(clicked()), this, SLOT(GoToNet()));
   319     connect(ui.pageMain->BtnNetLocal, SIGNAL(clicked()), this, SLOT(GoToNet()));
   320     connect(ui.pageMain->BtnNetOfficial, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   320     connect(ui.pageMain->BtnNetOfficial, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
   321 
       
   322     connect(ui.pageConnecting, SIGNAL(cancelConnection()), this, SLOT(GoBack()));
       
   323 
   321 
   324     connect(ui.pageVideos, SIGNAL(goBack()), config, SLOT(SaveVideosOptions()));
   322     connect(ui.pageVideos, SIGNAL(goBack()), config, SLOT(SaveVideosOptions()));
   325 
   323 
   326     ammoSchemeModel = new AmmoSchemeModel(this, cfgdir->absolutePath() + "/schemes.ini");
   324     ammoSchemeModel = new AmmoSchemeModel(this, cfgdir->absolutePath() + "/schemes.ini");
   327     ui.pageScheme->setModel(ammoSchemeModel);
   325     ui.pageScheme->setModel(ammoSchemeModel);
   470 {
   468 {
   471     QStringList teamslist = config->GetTeamsList();
   469     QStringList teamslist = config->GetTeamsList();
   472 
   470 
   473     if(teamslist.empty())
   471     if(teamslist.empty())
   474     {
   472     {
   475         QString currentNickName = config->value("net/nick","").toString().toUtf8();
   473         QString currentNickName = config->value("net/nick",tr("Guest")+QString("%1").arg(rand())).toString().toUtf8();
   476         QString teamName;
   474         QString teamName;
   477 
   475 
   478         if (currentNickName.isEmpty())
   476         if (currentNickName.isEmpty())
   479         {
   477         {
   480             teamName = tr("DefaultTeam");
   478             teamName = tr("DefaultTeam");
   596 #ifdef USE_XFIRE
   594 #ifdef USE_XFIRE
   597     updateXfire();
   595     updateXfire();
   598 #endif
   596 #endif
   599 
   597 
   600     qDebug("Leaving %s, entering %s", qPrintable(stringifyPageId(lastid)), qPrintable(stringifyPageId(id)));
   598     qDebug("Leaving %s, entering %s", qPrintable(stringifyPageId(lastid)), qPrintable(stringifyPageId(id)));
       
   599     if (lastid == ID_PAGE_MAIN)
       
   600     {
       
   601         ui.pageMain->resetNetworkChoice();
       
   602     }
   601 
   603 
   602     // pageEnter and pageLeave events
   604     // pageEnter and pageLeave events
   603     ((AbstractPage*)ui.Pages->widget(lastid))->triggerPageLeave();
   605     ((AbstractPage*)ui.Pages->widget(lastid))->triggerPageLeave();
   604     ((AbstractPage*)ui.Pages->widget(id))->triggerPageEnter();
   606     ((AbstractPage*)ui.Pages->widget(id))->triggerPageEnter();
   605 
   607 
  1371     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
  1373     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
  1372     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
  1374     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
  1373     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1375     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1374 
  1376 
  1375     //nick and pass stuff
  1377     //nick and pass stuff
  1376     QString nickname = config->value("net/nick", "").toString();
       
  1377 
       
  1378     hwnet->m_private_game = !(hostName == NETGAME_DEFAULT_SERVER && port == NETGAME_DEFAULT_PORT);
  1378     hwnet->m_private_game = !(hostName == NETGAME_DEFAULT_SERVER && port == NETGAME_DEFAULT_PORT);
  1379     if (hwnet->m_private_game == false)
  1379     if (hwnet->m_private_game == false && AskForNickAndPwd() != 0)
  1380         if (AskForNickAndPwd() != 0)
  1380         return;
  1381             return;
  1381 
  1382 
  1382     QString nickname = config->value("net/nick",tr("Guest")+QString("%1").arg(rand())).toString();
  1383     ui.pageRoomsList->setUser(nickname);
  1383     ui.pageRoomsList->setUser(nickname);
  1384     ui.pageNetGame->setUser(nickname);
  1384     ui.pageNetGame->setUser(nickname);
  1385 
  1385 
  1386     hwnet->Connect(hostName, port, nickname);
  1386     hwnet->Connect(hostName, port, nickname);
  1387 }
  1387 }
  1390 {
  1390 {
  1391     //remove temppasswordhash just in case
  1391     //remove temppasswordhash just in case
  1392     config->clearTempHash();
  1392     config->clearTempHash();
  1393 
  1393 
  1394     //initialize
  1394     //initialize
  1395     QString hash = config->passwordHash();
  1395     QString hash;
  1396     QString temphash = config->tempHash();
  1396     QString temphash;
  1397     QString nickname = config->value("net/nick", "").toString();
  1397     QString nickname;
  1398     QString password;
  1398     QString password;
  1399 
  1399 
  1400     //if something from login is missing, start dialog loop
  1400     do {
  1401     if (nickname.isEmpty() || hash.isEmpty())
  1401         nickname = config->value("net/nick",tr("Guest")+QString("%1").arg(rand())).toString();
  1402     {
  1402         hash = config->passwordHash();
  1403         while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())) //while a nickname, or both hashes are missing
  1403         temphash = config->tempHash();
  1404         {
  1404 
       
  1405         //if something from login is missing, start dialog loop
       
  1406         if (nickname.isEmpty() || hash.isEmpty()) {
  1405             //open dialog
  1407             //open dialog
  1406             HWPasswordDialog * pwDialog = new HWPasswordDialog(this);
  1408             HWPasswordDialog * pwDialog = new HWPasswordDialog(this);
  1407             // make the "new account" button dialog open a browser with the registration page
  1409             // make the "new account" button dialog open a browser with the registration page
  1408             connect(pwDialog->pbNewAccount, SIGNAL(clicked()), this, SLOT(openRegistrationPage()));
  1410             connect(pwDialog->pbNewAccount, SIGNAL(clicked()), this, SLOT(openRegistrationPage()));
  1409             pwDialog->cbSave->setChecked(config->value("net/savepassword", true).toBool());
  1411             pwDialog->cbSave->setChecked(config->value("net/savepassword", true).toBool());
  1416 
  1418 
  1417             //if dialog close, create an error message
  1419             //if dialog close, create an error message
  1418             if (pwDialog->exec() != QDialog::Accepted) {
  1420             if (pwDialog->exec() != QDialog::Accepted) {
  1419                 delete pwDialog;
  1421                 delete pwDialog;
  1420                 GoBack();
  1422                 GoBack();
  1421                 return -1;
  1423                 break;
  1422             }
  1424             }
  1423 
  1425 
  1424             //set nick and pass from the dialog
  1426             //set nick and pass from the dialog
  1425             nickname = pwDialog->leNickname->text();
  1427             nickname = pwDialog->leNickname->text();
  1426             password = pwDialog->lePassword->text();
  1428             password = pwDialog->lePassword->text();
       
  1429             bool save = pwDialog->cbSave->isChecked();
       
  1430             //clean up
       
  1431             delete pwDialog;
  1427 
  1432 
  1428             //check the nickname variable
  1433             //check the nickname variable
  1429             if (nickname.isEmpty()) {
  1434             if (nickname.isEmpty()) {
  1430                 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
  1435                 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
  1431                 GoBack();
  1436                 GoBack();
  1432                 delete pwDialog;
       
  1433                 if (retry) {
  1437                 if (retry) {
  1434                     if (hwnet->m_private_game) {
  1438                     if (hwnet->m_private_game) {
  1435                         QStringList list = hwnet->getHost().split(":");
  1439                         QStringList list = hwnet->getHost().split(":");
  1436                         NetConnectServer(list.at(0), list.at(1).toShort());
  1440                         NetConnectServer(list.at(0), list.at(1).toShort());
  1437                     } else
  1441                     } else
  1438                         NetConnectOfficialServer();
  1442                         NetConnectOfficialServer();
  1439                     }
  1443                 }
  1440                 return -1;
  1444                 break; //loop restart
       
  1445             } else {
       
  1446                 //update nickname if it's fine
       
  1447                 config->setValue("net/nick", nickname);
       
  1448                 config->updNetNick();
  1441             }
  1449             }
  1442 
  1450 
  1443             if (!password.isEmpty()) {
  1451             //check the password variable
       
  1452             if (password.isEmpty()) {
       
  1453                 config->clearPasswordHash();
       
  1454                 break;
       
  1455             }  else {
  1444                 //calculate temphash and set it into config
  1456                 //calculate temphash and set it into config
  1445                 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
  1457                 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
  1446                 config->setTempHash(temphash);
  1458                 config->setTempHash(temphash);
  1447 
  1459 
  1448                 //if user wants to save password
  1460                 //if user wants to save password
  1449                 bool save = pwDialog->cbSave->isChecked();
       
  1450                 config->setValue("net/savepassword", save);
  1461                 config->setValue("net/savepassword", save);
  1451                 if (save) // user wants to save password
  1462                 if (save) {
  1452                 {
  1463                     // user wants to save password
  1453                     ui.pageOptions->CBSavePassword->setChecked(true);
  1464                     ui.pageOptions->CBSavePassword->setChecked(true);
  1454                     config->setPasswordHash(temphash);
  1465                     config->setPasswordHash(temphash);
  1455                 }
  1466                 }
  1456             }
  1467             }
  1457             else {
  1468         }
  1458                 delete pwDialog;
  1469     } while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())); //while a nickname, or both hashes are missing
  1459                 config->setValue("net/nick", nickname);
  1470 
  1460                 config->updNetNick();
       
  1461                 config->clearPasswordHash();
       
  1462                 break;
       
  1463             }
       
  1464 
       
  1465             delete pwDialog;
       
  1466 
       
  1467             //update nickname
       
  1468             config->setValue("net/nick", nickname);
       
  1469             config->updNetNick();
       
  1470 
       
  1471             //and all the variables
       
  1472             hash = config->passwordHash();
       
  1473             temphash = config->tempHash();
       
  1474             nickname = config->value("net/nick", "").toString();
       
  1475         }
       
  1476     }
       
  1477     return 0;
  1471     return 0;
  1478 }
  1472 }
  1479 
  1473 
  1480 void HWForm::NetConnect()
  1474 void HWForm::NetConnect()
  1481 {
  1475 {
  1544     if (reason == "Reconnected too fast") { //TODO: this is a hack, which should be remade
  1538     if (reason == "Reconnected too fast") { //TODO: this is a hack, which should be remade
  1545         bool retry = RetryDialog(tr("Hedgewars - Connection error"), tr("You reconnected too fast.\nPlease wait a few seconds and try again."));
  1539         bool retry = RetryDialog(tr("Hedgewars - Connection error"), tr("You reconnected too fast.\nPlease wait a few seconds and try again."));
  1546         if (retry) {
  1540         if (retry) {
  1547             if (hwnet->m_private_game) {
  1541             if (hwnet->m_private_game) {
  1548                 QStringList list = hwnet->getHost().split(":");
  1542                 QStringList list = hwnet->getHost().split(":");
  1549                 NetConnectServer(list.at(0), list.at(1).toShort());
  1543                 NetConnectServer(list.at(0), list.at(1).toUInt());
  1550             } else
  1544             } else
  1551                 NetConnectOfficialServer();
  1545                 NetConnectOfficialServer();
  1552         }
  1546         }
  1553         else {
  1547         else {
  1554             while (ui.Pages->currentIndex() != ID_PAGE_NET
  1548             while (ui.Pages->currentIndex() != ID_PAGE_NET