multiple teams now available per host (still alpha)
authordisplacer
Sun, 14 Jan 2007 23:13:24 +0000
changeset 338 d1e75dcd285f
parent 337 a46abb65eb0c
child 339 7535ab6c3820
multiple teams now available per host (still alpha)
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/netserver.cpp
QTfrontend/netserver.h
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
--- a/QTfrontend/hwform.cpp	Sun Jan 14 21:51:17 2007 +0000
+++ b/QTfrontend/hwform.cpp	Sun Jan 14 23:13:24 2007 +0000
@@ -241,7 +241,7 @@
 	hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG);
 	connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &)));
 	connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
-	connect(hwnet, SIGNAL(ChangeInTeams(const QStringList &)), this, SLOT(ChangeInNetTeams(const QStringList &)));
+	connect(hwnet, SIGNAL(AddNetTeam(const QString&)), this, SLOT(AddNetTeam(const QString&)));
 
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam)));
 
@@ -314,26 +314,9 @@
 	hwnet->StartGame();
 }
 
-void HWForm::ChangeInNetTeams(const QStringList & teams)
+void HWForm::AddNetTeam(const QString& team)
 {
-  QStringList addedTeams=teams;
-  list<HWTeam> lstPlaying=ui.pageNetGame->pNetTeamsWidget->getPlayingTeams();
-  for(list<HWTeam>::iterator it=lstPlaying.begin(); it!=lstPlaying.end(); ++it) {
-    QString nm=it->TeamName;
-    QStringList::iterator itt=std::find(addedTeams.begin(), addedTeams.end(), nm);
-    if(itt!=addedTeams.end()) addedTeams.erase(itt);
-  }
-  for(QStringList::iterator it=addedTeams.begin(); it!=addedTeams.end(); ++it) {
-    ui.pageNetGame->pNetTeamsWidget->addTeam(*it, true);
-  }
-
-  /*
-  QStringList lstQSPlaying;
-  std::for_each(lstPlaying.begin(), lstPlaying.end(), lstQSPlaying.push_back);
-  QStringList removedTeams=teams;
-  for(QStringList::iterator it=teams.begin()
-  list<HWTeam>::iterator removedItem=std::find(addedTeams.begin(), addedTeams.end(), nm);
-  */
+  ui.pageNetGame->pNetTeamsWidget->addTeam(team, true);
 }
 
 void HWForm::StartMPGame()
--- a/QTfrontend/hwform.h	Sun Jan 14 21:51:17 2007 +0000
+++ b/QTfrontend/hwform.h	Sun Jan 14 23:13:24 2007 +0000
@@ -66,7 +66,7 @@
 	void AddGame(const QString & chan);
 	void NetGameEnter();
 	void NetStartGame();
-	void ChangeInNetTeams(const QStringList & teams);
+	void AddNetTeam(const QString& team);
 	void StartMPGame();
 	void GameStateChanged(GameState gameState);
 	void GameStats(char type, const QString & info);
--- 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);
 }
--- a/QTfrontend/netserver.h	Sun Jan 14 21:51:17 2007 +0000
+++ b/QTfrontend/netserver.h	Sun Jan 14 23:13:24 2007 +0000
@@ -40,15 +40,15 @@
   ~HWConnectedClient();
   QString getClientNick() const;
 
+  QList<QStringList> getTeamNames() const;
   class NoTeamNameException{};
-  QString getTeamName() const;
-  void teamChangedNotify();
   bool isReady() const;
 
   QString getHedgehogsDescription() const;
 
   bool readyToStart;
-  QMap<QString, QString> m_gameCfg;
+  QMap<QString, QString> m_gameCfg; // config_param - value
+  QList<QStringList> m_teamsCfg; // TeamName - hhs
   class ShouldDisconnectException {};
 
   QString client_nick;
@@ -56,7 +56,6 @@
 
   HWNetServer* m_hwserver;
   QTcpSocket* m_client;
-  HWTeam* pclent_team;
 
   void RawSendNet(const QString & buf);
   void RawSendNet(const QByteArray & buf);
@@ -85,7 +84,7 @@
   bool haveNick(const QString& nick) const;
   QString getRunningHostName() const;
   quint16 getRunningPort() const;
-  QStringList getTeams() const;
+  QList<QStringList> getTeamsConfig() const;
   void teamChanged();
   bool shouldStart(HWConnectedClient* client);
   QString prepareConfig(QStringList lst);
--- a/QTfrontend/newnetclient.cpp	Sun Jan 14 21:51:17 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Sun Jan 14 23:13:24 2007 +0000
@@ -104,7 +104,7 @@
 
 void HWNewNet::OnDisconnect()
 {
-  emit ChangeInTeams(QStringList());
+  //emit ChangeInTeams(QStringList());
   emit Disconnected();
 }
 
@@ -145,9 +145,9 @@
     return;
   }
 
-  if (lst[0] == "TEAMCHANGED") {
+  if (lst[0] == "ADDTEAM:") {
     lst.pop_front();
-    emit ChangeInTeams(lst);
+    emit AddNetTeam(lst[0]);
     return;
   }
 
--- a/QTfrontend/newnetclient.h	Sun Jan 14 21:51:17 2007 +0000
+++ b/QTfrontend/newnetclient.h	Sun Jan 14 23:13:24 2007 +0000
@@ -83,7 +83,7 @@
   void EnteredGame();
   void FromNet(const QByteArray & buf);
   void LocalCFG(const QString & team);
-  void ChangeInTeams(const QStringList & teams);
+  void AddNetTeam(const QString&);
 
   void seedChanged(const QString & seed);
   void mapChanged(const QString & map);