QTfrontend/netserver.cpp
changeset 317 e95340dbfc1d
parent 315 73003488240b
child 319 7f3bd9e31f18
equal deleted inserted replaced
316:57d50189ad86 317:e95340dbfc1d
    71 quint16 HWNetServer::getRunningPort() const
    71 quint16 HWNetServer::getRunningPort() const
    72 {
    72 {
    73   return ds_port;
    73   return ds_port;
    74 }
    74 }
    75 
    75 
       
    76 bool HWNetServer::isCheefClient(HWConnectedClient* cl) const
       
    77 {
       
    78   for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
       
    79     if((*it)->getClientNick()!="" && *it==cl)  return true;
       
    80   }
       
    81   return false;
       
    82 }
       
    83 
    76 bool HWNetServer::haveNick(const QString& nick) const
    84 bool HWNetServer::haveNick(const QString& nick) const
    77 {
    85 {
    78   for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
    86   for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
    79     if((*it)->getClientNick()==nick) {
    87     if((*it)->getClientNick()==nick) {
    80       return true;
    88       return true;
   119     if(!(*it)->isReady()) continue;
   127     if(!(*it)->isReady()) continue;
   120     msg+=(*it)->getHedgehogsDescription()+delimeter;
   128     msg+=(*it)->getHedgehogsDescription()+delimeter;
   121   }
   129   }
   122   qDebug() << msg;
   130   qDebug() << msg;
   123   return msg;
   131   return msg;
       
   132 }
       
   133 
       
   134 void HWNetServer::startAll(QString gameCfg)
       
   135 {
       
   136   for(QList<HWConnectedClient*>::iterator it=connclients.begin(); it!=connclients.end(); ++it) {
       
   137     (*it)->RawSendNet(gameCfg);
       
   138   }
   124 }
   139 }
   125 
   140 
   126 HWConnectedClient::HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client) :
   141 HWConnectedClient::HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client) :
   127   readyToStart(false),
   142   readyToStart(false),
   128   m_hwserver(hwserver),
   143   m_hwserver(hwserver),
   170 
   185 
   171     client_nick=lst[1];
   186     client_nick=lst[1];
   172     qDebug() << "send connected";
   187     qDebug() << "send connected";
   173     RawSendNet(QString("CONNECTED"));
   188     RawSendNet(QString("CONNECTED"));
   174     m_hwserver->teamChanged();
   189     m_hwserver->teamChanged();
       
   190     if(m_hwserver->isCheefClient(this)) RawSendNet(QString("CONFIGASKED"));
   175     return;
   191     return;
   176   }
   192   }
   177   if(client_nick=="") return;
   193   if(client_nick=="") return;
   178 
   194 
   179   if (lst[0]=="START:") {
   195   if (lst[0]=="START:") {
   180     readyToStart=true;
   196     readyToStart=true;
   181     if(m_hwserver->shouldStart(this)) {
   197     if(m_hwserver->shouldStart(this)) {
   182       // start
   198       // start
   183       RawSendNet(QString("CONFIGASKED"));
   199       m_hwserver->startAll(QString("CONFIGURED")+delimeter+m_hwserver->prepareConfig(gameCfg)+delimeter+"!"+delimeter);
   184     }
   200     }
   185     return;
   201     return;
   186   }
   202   }
   187 
   203 
   188   if(lst[0]=="CONFIGANSWER") {
   204   if(lst[0]=="CONFIGANSWER") {
   189     lst.pop_front();
   205     lst.pop_front();
   190     RawSendNet(QString("CONFIGURED")+QString(delimeter)+m_hwserver->prepareConfig(lst)+delimeter+"!"+delimeter);
   206     gameCfg=lst;
   191     return;
   207     return;
   192   }
   208   }
   193 
   209 
   194   if(lst.size()<10) return;
   210   if(lst.size()<10) return;
   195   if(lst[0]=="ADDTEAM:") {
   211   if(lst[0]=="ADDTEAM:") {