969 NetConnectServer("netserver.hedgewars.org", 46631); |
959 NetConnectServer("netserver.hedgewars.org", 46631); |
970 } |
960 } |
971 |
961 |
972 void HWForm::NetPassword(const QString & nick) |
962 void HWForm::NetPassword(const QString & nick) |
973 { |
963 { |
974 int passLength = config->value("net/passwordlength", 0).toInt(); |
964 //Get hashes |
975 QString hash = config->value("net/passwordhash", "").toString(); |
965 QString hash = config->value("net/passwordhash", "").toString(); |
976 |
966 QString temphash = config->value("net/temppasswordhash", "").toString(); |
977 // If the password is blank, ask the user to enter one in |
967 |
978 if (passLength == 0) |
968 //Check them |
979 { |
969 |
980 HWPasswordDialog * hpd = new HWPasswordDialog(this, tr("Your nickname %1 is\nregistered on Hedgewars.org\nPlease provide your password below\nor pick another nickname in game config:").arg(nick)); |
970 if (temphash.isEmpty() && hash.isEmpty()) { //If the user enters a registered nick with no password, sends a bogus hash |
981 hpd->cbSave->setChecked(config->value("net/savepassword", true).toBool()); |
971 hwnet->SendPasswordHash("THISISNOHASH"); |
982 if (hpd->exec() != QDialog::Accepted) |
972 } |
983 { |
973 else if (temphash.isEmpty()) { //Send saved hash as default |
984 ForcedDisconnect(tr("No password supplied.")); |
974 hwnet->SendPasswordHash(hash); |
985 delete hpd; |
975 } |
986 return; |
976 else { //Send the hash |
987 } |
977 hwnet->SendPasswordHash(temphash); |
988 |
978 } |
989 QString password = hpd->lePassword->text(); |
979 |
990 hash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex(); |
980 //Remove temporary hash from config |
991 |
981 QString key = "net/temppasswordhash"; |
992 bool save = hpd->cbSave->isChecked(); |
982 config->setValue(key, ""); |
993 config->setValue("net/savepassword", save); |
983 config->remove(key); |
994 if (save) // user wants to save password |
|
995 { |
|
996 config->setValue("net/passwordhash", hash); |
|
997 config->setValue("net/passwordlength", password.size()); |
|
998 config->setNetPasswordLength(password.size()); |
|
999 } |
|
1000 |
|
1001 delete hpd; |
|
1002 } |
|
1003 |
|
1004 hwnet->SendPasswordHash(hash); |
|
1005 } |
984 } |
1006 |
985 |
1007 void HWForm::NetNickTaken(const QString & nick) |
986 void HWForm::NetNickTaken(const QString & nick) |
1008 { |
987 { |
1009 bool ok = false; |
988 bool ok = false; |
1084 connect(hwnet, SIGNAL(NickTaken(const QString&)), this, SLOT(NetNickTaken(const QString&)), Qt::QueuedConnection); |
1063 connect(hwnet, SIGNAL(NickTaken(const QString&)), this, SLOT(NetNickTaken(const QString&)), Qt::QueuedConnection); |
1085 connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed()), Qt::QueuedConnection); |
1064 connect(hwnet, SIGNAL(AuthFailed()), this, SLOT(NetAuthFailed()), Qt::QueuedConnection); |
1086 //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom())); |
1065 //connect(ui.pageNetGame->BtnBack, SIGNAL(clicked()), hwnet, SLOT(partRoom())); |
1087 |
1066 |
1088 ui.pageRoomsList->chatWidget->setUsersModel(hwnet->lobbyPlayersModel()); |
1067 ui.pageRoomsList->chatWidget->setUsersModel(hwnet->lobbyPlayersModel()); |
1089 ui.pageNetGame->pChatWidget->setUsersModel(hwnet->roomPlayersModel()); |
1068 ui.pageNetGame->chatWidget->setUsersModel(hwnet->roomPlayersModel()); |
1090 |
1069 |
1091 // rooms list page stuff |
1070 // rooms list page stuff |
1092 ui.pageRoomsList->setModel(hwnet->roomsListModel()); |
1071 ui.pageRoomsList->setModel(hwnet->roomsListModel()); |
1093 connect(hwnet, SIGNAL(adminAccess(bool)), |
1072 connect(hwnet, SIGNAL(adminAccess(bool)), |
1094 ui.pageRoomsList, SLOT(setAdmin(bool)), Qt::QueuedConnection); |
1073 ui.pageRoomsList, SLOT(setAdmin(bool)), Qt::QueuedConnection); |
1113 connect(hwnet, SIGNAL(roomMaster(bool)), |
1092 connect(hwnet, SIGNAL(roomMaster(bool)), |
1114 this, SLOT(NetGameChangeStatus(bool)), Qt::QueuedConnection); |
1093 this, SLOT(NetGameChangeStatus(bool)), Qt::QueuedConnection); |
1115 |
1094 |
1116 // net page stuff |
1095 // net page stuff |
1117 connect(hwnet, SIGNAL(chatStringFromNet(const QString&)), |
1096 connect(hwnet, SIGNAL(chatStringFromNet(const QString&)), |
1118 ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1097 ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1119 |
1098 |
1120 connect(hwnet, SIGNAL(chatStringFromMe(const QString&)), |
1099 connect(hwnet, SIGNAL(chatStringFromMe(const QString&)), |
1121 ui.pageNetGame->pChatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1100 ui.pageNetGame->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1122 connect(hwnet, SIGNAL(roomMaster(bool)), |
1101 connect(hwnet, SIGNAL(roomMaster(bool)), |
1123 ui.pageNetGame->pChatWidget, SLOT(adminAccess(bool)), Qt::QueuedConnection); |
1102 ui.pageNetGame->chatWidget, SLOT(adminAccess(bool)), Qt::QueuedConnection); |
1124 connect(ui.pageNetGame->pChatWidget, SIGNAL(chatLine(const QString&)), |
1103 connect(ui.pageNetGame->chatWidget, SIGNAL(chatLine(const QString&)), |
1125 hwnet, SLOT(chatLineToNet(const QString&))); |
1104 hwnet, SLOT(chatLineToNet(const QString&))); |
1126 connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady())); |
1105 connect(ui.pageNetGame->BtnGo, SIGNAL(clicked()), hwnet, SLOT(ToggleReady())); |
1127 connect(hwnet, SIGNAL(setMyReadyStatus(bool)), |
1106 connect(hwnet, SIGNAL(setMyReadyStatus(bool)), |
1128 ui.pageNetGame, SLOT(setReadyStatus(bool)), Qt::QueuedConnection); |
1107 ui.pageNetGame, SLOT(setReadyStatus(bool)), Qt::QueuedConnection); |
1129 |
1108 |
1130 // chat widget actions |
1109 // chat widget actions |
1131 connect(ui.pageNetGame->pChatWidget, SIGNAL(kick(const QString&)), |
1110 connect(ui.pageNetGame->chatWidget, SIGNAL(kick(const QString&)), |
1132 hwnet, SLOT(kickPlayer(const QString&))); |
1111 hwnet, SLOT(kickPlayer(const QString&))); |
1133 connect(ui.pageNetGame->pChatWidget, SIGNAL(ban(const QString&)), |
1112 connect(ui.pageNetGame->chatWidget, SIGNAL(ban(const QString&)), |
1134 hwnet, SLOT(banPlayer(const QString&))); |
1113 hwnet, SLOT(banPlayer(const QString&))); |
1135 connect(ui.pageNetGame->pChatWidget, SIGNAL(info(const QString&)), |
1114 connect(ui.pageNetGame->chatWidget, SIGNAL(info(const QString&)), |
1136 hwnet, SLOT(infoPlayer(const QString&))); |
1115 hwnet, SLOT(infoPlayer(const QString&))); |
1137 connect(ui.pageNetGame->pChatWidget, SIGNAL(follow(const QString&)), |
1116 connect(ui.pageNetGame->chatWidget, SIGNAL(follow(const QString&)), |
1138 hwnet, SLOT(followPlayer(const QString&))); |
1117 hwnet, SLOT(followPlayer(const QString&))); |
1139 connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)), |
1118 connect(ui.pageRoomsList->chatWidget, SIGNAL(kick(const QString&)), |
1140 hwnet, SLOT(kickPlayer(const QString&))); |
1119 hwnet, SLOT(kickPlayer(const QString&))); |
1141 connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)), |
1120 connect(ui.pageRoomsList->chatWidget, SIGNAL(ban(const QString&)), |
1142 hwnet, SLOT(banPlayer(const QString&))); |
1121 hwnet, SLOT(banPlayer(const QString&))); |
1155 connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)), |
1134 connect(hwnet, SIGNAL(chatStringFromMeLobby(const QString&)), |
1156 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1135 ui.pageRoomsList->chatWidget, SLOT(onChatString(const QString&)), Qt::QueuedConnection); |
1157 |
1136 |
1158 // nick list stuff |
1137 // nick list stuff |
1159 connect(hwnet, SIGNAL(nickAdded(const QString&, bool)), |
1138 connect(hwnet, SIGNAL(nickAdded(const QString&, bool)), |
1160 ui.pageNetGame->pChatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection); |
1139 ui.pageNetGame->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection); |
1161 connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
1140 connect(hwnet, SIGNAL(nickRemoved(const QString&)), |
1162 ui.pageNetGame->pChatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection); |
1141 ui.pageNetGame->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection); |
1163 connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)), |
1142 connect(hwnet, SIGNAL(nickAddedLobby(const QString&, bool)), |
1164 ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection); |
1143 ui.pageRoomsList->chatWidget, SLOT(nickAdded(const QString&, bool)), Qt::QueuedConnection); |
1165 connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)), |
1144 connect(hwnet, SIGNAL(nickRemovedLobby(const QString&)), |
1166 ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection); |
1145 ui.pageRoomsList->chatWidget, SLOT(nickRemoved(const QString&)), Qt::QueuedConnection); |
1167 |
1146 |
1180 |
1159 |
1181 // admin stuff |
1160 // admin stuff |
1182 connect(hwnet, SIGNAL(serverMessageNew(const QString&)), ui.pageAdmin, SLOT(serverMessageNew(const QString &))); |
1161 connect(hwnet, SIGNAL(serverMessageNew(const QString&)), ui.pageAdmin, SLOT(serverMessageNew(const QString &))); |
1183 connect(hwnet, SIGNAL(serverMessageOld(const QString&)), ui.pageAdmin, SLOT(serverMessageOld(const QString &))); |
1162 connect(hwnet, SIGNAL(serverMessageOld(const QString&)), ui.pageAdmin, SLOT(serverMessageOld(const QString &))); |
1184 connect(hwnet, SIGNAL(latestProtocolVar(int)), ui.pageAdmin, SLOT(protocol(int))); |
1163 connect(hwnet, SIGNAL(latestProtocolVar(int)), ui.pageAdmin, SLOT(protocol(int))); |
|
1164 connect(hwnet, SIGNAL(bansList(const QStringList &)), ui.pageAdmin, SLOT(setBansList(const QStringList &))); |
1185 connect(ui.pageAdmin, SIGNAL(setServerMessageNew(const QString&)), hwnet, SLOT(setServerMessageNew(const QString &))); |
1165 connect(ui.pageAdmin, SIGNAL(setServerMessageNew(const QString&)), hwnet, SLOT(setServerMessageNew(const QString &))); |
1186 connect(ui.pageAdmin, SIGNAL(setServerMessageOld(const QString&)), hwnet, SLOT(setServerMessageOld(const QString &))); |
1166 connect(ui.pageAdmin, SIGNAL(setServerMessageOld(const QString&)), hwnet, SLOT(setServerMessageOld(const QString &))); |
1187 connect(ui.pageAdmin, SIGNAL(setProtocol(int)), hwnet, SLOT(setLatestProtocolVar(int))); |
1167 connect(ui.pageAdmin, SIGNAL(setProtocol(int)), hwnet, SLOT(setLatestProtocolVar(int))); |
1188 connect(ui.pageAdmin, SIGNAL(askServerVars()), hwnet, SLOT(askServerVars())); |
1168 connect(ui.pageAdmin, SIGNAL(askServerVars()), hwnet, SLOT(askServerVars())); |
1189 connect(ui.pageAdmin, SIGNAL(clearAccountsCache()), hwnet, SLOT(clearAccountsCache())); |
1169 connect(ui.pageAdmin, SIGNAL(clearAccountsCache()), hwnet, SLOT(clearAccountsCache())); |
|
1170 connect(ui.pageAdmin, SIGNAL(bansListRequest()), hwnet, SLOT(getBanList())); |
|
1171 connect(ui.pageAdmin, SIGNAL(removeBan(QString)), hwnet, SLOT(removeBan(QString))); |
|
1172 connect(ui.pageAdmin, SIGNAL(banIP(QString,QString,int)), hwnet, SLOT(banIP(QString,QString,int))); |
|
1173 connect(ui.pageAdmin, SIGNAL(banNick(QString,QString,int)), hwnet, SLOT(banNick(QString,QString,int))); |
1190 |
1174 |
1191 // disconnect |
1175 // disconnect |
1192 connect(hwnet, SIGNAL(disconnected(const QString&)), this, SLOT(ForcedDisconnect(const QString&)), Qt::QueuedConnection); |
1176 connect(hwnet, SIGNAL(disconnected(const QString&)), this, SLOT(ForcedDisconnect(const QString&)), Qt::QueuedConnection); |
1193 |
1177 |
1194 // config stuff |
1178 // config stuff |
1195 connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &))); |
1179 connect(hwnet, SIGNAL(paramChanged(const QString &, const QStringList &)), ui.pageNetGame->pGameCFG, SLOT(setParam(const QString &, const QStringList &))); |
1196 connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &))); |
1180 connect(ui.pageNetGame->pGameCFG, SIGNAL(paramChanged(const QString &, const QStringList &)), hwnet, SLOT(onParamChanged(const QString &, const QStringList &))); |
1197 connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig())); |
1181 connect(hwnet, SIGNAL(configAsked()), ui.pageNetGame->pGameCFG, SLOT(fullNetConfig())); |
1198 |
1182 |
1199 while (nick.isEmpty()) |
1183 //nick and pass stuff |
1200 { |
1184 |
1201 nick = QInputDialog::getText(this, |
1185 //remove temppasswordhash just in case |
1202 QObject::tr("Nickname"), |
1186 config->value("net/temppasswordhash", ""); |
1203 QObject::tr("Please enter your nickname"), |
1187 config->remove("net/temppasswordhash"); |
1204 QLineEdit::Normal, |
1188 |
1205 QDir::home().dirName()); |
1189 //initialize |
1206 config->setValue("net/nick",nick); |
1190 QString hash = config->value("net/passwordhash", "").toString(); |
|
1191 QString temphash = config->value("net/temppasswordhash", "").toString(); |
|
1192 QString nickname = config->value("net/nick", "").toString(); |
|
1193 QString password; |
|
1194 |
|
1195 if (nickname.isEmpty() || hash.isEmpty()) { //if something from login is missing, start dialog loop |
|
1196 |
|
1197 while (nickname.isEmpty() || (hash.isEmpty() && temphash.isEmpty())) //while a nickname, or both hashes are missing |
|
1198 { |
|
1199 //open dialog |
|
1200 HWPasswordDialog * hpd = new HWPasswordDialog(this); |
|
1201 hpd->cbSave->setChecked(config->value("net/savepassword", true).toBool()); |
|
1202 |
|
1203 //if nickname is present, put it into the field |
|
1204 if (!nickname.isEmpty()) { |
|
1205 hpd->leNickname->setText(nickname); |
|
1206 hpd->lePassword->setFocus(); |
|
1207 } |
|
1208 |
|
1209 //if dialog close, create an error message |
|
1210 if (hpd->exec() != QDialog::Accepted) |
|
1211 { |
|
1212 ForcedDisconnect(tr("Login info not supplied.")); |
|
1213 delete hpd; |
|
1214 return; |
|
1215 } |
|
1216 |
|
1217 //set nick and pass from the dialog |
|
1218 nickname = hpd->leNickname->text(); |
|
1219 password = hpd->lePassword->text(); |
|
1220 |
|
1221 //calculate temphash and set it into config |
|
1222 temphash = QCryptographicHash::hash(password.toUtf8(), QCryptographicHash::Md5).toHex(); |
|
1223 config->setValue("net/temppasswordhash", temphash); |
|
1224 |
|
1225 //if user wants to save password |
|
1226 bool save = hpd->cbSave->isChecked(); |
|
1227 config->setValue("net/savepassword", save); |
|
1228 if (save) // user wants to save password |
|
1229 { |
|
1230 config->setValue("net/passwordhash", temphash); |
|
1231 config->setValue("net/passwordlength", password.size()); |
|
1232 config->setNetPasswordLength(password.size()); |
|
1233 } |
|
1234 |
|
1235 delete hpd; |
|
1236 |
|
1237 |
|
1238 //update nickname |
|
1239 config->setValue("net/nick", nickname); |
1207 config->updNetNick(); |
1240 config->updNetNick(); |
1208 } |
1241 |
1209 |
1242 //and all the variables |
1210 ui.pageRoomsList->setUser(nick); |
1243 hash = config->value("net/passwordhash", "").toString(); |
1211 ui.pageNetGame->setUser(nick); |
1244 temphash = config->value("net/temppasswordhash", "").toString(); |
1212 |
1245 nickname = config->value("net/nick", "").toString(); |
1213 hwnet->Connect(hostName, port, nick); |
1246 } |
1214 } |
1247 |
|
1248 |
|
1249 //if pass is none (hash is generated anyway), remove the hash |
|
1250 if (password.size() <= 0) { |
|
1251 config->setValue("net/temppasswordhash", ""); |
|
1252 config->remove("net/temppasswordhash"); |
|
1253 } |
|
1254 } |
|
1255 |
|
1256 ui.pageRoomsList->setUser(nickname); |
|
1257 ui.pageNetGame->setUser(nickname); |
|
1258 |
|
1259 hwnet->Connect(hostName, port, nickname); |
|
1260 } |
|
1261 |
|
1262 |
1215 |
1263 |
1216 void HWForm::NetConnect() |
1264 void HWForm::NetConnect() |
1217 { |
1265 { |
1218 HWHostPortDialog * hpd = new HWHostPortDialog(this); |
1266 HWHostPortDialog * hpd = new HWHostPortDialog(this); |
1219 hpd->leHost->setText(*netHost); |
1267 hpd->leHost->setText(*netHost); |