QTfrontend/net/newnetclient.cpp
changeset 14924 5119203470f3
parent 14887 e088bd03812d
child 14927 8b5d06749026
equal deleted inserted replaced
14923:2dcc64515346 14924:5119203470f3
    39     m_game_connected(false),
    39     m_game_connected(false),
    40     netClientState(Disconnected)
    40     netClientState(Disconnected)
    41 {
    41 {
    42     m_private_game = false;
    42     m_private_game = false;
    43     m_nick_registered = false;
    43     m_nick_registered = false;
       
    44     m_demo_data_pending = false;
    44 
    45 
    45     m_roomsListModel = new RoomsListModel(this);
    46     m_roomsListModel = new RoomsListModel(this);
    46 
    47 
    47     m_playersModel = new PlayersListModel(this);
    48     m_playersModel = new PlayersListModel(this);
    48 
    49 
   796             emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i]));
   797             emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i]));
   797         }
   798         }
   798         return;
   799         return;
   799     }
   800     }
   800 
   801 
   801     if(netClientState == InRoom || netClientState == InGame)
   802     if(netClientState == InLobby && lst[0] == "REPLAY_START")
       
   803     {
       
   804         if(lst.size() < 2 || lst[1] != mynick)
       
   805         {
       
   806             qWarning("Net: Bad REPLAY_START message");
       
   807             return;
       
   808         }
       
   809 
       
   810         for(int i = 1; i < lst.size(); ++i)
       
   811         {
       
   812             if (lst[i] == mynick)
       
   813             {
       
   814                 netClientState = InRoom;
       
   815                 m_demo_data_pending = true;
       
   816                 emit EnteredGame();
       
   817                 emit roomMaster(false);
       
   818             }
       
   819         }
       
   820         return;
       
   821     }
       
   822 
       
   823     if(netClientState == InRoom || netClientState == InGame || netClientState == InDemo)
   802     {
   824     {
   803         if (lst[0] == "EM")
   825         if (lst[0] == "EM")
   804         {
   826         {
   805             if(lst.size() < 2)
   827             if(lst.size() < 2)
   806             {
   828             {
   807                 qWarning("Net: Bad EM message");
   829                 qWarning("Net: Bad EM message");
       
   830                 m_demo_data_pending = false;
   808                 return;
   831                 return;
   809             }
   832             }
   810             for(int i = 1; i < lst.size(); ++i)
   833             for(int i = 1; i < lst.size(); ++i)
   811             {
   834             {
   812                 QByteArray em = QByteArray::fromBase64(lst[i].toLatin1());
   835                 QByteArray em = QByteArray::fromBase64(lst[i].toLatin1());
   813                 emit FromNet(em);
   836                 emit FromNet(em);
   814             }
   837             }
   815             return;
   838             m_demo_data_pending = false;
   816         }
   839             return;
   817 
   840         }
       
   841     }
       
   842 
       
   843     if(netClientState == InRoom || netClientState == InGame)
       
   844     {
   818         if (lst[0] == "ROUND_FINISHED")
   845         if (lst[0] == "ROUND_FINISHED")
   819         {
   846         {
   820             emit FromNet(QByteArray("\x01o"));
   847             emit FromNet(QByteArray("\x01o"));
   821             return;
   848             return;
   822         }
   849         }
   854             return;
   881             return;
   855         }
   882         }
   856 
   883 
   857         if (lst[0] == "RUN_GAME")
   884         if (lst[0] == "RUN_GAME")
   858         {
   885         {
   859             netClientState = InGame;
   886             if(m_demo_data_pending)
   860             emit AskForRunGame();
   887             {
       
   888                 netClientState = InDemo;
       
   889                 emit AskForOfficialServerDemo();
       
   890             }
       
   891             else
       
   892             {
       
   893                 netClientState = InGame;
       
   894                 emit AskForRunGame();
       
   895             }
   861             return;
   896             return;
   862         }
   897         }
   863 
   898 
   864         if (lst[0] == "TEAM_ACCEPTED")
   899         if (lst[0] == "TEAM_ACCEPTED")
   865         {
   900         {
  1063     if (netClientState == InGame)
  1098     if (netClientState == InGame)
  1064     {
  1099     {
  1065         netClientState = InRoom;
  1100         netClientState = InRoom;
  1066         RawSendNet(QString("ROUNDFINISHED%1%2").arg(delimiter).arg(correctly ? "1" : "0"));
  1101         RawSendNet(QString("ROUNDFINISHED%1%2").arg(delimiter).arg(correctly ? "1" : "0"));
  1067     }
  1102     }
       
  1103     else if (netClientState == InDemo)
       
  1104     {
       
  1105         netClientState = InLobby;
       
  1106         askRoomsList();
       
  1107         emit LeftRoom(QString());
       
  1108         m_playersModel->resetRoomFlags();
       
  1109     }
  1068 }
  1110 }
  1069 
  1111 
  1070 void HWNewNet::banPlayer(const QString & nick)
  1112 void HWNewNet::banPlayer(const QString & nick)
  1071 {
  1113 {
  1072     RawSendNet(QString("BAN%1%2").arg(delimiter).arg(nick));
  1114     RawSendNet(QString("BAN%1%2").arg(delimiter).arg(nick));