CONFIG_PARAM for storing config
authordisplacer
Sun, 14 Jan 2007 21:10:36 +0000
changeset 335 751348947fce
parent 334 85eacbd9827f
child 336 82d654db133d
CONFIG_PARAM for storing config
QTfrontend/netserver.cpp
QTfrontend/netserver.h
QTfrontend/newnetclient.cpp
--- a/QTfrontend/netserver.cpp	Sun Jan 14 20:46:17 2007 +0000
+++ b/QTfrontend/netserver.cpp	Sun Jan 14 21:10:36 2007 +0000
@@ -87,13 +87,15 @@
   return getChiefClient()==cl;
 }
 
-QStringList HWNetServer::getGameCfg() const
+QMap<QString, QString> HWNetServer::getGameCfg() const
 {
   for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
-    if(isChiefClient(*it)) return (*it)->gameCfg;
+    if(isChiefClient(*it)) {
+      return (*it)->m_gameCfg;
+    }
   }
   // error happened if we are here
-  return QStringList();
+  return QMap<QString, QString>();
 }
 
 bool HWNetServer::haveNick(const QString& nick) const
@@ -212,7 +214,12 @@
     RawSendNet(QString("CONNECTED"));
     m_hwserver->teamChanged();
     if(m_hwserver->isChiefClient(this)) RawSendNet(QString("CONFIGASKED"));
-    else RawSendNet(QString("CONFIGURED")+delimeter+m_hwserver->getGameCfg().join(QString(delimeter)));
+    else {
+      QMap<QString, QString> conf=m_hwserver->getGameCfg();
+      for(QMap<QString, QString>::iterator it=conf.begin(); it!=conf.end(); ++it) {
+	RawSendNet(QString("CONFIG_PARAM")+delimeter+it.key()+delimeter+it.value());
+      }
+    }
     return;
   }
   if(client_nick=="") return;
@@ -225,10 +232,9 @@
     return;
   }
 
-  if(lst[0]=="CONFIGANSWER") {
-    lst.pop_front();
-    gameCfg=lst;
-    return;
+  if(lst[0]=="CONFIG_PARAM") {
+    if(!m_hwserver->isChiefClient(this) || lst.size()<3) return; // error or permission denied :)
+    else m_gameCfg[lst[1]]=lst[2];
   }
 
   if(lst[0]=="ADDTEAM:") {
--- a/QTfrontend/netserver.h	Sun Jan 14 20:46:17 2007 +0000
+++ b/QTfrontend/netserver.h	Sun Jan 14 21:10:36 2007 +0000
@@ -21,6 +21,7 @@
 
 #include <QObject>
 #include <QList>
+#include <QMap>
 
 #include "team.h"
 
@@ -78,7 +79,7 @@
   void StartServer();
   void StopServer();
   bool isChiefClient(HWConnectedClient* cl) const;
-  QStringList getGameCfg() const;
+  QMap<QString, QString> getGameCfg() const;
   void sendAll(QString gameCfg);
   void sendOthers(HWConnectedClient* this_cl, QString gameCfg);
   bool haveNick(const QString& nick) const;
--- a/QTfrontend/newnetclient.cpp	Sun Jan 14 20:46:17 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Sun Jan 14 21:10:36 2007 +0000
@@ -216,13 +216,11 @@
 
 void HWNewNet::ConfigAsked()
 {
-  QString _msg=QString("CONFIGANSWER")+delimeter;
-  _msg+=m_pGameCFGWidget->getCurrentSeed()+delimeter;
-  _msg+=m_pGameCFGWidget->getCurrentMap()+delimeter;
-  _msg+=m_pGameCFGWidget->getCurrentTheme()+delimeter;
-  _msg+=QString("%1").arg(m_pGameCFGWidget->getInitHealth())+delimeter;
-  _msg+=QString("%1").arg(m_pGameCFGWidget->getTurnTime());
-  RawSendNet(_msg);
+  onSeedChanged(m_pGameCFGWidget->getCurrentSeed());
+  onMapChanged(m_pGameCFGWidget->getCurrentMap());
+  onThemeChanged(m_pGameCFGWidget->getCurrentTheme());
+  onInitHealthChanged(m_pGameCFGWidget->getInitHealth());
+  onTurnTimeChanged(m_pGameCFGWidget->getTurnTime());
 }
 
 void HWNewNet::RunGame()