network to local teams map, addteams from server before team config bug, fixed some segfaults
--- a/QTfrontend/netserver.cpp Sun Jan 21 20:14:49 2007 +0000
+++ b/QTfrontend/netserver.cpp Sun Jan 21 21:27:07 2007 +0000
@@ -90,7 +90,7 @@
return getChiefClient()==cl;
}
-QMap<QString, QString> HWNetServer::getGameCfg() const
+QMap<QString, QStringList> HWNetServer::getGameCfg() const
{
for(QList<HWConnectedClient*>::const_iterator it=connclients.begin(); it!=connclients.end(); ++it) {
if(isChiefClient(*it)) {
@@ -98,7 +98,7 @@
}
}
// error happened if we are here
- return QMap<QString, QString>();
+ return QMap<QString, QStringList>();
}
bool HWNetServer::haveNick(const QString& nick) const
@@ -209,16 +209,16 @@
if(m_hwserver->isChiefClient(this)) RawSendNet(QString("CONFIGASKED"));
else {
RawSendNet(QString("SLAVE"));
- // send config
- QMap<QString, QString> conf=m_hwserver->getGameCfg();
- for(QMap<QString, QString>::iterator it=conf.begin(); it!=conf.end(); ++it) {
- RawSendNet(QString("CONFIG_PARAM")+delimeter+it.key()+delimeter+it.value());
- }
// send teams
QList<QStringList> team_conf=m_hwserver->getTeamsConfig();
for(QList<QStringList>::iterator tmit=team_conf.begin(); tmit!=team_conf.end(); ++tmit) {
RawSendNet(QString("ADDTEAM:")+delimeter+tmit->join(QString(delimeter)));
}
+ // send config
+ QMap<QString, QStringList> conf=m_hwserver->getGameCfg();
+ for(QMap<QString, QStringList>::iterator it=conf.begin(); it!=conf.end(); ++it) {
+ RawSendNet(QString("CONFIG_PARAM")+delimeter+it.key()+delimeter+it.value().join(QString(delimeter)));
+ }
}
return;
}
@@ -235,7 +235,7 @@
if(lst[0]=="CONFIG_PARAM") {
if(!m_hwserver->isChiefClient(this) || lst.size()<3) return; // error or permission denied :)
- else m_gameCfg[lst[1]]=lst[2];
+ else m_gameCfg[lst[1]]=lst.mid(2);
}
if(lst[0]=="ADDTEAM:") {
@@ -247,6 +247,7 @@
m_teamsCfg.push_back(lst);
m_hwserver->sendOthers(this, QString("ADDTEAM:")+delimeter+lst.join(QString(delimeter)));
+ RawSendNet(QString("TEAM_ACCEPTED%1%2%1%3").arg(delimeter).arg(lst[0]).arg(lst[1]));
return;
}
--- a/QTfrontend/netserver.h Sun Jan 21 20:14:49 2007 +0000
+++ b/QTfrontend/netserver.h Sun Jan 21 21:27:07 2007 +0000
@@ -47,7 +47,7 @@
QString getHedgehogsDescription() const;
bool readyToStart;
- QMap<QString, QString> m_gameCfg; // config_param - value
+ QMap<QString, QStringList> m_gameCfg; // config_param - value
QList<QStringList> m_teamsCfg; // TeamName - hhs
class ShouldDisconnectException {};
@@ -79,7 +79,7 @@
void StartServer();
void StopServer();
bool isChiefClient(HWConnectedClient* cl) const;
- QMap<QString, QString> getGameCfg() const;
+ QMap<QString, QStringList> getGameCfg() const;
void sendAll(QString gameCfg);
void sendOthers(HWConnectedClient* this_cl, QString gameCfg);
bool haveNick(const QString& nick) const;
--- a/QTfrontend/newnetclient.cpp Sun Jan 21 20:14:49 2007 +0000
+++ b/QTfrontend/newnetclient.cpp Sun Jan 21 21:27:07 2007 +0000
@@ -175,6 +175,7 @@
if(lst[0]=="SLAVE") {
m_pGameCFGWidget->setEnabled(false);
+ return;
}
if (lst[0] == "CONFIGASKED") {
@@ -204,6 +205,11 @@
return;
}
+ if(lst[0]=="TEAM_ACCEPTED") {
+ m_networkToLocalteams.insert(lst[2].toUInt(), lst[1]);
+ return;
+ }
+
if (lst[0] == "CONFIG_PARAM") {
if (lst[1] == "SEED") {
emit seedChanged(lst[2]);
@@ -274,7 +280,9 @@
void HWNewNet::onHedgehogsNumChanged(const HWTeam& team)
{
qDebug() << team.getNetID() << ":" << team.numHedgehogs;
- RawSendNet(QString("CONFIG_PARAM%1HHNUM%1%2%1%3%1%4").arg(delimeter).arg(team.TeamName).arg(team.getNetID()).arg(team.numHedgehogs));
+ RawSendNet(QString("CONFIG_PARAM%1HHNUM%1%2%1%3%1%4").arg(delimeter).arg(team.TeamName)\
+ .arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))\
+ .arg(team.numHedgehogs));
}
void HWNewNet::onSeedChanged(const QString & seed)
--- a/QTfrontend/newnetclient.h Sun Jan 21 20:14:49 2007 +0000
+++ b/QTfrontend/newnetclient.h Sun Jan 21 21:27:07 2007 +0000
@@ -22,6 +22,7 @@
#include <QObject>
#include <QString>
#include <QTcpSocket>
+#include <QMap>
#include "team.h"
@@ -52,6 +53,8 @@
QTcpSocket NetSocket;
QString seed;
+ QMap<unsigned int, QString> m_networkToLocalteams; // key is netID, value is local team name
+
void ConfigAsked();
void RunGame();
void SendConfigToEngine();