client/server net pre-alpha
authordisplacer
Wed, 10 Jan 2007 23:21:05 +0000
changeset 314 83773ccf4f09
parent 313 b26dbb909c4e
child 315 73003488240b
client/server net pre-alpha
QTfrontend/CMakeLists.txt
QTfrontend/hedgewars.pro
QTfrontend/hwform.cpp
QTfrontend/hwform.h
QTfrontend/mapContainer.cpp
QTfrontend/pages.cpp
QTfrontend/pages.h
QTfrontend/team.cpp
QTfrontend/team.h
--- a/QTfrontend/CMakeLists.txt	Mon Jan 08 21:44:57 2007 +0000
+++ b/QTfrontend/CMakeLists.txt	Wed Jan 10 23:21:05 2007 +0000
@@ -42,7 +42,9 @@
 	tcpBase.cpp
 	about.cpp
 	proto.cpp
-	fpsedit.cpp)
+	fpsedit.cpp
+	netserver.cpp
+	newnetclient.cpp)
 
 if (WIN32)
 	set(hwfr_src ${hwfr_src} res/hedgewars.rc)
@@ -70,7 +72,9 @@
 	about.h
 	KB.h
 	proto.h
-	fpsedit.h)
+	fpsedit.h
+	netserver.h
+	newnetclient.h)
 
 
 set(hwfr_rez
--- a/QTfrontend/hedgewars.pro	Mon Jan 08 21:44:57 2007 +0000
+++ b/QTfrontend/hedgewars.pro	Wed Jan 10 23:21:05 2007 +0000
@@ -33,7 +33,9 @@
            about.h \
            KB.h \
            proto.h \
-           fpsedit.h
+           fpsedit.h \
+           netserver.h \
+           newnetclient.h
            
            
 SOURCES += game.cpp \
@@ -56,7 +58,9 @@
            tcpBase.cpp \
            about.cpp \
            proto.cpp \
-           fpsedit.cpp
+           fpsedit.cpp \
+           netserver.cpp \
+           newnetclient.cpp
 
 TRANSLATIONS += translations/hedgewars_ru.ts
 
--- a/QTfrontend/hwform.cpp	Mon Jan 08 21:44:57 2007 +0000
+++ b/QTfrontend/hwform.cpp	Wed Jan 10 23:21:05 2007 +0000
@@ -34,9 +34,10 @@
 #include "gameuiconfig.h"
 #include "pages.h"
 #include "hwconsts.h"
+#include "newnetclient.h"
 
 HWForm::HWForm(QWidget *parent)
-	: QMainWindow(parent)
+  : QMainWindow(parent), pnetserver(0)
 {
 	ui.setupUi(this);
 
@@ -73,6 +74,7 @@
 
 	connect(ui.pageNet->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
 	connect(ui.pageNet->BtnNetConnect,	SIGNAL(clicked()),	this, SLOT(NetConnect()));
+	connect(ui.pageNet->BtnNetSvrStart, SIGNAL(clicked()), this, SLOT(NetStartServer()));
 
 	connect(ui.pageNetGame->BtnBack,	SIGNAL(clicked()),	this, SLOT(GoBack()));
 	connect(ui.pageNetGame->BtnAddTeam,	SIGNAL(clicked()),	this, SLOT(NetAddTeam()));
@@ -231,21 +233,40 @@
 	game->PlayDemo(cfgdir->absolutePath() + "/Demos/" + curritem->text() + ".hwd_" + cProtoVer);
 }
 
-void HWForm::NetConnect()
+void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick)
 {
-	hwnet = new HWNet(config);
+	hwnet = new HWNewNet(config);
 	connect(hwnet, SIGNAL(Connected()), this, SLOT(GoToNetChat()));
 	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 &)));
-	hwnet->Connect(ui.pageNet->editIP->text(), 6667, ui.pageNet->editNetNick->text());
+	hwnet->Connect(hostName, port, nick);
 	config->SaveOptions();
 }
 
+void HWForm::NetConnect()
+{
+  _NetConnect(ui.pageNet->editIP->text(), 46631, ui.pageNet->editNetNick->text());
+}
+
+void HWForm::NetStartServer()
+{
+  pnetserver = new HWNetServer;
+  pnetserver->StartServer();
+  _NetConnect(pnetserver->getRunningHostName(), pnetserver->getRunningPort(), ui.pageNet->editNetNick->text());
+}
+
 void HWForm::NetDisconnect()
 {
-	hwnet->Disconnect();
-	GoBack();
+  hwnet->Disconnect();
+  GoBack();
+  delete hwnet;
+  hwnet=0;
+  if(pnetserver) {
+    pnetserver->StopServer();
+    delete pnetserver;
+    pnetserver=0;
+  }
 }
 
 void HWForm::AddGame(const QString & chan)
