some changes
authordisplacer
Thu, 11 Jan 2007 23:29:57 +0000
changeset 319 7f3bd9e31f18
parent 318 46a43b02bbb3
child 320 1ee7f087195a
some changes
QTfrontend/netserver.cpp
QTfrontend/netserver.h
QTfrontend/newnetclient.cpp
QTfrontend/team.cpp
QTfrontend/team.h
--- a/QTfrontend/netserver.cpp	Thu Jan 11 23:19:18 2007 +0000
+++ b/QTfrontend/netserver.cpp	Thu Jan 11 23:29:57 2007 +0000
@@ -131,13 +131,21 @@
   return msg;
 }
 
-void HWNetServer::startAll(QString gameCfg)
+void HWNetServer::sendAll(QString gameCfg)
 {
   for(QList<HWConnectedClient*>::iterator it=connclients.begin(); it!=connclients.end(); ++it) {
     (*it)->RawSendNet(gameCfg);
   }
 }
 
+void HWNetServer::sendOthers(HWConnectedClient* this_cl, QString gameCfg)
+{
+  for(QList<HWConnectedClient*>::iterator it=connclients.begin(); it!=connclients.end(); ++it) {
+    if(*it==this_cl) continue;
+    (*it)->RawSendNet(gameCfg);
+  }
+}
+
 HWConnectedClient::HWConnectedClient(HWNetServer* hwserver, QTcpSocket* client) :
   readyToStart(false),
   m_hwserver(hwserver),
@@ -176,8 +184,9 @@
   qDebug() << "line " << msg << " received";
 
   QStringList lst = msg.split(delimeter);
-  if(lst.size()<2) return;
+  if(!lst.size()) return;
   if (lst[0] == "NICK") {
+    if(lst.size()<2) return;
     if(m_hwserver->haveNick(lst[1])) {
       RawSendNet(QString("ERRONEUSNICKNAME"));
       throw ShouldDisconnectException();
@@ -196,7 +205,7 @@
     readyToStart=true;
     if(m_hwserver->shouldStart(this)) {
       // start
-      m_hwserver->startAll(QString("CONFIGURED")+delimeter+m_hwserver->prepareConfig(gameCfg)+delimeter+"!"+delimeter);
+      m_hwserver->sendAll(QString("CONFIGURED")+delimeter+m_hwserver->prepareConfig(gameCfg)+delimeter+"!"+delimeter);
     }
     return;
   }
@@ -207,14 +216,16 @@
     return;
   }
 
-  if(lst.size()<10) return;
   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();
     return;
   }
+  
+  m_hwserver->sendOthers(this, msg);
 }
 
 void HWConnectedClient::teamChangedNotify()
@@ -256,5 +267,5 @@
 
 QString HWConnectedClient::getHedgehogsDescription() const
 {
-  return pclent_team->TeamGameConfig(65535, 4, 100).join((QString)delimeter);
+  return pclent_team->TeamGameConfig(65535, 4, 100, true).join((QString)delimeter);
 }
--- a/QTfrontend/netserver.h	Thu Jan 11 23:19:18 2007 +0000
+++ b/QTfrontend/netserver.h	Thu Jan 11 23:29:57 2007 +0000
@@ -78,7 +78,8 @@
   void StartServer();
   void StopServer();
   bool isCheefClient(HWConnectedClient* cl) const;
-  void startAll(QString gameCfg);
+  void sendAll(QString gameCfg);
+  void sendOthers(HWConnectedClient* this_cl, QString gameCfg);
   bool haveNick(const QString& nick) const;
   QString getRunningHostName() const;
   quint16 getRunningPort() const;
--- a/QTfrontend/newnetclient.cpp	Thu Jan 11 23:19:18 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Thu Jan 11 23:29:57 2007 +0000
@@ -70,10 +70,11 @@
 
 void HWNewNet::SendNet(const QByteArray & buf)
 {
+  qDebug() << "to net:" << buf;
   QString msg = QString(buf.toBase64());
 
   //NetBuffer += buf;
-  //RawSendNet(QString("PRIVMSG %1 :"MAGIC_CHAR MAGIC_CHAR"%2").arg(channel, msg));
+  RawSendNet(QString(msg));
 }
 
 void HWNewNet::RawSendNet(const QString & str)
@@ -169,6 +170,7 @@
   }
 
   QByteArray em = QByteArray::fromBase64(msg.toAscii());
+  qDebug() << "to engine:" << em;
   emit FromNet(em);
 }
 
@@ -177,6 +179,7 @@
 {
   QByteArray cache;
   HWProto::addStringToBuffer(cache, "eseed " + seed);
+  HWProto::addStringToBuffer(cache, "TN");
   HWProto::addStringToBuffer(cache, "e$gmflags 0");
   HWProto::addStringToBuffer(cache, QString("etheme %1").arg(config->GetRandomTheme()));
   QString _msg = QString("CONFIGANSWER") + delimeter + QString(cache.toBase64());
--- a/QTfrontend/team.cpp	Thu Jan 11 23:19:18 2007 +0000
+++ b/QTfrontend/team.cpp	Thu Jan 11 23:29:57 2007 +0000
@@ -198,7 +198,7 @@
 	}
 }
 
-QStringList HWTeam::TeamGameConfig(quint32 color, int hedgehogs, quint32 InitHealth) const
+QStringList HWTeam::TeamGameConfig(quint32 color, int hedgehogs, quint32 InitHealth, bool netTeam) const
 {
 	QStringList sl;
 	sl.push_back("eaddteam");
@@ -206,16 +206,18 @@
 	sl.push_back("ename team " + TeamName);
 	for (int i = 0; i < hedgehogs; i++)
 		sl.push_back(QString("ename hh%1 ").arg(i).append(HHName[i]));
-	sl.push_back(QString("egrave " + Grave));
-	sl.push_back(QString("efort " + Fort));
-	for(int i = 0; i < BINDS_NUMBER; i++)
-	{
-		sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action));
+	if(!netTeam) {
+	  sl.push_back(QString("egrave " + Grave));
+	  sl.push_back(QString("efort " + Fort));
+	  for(int i = 0; i < BINDS_NUMBER; i++)
+	    {
+	      sl.push_back(QString("ebind " + binds[i].strbind + " " + binds[i].action));
+	    }
 	}
 	for (int t = 0; t < hedgehogs; t++)
-		sl.push_back(QString("eaddhh %1 %2")
-				.arg(QString::number(difficulty),
-				QString::number(InitHealth)));
+	  sl.push_back(QString("eaddhh %1 %2")
+		       .arg(QString::number(difficulty),
+			    QString::number(InitHealth)));
 	return sl;
 }
 
--- a/QTfrontend/team.h	Thu Jan 11 23:19:18 2007 +0000
+++ b/QTfrontend/team.h	Thu Jan 11 23:29:57 2007 +0000
@@ -48,7 +48,7 @@
 		bool SaveToFile();
 		void SetToPage(HWForm * hwform);
 		void GetFromPage(HWForm * hwform);
-		QStringList TeamGameConfig(quint32 color, int hedgehogs, quint32 InitHealth) const;
+		QStringList TeamGameConfig(quint32 color, int hedgehogs, quint32 InitHealth, bool netTeam=false) const;
 
 		bool operator==(const HWTeam& t1) const;
 		bool operator<(const HWTeam& t1) const;