QTfrontend/netserver.cpp
changeset 354 60e4af0a4375
parent 352 4665bfe25470
child 382 e7220e48ead1
equal deleted inserted replaced
353:5ec611d702a0 354:60e4af0a4375
    88 bool HWNetServer::isChiefClient(HWConnectedClient* cl) const
    88 bool HWNetServer::isChiefClient(HWConnectedClient* cl) const
    89 {
    89 {
    90   return getChiefClient()==cl;
    90   return getChiefClient()==cl;
    91 }
    91 }
    92 
    92 
    93 QMap<QString, QString> HWNetServer::getGameCfg() const
    93 QMap<QString, QStringList> HWNetServer::getGameCfg() const
    94 {
    94 {
    95   for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
    95   for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
    96     if(isChiefClient(*it)) {
    96     if(isChiefClient(*it)) {
    97       return (*it)->m_gameCfg;
    97       return (*it)->m_gameCfg;
    98     }
    98     }
    99   }
    99   }
   100   // error happened if we are here
   100   // error happened if we are here
   101   return QMap<QString, QString>();
   101   return QMap<QString, QStringList>();
   102 }
   102 }
   103 
   103 
   104 bool HWNetServer::haveNick(const QString& nick) const
   104 bool HWNetServer::haveNick(const QString& nick) const
   105 {
   105 {
   106   for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
   106   for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
   207     qDebug() << "send connected";
   207     qDebug() << "send connected";
   208     RawSendNet(QString("CONNECTED"));
   208     RawSendNet(QString("CONNECTED"));
   209     if(m_hwserver->isChiefClient(this)) RawSendNet(QString("CONFIGASKED"));
   209     if(m_hwserver->isChiefClient(this)) RawSendNet(QString("CONFIGASKED"));
   210     else {
   210     else {
   211       RawSendNet(QString("SLAVE"));
   211       RawSendNet(QString("SLAVE"));
   212       // send config
       
   213       QMap<QString, QString> conf=m_hwserver->getGameCfg();
       
   214       for(QMap<QString, QString>::iterator it=conf.begin(); it!=conf.end(); ++it) {
       
   215 	RawSendNet(QString("CONFIG_PARAM")+delimeter+it.key()+delimeter+it.value());
       
   216       }
       
   217       // send teams
   212       // send teams
   218       QList<QStringList> team_conf=m_hwserver->getTeamsConfig();
   213       QList<QStringList> team_conf=m_hwserver->getTeamsConfig();
   219       for(QList<QStringList>::iterator tmit=team_conf.begin(); tmit!=team_conf.end(); ++tmit) {
   214       for(QList<QStringList>::iterator tmit=team_conf.begin(); tmit!=team_conf.end(); ++tmit) {
   220 	RawSendNet(QString("ADDTEAM:")+delimeter+tmit->join(QString(delimeter)));
   215 	RawSendNet(QString("ADDTEAM:")+delimeter+tmit->join(QString(delimeter)));
   221       }
   216       }
       
   217       // send config
       
   218       QMap<QString, QStringList> conf=m_hwserver->getGameCfg();
       
   219       for(QMap<QString, QStringList>::iterator it=conf.begin(); it!=conf.end(); ++it) {
       
   220 	RawSendNet(QString("CONFIG_PARAM")+delimeter+it.key()+delimeter+it.value().join(QString(delimeter)));
       
   221       }
   222     }
   222     }
   223     return;
   223     return;
   224   }
   224   }
   225   if(client_nick=="") return;
   225   if(client_nick=="") return;
   226 
   226 
   233     return;
   233     return;
   234   }
   234   }
   235 
   235 
   236   if(lst[0]=="CONFIG_PARAM") {
   236   if(lst[0]=="CONFIG_PARAM") {
   237     if(!m_hwserver->isChiefClient(this) || lst.size()<3) return; // error or permission denied :)
   237     if(!m_hwserver->isChiefClient(this) || lst.size()<3) return; // error or permission denied :)
   238     else m_gameCfg[lst[1]]=lst[2];
   238     else m_gameCfg[lst[1]]=lst.mid(2);
   239   }
   239   }
   240 
   240 
   241   if(lst[0]=="ADDTEAM:") {
   241   if(lst[0]=="ADDTEAM:") {
   242     if(lst.size()<10) return;
   242     if(lst.size()<10) return;
   243     lst.pop_front();
   243     lst.pop_front();
   245     static unsigned int netTeamID=1;
   245     static unsigned int netTeamID=1;
   246     lst.insert(1, QString::number(netTeamID++));
   246     lst.insert(1, QString::number(netTeamID++));
   247 
   247 
   248     m_teamsCfg.push_back(lst);
   248     m_teamsCfg.push_back(lst);
   249     m_hwserver->sendOthers(this, QString("ADDTEAM:")+delimeter+lst.join(QString(delimeter)));
   249     m_hwserver->sendOthers(this, QString("ADDTEAM:")+delimeter+lst.join(QString(delimeter)));
       
   250     RawSendNet(QString("TEAM_ACCEPTED%1%2%1%3").arg(delimeter).arg(lst[0]).arg(lst[1]));
   250     return;
   251     return;
   251   }
   252   }
   252 
   253 
   253   if(lst[0]=="REMOVETEAM:") {
   254   if(lst[0]=="REMOVETEAM:") {
   254     if(lst.size()<2) return;
   255     if(lst.size()<2) return;