--- a/QTfrontend/hwform.h	Mon Jan 08 21:44:57 2007 +0000
+++ b/QTfrontend/hwform.h	Wed Jan 10 23:21:05 2007 +0000
@@ -24,12 +24,13 @@
 #include <QDir>
 #include <QStack>
 
+#include "netserver.h"
 #include "game.h"
 #include "ui_hwform.h"
 
 class HWGame;
 class HWTeam;
-class HWNet;
+class HWNewNet;
 class GameUIConfig;
 
 class HWForm : public QMainWindow
@@ -58,6 +59,7 @@
 	void SimpleGame();
 	void PlayDemo();
 	void NetConnect();
+	void NetStartServer();
 	void NetDisconnect();
 	void NetJoin();
 	void NetCreate();
@@ -71,7 +73,9 @@
 	void GameStats(char type, const QString & info);
 
 private:
+	void _NetConnect(const QString & hostName, quint16 port, const QString & nick);
 	void UpdateTeamsLists();
+	void CreateGame(GameCFGWidget * gamecfg);
 	enum PageIDs {
 		ID_PAGE_SINGLEPLAYER	= 0,
 		ID_PAGE_SETUP_TEAM	= 1,
@@ -87,11 +91,10 @@
 		};
 	HWGame * game;
 	HWTeam * editedTeam;
-	HWNet * hwnet;
+	HWNewNet * hwnet;
 	GameUIConfig * config;
 	QStack<quint8> PagesStack;
-
-	void CreateGame(GameCFGWidget * gamecfg);
+	HWNetServer* pnetserver;
 	void AddStatText(const QString & msg);
 	void OnPageShown(quint8 id);
 };
--- a/QTfrontend/mapContainer.cpp	Mon Jan 08 21:44:57 2007 +0000
+++ b/QTfrontend/mapContainer.cpp	Wed Jan 10 23:21:05 2007 +0000
@@ -117,9 +117,9 @@
     QTextStream input(&mapCfgFile);
     QString theme;
     input >> theme;
+    mapCfgFile.close();
     if(theme.length()>256) throw MapFileErrorException(); // theme name too long
     return theme;
-    mapCfgFile.close();
   } else {
     throw MapFileErrorException();
   }
--- a/QTfrontend/pages.cpp	Mon Jan 08 21:44:57 2007 +0000
+++ b/QTfrontend/pages.cpp	Wed Jan 10 23:21:05 2007 +0000
@@ -376,7 +376,7 @@
 	pageLayout->setColumnStretch(2, 1);
 
 	NNGroupBox = new QGroupBox(this);
-	NNGroupBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
+	NNGroupBox->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
 	NNGroupBox->setTitle(QGroupBox::tr("Net options"));
 	pageLayout->addWidget(NNGroupBox, 0, 1);
 
@@ -405,6 +405,11 @@
 	BtnNetConnect->setText(QPushButton::tr("Connect"));
 	pageLayout->addWidget(BtnNetConnect, 2, 2);
 
+	BtnNetSvrStart = new	QPushButton(this);
+	BtnNetSvrStart->setFont(*font14);
+	BtnNetSvrStart->setText(QPushButton::tr("Start server"));
+	pageLayout->addWidget(BtnNetSvrStart, 2, 1);
+
 	BtnBack = new QPushButton(this);
 	BtnBack->setFont(*font14);
 	BtnBack->setText(QPushButton::tr("Back"));
--- a/QTfrontend/pages.h	Mon Jan 08 21:44:57 2007 +0000
+++ b/QTfrontend/pages.h	Wed Jan 10 23:21:05 2007 +0000
@@ -157,6 +157,7 @@
 
 	QPushButton *BtnBack;
 	QPushButton *BtnNetConnect;
+	QPushButton* BtnNetSvrStart;
 	QGroupBox *NNGroupBox;
 	QLabel *labelNN;
 	QLineEdit *editNetNick;
--- a/QTfrontend/team.cpp	Mon Jan 08 21:44:57 2007 +0000
+++ b/QTfrontend/team.cpp	Wed Jan 10 23:21:05 2007 +0000
@@ -26,6 +26,9 @@
 #include "pages.h"
 #include "hwconsts.h"
 
+#include <QStringList>
+#include <QDebug>
+
 HWTeam::HWTeam(const QString & teamname) :
   difficulty(0)
 {
@@ -41,6 +44,13 @@
 	}
 }
 
+HWTeam::HWTeam(const QStringList& strLst)
+{
+  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)
 {
--- a/QTfrontend/team.h	Mon Jan 08 21:44:57 2007 +0000
+++ b/QTfrontend/team.h	Wed Jan 10 23:21:05 2007 +0000
@@ -26,10 +26,15 @@
 class HWForm;
 class GameUIConfig;
 
+class HWTeamConstructException
+{
+};
+
 class HWTeam
 {
 	public:
 		HWTeam(const QString & teamname);
+		HWTeam(const QStringList& strLst);
 		HWTeam(quint8 num);
 
 		QString TeamName;