QTfrontend/net/newnetclient.cpp
branchqt5transition
changeset 12897 fc47fc4af6bd
parent 11865 047be82b6f67
child 13322 b77a9380dd0f
equal deleted inserted replaced
12896:8869b5256720 12897:fc47fc4af6bd
   240 }
   240 }
   241 
   241 
   242 void HWNewNet::SendPasswordHash(const QString & hash)
   242 void HWNewNet::SendPasswordHash(const QString & hash)
   243 {
   243 {
   244     // don't send it immediately, only store and check if server asked us for a password
   244     // don't send it immediately, only store and check if server asked us for a password
   245     m_passwordHash = hash.toAscii();
   245     m_passwordHash = hash.toLatin1();
   246 
   246 
   247     maybeSendPassword();
   247     maybeSendPassword();
   248 }
   248 }
   249 
   249 
   250 void HWNewNet::ParseCmd(const QStringList & lst)
   250 void HWNewNet::ParseCmd(const QStringList & lst)
   269         return ;
   269         return ;
   270 
   270 
   271     if (lst[0] == "ERROR")
   271     if (lst[0] == "ERROR")
   272     {
   272     {
   273         if (lst.size() == 2)
   273         if (lst.size() == 2)
   274             emit Error(HWApplication::translate("server", lst[1].toAscii().constData()));
   274             emit Error(HWApplication::translate("server", lst[1].toLatin1().constData()));
   275         else
   275         else
   276             emit Error("Unknown error");
   276             emit Error("Unknown error");
   277         return;
   277         return;
   278     }
   278     }
   279 
   279 
   280     if (lst[0] == "WARNING")
   280     if (lst[0] == "WARNING")
   281     {
   281     {
   282         if (lst.size() == 2)
   282         if (lst.size() == 2)
   283             emit Warning(HWApplication::translate("server", lst[1].toAscii().constData()));
   283             emit Warning(HWApplication::translate("server", lst[1].toLatin1().constData()));
   284         else
   284         else
   285             emit Warning("Unknown warning");
   285             emit Warning("Unknown warning");
   286         return;
   286         return;
   287     }
   287     }
   288 
   288 
   445         const QStringList nicks = lst.mid(2);
   445         const QStringList nicks = lst.mid(2);
   446 
   446 
   447         while(flags.size() > 1)
   447         while(flags.size() > 1)
   448         {
   448         {
   449             flags.remove(0, 1);
   449             flags.remove(0, 1);
   450             char c = flags[0].toAscii();
   450             char c = flags[0].toLatin1();
   451             bool inRoom = (netClientState == InRoom || netClientState == InGame);
   451             bool inRoom = (netClientState == InRoom || netClientState == InGame);
   452 
   452 
   453             switch(c)
   453             switch(c)
   454             {
   454             {
   455                 // flag indicating if a player is ready to start a game
   455                 // flag indicating if a player is ready to start a game
   671             //omitted 'emit disconnected()', we don't want the error message
   671             //omitted 'emit disconnected()', we don't want the error message
   672             return;
   672             return;
   673         }
   673         }
   674         m_game_connected = false;
   674         m_game_connected = false;
   675         Disconnect();
   675         Disconnect();
   676         emit disconnected(HWApplication::translate("server", lst[1].toAscii().constData()));
   676         emit disconnected(HWApplication::translate("server", lst[1].toLatin1().constData()));
   677         return;
   677         return;
   678     }
   678     }
   679 
   679 
   680     if(lst[0] == "JOINING")
   680     if(lst[0] == "JOINING")
   681     {
   681     {
   725                 qWarning("Net: Bad EM message");
   725                 qWarning("Net: Bad EM message");
   726                 return;
   726                 return;
   727             }
   727             }
   728             for(int i = 1; i < lst.size(); ++i)
   728             for(int i = 1; i < lst.size(); ++i)
   729             {
   729             {
   730                 QByteArray em = QByteArray::fromBase64(lst[i].toAscii());
   730                 QByteArray em = QByteArray::fromBase64(lst[i].toLatin1());
   731                 emit FromNet(em);
   731                 emit FromNet(em);
   732             }
   732             }
   733             return;
   733             return;
   734         }
   734         }
   735 
   735 
  1153 
  1153 
  1154     if(m_passwordHash.isEmpty() || m_serverSalt.isEmpty())
  1154     if(m_passwordHash.isEmpty() || m_serverSalt.isEmpty())
  1155         return;
  1155         return;
  1156 
  1156 
  1157     QString hash = QCryptographicHash::hash(
  1157     QString hash = QCryptographicHash::hash(
  1158                 m_clientSalt.toAscii()
  1158                 m_clientSalt.toLatin1()
  1159                 .append(m_serverSalt.toAscii())
  1159                 .append(m_serverSalt.toLatin1())
  1160                 .append(m_passwordHash)
  1160                 .append(m_passwordHash)
  1161                 .append(cProtoVer->toAscii())
  1161                 .append(cProtoVer->toLatin1())
  1162                 .append("!hedgewars")
  1162                 .append("!hedgewars")
  1163                 , QCryptographicHash::Sha1).toHex();
  1163                 , QCryptographicHash::Sha1).toHex();
  1164 
  1164 
  1165     m_serverHash = QCryptographicHash::hash(
  1165     m_serverHash = QCryptographicHash::hash(
  1166                 m_serverSalt.toAscii()
  1166                 m_serverSalt.toLatin1()
  1167                 .append(m_clientSalt.toAscii())
  1167                 .append(m_clientSalt.toLatin1())
  1168                 .append(m_passwordHash)
  1168                 .append(m_passwordHash)
  1169                 .append(cProtoVer->toAscii())
  1169                 .append(cProtoVer->toLatin1())
  1170                 .append("!hedgewars")
  1170                 .append("!hedgewars")
  1171                 , QCryptographicHash::Sha1).toHex();
  1171                 , QCryptographicHash::Sha1).toHex();
  1172 
  1172 
  1173     RawSendNet(QString("PASSWORD%1%2%1%3").arg(delimiter).arg(hash).arg(m_clientSalt));
  1173     RawSendNet(QString("PASSWORD%1%2%1%3").arg(delimiter).arg(hash).arg(m_clientSalt));
  1174 }
  1174 }