hedgehogs num bugfix for netgame
authordisplacer
Mon, 19 Feb 2007 15:31:40 +0000
changeset 455 925891c52e40
parent 454 19b0164f4284
child 456 35080d4b806b
hedgehogs num bugfix for netgame
QTfrontend/netconnectedclient.cpp
QTfrontend/newnetclient.cpp
--- a/QTfrontend/netconnectedclient.cpp	Sun Feb 18 21:16:41 2007 +0000
+++ b/QTfrontend/netconnectedclient.cpp	Mon Feb 19 15:31:40 2007 +0000
@@ -88,6 +88,7 @@
 	qDebug() << QString("CONFIG_PARAM")+delimeter+it.key()+delimeter+it.value().join(QString(delimeter));
       }
     }
+    m_hwserver->sendAll(QString("JOINED")+delimeter+client_nick);
     return;
   }
   if(client_nick=="") return;
@@ -102,6 +103,17 @@
     return;
   }
 
+  if(lst[0]=="HHNUM") {
+    if(!m_hwserver->isChiefClient(this) || lst.size()<4) return; // error or permission denied :)
+    const QString confstr=lst[0]+"+"+lst[1]+"+"+lst[2];
+    QMap<QString, QStringList>::iterator it=m_hwserver->m_gameCfg.find(confstr);
+    int oldTeamHHNum = it==m_hwserver->m_gameCfg.end() ? 0 : it.value()[0].toUInt();
+    int newTeamHHNum = lst[3].toUInt();
+    m_hwserver->hhnum+=newTeamHHNum-oldTeamHHNum;
+    // create CONFIG_PARAM to save HHNUM at server from lst
+    lst=QStringList("CONFIG_PARAM") << confstr << lst[3];
+  }
+
   if(lst[0]=="CONFIG_PARAM") {
     if(!m_hwserver->isChiefClient(this) || lst.size()<3) return; // error or permission denied :)
     else m_hwserver->m_gameCfg[lst[1]]=lst.mid(2);
@@ -121,6 +133,7 @@
     if (maxAdd<=0) return; // reject command
     int toAdd=maxAdd<4 ? maxAdd : 4;
     m_hwserver->hhnum+=toAdd;
+    qDebug() << "added " << toAdd << " hedgehogs";
     // hedgehogs num config
     QString hhnumCfg=QString("CONFIG_PARAM%1HHNUM+%2+%3%1%4").arg(delimeter).arg(lst[0])\
       .arg(netTeamID)\
@@ -149,9 +162,8 @@
     for(QMap<QString, QStringList>::iterator it=m_hwserver->m_gameCfg.begin(); it!=m_hwserver->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();
+	  qDebug() << "removed " << it.value()[0].toUInt() << " hedgehogs";
 	  m_hwserver->hhnum-=it.value()[0].toUInt();
 	  break;
 	}
--- a/QTfrontend/newnetclient.cpp	Sun Feb 18 21:16:41 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Mon Feb 19 15:31:40 2007 +0000
@@ -184,6 +184,12 @@
     return;
   }
 
+  if(lst[0]=="JOINED") {
+    if(lst.size()<2) return;
+    qDebug() << "JOINED" << lst[1];
+    return;
+  }
+
   if (lst[0] == "CONFIGASKED") {
     isChief=true;
     ConfigAsked();
@@ -251,7 +257,6 @@
 	  return;
   	}
   	if (hhTmpList[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
@@ -308,8 +313,7 @@
 
 void HWNewNet::onHedgehogsNumChanged(const HWTeam& team)
 {
-  qDebug() << team.getNetID() << ":" << team.numHedgehogs;
-  RawSendNet(QString("CONFIG_PARAM%1HHNUM+%2+%3%1%4").arg(delimeter).arg(team.TeamName)\
+  RawSendNet(QString("HHNUM%1%2%1%3%1%4").arg(delimeter).arg(team.TeamName)\
 	     .arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))\
 	     .arg(team.numHedgehogs));
 }