QTfrontend/netserver.cpp
changeset 338 d1e75dcd285f
parent 335 751348947fce
child 339 7535ab6c3820
--- a/QTfrontend/netserver.cpp	Sun Jan 14 21:51:17 2007 +0000
+++ b/QTfrontend/netserver.cpp	Sun Jan 14 23:13:24 2007 +0000
@@ -60,7 +60,7 @@
 {
   QList<HWConnectedClient*>::iterator it=std::find(connclients.begin(), connclients.end(), client);
   connclients.erase(it);
-  teamChanged();
+  //teamChanged();
 }
 
 QString HWNetServer::getRunningHostName() const
@@ -108,25 +108,18 @@
   return false;
 }
 
-QStringList HWNetServer::getTeams() const
+QList<QStringList> HWNetServer::getTeamsConfig() const
 {
-  QStringList lst;
+  QList<QStringList> lst;
   for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
     try {
-      lst.push_back((*it)->getTeamName());
+      lst+=(*it)->getTeamNames();
     } catch(HWConnectedClient::NoTeamNameException& e) {
     }
   }
   return lst;
 }
 
-void HWNetServer::teamChanged()
-{
-  for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
-    (*it)->teamChangedNotify();
-  }
-}
-
 bool HWNetServer::shouldStart(HWConnectedClient* client)
 {
   QList<HWConnectedClient*>::iterator it=std::find(connclients.begin(), connclients.end(), client);
@@ -166,8 +159,7 @@
 HWConnectedClient::HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client) :
   readyToStart(false),
   m_hwserver(hwserver),
-  m_client(client),
-  pclent_team(0)
+  m_client(client)
 {
   connect(client, SIGNAL(disconnected()), this, SLOT(ClientDisconnect()));
   connect(client, SIGNAL(readyRead()), this, SLOT(ClientRead()));
@@ -175,7 +167,6 @@
 
 HWConnectedClient::~HWConnectedClient()
 {
-  if(pclent_team) delete pclent_team;
 }
 
 void HWConnectedClient::ClientDisconnect()
@@ -212,13 +203,18 @@
     client_nick=lst[1];
     qDebug() << "send connected";
     RawSendNet(QString("CONNECTED"));
-    m_hwserver->teamChanged();
     if(m_hwserver->isChiefClient(this)) RawSendNet(QString("CONFIGASKED"));
     else {
+      // send config
       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());
       }
+      // send teams
+      QList<QStringList> team_conf=m_hwserver->getTeamsConfig();
+      for(QList<QStringList>::iterator tmit=team_conf.begin(); tmit!=team_conf.end(); ++tmit) {
+	RawSendNet(QString("ADDTEAM:")+delimeter+tmit->join(QString(delimeter)));
+      }
     }
     return;
   }
@@ -240,23 +236,17 @@
   if(lst[0]=="ADDTEAM:") {
     if(lst.size()<10) return;
     lst.pop_front();
-    if(pclent_team) delete pclent_team;
-    pclent_team=new HWTeam(lst);
-    m_hwserver->teamChanged();
+    m_teamsCfg.push_back(lst);
+    m_hwserver->sendOthers(this, msg);
     return;
   }
 
   m_hwserver->sendOthers(this, msg);
 }
 
-void HWConnectedClient::teamChangedNotify()
+QList<QStringList> HWConnectedClient::getTeamNames() const
 {
-  QString teams;
-  QStringList lst=m_hwserver->getTeams();
-  for(int i=0; i<lst.size(); i++) {
-    teams+=delimeter+lst[i];
-  }
-  RawSendNet(QString("TEAMCHANGED")+teams);
+  return m_teamsCfg;
 }
 
 void HWConnectedClient::RawSendNet(const QString & str)
@@ -275,12 +265,6 @@
   return client_nick;
 }
 
-QString HWConnectedClient::getTeamName() const
-{
-  if(!pclent_team) throw NoTeamNameException();
-  return pclent_team->TeamName;
-}
-
 bool HWConnectedClient::isReady() const
 {
   return readyToStart;
@@ -288,5 +272,5 @@
 
 QString HWConnectedClient::getHedgehogsDescription() const
 {
-  return pclent_team->TeamGameConfig(65535, 4, 100, true).join((QString)delimeter);
+  return QString();//pclent_team->TeamGameConfig(65535, 4, 100, true).join((QString)delimeter);
 }