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 IPC_PORT 46631
|
|
33 |
#define MAXMSGCHARS 255
|
|
34 |
|
|
35 |
class TCPBase : public QObject
|
|
36 |
{
|
|
37 |
Q_OBJECT
|
185
|
38 |
|
184
|
39 |
public:
|
|
40 |
TCPBase(bool demoMode);
|
|
41 |
|
|
42 |
signals:
|
|
43 |
void isReadyNow();
|
|
44 |
|
|
45 |
protected:
|
|
46 |
void Start();
|
|
47 |
|
|
48 |
QByteArray readbuffer;
|
|
49 |
|
|
50 |
QByteArray toSendBuf;
|
|
51 |
QByteArray * demo;
|
|
52 |
|
|
53 |
void SendIPC(const QByteArray & buf);
|
|
54 |
void RawSendIPC(const QByteArray & buf);
|
|
55 |
|
|
56 |
virtual QStringList setArguments()=0;
|
|
57 |
virtual void onClientRead();
|
|
58 |
virtual void onClientDisconnect();
|
|
59 |
virtual void SendToClientFirst();
|
|
60 |
|
|
61 |
private:
|
185
|
62 |
static int isIPCServerStarted;
|
|
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
|