172 void HWNewNet::SendNet(const QByteArray & buf) |
172 void HWNewNet::SendNet(const QByteArray & buf) |
173 { |
173 { |
174 QString msg = QString(buf.toBase64()); |
174 QString msg = QString(buf.toBase64()); |
175 |
175 |
176 RawSendNet(QString("EM%1%2").arg(delimiter).arg(msg)); |
176 RawSendNet(QString("EM%1%2").arg(delimiter).arg(msg)); |
|
177 } |
|
178 |
|
179 int HWNewNet::ByteLength(const QString & str) |
|
180 { |
|
181 return str.toUtf8().size(); |
177 } |
182 } |
178 |
183 |
179 void HWNewNet::RawSendNet(const QString & str) |
184 void HWNewNet::RawSendNet(const QString & str) |
180 { |
185 { |
181 RawSendNet(str.toUtf8()); |
186 RawSendNet(str.toUtf8()); |
240 } |
245 } |
241 |
246 |
242 void HWNewNet::SendPasswordHash(const QString & hash) |
247 void HWNewNet::SendPasswordHash(const QString & hash) |
243 { |
248 { |
244 // don't send it immediately, only store and check if server asked us for a password |
249 // don't send it immediately, only store and check if server asked us for a password |
245 m_passwordHash = hash.toAscii(); |
250 m_passwordHash = hash.toLatin1(); |
246 |
251 |
247 maybeSendPassword(); |
252 maybeSendPassword(); |
248 } |
253 } |
249 |
254 |
250 void HWNewNet::ParseCmd(const QStringList & lst) |
255 void HWNewNet::ParseCmd(const QStringList & lst) |
269 return ; |
274 return ; |
270 |
275 |
271 if (lst[0] == "ERROR") |
276 if (lst[0] == "ERROR") |
272 { |
277 { |
273 if (lst.size() == 2) |
278 if (lst.size() == 2) |
274 emit Error(HWApplication::translate("server", lst[1].toAscii().constData())); |
279 emit Error(HWApplication::translate("server", lst[1].toLatin1().constData())); |
275 else |
280 else |
276 emit Error("Unknown error"); |
281 emit Error("Unknown error"); |
277 return; |
282 return; |
278 } |
283 } |
279 |
284 |
280 if (lst[0] == "WARNING") |
285 if (lst[0] == "WARNING") |
281 { |
286 { |
282 if (lst.size() == 2) |
287 if (lst.size() == 2) |
283 emit Warning(HWApplication::translate("server", lst[1].toAscii().constData())); |
288 emit Warning(HWApplication::translate("server", lst[1].toLatin1().constData())); |
284 else |
289 else |
285 emit Warning("Unknown warning"); |
290 emit Warning("Unknown warning"); |
286 return; |
291 return; |
287 } |
292 } |
288 |
293 |
445 const QStringList nicks = lst.mid(2); |
450 const QStringList nicks = lst.mid(2); |
446 |
451 |
447 while(flags.size() > 1) |
452 while(flags.size() > 1) |
448 { |
453 { |
449 flags.remove(0, 1); |
454 flags.remove(0, 1); |
450 char c = flags[0].toAscii(); |
455 char c = flags[0].toLatin1(); |
451 bool inRoom = (netClientState == InRoom || netClientState == InGame); |
456 bool inRoom = (netClientState == InRoom || netClientState == InGame); |
452 |
457 |
453 switch(c) |
458 switch(c) |
454 { |
459 { |
455 // flag indicating if a player is ready to start a game |
460 // flag indicating if a player is ready to start a game |
671 //omitted 'emit disconnected()', we don't want the error message |
676 //omitted 'emit disconnected()', we don't want the error message |
672 return; |
677 return; |
673 } |
678 } |
674 m_game_connected = false; |
679 m_game_connected = false; |
675 Disconnect(); |
680 Disconnect(); |
676 emit disconnected(HWApplication::translate("server", lst[1].toAscii().constData())); |
681 emit disconnected(HWApplication::translate("server", lst[1].toLatin1().constData())); |
677 return; |
682 return; |
678 } |
683 } |
679 |
684 |
680 if(lst[0] == "JOINING") |
685 if(lst[0] == "JOINING") |
681 { |
686 { |
1153 |
1158 |
1154 if(m_passwordHash.isEmpty() || m_serverSalt.isEmpty()) |
1159 if(m_passwordHash.isEmpty() || m_serverSalt.isEmpty()) |
1155 return; |
1160 return; |
1156 |
1161 |
1157 QString hash = QCryptographicHash::hash( |
1162 QString hash = QCryptographicHash::hash( |
1158 m_clientSalt.toAscii() |
1163 m_clientSalt.toLatin1() |
1159 .append(m_serverSalt.toAscii()) |
1164 .append(m_serverSalt.toLatin1()) |
1160 .append(m_passwordHash) |
1165 .append(m_passwordHash) |
1161 .append(cProtoVer->toAscii()) |
1166 .append(cProtoVer->toLatin1()) |
1162 .append("!hedgewars") |
1167 .append("!hedgewars") |
1163 , QCryptographicHash::Sha1).toHex(); |
1168 , QCryptographicHash::Sha1).toHex(); |
1164 |
1169 |
1165 m_serverHash = QCryptographicHash::hash( |
1170 m_serverHash = QCryptographicHash::hash( |
1166 m_serverSalt.toAscii() |
1171 m_serverSalt.toLatin1() |
1167 .append(m_clientSalt.toAscii()) |
1172 .append(m_clientSalt.toLatin1()) |
1168 .append(m_passwordHash) |
1173 .append(m_passwordHash) |
1169 .append(cProtoVer->toAscii()) |
1174 .append(cProtoVer->toLatin1()) |
1170 .append("!hedgewars") |
1175 .append("!hedgewars") |
1171 , QCryptographicHash::Sha1).toHex(); |
1176 , QCryptographicHash::Sha1).toHex(); |
1172 |
1177 |
1173 RawSendNet(QString("PASSWORD%1%2%1%3").arg(delimiter).arg(hash).arg(m_clientSalt)); |
1178 RawSendNet(QString("PASSWORD%1%2%1%3").arg(delimiter).arg(hash).arg(m_clientSalt)); |
1174 } |
1179 } |