Run game message added, team and config info provided for net game
authordisplacer
Mon, 15 Jan 2007 18:45:07 +0000
changeset 339 7535ab6c3820
parent 338 d1e75dcd285f
child 340 f5d4db927eba
Run game message added, team and config info provided for net game
QTfrontend/game.cpp
QTfrontend/game.h
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/netserver.cpp
QTfrontend/newnetclient.cpp
QTfrontend/newnetclient.h
QTfrontend/team.cpp
QTfrontend/team.h
QTfrontend/teamselect.cpp
QTfrontend/teamselect.h
--- a/QTfrontend/game.cpp	Sun Jan 14 23:13:24 2007 +0000
+++ b/QTfrontend/game.cpp	Mon Jan 15 18:45:07 2007 +0000
@@ -29,11 +29,13 @@
 #include "hwconsts.h"
 #include "gameuiconfig.h"
 #include "gamecfgwidget.h"
+#include "teamselect.h"
 #include "KB.h"
 #include "proto.h"
 
-HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg) :
-  TCPBase(true)
+HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget) :
+  TCPBase(true),
+  m_pTeamSelWidget(pTeamSelWidget)
 {
 	this->config = config;
 	this->gamecfg = gamecfg;
--- a/QTfrontend/game.h	Sun Jan 14 23:13:24 2007 +0000
+++ b/QTfrontend/game.h	Mon Jan 15 18:45:07 2007 +0000
@@ -30,6 +30,7 @@
 
 class GameUIConfig;
 class GameCFGWidget;
+class TeamSelWidget;
 
 enum GameState {
 	gsNotStarted = 0,
@@ -44,7 +45,7 @@
 {
 	Q_OBJECT
 public:
-	HWGame(GameUIConfig * config, GameCFGWidget * gamecfg);
+	HWGame(GameUIConfig * config, GameCFGWidget * gamecfg, TeamSelWidget* pTeamSelWidget=0);
 	void AddTeam(const QString & team, HWTeamTempParams teamParams);
 	void PlayDemo(const QString & demofilename);
 	void StartLocal();
@@ -79,6 +80,7 @@
 	int TeamCount;
 	GameUIConfig * config;
 	GameCFGWidget * gamecfg;
+	TeamSelWidget* m_pTeamSelWidget;
 	GameType gameType;
 
 	void commonConfig();
--- a/QTfrontend/hwform.cpp	Sun Jan 14 23:13:24 2007 +0000
+++ b/QTfrontend/hwform.cpp	Mon Jan 15 18:45:07 2007 +0000
@@ -238,10 +238,10 @@
 
 void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick)
 {
-	hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG);
+	hwnet = new HWNewNet(config, ui.pageNetGame->pGameCFG, ui.pageNetGame->pNetTeamsWidget);
 	connect(hwnet, SIGNAL(AddGame(const QString &)), this, SLOT(AddGame(const QString &)));
 	connect(hwnet, SIGNAL(EnteredGame()), this, SLOT(NetGameEnter()));
-	connect(hwnet, SIGNAL(AddNetTeam(const QString&)), this, SLOT(AddNetTeam(const QString&)));
+	connect(hwnet, SIGNAL(AddNetTeam(const HWTeam&)), this, SLOT(AddNetTeam(const HWTeam&)));
 
 	connect(ui.pageNetGame->pNetTeamsWidget, SIGNAL(teamWillPlay(HWTeam)), hwnet, SLOT(AddTeam(HWTeam)));
 
@@ -314,9 +314,9 @@
 	hwnet->StartGame();
 }
 
-void HWForm::AddNetTeam(const QString& team)
+void HWForm::AddNetTeam(const HWTeam& team)
 {
-  ui.pageNetGame->pNetTeamsWidget->addTeam(team, true);
+  ui.pageNetGame->pNetTeamsWidget->addTeam(team);
 }
 
 void HWForm::StartMPGame()
--- a/QTfrontend/hwform.h	Sun Jan 14 23:13:24 2007 +0000
+++ b/QTfrontend/hwform.h	Mon Jan 15 18:45:07 2007 +0000
@@ -66,7 +66,7 @@
 	void AddGame(const QString & chan);
 	void NetGameEnter();
 	void NetStartGame();
-	void AddNetTeam(const QString& team);
+	void AddNetTeam(const HWTeam& team);
 	void StartMPGame();
 	void GameStateChanged(GameState gameState);
 	void GameStats(char type, const QString & info);
--- a/QTfrontend/netserver.cpp	Sun Jan 14 23:13:24 2007 +0000
+++ b/QTfrontend/netserver.cpp	Mon Jan 15 18:45:07 2007 +0000
@@ -224,6 +224,7 @@
     readyToStart=true;
     if(m_hwserver->shouldStart(this)) {
       // start
+      m_hwserver->sendAll("RUNGAME");
     }
     return;
   }
--- a/QTfrontend/newnetclient.cpp	Sun Jan 14 23:13:24 2007 +0000
+++ b/QTfrontend/newnetclient.cpp	Mon Jan 15 18:45:07 2007 +0000
@@ -27,9 +27,10 @@
 
 char delimeter='\t';
 
