QTfrontend/netserver.cpp
changeset 399 c7da1bd32b4e
parent 391 e7565bb852a2
child 401 bcebe3921740
equal deleted inserted replaced
398:fd2cf7827f31 399:c7da1bd32b4e
    30 
    30 
    31 extern char delimeter;
    31 extern char delimeter;
    32 
    32 
    33 void HWNetServer::StartServer()
    33 void HWNetServer::StartServer()
    34 {
    34 {
       
    35   hhnum=0;
    35   IPCServer = new QTcpServer(this);
    36   IPCServer = new QTcpServer(this);
    36   if (!IPCServer->listen(QHostAddress::Any, ds_port)) {
    37   if (!IPCServer->listen(QHostAddress::Any, ds_port)) {
    37     QMessageBox::critical(0, tr("Error"),
    38     QMessageBox::critical(0, tr("Error"),
    38 			  tr("Unable to start the server: %1.")
    39 			  tr("Unable to start the server: %1.")
    39 			  .arg(IPCServer->errorString()));
    40 			  .arg(IPCServer->errorString()));
   256     
   257     
   257     // add team ID
   258     // add team ID
   258     static unsigned int netTeamID=1;
   259     static unsigned int netTeamID=1;
   259     lst.insert(1, QString::number(netTeamID++));
   260     lst.insert(1, QString::number(netTeamID++));
   260 
   261 
       
   262     // hedgehogs num count
       
   263     int maxAdd=18-m_hwserver->hhnum;
       
   264     if (maxAdd<=0) return; // reject command
       
   265     int toAdd=maxAdd<4 ? maxAdd : 4;
       
   266     m_hwserver->hhnum+=toAdd;
       
   267     // hedgehogs num config
       
   268     QString hhnumCfg=QString("CONFIG_PARAM%1HHNUM+%2+%3%1%4").arg(delimeter).arg(lst[0])\
       
   269       .arg(netTeamID)\
       
   270       .arg(toAdd);
       
   271     
   261     // creating color config for new team
   272     // creating color config for new team
   262     QString colorCfg=QString("CONFIG_PARAM%1TEAM_COLOR%1%2%1%3%1%4").arg(delimeter).arg(lst[0])\
   273     QString colorCfg=QString("CONFIG_PARAM%1TEAM_COLOR%1%2%1%3%1%4").arg(delimeter).arg(lst[0])\
   263       .arg(netTeamID)\
   274       .arg(netTeamID)\
   264       .arg(lst.takeAt(2));
   275       .arg(lst.takeAt(2));
   265     qDebug() << "color config:" << colorCfg;
   276     qDebug() << "color config:" << colorCfg;
   266 
   277 
   267     m_gameCfg[colorCfg.split(delimeter)[1]]=colorCfg.split(delimeter).mid(2);
   278     m_gameCfg[colorCfg.split(delimeter)[1]]=colorCfg.split(delimeter).mid(2);
       
   279     m_gameCfg[hhnumCfg.split(delimeter)[1]]=hhnumCfg.split(delimeter).mid(2);
   268     m_teamsCfg.push_back(lst);
   280     m_teamsCfg.push_back(lst);
   269 
   281 
   270     m_hwserver->sendOthers(this, QString("ADDTEAM:")+delimeter+lst.join(QString(delimeter)));
   282     m_hwserver->sendOthers(this, QString("ADDTEAM:")+delimeter+lst.join(QString(delimeter)));
   271     RawSendNet(QString("TEAM_ACCEPTED%1%2%1%3").arg(delimeter).arg(lst[0]).arg(lst[1]));
   283     RawSendNet(QString("TEAM_ACCEPTED%1%2%1%3").arg(delimeter).arg(lst[0]).arg(lst[1]));
       
   284     m_hwserver->sendAll(hhnumCfg);
   272     return;
   285     return;
   273   }
   286   }
   274 
   287 
   275   if(lst[0]=="REMOVETEAM:") {
   288   if(lst[0]=="REMOVETEAM:") {
   276     if(lst.size()<2) return;
   289     if(lst.size()<2) return;
       
   290     
       
   291     for(QMap<QString, QStringList>::iterator it=m_gameCfg.begin(); it!=m_gameCfg.end(); ++it) {
       
   292       QStringList hhTmpList=it.key().split('+');
       
   293       if(hhTmpList[0] == "HHNUM") {
       
   294 	qDebug() << "hhnum config found";
       
   295 	if(hhTmpList[1]==lst[1]) {
       
   296 	  qDebug() << "hhnum config team found with: " << lst[1] << ":" << it.value()[0].toUInt();
       
   297 	  m_hwserver->hhnum-=it.value()[0].toUInt();
       
   298 	  break;
       
   299 	}
       
   300       }
       
   301     }
       
   302 
   277     unsigned int netID=removeTeam(lst[1]);
   303     unsigned int netID=removeTeam(lst[1]);
   278     m_hwserver->sendOthers(this, QString("REMOVETEAM:")+delimeter+lst[1]+delimeter+QString::number(netID));
   304     m_hwserver->sendOthers(this, QString("REMOVETEAM:")+delimeter+lst[1]+delimeter+QString::number(netID));
   279     return;
   305     return;
   280   }
   306   }
   281 
   307