QTfrontend/net/newnetclient.cpp
changeset 13322 b77a9380dd0f
parent 12897 fc47fc4af6bd
child 13658 73993abb85d7
equal deleted inserted replaced
13321:23ade5604f8d 13322:b77a9380dd0f
    97     NetSocket.disconnectFromHost();
    97     NetSocket.disconnectFromHost();
    98 }
    98 }
    99 
    99 
   100 void HWNewNet::CreateRoom(const QString & room, const QString & password)
   100 void HWNewNet::CreateRoom(const QString & room, const QString & password)
   101 {
   101 {
   102     if(netClientState != InLobby)
   102     if(netClientState != InLobby || !ByteLength(room))
   103     {
   103     {
   104         qWarning("Illegal try to create room!");
   104         qWarning("Illegal try to create room!");
   105         return;
   105         return;
   106     }
   106     }
   107 
   107 
   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());
   907     }
   912     }
   908 }
   913 }
   909 
   914 
   910 void HWNewNet::chatLineToNet(const QString& str)
   915 void HWNewNet::chatLineToNet(const QString& str)
   911 {
   916 {
   912     if(str != "")
   917     if(ByteLength(str))
   913     {
   918     {
   914         RawSendNet(QString("CHAT") + delimiter + str);
   919         RawSendNet(QString("CHAT") + delimiter + str);
   915         QString action = HWProto::chatStringToAction(str);
   920         QString action = HWProto::chatStringToAction(str);
   916         if (action != NULL)
   921         if (action != NULL)
   917             emit(roomChatAction(mynick, action));
   922             emit(roomChatAction(mynick, action));
   920     }
   925     }
   921 }
   926 }
   922 
   927 
   923 void HWNewNet::chatLineToLobby(const QString& str)
   928 void HWNewNet::chatLineToLobby(const QString& str)
   924 {
   929 {
   925     if(str != "")
   930     if(ByteLength(str))
   926     {
   931     {
   927         RawSendNet(QString("CHAT") + delimiter + str);
   932         RawSendNet(QString("CHAT") + delimiter + str);
   928         QString action = HWProto::chatStringToAction(str);
   933         QString action = HWProto::chatStringToAction(str);
   929         if (action != NULL)
   934         if (action != NULL)
   930             emit(lobbyChatAction(mynick, action));
   935             emit(lobbyChatAction(mynick, action));