--- a/QTfrontend/game.cpp Sun Oct 01 20:31:48 2006 +0000
+++ b/QTfrontend/game.cpp Mon Oct 02 18:09:39 2006 +0000
@@ -45,7 +45,8 @@
#include "gameuiconfig.h"
#include "gamecfgwidget.h"
-HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg)
+HWGame::HWGame(GameUIConfig * config, GameCFGWidget * gamecfg) :
+ TCPBase(true)
{
this->config = config;
this->gamecfg = gamecfg;
@@ -65,41 +66,41 @@
void HWGame::SendConfig()
{
- SendIPC(QString("eseed %1").arg(seed));
- SendIPC(QString("etheme %1").arg(config->GetRandomTheme()));
- SENDIPC("TL");
- SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()));
+ SendIPC(QString("eseed %1").arg(seed).toAscii());
+ SendIPC(QString("etheme %1").arg(config->GetRandomTheme()).toAscii());
+ SendIPC("TL");
+ SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()).toAscii());
for (int i = 0; i < TeamCount; i++)
{
- SENDIPC("eaddteam");
+ SendIPC("eaddteam");
LocalCFG(teams[i]);
- SendIPC(QString("ecolor %1").arg(65535 << i * 8));
+ SendIPC(QString("ecolor %1").arg(65535 << i * 8).toAscii());
for (int t = 0; t < hdNum[teams[i]]; t++)
- SendIPC(QString("eadd hh%1 0").arg(t));
+ SendIPC(QString("eadd hh%1 0").arg(t).toAscii());
}
}
void HWGame::SendQuickConfig()
{
- SendIPC(QString("eseed %1").arg(seed));
- SendIPC(QString("etheme %1").arg(config->GetRandomTheme()));
- SENDIPC("TL");
- SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()));
- SENDIPC("eaddteam");
+ SendIPC(QString("eseed %1").arg(seed).toAscii());
+ SendIPC(QString("etheme %1").arg(config->GetRandomTheme()).toAscii());
+ SendIPC("TL");
+ SendIPC(QString("e$gmflags %1").arg(gamecfg->getGameFlags()).toAscii());
+ SendIPC("eaddteam");
LocalCFG(0);
- SENDIPC("ecolor 65535");
- SENDIPC("eadd hh0 0");
- SENDIPC("eadd hh1 0");
- SENDIPC("eadd hh2 0");
- SENDIPC("eadd hh3 0");
- SENDIPC("eaddteam");
+ SendIPC("ecolor 65535");
+ SendIPC("eadd hh0 0");
+ SendIPC("eadd hh1 0");
+ SendIPC("eadd hh2 0");
+ SendIPC("eadd hh3 0");
+ SendIPC("eaddteam");
LocalCFG(2);
- SENDIPC("ecolor 16776960");
- SENDIPC("eadd hh0 1");
- SENDIPC("eadd hh1 1");
- SENDIPC("eadd hh2 1");
- SENDIPC("eadd hh3 1");
+ SendIPC("ecolor 16776960");
+ SendIPC("eadd hh0 1");
+ SendIPC("eadd hh1 1");
+ SendIPC("eadd hh2 1");
+ SendIPC("eadd hh3 1");
}
void HWGame::ParseMessage(const QByteArray & msg)
@@ -109,7 +110,7 @@
if (gameType == gtNet)
emit SendNet(QByteArray("\x01""?"));
else
- SENDIPC("!");
+ SendIPC("!");
break;
}
case 'C': {
@@ -124,7 +125,7 @@
}
case gtDemo: break;
case gtNet: {
- SENDIPC("TN");
+ SendIPC("TN");
emit SendNet(QByteArray("\x01""C"));
break;
}
@@ -157,41 +158,6 @@
}
}
-void HWGame::SendIPC(const char * msg, quint8 len)
-{
- SendIPC(QByteArray::fromRawData(msg, len));
-}
-
-void HWGame::SendIPC(const QString & buf)
-{
- SendIPC(QByteArray().append(buf));
-}
-
-void HWGame::SendIPC(const QByteArray & buf)
-{
- if (buf.size() > MAXMSGCHARS) return;
- quint8 len = buf.size();
- RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf);
-}
-
-void HWGame::RawSendIPC(const QByteArray & buf)
-{
- if (!IPCSocket)
- {
- toSendBuf += buf;
- } else
- {
- if (toSendBuf.size() > 0)
- {
- IPCSocket->write(toSendBuf);
- demo->append(toSendBuf);
- toSendBuf.clear();
- }
- IPCSocket->write(buf);
- demo->append(buf);
- }
-}
-
void HWGame::FromNet(const QByteArray & msg)
{
RawSendIPC(msg);
@@ -273,6 +239,7 @@
{
readbytes = stream.readRawData((char *)&buf, 512);
toSendBuf.append(QByteArray((char *)&buf, readbytes));
+ //SendIPC(QByteArray((char *)&buf, readbytes));
} while (readbytes > 0);
demofile.close();
--- a/QTfrontend/game.h Sun Oct 01 20:31:48 2006 +0000
+++ b/QTfrontend/game.h Mon Oct 02 18:09:39 2006 +0000
@@ -35,21 +35,14 @@
#define GAME_H
#include <QObject>
-#include <QTcpServer>
-#include <QTcpSocket>
#include <QByteArray>
#include <QString>
-#include <QDir>
-#include <QProcess>
#include "team.h"
#include <map>
#include "tcpBase.h"
-#define MAXMSGCHARS 255
-#define SENDIPC(a) SendIPC(a, sizeof(a) - 1)
-
class GameUIConfig;
class GameCFGWidget;
@@ -89,8 +82,6 @@
std::map<QString, unsigned char> hdNum;
QString seed;
int TeamCount;
- QByteArray * demo;
- QByteArray toSendBuf;
GameUIConfig * config;
GameCFGWidget * gamecfg;
GameType gameType;
@@ -99,10 +90,6 @@
void SendQuickConfig();
void SendTeamConfig(int index);
void ParseMessage(const QByteArray & msg);
- void SendIPC(const char * msg, quint8 len);
- void SendIPC(const QByteArray & buf);
- void SendIPC(const QString & buf);
- void RawSendIPC(const QByteArray & buf);
void SaveDemo(const QString & filename);
};
--- a/QTfrontend/hwmap.cpp Sun Oct 01 20:31:48 2006 +0000
+++ b/QTfrontend/hwmap.cpp Mon Oct 02 18:09:39 2006 +0000
@@ -33,7 +33,8 @@
#include "hwmap.h"
-HWMap::HWMap()
+HWMap::HWMap() :
+ TCPBase(false)
{
}
@@ -65,9 +66,6 @@
void HWMap::SendToClientFirst()
{
std::string toSend=std::string("eseed ")+m_seed;
- char ln=(char)toSend.length();
- IPCSocket->write(&ln, 1);
- IPCSocket->write(toSend.c_str(), ln);
-
- IPCSocket->write("\x01!", 2);
+ SendIPC(toSend.c_str());
+ SendIPC("!");
}
--- a/QTfrontend/hwmap.h Sun Oct 01 20:31:48 2006 +0000
+++ b/QTfrontend/hwmap.h Mon Oct 02 18:09:39 2006 +0000
@@ -34,13 +34,8 @@
#ifndef _HWMAP_INCLUDED
#define _HWMAP_INCLUDED
-#include <QObject>
-#include <QTcpServer>
-#include <QTcpSocket>
#include <QByteArray>
#include <QString>
-#include <QDir>
-#include <QProcess>
#include <QImage>
#include "tcpBase.h"
--- a/QTfrontend/tcpBase.cpp Sun Oct 01 20:31:48 2006 +0000
+++ b/QTfrontend/tcpBase.cpp Mon Oct 02 18:09:39 2006 +0000
@@ -42,7 +42,8 @@
QList<TCPBase*> srvsList;
-TCPBase::TCPBase()
+TCPBase::TCPBase(bool demoMode) :
+ m_isDemoMode(demoMode)
{
IPCServer = new QTcpServer(this);
connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection()));
@@ -138,3 +139,28 @@
void TCPBase::SendToClientFirst()
{
}
+
+void TCPBase::SendIPC(const QByteArray & buf)
+{
+ if (buf.size() > MAXMSGCHARS) return;
+ quint8 len = buf.size();
+ RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf);
+}
+
+void TCPBase::RawSendIPC(const QByteArray & buf)
+{
+ if (!IPCSocket)
+ {
+ toSendBuf += buf;
+ } else
+ {
+ if (toSendBuf.size() > 0)
+ {
+ IPCSocket->write(toSendBuf);
+ if(m_isDemoMode) demo->append(toSendBuf);
+ toSendBuf.clear();
+ }
+ IPCSocket->write(buf);
+ if(m_isDemoMode) demo->append(buf);
+ }
+}
--- a/QTfrontend/tcpBase.h Sun Oct 01 20:31:48 2006 +0000
+++ b/QTfrontend/tcpBase.h Mon Oct 02 18:09:39 2006 +0000
@@ -45,13 +45,14 @@
#include <QImage>
#define IPC_PORT 46631
+#define MAXMSGCHARS 255
class TCPBase : public QObject
{
Q_OBJECT
public:
- TCPBase();
+ TCPBase(bool demoMode);
signals:
void isReadyNow();
@@ -59,18 +60,24 @@
protected:
void Start();
- QTcpSocket * IPCSocket;
QByteArray readbuffer;
+ QByteArray toSendBuf;
+ QByteArray * demo;
+
+ void SendIPC(const QByteArray & buf);
+ void RawSendIPC(const QByteArray & buf);
+
virtual QStringList setArguments()=0;
virtual void onClientRead();
virtual void onClientDisconnect();
virtual void SendToClientFirst();
-
private:
+ bool m_isDemoMode;
void RealStart();
QTcpServer * IPCServer;
+ QTcpSocket * IPCSocket;
private slots:
void NewConnection();