Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
authorunc0rr
Sun, 14 Jan 2007 14:08:40 +0000
changeset 329 4c3aad46baa5
parent 328 95625db21bf8
child 330 09cfe028a629
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
QTfrontend/hwform.cpp
QTfrontend/mapContainer.cpp
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
QTfrontend/pages.cpp
QTfrontend/pages.h
--- a/QTfrontend/hwform.cpp	Sun Jan 14 13:23:15 2007 +0000
+++ b/QTfrontend/hwform.cpp	Sun Jan 14 14:08:40 2007 +0000
@@ -35,6 +35,7 @@
 #include "pages.h"
 #include "hwconsts.h"
 #include "newnetclient.h"
+#include "gamecfgwidget.h"
 
 HWForm::HWForm(QWidget *parent)
   : QMainWindow(parent), pnetserver(0)
@@ -241,7 +242,24 @@
 	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(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam)));
+
+	connect(ui.pageNetGame->pGameCFG, SIGNAL(seedChanged(const QString &)), hwnet, SLOT(onSeedChanged(const QString &)));
+	connect(ui.pageNetGame->pGameCFG, SIGNAL(mapChanged(const QString &)), hwnet, SLOT(onMapChanged(const QString &)));
+	connect(ui.pageNetGame->pGameCFG, SIGNAL(themeChanged(const QString &)), hwnet, SLOT(onThemeChanged(const QString &)));
+	connect(ui.pageNetGame->pGameCFG, SIGNAL(initHealthChanged(quint32)), hwnet, SLOT(onInitHealthChanged(quint32)));
+	connect(ui.pageNetGame->pGameCFG, SIGNAL(turnTimeChanged(quint32)), hwnet, SLOT(onTurnTimeChanged(quint32)));
+	connect(ui.pageNetGame->pGameCFG, SIGNAL(fortsModeChanged(bool)), hwnet, SLOT(onFortsModeChanged(bool)));
+
+	connect(hwnet, SIGNAL(seedChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(onSeedChanged(const QString &)));
+	connect(hwnet, SIGNAL(mapChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(onMapChanged(const QString &)));
+	connect(hwnet, SIGNAL(themeChanged(const QString &)), ui.pageNetGame->pGameCFG, SLOT(onThemeChanged(const QString &)));
+	connect(hwnet, SIGNAL(initHealthChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(onInitHealthChanged(quint32)));
+	connect(hwnet, SIGNAL(turnTimeChanged(quint32)), ui.pageNetGame->pGameCFG, SLOT(onTurnTimeChanged(quint32)));
+	connect(hwnet, SIGNAL(fortsModeChanged(bool)), ui.pageNetGame->pGameCFG, SLOT(onFortsModeChanged(bool)));
+
+
 	hwnet->Connect(hostName, port, nick);
 	config->SaveOptions();
 }
--- a/QTfrontend/mapContainer.cpp	Sun Jan 14 13:23:15 2007 +0000
+++ b/QTfrontend/mapContainer.cpp	Sun Jan 14 14:08:40 2007 +0000
@@ -101,10 +101,8 @@
 {
   pMap = new HWMap();
   connect(pMap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage)));
-  emit seedChanged(m_seed);
   pMap->getImage(m_seed.toStdString());
   theme = (Themes->size() > 0) ? Themes->at(rand() % Themes->size()) : "steel";
-  emit themeChanged(theme);
 }
 
 QString HWMapContainer::getCurrentSeed() const
@@ -147,5 +145,7 @@
 void HWMapContainer::setRandomSeed()
 {
   m_seed = QUuid::createUuid().toString();
+  emit seedChanged(m_seed);
   changeImage();
+  emit themeChanged(theme);
 }
--- a/QTfrontend/newnetclient.cpp	Sun Jan 14 13:23:15 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Sun Jan 14 14:08:40 2007 +0000
@@ -16,7 +16,6 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  */
 
-#include <QUuid>
 #include <QMessageBox>
 #include <QDebug>
 
@@ -64,8 +63,7 @@
 
 void HWNewNet::StartGame()
 {
-  seed = QUuid::createUuid().toString();
-  RawSendNet(QString("START:") + delimeter + seed);
+  RawSendNet(QString("START:"));
 }
 
 void HWNewNet::SendNet(const QByteArray & buf)
@@ -74,7 +72,7 @@
   qDebug() << "to net:" << buf << ":" << msg;
 
   //NetBuffer += buf;
-  RawSendNet(QString(msg));
+  RawSendNet(QString("GAMEMSG:%1%2").arg(delimeter).arg(msg));
 }
 
 void HWNewNet::RawSendNet(const QString & str)
@@ -84,7 +82,6 @@
 
 void HWNewNet::RawSendNet(const QByteArray & buf)
 {
-  if (buf.size() > 510) return;
   NetSocket.write(buf);
   NetSocket.write("\n", 1);
 }
@@ -169,9 +166,47 @@
     return;
   }
 
