QTfrontend/netserver.cpp
changeset 319 7f3bd9e31f18
parent 317 e95340dbfc1d
child 326 c6718bfdd642
equal deleted inserted replaced
318:46a43b02bbb3 319:7f3bd9e31f18
   129   }
   129   }
   130   qDebug() << msg;
   130   qDebug() << msg;
   131   return msg;
   131   return msg;
   132 }
   132 }
   133 
   133 
   134 void HWNetServer::startAll(QString gameCfg)
   134 void HWNetServer::sendAll(QString gameCfg)
   135 {
   135 {
   136   for(QList<HWConnectedClient*>::iterator it=connclients.begin(); it!=connclients.end(); ++it) {
   136   for(QList<HWConnectedClient*>::iterator it=connclients.begin(); it!=connclients.end(); ++it) {
       
   137     (*it)->RawSendNet(gameCfg);
       
   138   }
       
   139 }
       
   140 
       
   141 void HWNetServer::sendOthers(HWConnectedClient* this_cl, QString gameCfg)
       
   142 {
       
   143   for(QList<HWConnectedClient*>::iterator it=connclients.begin(); it!=connclients.end(); ++it) {
       
   144     if(*it==this_cl) continue;
   137     (*it)->RawSendNet(gameCfg);
   145     (*it)->RawSendNet(gameCfg);
   138   }
   146   }
   139 }
   147 }
   140 
   148 
   141 HWConnectedClient::HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client) :
   149 HWConnectedClient::HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client) :
   174   QString msg = QString::fromUtf8 (line.data(), line.size());
   182   QString msg = QString::fromUtf8 (line.data(), line.size());
   175 
   183 
   176   qDebug() << "line " << msg << " received";
   184   qDebug() << "line " << msg << " received";
   177 
   185 
   178   QStringList lst = msg.split(delimeter);
   186   QStringList lst = msg.split(delimeter);
   179   if(lst.size()<2) return;
   187   if(!lst.size()) return;
   180   if (lst[0] == "NICK") {
   188   if (lst[0] == "NICK") {
       
   189     if(lst.size()<2) return;
   181     if(m_hwserver->haveNick(lst[1])) {
   190     if(m_hwserver->haveNick(lst[1])) {
   182       RawSendNet(QString("ERRONEUSNICKNAME"));
   191       RawSendNet(QString("ERRONEUSNICKNAME"));
   183       throw ShouldDisconnectException();
   192       throw ShouldDisconnectException();
   184     }
   193     }
   185 
   194 
   194 
   203 
   195   if (lst[0]=="START:") {
   204   if (lst[0]=="START:") {
   196     readyToStart=true;
   205     readyToStart=true;
   197     if(m_hwserver->shouldStart(this)) {
   206     if(m_hwserver->shouldStart(this)) {
   198       // start
   207       // start
   199       m_hwserver->startAll(QString("CONFIGURED")+delimeter+m_hwserver->prepareConfig(gameCfg)+delimeter+"!"+delimeter);
   208       m_hwserver->sendAll(QString("CONFIGURED")+delimeter+m_hwserver->prepareConfig(gameCfg)+delimeter+"!"+delimeter);
   200     }
   209     }
   201     return;
   210     return;
   202   }
   211   }
   203 
   212 
   204   if(lst[0]=="CONFIGANSWER") {
   213   if(lst[0]=="CONFIGANSWER") {
   205     lst.pop_front();
   214     lst.pop_front();
   206     gameCfg=lst;
   215     gameCfg=lst;
   207     return;
   216     return;
   208   }
   217   }
   209 
   218 
   210   if(lst.size()<10) return;
       
   211   if(lst[0]=="ADDTEAM:") {
   219   if(lst[0]=="ADDTEAM:") {
       
   220     if(lst.size()<10) return;
   212     lst.pop_front();
   221     lst.pop_front();
   213     if(pclent_team) delete pclent_team;
   222     if(pclent_team) delete pclent_team;
   214     pclent_team=new HWTeam(lst);
   223     pclent_team=new HWTeam(lst);
   215     m_hwserver->teamChanged();
   224     m_hwserver->teamChanged();
   216     return;
   225     return;
   217   }
   226   }
       
   227   
       
   228   m_hwserver->sendOthers(this, msg);
   218 }
   229 }
   219 
   230 
   220 void HWConnectedClient::teamChangedNotify()
   231 void HWConnectedClient::teamChangedNotify()
   221 {
   232 {
   222   QString teams;
   233   QString teams;
   254   return readyToStart;
   265   return readyToStart;
   255 }
   266 }
   256 
   267 
   257 QString HWConnectedClient::getHedgehogsDescription() const
   268 QString HWConnectedClient::getHedgehogsDescription() const
   258 {
   269 {
   259   return pclent_team->TeamGameConfig(65535, 4, 100).join((QString)delimeter);
   270   return pclent_team->TeamGameConfig(65535, 4, 100, true).join((QString)delimeter);
   260 }
   271 }