184
|
1 |
/*
|
|
2 |
* Hedgewars, a worms-like game
|
|
3 |
* Copyright (c) 2006 Igor Ulyanov <iulyanov@gmail.com>
|
|
4 |
*
|
|
5 |
* This program is free software; you can redistribute it and/or modify
|
|
6 |
* it under the terms of the GNU General Public License as published by
|
|
7 |
* the Free Software Foundation; version 2 of the License
|
|
8 |
*
|
|
9 |
* This program is distributed in the hope that it will be useful,
|
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
* GNU General Public License for more details.
|
|
13 |
*
|
|
14 |
* You should have received a copy of the GNU General Public License
|
|
15 |
* along with this program; if not, write to the Free Software
|
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
17 |
*/
|
|
18 |
|
|
19 |
#ifndef _TCPBASE_INCLUDED
|
|
20 |
#define _TCPBASE_INCLUDED
|
|
21 |
|
|
22 |
#include <QObject>
|
|
23 |
#include <QTcpServer>
|
|
24 |
#include <QTcpSocket>
|
|
25 |
#include <QByteArray>
|
|
26 |
#include <QString>
|
|
27 |
#include <QDir>
|
|
28 |
#include <QProcess>
|
|
29 |
|
|
30 |
#include <QImage>
|
|
31 |
|
|
32 |
#define MAXMSGCHARS 255
|
|
33 |
|
|
34 |
class TCPBase : public QObject
|
|
35 |
{
|
|
36 |
Q_OBJECT
|
185
|
37 |
|
184
|
38 |
public:
|
|
39 |
TCPBase(bool demoMode);
|
|
40 |
|
|
41 |
signals:
|
|
42 |
void isReadyNow();
|
|
43 |
|
|
44 |
protected:
|
291
|
45 |
quint16 ipc_port;
|
|
46 |
|
184
|
47 |
void Start();
|
|
48 |
|
|
49 |
QByteArray readbuffer;
|
|
50 |
|
|
51 |
QByteArray toSendBuf;
|
|
52 |
QByteArray * demo;
|
|
53 |
|
|
54 |
void SendIPC(const QByteArray & buf);
|
|
55 |
void RawSendIPC(const QByteArray & buf);
|
|
56 |
|
|
57 |
virtual QStringList setArguments()=0;
|
|
58 |
virtual void onClientRead();
|
|
59 |
virtual void onClientDisconnect();
|
|
60 |
virtual void SendToClientFirst();
|
|
61 |
|
|
62 |
private:
|
185
|
63 |
static QTcpServer* IPCServer;
|
|
64 |
|
184
|
65 |
bool m_isDemoMode;
|
185
|
66 |
void RealStart();
|
184
|
67 |
QTcpSocket * IPCSocket;
|
|
68 |
|
|
69 |
private slots:
|
|
70 |
void NewConnection();
|
|
71 |
void ClientDisconnect();
|
|
72 |
void ClientRead();
|
|
73 |
void StartProcessError(QProcess::ProcessError error);
|
|
74 |
|
|
75 |
void tcpServerReady();
|
|
76 |
};
|
|
77 |
|
|
78 |
#endif // _TCPBASE_INCLUDED
|