-  QByteArray em = QByteArray::fromBase64(msg.toAscii());
-  qDebug() << "to engine:" << em;
-  emit FromNet(em);
+  if (lst[0] == "CONFIG_PARAM") {
+  	if (lst[1] == "SEED") {
+      emit seedChanged(lst[2]);
+	  return;
+  	}
+  	if (lst[1] == "MAP") {
+      emit mapChanged(lst[2]);
+	  return;
+  	}
+  	if (lst[1] == "THEME") {
+      emit themeChanged(lst[2]);
+	  return;
+  	}
+  	if (lst[1] == "HEALTH") {
+      emit initHealthChanged(lst[2].toUInt());
+	  return;
+  	}
+  	if (lst[1] == "TURNTIME") {
+      emit turnTimeChanged(lst[2].toUInt());
+	  return;
+  	}
+  	if (lst[1] == "FORTSMODE") {
+      emit fortsModeChanged(lst[2].toInt() != 0);
+	  return;
+  	}
+  	qDebug() << "unknow config param: " << lst[1];
+    return;
+  }
+
+
+  // should be kinda game states, which don't allow "GAMEMSG:" at configure step,
+  // "CONNECTED" at round phase, etc.
+  if (lst[0] == "GAMEMSG:") {
+    QByteArray em = QByteArray::fromBase64(lst[1].toAscii());
+    qDebug() << "to engine:" << em;
+    emit FromNet(em);
+    return;
+  }
+
+  qDebug() << "unknown net command: " << msg;
+
 }
 
 
@@ -194,3 +229,33 @@
   connect(this, SIGNAL(LocalCFG(const QString &)), game, SLOT(LocalCFG(const QString &)));
   game->StartNet();
 }
+
+void HWNewNet::onSeedChanged(const QString & seed)
+{
+  RawSendNet(QString("CONFIG_PARAM%1SEED%1%2").arg(delimeter).arg(seed));
+}
+
+void HWNewNet::onMapChanged(const QString & map)
+{
+  RawSendNet(QString("CONFIG_PARAM%1MAP%1%2").arg(delimeter).arg(map));
+}
+
+void HWNewNet::onThemeChanged(const QString & theme)
+{
+  RawSendNet(QString("CONFIG_PARAM%1THEME%1%2").arg(delimeter).arg(theme));
+}
+
+void HWNewNet::onInitHealthChanged(quint32 health)
+{
+  RawSendNet(QString("CONFIG_PARAM%1HEALTH%1%2").arg(delimeter).arg(health));
+}
+
+void HWNewNet::onTurnTimeChanged(quint32 time)
+{
+  RawSendNet(QString("CONFIG_PARAM%1TURNTIME%1%2").arg(delimeter).arg(time));
+}
+
+void HWNewNet::onFortsModeChanged(bool value)
+{
+  RawSendNet(QString("CONFIG_PARAM%1FORTSMODE%1%2").arg(delimeter).arg(value));
+}
--- a/QTfrontend/newnetclient.h	Sun Jan 14 13:23:15 2007 +0000
+++ b/QTfrontend/newnetclient.h	Sun Jan 14 14:08:40 2007 +0000
@@ -82,9 +82,22 @@
   void LocalCFG(const QString & team);
   void ChangeInTeams(const QStringList & teams);
 
+  void seedChanged(const QString & seed);
+  void mapChanged(const QString & map);
+  void themeChanged(const QString & theme);
+  void initHealthChanged(quint32 health);
+  void turnTimeChanged(quint32 time);
+  void fortsModeChanged(bool value);
+
  public slots:
   void SendNet(const QByteArray & buf);
   void AddTeam(const HWTeam & team);
+  void onSeedChanged(const QString & seed);
+  void onMapChanged(const QString & map);
+  void onThemeChanged(const QString & theme);
+  void onInitHealthChanged(quint32 health);
+  void onTurnTimeChanged(quint32 time);
+  void onFortsModeChanged(bool value);
 
  private slots:
   void ClientRead();
--- a/QTfrontend/pages.cpp	Sun Jan 14 13:23:15 2007 +0000
+++ b/QTfrontend/pages.cpp	Sun Jan 14 14:08:40 2007 +0000
@@ -448,10 +448,10 @@
 	QFont * font14 = new QFont("MS Shell Dlg", 14);
 	QGridLayout * pageLayout = new QGridLayout(this);
 
-	pGameCFG=new GameCFGWidget(this);
+	pGameCFG = new GameCFGWidget(this);
 	pageLayout->addWidget(pGameCFG, 0, 0);
-	
-	pNetTeamsWidget=new TeamSelWidget(this);
+
+	pNetTeamsWidget = new TeamSelWidget(this);
 	pageLayout->addWidget(pNetTeamsWidget, 0, 1);
 
 	BtnBack = new QPushButton(this);
--- a/QTfrontend/pages.h	Sun Jan 14 13:23:15 2007 +0000
+++ b/QTfrontend/pages.h	Sun Jan 14 14:08:40 2007 +0000
@@ -190,8 +190,6 @@
 	QPushButton *BtnGo;
 
 	TeamSelWidget* pNetTeamsWidget;
-
- private:
 	GameCFGWidget* pGameCFG;
 };