# HG changeset patch # User displacer # Date 1159734303 0 # Node ID efdc2a63be8e6296130608e42d0f540a4f237f1f # Parent c67c15e6fae3c824b56502ac4ee5350151455ac8 united TCP transfers for start game and receive preview diff -r c67c15e6fae3 -r efdc2a63be8e QTfrontend/game.cpp --- a/QTfrontend/game.cpp Sun Oct 01 20:14:30 2006 +0000 +++ b/QTfrontend/game.cpp Sun Oct 01 20:25:03 2006 +0000 @@ -53,30 +53,9 @@ seed = ""; } -void HWGame::NewConnection() -{ - QTcpSocket * client = IPCServer->nextPendingConnection(); - if(!IPCSocket) - { - IPCServer->close(); - IPCSocket = client; - connect(client, SIGNAL(disconnected()), this, SLOT(ClientDisconnect())); - connect(client, SIGNAL(readyRead()), this, SLOT(ClientRead())); - if (toSendBuf.size() > 0) - SENDIPC("?"); - } else - { - qWarning("2nd IPC client?!"); - client->disconnectFromHost(); - } -} - -void HWGame::ClientDisconnect() +void HWGame::onClientDisconnect() { SaveDemo(cfgdir->absolutePath() + "/Demos/LastRound.hwd_1"); - IPCSocket->deleteLater(); - IPCSocket = 0; - deleteLater(); } void HWGame::SendTeamConfig(int index) @@ -218,12 +197,6 @@ RawSendIPC(msg); } -void HWGame::ClientRead() -{ - readbuffer.append(IPCSocket->readAll()); - onClientRead(); -} - void HWGame::onClientRead() { quint8 msglen; @@ -237,27 +210,6 @@ } } -void HWGame::Start() -{ - IPCServer = new QTcpServer(this); - connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); - IPCServer->setMaxPendingConnections(1); - IPCSocket = 0; - if (!IPCServer->listen(QHostAddress::LocalHost, IPC_PORT)) - { - QMessageBox::critical(0, tr("Error"), - tr("Unable to start the server: %1.") - .arg(IPCServer->errorString())); - } - - demo = new QByteArray; - QProcess * process; - process = new QProcess; - connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError))); - QStringList arguments=setArguments(); - process->start(bindir->absolutePath() + "/hwengine", arguments); -} - QStringList HWGame::setArguments() { QStringList arguments; @@ -272,13 +224,6 @@ return arguments; } -void HWGame::StartProcessError(QProcess::ProcessError error) -{ - QMessageBox::critical(0, tr("Error"), - tr("Unable to run engine: %1 (") - .arg(error) + bindir->absolutePath() + "/hwengine)"); -} - void HWGame::AddTeam(const QString & teamname, unsigned char numHedgedogs) { if (TeamCount == 5) return; @@ -333,6 +278,7 @@ demofile.close(); // run engine + demo = new QByteArray; Start(); } @@ -348,6 +294,7 @@ gameType = gtLocal; if (TeamCount < 2) return; seed = gamecfg->getCurrentSeed();//QUuid::createUuid().toString(); + demo = new QByteArray; Start(); } @@ -355,6 +302,7 @@ { gameType = gtQLocal; seed = gamecfg->getCurrentSeed();//QUuid::createUuid().toString(); + demo = new QByteArray; Start(); } diff -r c67c15e6fae3 -r efdc2a63be8e QTfrontend/game.h --- a/QTfrontend/game.h Sun Oct 01 20:14:30 2006 +0000 +++ b/QTfrontend/game.h Sun Oct 01 20:25:03 2006 +0000 @@ -53,7 +53,7 @@ class GameUIConfig; class GameCFGWidget; -class HWGame : public QObject +class HWGame : public TCPBase { Q_OBJECT public: @@ -67,6 +67,7 @@ protected: virtual QStringList setArguments(); virtual void onClientRead(); + virtual void onClientDisconnect(); signals: void SendNet(const QByteArray & msg); @@ -83,10 +84,7 @@ gtDemo = 3, gtNet = 4 }; - QTcpServer * IPCServer; - QTcpSocket * IPCSocket; char msgbuf[MAXMSGCHARS]; - QByteArray readbuffer; QString teams[5]; std::map hdNum; QString seed; @@ -97,7 +95,6 @@ GameCFGWidget * gamecfg; GameType gameType; - void Start(); void SendConfig(); void SendQuickConfig(); void SendTeamConfig(int index); @@ -107,12 +104,6 @@ void SendIPC(const QString & buf); void RawSendIPC(const QByteArray & buf); void SaveDemo(const QString & filename); - -private slots: - void NewConnection(); - void ClientDisconnect(); - void ClientRead(); - void StartProcessError(QProcess::ProcessError error); }; #endif