-HWNewNet::HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget) :
+HWNewNet::HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget) :
   config(config),
   m_pGameCFGWidget(pGameCFGWidget),
+  m_pTeamSelWidget(pTeamSelWidget),
   isChief(false)
 {
   connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
@@ -147,7 +148,7 @@
 
   if (lst[0] == "ADDTEAM:") {
     lst.pop_front();
-    emit AddNetTeam(lst[0]);
+    emit AddNetTeam(lst);
     return;
   }
 
@@ -157,6 +158,14 @@
     return;
   }
 
+  if (lst[0] == "RUNGAME") {
+    HWGame* game = new HWGame(config, m_pGameCFGWidget, m_pTeamSelWidget); // FIXME: memory leak here (stackify it?)
+    connect(game, SIGNAL(SendNet(const QByteArray &)), this, SLOT(SendNet(const QByteArray &)));
+    connect(this, SIGNAL(FromNet(const QByteArray &)), game, SLOT(FromNet(const QByteArray &)));
+    connect(this, SIGNAL(LocalCFG(const QString &)), game, SLOT(LocalCFG(const QString &)));
+    game->StartNet();
+  }
+
   if (lst[0] == "CONFIGURED") {
     lst.pop_front();
     if(lst.size()<5) return;
--- a/QTfrontend/newnetclient.h	Sun Jan 14 23:13:24 2007 +0000
+++ b/QTfrontend/newnetclient.h	Mon Jan 15 18:45:07 2007 +0000
@@ -27,6 +27,7 @@
 
 class GameUIConfig;
 class GameCFGWidget;
+class TeamSelWidget;
 
 extern char delimeter;
 
@@ -35,7 +36,7 @@
   Q_OBJECT
 
  public:
-  HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget);
+  HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget);
   void Connect(const QString & hostName, quint16 port, const QString & nick);
   void Disconnect();
   void JoinGame(const QString & game);
@@ -44,6 +45,7 @@
  private:
   GameUIConfig* config;
   GameCFGWidget* m_pGameCFGWidget;
+  TeamSelWidget* m_pTeamSelWidget;
 
   bool isChief;
   QString mynick;
@@ -83,7 +85,7 @@
   void EnteredGame();
   void FromNet(const QByteArray & buf);
   void LocalCFG(const QString & team);
-  void AddNetTeam(const QString&);
+  void AddNetTeam(const HWTeam&);
 
   void seedChanged(const QString & seed);
   void mapChanged(const QString & map);
--- a/QTfrontend/team.cpp	Sun Jan 14 23:13:24 2007 +0000
+++ b/QTfrontend/team.cpp	Mon Jan 15 18:45:07 2007 +0000
@@ -30,7 +30,8 @@
 #include <QDebug>
 
 HWTeam::HWTeam(const QString & teamname) :
-  difficulty(0)
+  difficulty(0),
+  netTeam(false)
 {
 	TeamName = teamname;
 	OldTeamName = TeamName;
@@ -44,15 +45,18 @@
 	}
 }
 
-HWTeam::HWTeam(const QStringList& strLst)
+HWTeam::HWTeam(const QStringList& strLst) :
+  netTeam(true)
 {
+  // net teams are configured from QStringList
   if(strLst.size()<9) throw HWTeamConstructException();
   TeamName=strLst[0];
   for(int i = 0; i < 8; i++) HHName[i]=strLst[i+1];
 }
 
 HWTeam::HWTeam(quint8 num) :
-  difficulty(0)
+  difficulty(0),
+  netTeam(false)
 {
 	num %= PREDEFTEAMS_COUNT;
 	TeamName = QApplication::translate("teams", pteams[num].TeamName);
--- a/QTfrontend/team.h	Sun Jan 14 23:13:24 2007 +0000
+++ b/QTfrontend/team.h	Mon Jan 15 18:45:07 2007 +0000
@@ -43,6 +43,7 @@
 		QString Fort;
 		unsigned int difficulty;
 		BindAction binds[BINDS_NUMBER];
+		bool netTeam;
 
 		bool LoadFromFile();
 		bool SaveToFile();
--- a/QTfrontend/teamselect.cpp	Sun Jan 14 23:13:24 2007 +0000
+++ b/QTfrontend/teamselect.cpp	Mon Jan 15 18:45:07 2007 +0000
@@ -26,9 +26,9 @@
 #include "teamselhelper.h"
 #include "frameTeam.h"
 
-void TeamSelWidget::addTeam(HWTeam team, bool netTeam)
+void TeamSelWidget::addTeam(HWTeam team)
 {
-  if(netTeam) {
+  if(team.netTeam) {
     framePlaying->addTeam(team, true);
     curPlayingTeams.push_back(team);
   } else {
--- a/QTfrontend/teamselect.h	Sun Jan 14 23:13:24 2007 +0000
+++ b/QTfrontend/teamselect.h	Mon Jan 15 18:45:07 2007 +0000
@@ -47,7 +47,7 @@
   list<HWTeam> getPlayingTeams() const;
 
  public slots:
-  void addTeam(HWTeam team, bool netTeam=false);
+  void addTeam(HWTeam team);
 
  signals:
   void NewTeam();