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>
|
389
|
29 |
#include <QPointer>
|
184
|
30 |
|
|
31 |
#include <QImage>
|
|
32 |
|
|
33 |
#define MAXMSGCHARS 255
|
|
34 |
|
|
35 |
class TCPBase : public QObject
|
|
36 |
{
|
|
37 |
Q_OBJECT
|
389
|
38 |
|
184
|
39 |
public:
|
|
40 |
TCPBase(bool demoMode);
|
|
41 |
|
|
42 |
signals:
|
|
43 |
void isReadyNow();
|
|
44 |
|
|
45 |
protected:
|
291
|
46 |
quint16 ipc_port;
|
|
47 |
|
184
|
48 |
void Start();
|
|
49 |
|
|
50 |
QByteArray readbuffer;
|
|
51 |
|
|
52 |
QByteArray toSendBuf;
|
|
53 |
QByteArray * demo;
|
|
54 |
|
|
55 |
void SendIPC(const QByteArray & buf);
|
|
56 |
void RawSendIPC(const QByteArray & buf);
|
|
57 |
|
|
58 |
virtual QStringList setArguments()=0;
|
|
59 |
virtual void onClientRead();
|
|
60 |
virtual void onClientDisconnect();
|
|
61 |
virtual void SendToClientFirst();
|
|
62 |
|
|
63 |
private:
|
389
|
64 |
static QPointer<QTcpServer> IPCServer;
|
185
|
65 |
|
184
|
66 |
bool m_isDemoMode;
|
185
|
67 |
void RealStart();
|
389
|
68 |
QPointer<QTcpSocket> IPCSocket;
|
184
|
69 |
|
|
70 |
private slots:
|
|
71 |
void NewConnection();
|
|
72 |
void ClientDisconnect();
|
|
73 |
void ClientRead();
|
|
74 |
void StartProcessError(QProcess::ProcessError error);
|
|
75 |
|
|
76 |
void tcpServerReady();
|
|
77 |
};
|
|
78 |
|
|
79 |
#endif // _TCPBASE_INCLUDED
|