751 void HWForm::NetConnectOfficialServer() |
752 void HWForm::NetConnectOfficialServer() |
752 { |
753 { |
753 NetConnectServer("netserver.hedgewars.org", 46631); |
754 NetConnectServer("netserver.hedgewars.org", 46631); |
754 } |
755 } |
755 |
756 |
756 void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick) |
757 void HWForm::NetPassword(const QString & nick) |
|
758 { |
|
759 bool ok = false; |
|
760 int passLength = config->value("net/passwordlength", 0).toInt(); |
|
761 QString hash = config->value("net/passwordhash", "").toString(); |
|
762 |
|
763 // If the password is blank, ask the user to enter one in |
|
764 if (passLength == 0) |
|
765 { |
|
766 QString password = QInputDialog::getText(this, tr("Password"), tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(nick), QLineEdit::Password, passLength==0?NULL:QString(passLength,'\0'), &ok); |
|
767 |
|
768 if (!ok) { |
|
769 ForcedDisconnect(tr("No password supplied.")); |
|
770 return; |
|
771 } |
|
772 |
|
773 hash = QCryptographicHash::hash(password.toLatin1(), QCryptographicHash::Md5).toHex(); |
|
774 config->setValue("net/passwordhash", hash); |
|
775 config->setValue("net/passwordlength", password.size()); |
|
776 config->setNetPasswordLength(password.size()); |
|
777 } |
|
778 |
|
779 hwnet->SendPasswordHash(hash); |
|
780 } |
|
781 |
|
782 void HWForm::NetNickTaken(const QString & nick) |
|
783 { |
|
784 bool ok = false; |
|
785 QString newNick = QInputDialog::getText(this, tr("Nickname"), tr("Some one already uses\n your nickname %1\non the server.\nPlease pick another nickname:").arg(nick), QLineEdit::Normal, nick, &ok); |
|
786 |
|
787 if (!ok || newNick.isEmpty()) { |
|
788 ForcedDisconnect(tr("No nickname supplied.")); |
|
789 return; |
|
790 } |
|
791 |
|
792 hwnet->NewNick(newNick); |
|
793 config->setValue("net/nick", newNick); |
|
794 config->updNetNick(); |
|
795 } |
|
796 |
|
797 void HWForm::NetAuthFailed() |
|
798 { |
|
799 // Set the password blank if case the user tries to join and enter his password again |
|
800 config->setValue("net/passwordlength", 0); |
|
801 config->setNetPasswordLength(0); |
|
802 } |
|
803 |
|
804 void HWForm::NetTeamAccepted(const QString & team) |
|
805 { |
|
806 ui.pageNetGame->pNetTeamsWidget->changeTeamStatus(team); |
|
807 } |
|
808 |
|
809 void HWForm::NetError(const QString & errmsg) |
|
810 { |
|
811 switch (ui.Pages->currentIndex()) |
|
812 { |
|
813 case ID_PAGE_INGAME: |
|
814 ShowErrorMessage(errmsg); |
|
815 // no break |
|
816 case ID_PAGE_NETGAME: |
|
817 ui.pageNetGame->pChatWidget->addLine("Error",errmsg); |
|
818 break; |
|
819 default: |
|
820 ui.pageRoomsList->chatWidget->addLine("Error",errmsg); |
|
821 } |
|
822 } |
|
823 |
|
824 void HWForm::NetWarning(const QString & wrnmsg) |
|
825 { |
|
826 if (ui.Pages->currentIndex() == ID_PAGE_NETGAME || ui.Pages->currentIndex() == ID_PAGE_INGAME) |
|
827 ui.pageNetGame->pChatWidget->addLine("Warning",wrnmsg); |
|
828 else |
|
829 ui.pageRoomsList->chatWidget->addLine("Warning",wrnmsg); |
|
830 } |
|
831 |
|
832 void HWForm::_NetConnect(const QString & hostName, quint16 port, QString nick) |
757 { |
833 { |
758 if(hwnet) { |
834 if(hwnet) { |
759 hwnet->Disconnect(); |
835 hwnet->Disconnect(); |
760 delete hwnet; |
836 delete hwnet; |
761 hwnet=0; |
837 hwnet=0; |
762 } |
838 } |
763 |
839 |
764 ui.pageRoomsList->chatWidget->clear(); |
840 ui.pageRoomsList->chatWidget->clear(); |
765 |
841 |
766 hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget); |
842 hwnet = new HWNewNet(); |
767 |
843 |
768 GoToPage(ID_PAGE_CONNECTING); |
844 GoToPage(ID_PAGE_CONNECTING); |
769 |
|
770 connect(hwnet, SIGNAL(showMessage(const QString &)), this, SLOT(ShowErrorMessage(const QString &)), Qt::QueuedConnection); |
|
771 |
845 |
772 connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame())); |
846 connect(hwnet, SIGNAL(AskForRunGame()), this, SLOT(CreateNetGame())); |
773 connect(hwnet, SIGNAL(Connected()), this, SLOT(NetConnected())); |
847 connect(hwnet, SIGNAL(Connected()), this, SLOT(NetConnected())); |
|
848 connect(hwnet, SIGNAL(Error(const QString&)), this, SLOT(NetError(const QString&))); |
|
849 connect(hwnet, SIGNAL(Warning(const QString&)), this, SLOT(NetWarning(const QString&))); |
774 connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
850 connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter())); |
775 connect(hwnet, SIGNAL(LeftRoom()), this, SLOT(NetLeftRoom())); |
851 connect(hwnet, SIGNAL(LeftRoom(const QString&)), this, SLOT(NetLeftRoom(const QString&))); |
776 connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&))); |
852 connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&))); |
|
853 connect(hwnet, SIGNAL(RemoveNetTeam(const HWTeam&)), this, SLOT(RemoveNetTeam(const HWTeam&))); |
|
854 connect(hwnet, SIGNAL(TeamAccepted(const QString&)), this, SLOT(NetTeamAccepted(const QString&))); |
|
855 connect(hwnet, SIGNAL(AskForPassword(const QString&)), this, SLOT(NetPassword(const QString&))); |
|
856 connect(hwnet, SIGNAL(NickTaken(const QString&)), this, SLOT(NetNickTaken(const QString&))); |
|
857 connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed())); |
777 //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom())); |
858 //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom())); |
778 |
859 |
779 // rooms list page stuff |
860 // rooms list page stuff |
780 connect(hwnet, SIGNAL(roomsList(const QStringList&)), |
861 connect(hwnet, SIGNAL(roomsList(const QStringList&)), |
781 ui.pageRoomsList, SLOT(setRoomsList(const QStringList&))); |
862 ui.pageRoomsList, SLOT(setRoomsList(const QStringList&))); |
877 connect(ui.pageAdmin, SIGNAL(setProtocol(int)), hwnet, SLOT(setLatestProtocolVar(int))); |
958 connect(ui.pageAdmin, SIGNAL(setProtocol(int)), hwnet, SLOT(setLatestProtocolVar(int))); |
878 connect(ui.pageAdmin, SIGNAL(askServerVars()), hwnet, SLOT(askServerVars())); |
959 connect(ui.pageAdmin, SIGNAL(askServerVars()), hwnet, SLOT(askServerVars())); |
879 connect(ui.pageAdmin->pbClearAccountsCache, SIGNAL(clicked()), hwnet, SLOT(clearAccountsCache())); |
960 connect(ui.pageAdmin->pbClearAccountsCache, SIGNAL(clicked()), hwnet, SLOT(clearAccountsCache())); |
880 |
961 |
881 // disconnect |
962 // disconnect |
882 connect(hwnet, SIGNAL(Disconnected()), this, SLOT(ForcedDisconnect()), Qt::QueuedConnection); |
963 connect(hwnet, SIGNAL(Disconnected(const QString&)), this, SLOT(ForcedDisconnect(const QString&)), Qt::QueuedConnection); |
883 |
964 |
|
965 // config stuff |
|
966 connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &))); |
|
967 connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &))); |
|
968 connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig())); |
|
969 |
|
970 while (nick.isEmpty()) { |
|
971 nick = QInputDialog::getText(this, |
|
972 QObject::tr("Nickname"), |
|
973 QObject::tr("Please enter your nickname"), |
|
974 QLineEdit::Normal, |
|
975 QDir::home().dirName()); |
|
976 config->setValue("net/nick",nick); |
|
977 config->updNetNick(); |
|
978 } |
884 hwnet->Connect(hostName, port, nick); |
979 hwnet->Connect(hostName, port, nick); |
885 } |
980 } |
886 |
981 |
887 void HWForm::NetConnect() |
982 void HWForm::NetConnect() |
888 { |
983 { |