--- a/QTfrontend/hwform.cpp Sun Jan 14 19:47:11 2007 +0000
+++ b/QTfrontend/hwform.cpp Sun Jan 14 20:46:17 2007 +0000
@@ -238,7 +238,7 @@
void HWForm::_NetConnect(const QString & hostName, quint16 port, const QString & nick)
{
- hwnet = new HWNewNet(config);
+ 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 &)));
--- a/QTfrontend/netserver.cpp Sun Jan 14 19:47:11 2007 +0000
+++ b/QTfrontend/netserver.cpp Sun Jan 14 20:46:17 2007 +0000
@@ -73,14 +73,27 @@
return ds_port;
}
-bool HWNetServer::isChiefClient(HWConnectedClient* cl) const
+HWConnectedClient* HWNetServer::getChiefClient() const
{
for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
- // watch for first fully connected client (with confirmed nick) and test it for chief
- if((*it)->getClientNick()=="") continue;
- if(*it==cl) return true;
- else return false;
+ // watch for first fully connected client (with confirmed nick)
+ if((*it)->getClientNick()!="") return *it;
}
+ return 0;
+}
+
+bool HWNetServer::isChiefClient(HWConnectedClient* cl) const
+{
+ return getChiefClient()==cl;
+}
+
+QStringList HWNetServer::getGameCfg() const
+{
+ for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
+ if(isChiefClient(*it)) return (*it)->gameCfg;
+ }
+ // error happened if we are here
+ return QStringList();
}
bool HWNetServer::haveNick(const QString& nick) const
@@ -199,6 +212,7 @@
RawSendNet(QString("CONNECTED"));
m_hwserver->teamChanged();
if(m_hwserver->isChiefClient(this)) RawSendNet(QString("CONFIGASKED"));
+ else RawSendNet(QString("CONFIGURED")+delimeter+m_hwserver->getGameCfg().join(QString(delimeter)));
return;
}
if(client_nick=="") return;
@@ -207,7 +221,6 @@
readyToStart=true;
if(m_hwserver->shouldStart(this)) {
// start
- m_hwserver->sendAll(QString("CONFIGURED")+delimeter+m_hwserver->prepareConfig(gameCfg)+delimeter+"!"+delimeter);
}
return;
}
--- a/QTfrontend/netserver.h Sun Jan 14 19:47:11 2007 +0000
+++ b/QTfrontend/netserver.h Sun Jan 14 20:46:17 2007 +0000
@@ -47,7 +47,7 @@
QString getHedgehogsDescription() const;
bool readyToStart;
- QStringList gameCfg;
+ QMap<QString, QString> m_gameCfg;
class ShouldDisconnectException {};
QString client_nick;
@@ -78,6 +78,7 @@
void StartServer();
void StopServer();
bool isChiefClient(HWConnectedClient* cl) const;
+ QStringList getGameCfg() const;
void sendAll(QString gameCfg);
void sendOthers(HWConnectedClient* this_cl, QString gameCfg);
bool haveNick(const QString& nick) const;
@@ -89,6 +90,7 @@
QString prepareConfig(QStringList lst);
private:
+ HWConnectedClient* getChiefClient() const;
static const quint16 ds_port;
QTcpServer* IPCServer;
QList<HWConnectedClient*> connclients;
--- a/QTfrontend/newnetclient.cpp Sun Jan 14 19:47:11 2007 +0000
+++ b/QTfrontend/newnetclient.cpp Sun Jan 14 20:46:17 2007 +0000
@@ -23,11 +23,14 @@
#include "proto.h"
#include "gameuiconfig.h"
#include "game.h"
+#include "gamecfgwidget.h"
char delimeter='\t';
-HWNewNet::HWNewNet(GameUIConfig * config) :
- config(config)
+HWNewNet::HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget) :
+ config(config),
+ m_pGameCFGWidget(pGameCFGWidget),
+ isChief(false)
{
connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead()));
connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect()));
@@ -149,20 +152,21 @@
}
if (lst[0] == "CONFIGASKED") {
+ isChief=true;
ConfigAsked();
return;
}
if (lst[0] == "CONFIGURED") {
lst.pop_front();
- RunGame();
- qDebug() << lst[0];
- QByteArray ar=QByteArray::fromBase64(lst[0].toAscii());
- emit FromNet(ar);
-
- lst.pop_front();
- QByteArray cache;
- emit FromNet(HWProto::addStringListToBuffer(cache, lst));
+ if(lst.size()<5) return;
+ qDebug() << lst;
+ emit seedChanged(lst[0]);
+ emit mapChanged(lst[1]);
+ emit themeChanged(lst[2]);
+ emit initHealthChanged(lst[3].toUInt());
+ emit turnTimeChanged(lst[4].toUInt());
+ //emit fortsModeChanged(lst[5].toInt() != 0); // FIXME: add a getFortsMode in ConfigAsked
return;
}
@@ -212,12 +216,12 @@
void HWNewNet::ConfigAsked()
{
- QByteArray cache;
- HWProto::addStringToBuffer(cache, "eseed " + seed);
- HWProto::addStringToBuffer(cache, "TN");
- HWProto::addStringToBuffer(cache, "e$gmflags 0");
- HWProto::addStringToBuffer(cache, QString("etheme steel"));
- QString _msg = QString("CONFIGANSWER") + delimeter + QString(cache.toBase64());
+ QString _msg=QString("CONFIGANSWER")+delimeter;
+ _msg+=m_pGameCFGWidget->getCurrentSeed()+delimeter;
+ _msg+=m_pGameCFGWidget->getCurrentMap()+delimeter;
+ _msg+=m_pGameCFGWidget->getCurrentTheme()+delimeter;
+ _msg+=QString("%1").arg(m_pGameCFGWidget->getInitHealth())+delimeter;
+ _msg+=QString("%1").arg(m_pGameCFGWidget->getTurnTime());
RawSendNet(_msg);
}
--- a/QTfrontend/newnetclient.h Sun Jan 14 19:47:11 2007 +0000
+++ b/QTfrontend/newnetclient.h Sun Jan 14 20:46:17 2007 +0000
@@ -26,6 +26,7 @@
#include "team.h"
class GameUIConfig;
+class GameCFGWidget;
extern char delimeter;
@@ -34,7 +35,7 @@
Q_OBJECT
public:
- HWNewNet(GameUIConfig * config);
+ HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget);
void Connect(const QString & hostName, quint16 port, const QString & nick);
void Disconnect();
void JoinGame(const QString & game);
@@ -42,7 +43,9 @@
private:
GameUIConfig* config;
+ GameCFGWidget* m_pGameCFGWidget;
+ bool isChief;
QString mynick;
QTcpSocket NetSocket;
QString seed;