author | koda |
Tue, 04 Dec 2012 01:52:14 +0100 | |
changeset 8211 | 555a6e06cb33 |
parent 8082 | 675372256a01 |
child 8092 | 08960209db8c |
child 8310 | a98c349bc06b |
permissions | -rw-r--r-- |
184 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
486 | 3 |
* Copyright (c) 2006-2007 Igor Ulyanov <iulyanov@gmail.com> |
6952 | 4 |
* Copyright (c) 2004-2012 Andrey Korotaev <unC0Rr@gmail.com> |
184 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License as published by |
|
8 |
* the Free Software Foundation; version 2 of the License |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
18 |
*/ |
|
19 |
||
20 |
#include "tcpBase.h" |
|
21 |
||
22 |
#include <QMessageBox> |
|
23 |
#include <QList> |
|
7794
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
24 |
#include <QApplication> |
184 | 25 |
#include <QImage> |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
26 |
#include <QThread> |
184 | 27 |
|
28 |
#include "hwconsts.h" |
|
29 |
||
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
30 |
#ifdef HWLIBRARY |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
31 |
extern "C" void Game(char**arguments); |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
32 |
|
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
33 |
//NOTE: most likely subclassing QThread is wrong |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
34 |
class EngineThread : public QThread |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
35 |
{ |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
36 |
protected: |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
37 |
void run(); |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
38 |
}; |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
39 |
|
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
40 |
void EngineThread::run() |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
41 |
{ |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
42 |
char *args[12]; |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
43 |
args[0] = "1"; //cShowFPS |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
44 |
args[1] = "65000"; //ipcPort |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
45 |
args[2] = "1024"; //cScreenWidth |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
46 |
args[3] = "768"; //cScreenHeight |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
47 |
args[4] = "0"; //cReducedQuality |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
48 |
args[5] = "en.txt"; //cLocaleFName |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
49 |
args[6] = "koda"; //UserNick |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
50 |
args[7] = "1"; //SetSound |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
51 |
args[8] = "1"; //SetMusic |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
52 |
args[9] = "0"; //cAltDamage |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
53 |
args[10]= "../Resources/hedgewars/Data"; //cPathPrefix |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
54 |
args[11]= NULL; //recordFileName |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
55 |
Game(args); |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
56 |
} |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
57 |
#endif |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
58 |
|
184 | 59 |
QList<TCPBase*> srvsList; |
389 | 60 |
QPointer<QTcpServer> TCPBase::IPCServer(0); |
184 | 61 |
|
419
fdeed9718e6b
virtual destructors for tcpBase derived classes, readarray clear removed as unneeded
displacer
parents:
390
diff
changeset
|
62 |
TCPBase::~TCPBase() |
fdeed9718e6b
virtual destructors for tcpBase derived classes, readarray clear removed as unneeded
displacer
parents:
390
diff
changeset
|
63 |
{ |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
64 |
// make sure this object is not in the server list anymore |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
65 |
srvsList.removeOne(this); |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
66 |
|
7289
835bb2852579
Restore almost old TCPBase behaviour
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
67 |
if (IPCSocket) |
835bb2852579
Restore almost old TCPBase behaviour
Stepan777 <stepik-777@mail.ru>
parents:
7180
diff
changeset
|
68 |
IPCSocket->deleteLater(); |
419
fdeed9718e6b
virtual destructors for tcpBase derived classes, readarray clear removed as unneeded
displacer
parents:
390
diff
changeset
|
69 |
} |
fdeed9718e6b
virtual destructors for tcpBase derived classes, readarray clear removed as unneeded
displacer
parents:
390
diff
changeset
|
70 |
|
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
71 |
TCPBase::TCPBase(bool demoMode, QObject *parent) : |
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
72 |
QObject(parent), |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
73 |
m_hasStarted(false), |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
74 |
m_isDemoMode(demoMode), |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
75 |
IPCSocket(0) |
184 | 76 |
{ |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
77 |
if(!IPCServer) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
78 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
79 |
IPCServer = new QTcpServer(0); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
80 |
IPCServer->setMaxPendingConnections(1); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
81 |
if (!IPCServer->listen(QHostAddress::LocalHost)) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
82 |
{ |
7794
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
83 |
QMessageBox deniedMsg(QApplication::activeWindow()); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
84 |
deniedMsg.setIcon(QMessageBox::Critical); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
85 |
deniedMsg.setWindowTitle(QMessageBox::tr("TCP - Error")); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
86 |
deniedMsg.setText(QMessageBox::tr("Unable to start the server: %1.").arg(IPCServer->errorString())); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
87 |
deniedMsg.setWindowModality(Qt::WindowModal); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
88 |
deniedMsg.exec(); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
89 |
|
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
90 |
exit(0); // FIXME - should be graceful exit here (lower Critical -> Warning above when implemented) |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
91 |
} |
185 | 92 |
} |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
93 |
#ifdef HWLIBRARY |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
94 |
ipc_port=65000; //HACK |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
95 |
#else |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
96 |
ipc_port=IPCServer->serverPort(); |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
97 |
#endif |
184 | 98 |
} |
99 |
||
100 |
void TCPBase::NewConnection() |
|
101 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
102 |
if(IPCSocket) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
103 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
104 |
// connection should be already finished |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
105 |
return; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
106 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
107 |
disconnect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
108 |
IPCSocket = IPCServer->nextPendingConnection(); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
109 |
if(!IPCSocket) return; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
110 |
connect(IPCSocket, SIGNAL(disconnected()), this, SLOT(ClientDisconnect())); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
111 |
connect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
112 |
SendToClientFirst(); |
184 | 113 |
} |
114 |
||
115 |
void TCPBase::RealStart() |
|
116 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
117 |
connect(IPCServer, SIGNAL(newConnection()), this, SLOT(NewConnection())); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
118 |
IPCSocket = 0; |
389 | 119 |
|
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
120 |
#ifdef HWLIBRARY |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
121 |
EngineThread engineThread;// = new EngineThread(this); |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
122 |
engineThread.start(); |
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
123 |
#else |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
124 |
QProcess * process; |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
125 |
process = new QProcess(); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
126 |
connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(StartProcessError(QProcess::ProcessError))); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
127 |
QStringList arguments=getArguments(); |
3697 | 128 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
129 |
// redirect everything written on stdout/stderr |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
130 |
if(isDevBuild) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
131 |
process->setProcessChannelMode(QProcess::ForwardedChannels); |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
132 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
133 |
process->start(bindir->absolutePath() + "/hwengine", arguments); |
8082
675372256a01
lotsa hackery to get frontend somehow link libengine...
koda
parents:
8070
diff
changeset
|
134 |
#endif |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
135 |
m_hasStarted = true; |
184 | 136 |
} |
137 |
||
138 |
void TCPBase::ClientDisconnect() |
|
139 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
140 |
disconnect(IPCSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
141 |
onClientDisconnect(); |
184 | 142 |
|
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
143 |
emit isReadyNow(); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
144 |
IPCSocket->deleteLater(); |
7673
e06b83cbde74
fix a segfault related to tcp servers deleting themselves without removing themselves from the internal server list first.
sheepluva
parents:
7615
diff
changeset
|
145 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
146 |
deleteLater(); |
184 | 147 |
} |
148 |
||
149 |
void TCPBase::ClientRead() |
|
150 |
{ |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
151 |
QByteArray readed=IPCSocket->readAll(); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
152 |
if(readed.isEmpty()) return; |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
153 |
readbuffer.append(readed); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
154 |
onClientRead(); |
184 | 155 |
} |
156 |
||
157 |
void TCPBase::StartProcessError(QProcess::ProcessError error) |
|
158 |
{ |
|
7794
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
159 |
QMessageBox deniedMsg(QApplication::activeWindow()); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
160 |
deniedMsg.setIcon(QMessageBox::Critical); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
161 |
deniedMsg.setWindowTitle(QMessageBox::tr("TCP - Error")); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
162 |
deniedMsg.setText(QMessageBox::tr("Unable to run engine at ") + bindir->absolutePath() + "/hwengine\n" + |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
163 |
QMessageBox::tr("Error code: %1").arg(error)); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
164 |
deniedMsg.setWindowModality(Qt::WindowModal); |
ab7b94c03bc9
QMessageBox overhaul: unify buttons, style and appearance of info dialogs, fixing a few typos and return values along the way
koda
parents:
7673
diff
changeset
|
165 |
deniedMsg.exec(); |
7587
688076d61b83
Don't leave frontend in engine waiting state when there's error occured on attempt to start engine
unc0rr
parents:
6952
diff
changeset
|
166 |
|
688076d61b83
Don't leave frontend in engine waiting state when there's error occured on attempt to start engine
unc0rr
parents:
6952
diff
changeset
|
167 |
ClientDisconnect(); |
184 | 168 |
} |
169 |
||
170 |
void TCPBase::tcpServerReady() |
|
171 |
{ |
|
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
172 |
disconnect(srvsList.first(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady())); |
184 | 173 |
|
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
174 |
RealStart(); |
184 | 175 |
} |
176 |
||
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
177 |
void TCPBase::Start(bool couldCancelPreviousRequest) |
184 | 178 |
{ |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
179 |
if(srvsList.isEmpty()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
180 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
181 |
srvsList.push_back(this); |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
182 |
RealStart(); |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
183 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
184 |
else |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
185 |
{ |
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
186 |
TCPBase * last = srvsList.last(); |
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
187 |
if(couldCancelPreviousRequest |
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
188 |
&& last->couldBeRemoved() |
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
189 |
&& (last->parent() == parent())) |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
190 |
{ |
8070
66bc20d089fc
Okay, remove previous request only if it has same parent
unc0rr
parents:
8069
diff
changeset
|
191 |
srvsList.removeLast(); |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
192 |
last->deleteLater(); |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
193 |
Start(couldCancelPreviousRequest); |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
194 |
} else |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
195 |
{ |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
196 |
connect(srvsList.last(), SIGNAL(isReadyNow()), this, SLOT(tcpServerReady())); |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
197 |
srvsList.push_back(this); |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
198 |
} |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
199 |
} |
184 | 200 |
} |
201 |
||
202 |
void TCPBase::onClientRead() |
|
203 |
{ |
|
204 |
} |
|
205 |
||
206 |
void TCPBase::onClientDisconnect() |
|
207 |
{ |
|
208 |
} |
|
209 |
||
210 |
void TCPBase::SendToClientFirst() |
|
211 |
{ |
|
212 |
} |
|
213 |
||
214 |
void TCPBase::SendIPC(const QByteArray & buf) |
|
215 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
216 |
if (buf.size() > MAXMSGCHARS) return; |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
217 |
quint8 len = buf.size(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
218 |
RawSendIPC(QByteArray::fromRawData((char *)&len, 1) + buf); |
184 | 219 |
} |
220 |
||
221 |
void TCPBase::RawSendIPC(const QByteArray & buf) |
|
222 |
{ |
|
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
223 |
if (!IPCSocket) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
224 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
225 |
toSendBuf += buf; |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
226 |
} |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
227 |
else |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
228 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
229 |
if (toSendBuf.size() > 0) |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
230 |
{ |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
231 |
IPCSocket->write(toSendBuf); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
232 |
if(m_isDemoMode) demo.append(toSendBuf); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
233 |
toSendBuf.clear(); |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
234 |
} |
6616
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
235 |
if(!buf.isEmpty()) |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
236 |
{ |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
237 |
IPCSocket->write(buf); |
f77bb02b669f
astyle -C -S -L -N --style=allman --recursive "QTfrontend/*.cpp" "QTfrontend/*.h"
nemo
parents:
6060
diff
changeset
|
238 |
if(m_isDemoMode) demo.append(buf); |
2948
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
239 |
} |
3f21a9dc93d0
Replace tabs with spaces using 'expand -t 4' command
unc0rr
parents:
1066
diff
changeset
|
240 |
} |
184 | 241 |
} |
8069
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
242 |
|
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
243 |
bool TCPBase::couldBeRemoved() |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
244 |
{ |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
245 |
return false; |
bb7671829935
- Only allow one engine instance running at the moment
unc0rr
parents:
7794
diff
changeset
|
246 |
} |