QTfrontend/net/newnetclient.cpp
changeset 8759 1a4b9b9fe2b0
parent 8720 5603527f9803
child 8762 388d2bf73ff9
equal deleted inserted replaced
8757:266df6d5ed73 8759:1a4b9b9fe2b0
   334         if(lst.size() < 3)
   334         if(lst.size() < 3)
   335         {
   335         {
   336             qWarning("Net: Empty CHAT message");
   336             qWarning("Net: Empty CHAT message");
   337             return;
   337             return;
   338         }
   338         }
       
   339 
       
   340         QString action = HWProto::chatStringToAction(lst[2]);
       
   341 
   339         if (netClientState == InLobby)
   342         if (netClientState == InLobby)
   340             emit chatStringLobby(lst[1], HWProto::formatChatMsgForFrontend(lst[2]));
   343         {
       
   344             if (action != NULL)
       
   345                 emit lobbyChatAction(lst[1], action);
       
   346             else
       
   347                 emit lobbyChatMessage(lst[1], lst[2]);
       
   348         }
   341         else
   349         else
       
   350         {
   342             emit chatStringFromNet(HWProto::formatChatMsg(lst[1], lst[2]));
   351             emit chatStringFromNet(HWProto::formatChatMsg(lst[1], lst[2]));
       
   352             if (action != NULL)
       
   353                 emit roomChatAction(lst[1], action);
       
   354             else
       
   355                 emit roomChatMessage(lst[1], lst[2]);
       
   356         }
   343         return;
   357         return;
   344     }
   358     }
   345 
   359 
   346     if (lst[0] == "INFO")
   360     if (lst[0] == "INFO")
   347     {
   361     {
   348         if(lst.size() < 5)
   362         if(lst.size() < 5)
   349         {
   363         {
   350             qWarning("Net: Malformed INFO message");
   364             qWarning("Net: Malformed INFO message");
   351             return;
   365             return;
   352         }
   366         }
   353         QStringList tmp = lst;
   367         emit playerInfo(lst[1], lst[2], lst[3], lst[4]);
   354         tmp.removeFirst();
   368         if (netClientState != InLobby)
   355         if (netClientState == InLobby)
   369         {
   356             emit chatStringLobby(tmp.join("\n").prepend('\x01'));
   370             QStringList tmp = lst;
   357         else
   371             tmp.removeFirst();
   358             emit chatStringFromNet(tmp.join("\n").prepend('\x01'));
   372             emit chatStringFromNet(tmp.join("\n").prepend('\x01'));
       
   373         }
   359         return;
   374         return;
   360     }
   375     }
   361 
   376 
   362     if (lst[0] == "SERVER_VARS")
   377     if (lst[0] == "SERVER_VARS")
   363     {
   378     {
   490                 emit connected();
   505                 emit connected();
   491             }
   506             }
   492 
   507 
   493             m_playersModel->addPlayer(lst[i]);
   508             m_playersModel->addPlayer(lst[i]);
   494             emit nickAddedLobby(lst[i], false);
   509             emit nickAddedLobby(lst[i], false);
   495             emit chatStringLobby(lst[i], tr("%1 *** %2 has joined").arg('\x03').arg("|nick|"));
       
   496         }
   510         }
   497         return;
   511         return;
   498     }
   512     }
   499 
   513 
   500     if(lst[0] == "ROOM" && lst.size() == 10 && lst[1] == "ADD")
   514     if(lst[0] == "ROOM" && lst.size() == 10 && lst[1] == "ADD")
   537         if(lst.size() < 2)
   551         if(lst.size() < 2)
   538         {
   552         {
   539             qWarning("Net: Bad LOBBY:LEFT message");
   553             qWarning("Net: Bad LOBBY:LEFT message");
   540             return;
   554             return;
   541         }
   555         }
   542         emit nickRemovedLobby(lst[1]);
   556 
   543         if (lst.size() < 3)
   557         if (lst.size() < 3)
   544             emit chatStringLobby(tr("%1 *** %2 has left").arg('\x03').arg(lst[1]));
   558             emit nickRemovedLobby(lst[1]);
   545         else
   559         else
   546             emit chatStringLobby(lst[1], tr("%1 *** %2 has left (%3)").arg('\x03').arg("|nick|", lst[2]));
   560             emit nickRemovedLobby(lst[1], lst[2]);
   547 
   561 
   548         m_playersModel->removePlayer(lst[1]);
   562         m_playersModel->removePlayer(lst[1]);
   549 
   563 
   550         return;
   564         return;
   551     }
   565     }
   839 void HWNewNet::chatLineToNet(const QString& str)
   853 void HWNewNet::chatLineToNet(const QString& str)
   840 {
   854 {
   841     if(str != "")
   855     if(str != "")
   842     {
   856     {
   843         RawSendNet(QString("CHAT") + delimeter + str);
   857         RawSendNet(QString("CHAT") + delimeter + str);
   844         emit(chatStringFromMe(HWProto::formatChatMsg(mynick, str)));
   858         QString action = HWProto::chatStringToAction(str);
       
   859         if (action != NULL)
       
   860             emit(roomChatAction(mynick, action));
       
   861         else
       
   862             emit(roomChatMessage(mynick, str));
   845     }
   863     }
   846 }
   864 }
   847 
   865 
   848 void HWNewNet::chatLineToLobby(const QString& str)
   866 void HWNewNet::chatLineToLobby(const QString& str)
   849 {
   867 {
   850     if(str != "")
   868     if(str != "")
   851     {
   869     {
   852         RawSendNet(QString("CHAT") + delimeter + str);
   870         RawSendNet(QString("CHAT") + delimeter + str);
   853         emit chatStringLobby(mynick, HWProto::formatChatMsgForFrontend(str));
   871         QString action = HWProto::chatStringToAction(str);
       
   872         if (action != NULL)
       
   873             emit(lobbyChatAction(mynick, action));
       
   874         else
       
   875             emit(lobbyChatMessage(mynick, str));
   854     }
   876     }
   855 }
   877 }
   856 
   878 
   857 void HWNewNet::SendTeamMessage(const QString& str)
   879 void HWNewNet::SendTeamMessage(const QString& str)
   858 {
   880 {