QTfrontend/hwform.cpp
changeset 8720 5603527f9803
parent 8716 e09633d10f16
child 8722 2dead6b84bca
equal deleted inserted replaced
8719:0f55bcfe7f36 8720:5603527f9803
  1000     game->PlayDemo(demofilename, false);
  1000     game->PlayDemo(demofilename, false);
  1001 }
  1001 }
  1002 
  1002 
  1003 void HWForm::NetConnectQuick(const QString & host, quint16 port)
  1003 void HWForm::NetConnectQuick(const QString & host, quint16 port)
  1004 {
  1004 {
       
  1005     GoToPage(ID_PAGE_MAIN);
  1005     NetConnectServer(host, port);
  1006     NetConnectServer(host, port);
  1006 }
  1007 }
  1007 
  1008 
  1008 void HWForm::NetConnectServer(const QString & host, quint16 port)
  1009 void HWForm::NetConnectServer(const QString & host, quint16 port)
  1009 {
  1010 {
  1101     QString newNick = QInputDialog::getText(this, tr("Nickname"), tr("Someone already uses your nickname %1 on the server.\nPlease pick another nickname:").arg(nick), QLineEdit::Normal, nick, &ok);
  1102     QString newNick = QInputDialog::getText(this, tr("Nickname"), tr("Someone already uses your nickname %1 on the server.\nPlease pick another nickname:").arg(nick), QLineEdit::Normal, nick, &ok);
  1102 
  1103 
  1103     if (!ok || newNick.isEmpty())
  1104     if (!ok || newNick.isEmpty())
  1104     {
  1105     {
  1105         //ForcedDisconnect(tr("No nickname supplied."));
  1106         //ForcedDisconnect(tr("No nickname supplied."));
  1106     bool retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
  1107         bool retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
  1107     GoBack();
  1108         GoBack();
  1108         if (retry) {
  1109         if (retry) {
  1109             NetConnectOfficialServer();
  1110             if (hwnet->m_private_game) {
       
  1111                 QStringList list = hwnet->getHost().split(":");
       
  1112                 NetConnectServer(list.at(0), list.at(1).toShort());
       
  1113             } else
       
  1114                 NetConnectOfficialServer();
  1110         }
  1115         }
  1111         return;
  1116         return;
  1112     }
  1117     }
  1113 
  1118 
  1114     hwnet->NewNick(newNick);
  1119     hwnet->NewNick(newNick);
  1187 
  1192 
  1188 void HWForm::_NetConnect(const QString & hostName, quint16 port, QString nick)
  1193 void HWForm::_NetConnect(const QString & hostName, quint16 port, QString nick)
  1189 {
  1194 {
  1190     Q_UNUSED(nick);
  1195     Q_UNUSED(nick);
  1191 
  1196 
  1192     if(hwnet)
  1197     if (hwnet) {
  1193     {
  1198         // destroy old connection
  1194         hwnet->Disconnect();
  1199         hwnet->Disconnect();
  1195         delete hwnet;
  1200         delete hwnet;
  1196         hwnet=0;
  1201         hwnet = NULL;
  1197     }
  1202     }
  1198 
  1203 
  1199     hwnet = new HWNewNet();
  1204     hwnet = new HWNewNet();
  1200 
  1205 
  1201     GoToPage(ID_PAGE_CONNECTING);
  1206     GoToPage(ID_PAGE_CONNECTING);
  1335 // config stuff
  1340 // config stuff
  1336     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
  1341     connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &)));
  1337     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
  1342     connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &)));
  1338     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1343     connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig()));
  1339 
  1344 
  1340 //nick and pass stuff
  1345     //nick and pass stuff
  1341 
  1346     QString nickname = config->value("net/nick", "").toString();
       
  1347 
       
  1348     hwnet->m_private_game = !(hostName == "netserver.hedgewars.org" && port == NETGAME_DEFAULT_PORT);
       
  1349     if (hwnet->m_private_game == false)
       
  1350         if (AskForNickAndPwd() != 0)
       
  1351             return;
       
  1352 
       
  1353     ui.pageRoomsList->setUser(nickname);
       
  1354     ui.pageNetGame->setUser(nickname);
       
  1355 
       
  1356     hwnet->Connect(hostName, port, nickname);
       
  1357 }
       
  1358 
       
  1359 int HWForm::AskForNickAndPwd(void)
       
  1360 {
  1342     //remove temppasswordhash just in case
  1361     //remove temppasswordhash just in case
  1343     config->clearTempHash();
  1362     config->clearTempHash();
  1344 
  1363 
  1345     //initialize
  1364     //initialize
  1346     QString hash = config->passwordHash();
  1365     QString hash = config->passwordHash();
  1367 
  1386 
  1368             //if dialog close, create an error message
  1387             //if dialog close, create an error message
  1369             if (pwDialog->exec() != QDialog::Accepted) {
  1388             if (pwDialog->exec() != QDialog::Accepted) {
  1370                 delete pwDialog;
  1389                 delete pwDialog;
  1371                 GoBack();
  1390                 GoBack();
  1372                 return;
  1391                 return -1;
  1373             }
  1392             }
  1374 
  1393 
  1375             //set nick and pass from the dialog
  1394             //set nick and pass from the dialog
  1376             nickname = pwDialog->leNickname->text();
  1395             nickname = pwDialog->leNickname->text();
  1377             password = pwDialog->lePassword->text();
  1396             password = pwDialog->lePassword->text();
  1380             if (nickname.isEmpty()) {
  1399             if (nickname.isEmpty()) {
  1381                 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
  1400                 int retry = RetryDialog(tr("Hedgewars - Empty nickname"), tr("No nickname supplied."));
  1382                 GoBack();
  1401                 GoBack();
  1383                 delete pwDialog;
  1402                 delete pwDialog;
  1384                 if (retry) {
  1403                 if (retry) {
  1385                     NetConnectOfficialServer();
  1404                     if (hwnet->m_private_game) {
  1386                 }
  1405                         QStringList list = hwnet->getHost().split(":");
  1387                 return;
  1406                         NetConnectServer(list.at(0), list.at(1).toShort());
       
  1407                     } else
       
  1408                         NetConnectOfficialServer();
       
  1409                     }
       
  1410                 return -1;
  1388             }
  1411             }
  1389 
  1412 
  1390             if (!password.isEmpty()) {
  1413             if (!password.isEmpty()) {
  1391                 //calculate temphash and set it into config
  1414                 //calculate temphash and set it into config
  1392                 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
  1415                 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex();
  1419             hash = config->passwordHash();
  1442             hash = config->passwordHash();
  1420             temphash = config->tempHash();
  1443             temphash = config->tempHash();
  1421             nickname = config->value("net/nick", "").toString();
  1444             nickname = config->value("net/nick", "").toString();
  1422         }
  1445         }
  1423     }
  1446     }
  1424 
  1447     return 0;
  1425     ui.pageRoomsList->setUser(nickname);
  1448 }
  1426     ui.pageNetGame->setUser(nickname);
       
  1427 
       
  1428     hwnet->Connect(hostName, port, nickname);
       
  1429 }
       
  1430 
       
  1431 
       
  1432 
  1449 
  1433 void HWForm::NetConnect()
  1450 void HWForm::NetConnect()
  1434 {
  1451 {
  1435     HWHostPortDialog * hpd = new HWHostPortDialog(this);
  1452     HWHostPortDialog * hpd = new HWHostPortDialog(this);
  1436     hpd->leHost->setText(*netHost);
  1453     hpd->leHost->setText(*netHost);
  1495 void HWForm::ForcedDisconnect(const QString & reason)
  1512 void HWForm::ForcedDisconnect(const QString & reason)
  1496 {
  1513 {
  1497     if (reason == "Reconnected too fast") { //TODO: this is a hack, which should be remade
  1514     if (reason == "Reconnected too fast") { //TODO: this is a hack, which should be remade
  1498         bool retry = RetryDialog(tr("Hedgewars - Connection error"), tr("You reconnected too fast.\nPlease wait a few seconds and try again."));
  1515         bool retry = RetryDialog(tr("Hedgewars - Connection error"), tr("You reconnected too fast.\nPlease wait a few seconds and try again."));
  1499         if (retry) {
  1516         if (retry) {
  1500             NetConnectOfficialServer();
  1517             if (hwnet->m_private_game) {
       
  1518                 QStringList list = hwnet->getHost().split(":");
       
  1519                 NetConnectServer(list.at(0), list.at(1).toShort());
       
  1520             } else
       
  1521                 NetConnectOfficialServer();
  1501         }
  1522         }
  1502         else {
  1523         else {
  1503             while (ui.Pages->currentIndex() != ID_PAGE_NET
  1524             while (ui.Pages->currentIndex() != ID_PAGE_NET
  1504                 && ui.Pages->currentIndex() != ID_PAGE_MAIN)
  1525                 && ui.Pages->currentIndex() != ID_PAGE_MAIN)
  1505             {
  1526             {
  1508         }
  1529         }
  1509         return;
  1530         return;
  1510     }
  1531     }
  1511     if (pnetserver)
  1532     if (pnetserver)
  1512         return; // we have server - let it care of all things
  1533         return; // we have server - let it care of all things
  1513     if (hwnet)
  1534     if (hwnet) {
  1514     {
       
  1515         QString errorStr = QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"'));
  1535         QString errorStr = QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"'));
  1516         MessageDialog::ShowErrorMessage(errorStr, this);
  1536         MessageDialog::ShowErrorMessage(errorStr, this);
  1517     }
  1537     }
  1518 
  1538 
  1519     while (ui.Pages->currentIndex() != ID_PAGE_NET
  1539     while (ui.Pages->currentIndex() != ID_PAGE_NET