QTfrontend/net/newnetclient.cpp
branchwebgl
changeset 8833 c13ebed437cb
parent 8444 75db7bb8dce8
parent 8720 5603527f9803
child 9127 e350500c4edb
equal deleted inserted replaced
8450:404ddce27b23 8833:c13ebed437cb
    61     connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
    61     connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
    62     connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect()));
    62     connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect()));
    63     connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect()));
    63     connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect()));
    64     connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this,
    64     connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this,
    65             SLOT(displayError(QAbstractSocket::SocketError)));
    65             SLOT(displayError(QAbstractSocket::SocketError)));
       
    66 
       
    67     connect(this, SIGNAL(messageProcessed()), this, SLOT(ClientRead()), Qt::QueuedConnection);
    66 }
    68 }
    67 
    69 
    68 HWNewNet::~HWNewNet()
    70 HWNewNet::~HWNewNet()
    69 {
    71 {
    70     if (m_game_connected)
    72     if (m_game_connected)
   184 
   186 
   185         if (s.size() == 0)
   187         if (s.size() == 0)
   186         {
   188         {
   187             ParseCmd(cmdbuf);
   189             ParseCmd(cmdbuf);
   188             cmdbuf.clear();
   190             cmdbuf.clear();
       
   191             emit messageProcessed();
       
   192             return ;
   189         }
   193         }
   190         else
   194         else
   191             cmdbuf << s;
   195             cmdbuf << s;
   192     }
   196     }
   193 }
   197 }
   305             return;
   309             return;
   306         }
   310         }
   307         QStringList tmp = lst;
   311         QStringList tmp = lst;
   308         tmp.removeFirst();
   312         tmp.removeFirst();
   309         m_roomsListModel->setRoomsList(tmp);
   313         m_roomsListModel->setRoomsList(tmp);
   310         if (m_nick_registered == false)
   314         if (m_private_game == false && m_nick_registered == false)
   311         {
   315         {
   312             emit NickNotRegistered(mynick);
   316             emit NickNotRegistered(mynick);
   313         }
   317         }
   314         return;
   318         return;
   315     }
   319     }
   484                 netClientState = InLobby;
   488                 netClientState = InLobby;
   485                 RawSendNet(QString("LIST"));
   489                 RawSendNet(QString("LIST"));
   486                 emit connected();
   490                 emit connected();
   487             }
   491             }
   488 
   492 
       
   493             m_playersModel->addPlayer(lst[i]);
   489             emit nickAddedLobby(lst[i], false);
   494             emit nickAddedLobby(lst[i], false);
   490             emit chatStringLobby(lst[i], tr("%1 *** %2 has joined").arg('\x03').arg("|nick|"));
   495             emit chatStringLobby(lst[i], tr("%1 *** %2 has joined").arg('\x03').arg("|nick|"));
   491             m_playersModel->addPlayer(lst[i]);
       
   492         }
   496         }
   493         return;
   497         return;
   494     }
   498     }
   495 
   499 
   496     if(lst[0] == "ROOM" && lst.size() == 10 && lst[1] == "ADD")
   500     if(lst[0] == "ROOM" && lst.size() == 10 && lst[1] == "ADD")
   510         tmp.removeFirst();
   514         tmp.removeFirst();
   511 
   515 
   512         QString roomName = tmp.takeFirst();
   516         QString roomName = tmp.takeFirst();
   513         m_roomsListModel->updateRoom(roomName, tmp);
   517         m_roomsListModel->updateRoom(roomName, tmp);
   514 
   518 
   515         // keep track of room name so correct name is displayed when you become room admin
   519         // keep track of room name so correct name is displayed
   516         if(myroom == roomName)
   520         if(myroom == roomName)
       
   521         {
   517             myroom = tmp[1];
   522             myroom = tmp[1];
       
   523             emit roomNameUpdated(myroom);
       
   524         }
   518 
   525 
   519         return;
   526         return;
   520     }
   527     }
   521 
   528 
   522     if(lst[0] == "ROOM" && lst.size() == 3 && lst[1] == "DEL")
   529     if(lst[0] == "ROOM" && lst.size() == 3 && lst[1] == "DEL")
   596     {
   603     {
   597         // obsolete, see +a client flag
   604         // obsolete, see +a client flag
   598         return;
   605         return;
   599     }
   606     }
   600 
   607 
       
   608     if(lst[0] == "JOINING")
       
   609     {
       
   610         if(lst.size() < 2)
       
   611         {
       
   612             qWarning("Net: Bad JOINING message");
       
   613             return;
       
   614         }
       
   615 
       
   616         myroom = lst[1];
       
   617         emit roomNameUpdated(myroom);
       
   618     }
       
   619 
   601     if(netClientState == InLobby && lst[0] == "JOINED")
   620     if(netClientState == InLobby && lst[0] == "JOINED")
   602     {
   621     {
   603         if(lst.size() < 2 || lst[1] != mynick)
   622         if(lst.size() < 2 || lst[1] != mynick)
   604         {
   623         {
   605             qWarning("Net: Bad JOINED message");
   624             qWarning("Net: Bad JOINED message");
   615                 emit roomMaster(isChief);
   634                 emit roomMaster(isChief);
   616                 if (isChief)
   635                 if (isChief)
   617                     emit configAsked();
   636                     emit configAsked();
   618             }
   637             }
   619 
   638 
       
   639             m_playersModel->playerJoinedRoom(lst[i]);
   620             emit nickAdded(lst[i], isChief && (lst[i] != mynick));
   640             emit nickAdded(lst[i], isChief && (lst[i] != mynick));
   621             emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i]));
   641             emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i]));
   622             m_playersModel->playerJoinedRoom(lst[i]);
       
   623         }
   642         }
   624         return;
   643         return;
   625     }
   644     }
   626 
   645 
   627     if(netClientState == InRoom || netClientState == InGame)
   646     if(netClientState == InRoom || netClientState == InGame)
   961 void HWNewNet::toggleRestrictTeamAdds()
   980 void HWNewNet::toggleRestrictTeamAdds()
   962 {
   981 {
   963     RawSendNet(QString("TOGGLE_RESTRICT_TEAMS"));
   982     RawSendNet(QString("TOGGLE_RESTRICT_TEAMS"));
   964 }
   983 }
   965 
   984 
       
   985 void HWNewNet::toggleRegisteredOnly()
       
   986 {
       
   987     RawSendNet(QString("TOGGLE_REGISTERED_ONLY"));
       
   988 }
       
   989 
   966 void HWNewNet::clearAccountsCache()
   990 void HWNewNet::clearAccountsCache()
   967 {
   991 {
   968     RawSendNet(QString("CLEAR_ACCOUNTS_CACHE"));
   992     RawSendNet(QString("CLEAR_ACCOUNTS_CACHE"));
   969 }
   993 }
   970 
   994