more correct network hhnum
authordisplacer
Tue, 06 Feb 2007 19:34:21 +0000
changeset 399 c7da1bd32b4e
parent 398 fd2cf7827f31
child 400 450ff6326084
more correct network hhnum
QTfrontend/netserver.cpp
QTfrontend/netserver.h
QTfrontend/newnetclient.cpp
--- a/QTfrontend/netserver.cpp	Tue Feb 06 16:30:23 2007 +0000
+++ b/QTfrontend/netserver.cpp	Tue Feb 06 19:34:21 2007 +0000
@@ -32,6 +32,7 @@
 
 void HWNetServer::StartServer()
 {
+  hhnum=0;
   IPCServer = new QTcpServer(this);
   if (!IPCServer->listen(QHostAddress::Any, ds_port)) {
     QMessageBox::critical(0, tr("Error"),
@@ -258,6 +259,16 @@
     static unsigned int netTeamID=1;
     lst.insert(1, QString::number(netTeamID++));
 
+    // hedgehogs num count
+    int maxAdd=18-m_hwserver->hhnum;
+    if (maxAdd<=0) return; // reject command
+    int toAdd=maxAdd<4 ? maxAdd : 4;
+    m_hwserver->hhnum+=toAdd;
+    // hedgehogs num config
+    QString hhnumCfg=QString("CONFIG_PARAM%1HHNUM+%2+%3%1%4").arg(delimeter).arg(lst[0])\
+      .arg(netTeamID)\
+      .arg(toAdd);
+    
     // creating color config for new team
     QString colorCfg=QString("CONFIG_PARAM%1TEAM_COLOR%1%2%1%3%1%4").arg(delimeter).arg(lst[0])\
       .arg(netTeamID)\
@@ -265,15 +276,30 @@
     qDebug() << "color config:" << colorCfg;
 
     m_gameCfg[colorCfg.split(delimeter)[1]]=colorCfg.split(delimeter).mid(2);
+    m_gameCfg[hhnumCfg.split(delimeter)[1]]=hhnumCfg.split(delimeter).mid(2);
     m_teamsCfg.push_back(lst);
 
     m_hwserver->sendOthers(this, QString("ADDTEAM:")+delimeter+lst.join(QString(delimeter)));
     RawSendNet(QString("TEAM_ACCEPTED%1%2%1%3").arg(delimeter).arg(lst[0]).arg(lst[1]));
+    m_hwserver->sendAll(hhnumCfg);
     return;
   }
 
   if(lst[0]=="REMOVETEAM:") {
     if(lst.size()<2) return;
+    
+    for(QMap<QString, QStringList>::iterator it=m_gameCfg.begin(); it!=m_gameCfg.end(); ++it) {
+      QStringList hhTmpList=it.key().split('+');
+      if(hhTmpList[0] == "HHNUM") {
+	qDebug() << "hhnum config found";
+	if(hhTmpList[1]==lst[1]) {
+	  qDebug() << "hhnum config team found with: " << lst[1] << ":" << it.value()[0].toUInt();
+	  m_hwserver->hhnum-=it.value()[0].toUInt();
+	  break;
+	}
+      }
+    }
+
     unsigned int netID=removeTeam(lst[1]);
     m_hwserver->sendOthers(this, QString("REMOVETEAM:")+delimeter+lst[1]+delimeter+QString::number(netID));
     return;
--- a/QTfrontend/netserver.h	Tue Feb 06 16:30:23 2007 +0000
+++ b/QTfrontend/netserver.h	Tue Feb 06 19:34:21 2007 +0000
@@ -91,6 +91,8 @@
   QString prepareConfig(QStringList lst);
   void resetStart();
 
+  int hhnum;
+
  private:
   HWConnectedClient* getChiefClient() const;
   static const quint16 ds_port;
--- a/QTfrontend/newnetclient.cpp	Tue Feb 06 16:30:23 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Tue Feb 06 19:34:21 2007 +0000
@@ -227,15 +227,6 @@
 	  emit fortsModeChanged(lst[2].toInt() != 0);
 	  return;
   	}
-  	if (lst[1] == "HHNUM") {
-	  HWTeam tmptm(lst[2], lst[3].toUInt());
-	  if(m_networkToLocalteams.find(lst[3].toUInt())!=m_networkToLocalteams.end()) {
-	    tmptm=HWTeam(lst[2]); // local team should be changed
-	  }
-	  tmptm.numHedgehogs=lst[4].toUInt();
-	  emit hhnumChanged(tmptm);
-	  return;
-  	}
   	if (lst[1] == "TEAM_COLOR") {
 	  HWTeam tmptm(lst[2], lst[3].toUInt());
 	  if(m_networkToLocalteams.find(lst[3].toUInt())!=m_networkToLocalteams.end()) {
@@ -245,6 +236,17 @@
 	  emit teamColorChanged(tmptm);
 	  return;
   	}
+	QStringList hhTmpList;
+  	if ((hhTmpList=lst[1].split('+'))[0] == "HHNUM") {
+	  qDebug() << "NEW HHNUM!";
+	  HWTeam tmptm(hhTmpList[1], hhTmpList[2].toUInt());
+	  if(m_networkToLocalteams.find(hhTmpList[2].toUInt())!=m_networkToLocalteams.end()) {
+	    tmptm=HWTeam(hhTmpList[1]); // local team should be changed
+	  }
+	  tmptm.numHedgehogs=lst[2].toUInt();
+	  emit hhnumChanged(tmptm);
+	  return;
+  	}
   	qDebug() << "unknow config param: " << lst[1];
     return;
   }
@@ -284,7 +286,7 @@
 void HWNewNet::onHedgehogsNumChanged(const HWTeam& team)
 {
   qDebug() << team.getNetID() << ":" << team.numHedgehogs;
-  RawSendNet(QString("CONFIG_PARAM%1HHNUM%1%2%1%3%1%4").arg(delimeter).arg(team.TeamName)\
+  RawSendNet(QString("CONFIG_PARAM%1HHNUM+%2+%3%1%4").arg(delimeter).arg(team.TeamName)\
 	     .arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))\
 	     .arg(team.numHedgehogs));
 }