|
1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2006-2007 Igor Ulyanov <iulyanov@gmail.com> |
|
4 * Copyright (c) 2007-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
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 #ifndef _TCPBASE_INCLUDED |
|
21 #define _TCPBASE_INCLUDED |
|
22 |
|
23 #include <QObject> |
|
24 #include <QTcpServer> |
|
25 #include <QTcpSocket> |
|
26 #include <QByteArray> |
|
27 #include <QString> |
|
28 #include <QDir> |
|
29 #include <QProcess> |
|
30 #include <QPointer> |
|
31 |
|
32 #include <QImage> |
|
33 |
|
34 #define MAXMSGCHARS 255 |
|
35 |
|
36 class TCPBase : public QObject |
|
37 { |
|
38 Q_OBJECT |
|
39 |
|
40 public: |
|
41 TCPBase(bool demoMode); |
|
42 virtual ~TCPBase(); |
|
43 |
|
44 signals: |
|
45 void isReadyNow(); |
|
46 |
|
47 protected: |
|
48 quint16 ipc_port; |
|
49 |
|
50 void Start(); |
|
51 |
|
52 QByteArray readbuffer; |
|
53 |
|
54 QByteArray toSendBuf; |
|
55 QByteArray demo; |
|
56 |
|
57 void SendIPC(const QByteArray & buf); |
|
58 void RawSendIPC(const QByteArray & buf); |
|
59 |
|
60 virtual QStringList getArguments()=0; |
|
61 virtual void onClientRead(); |
|
62 virtual void onClientDisconnect(); |
|
63 virtual void SendToClientFirst(); |
|
64 |
|
65 private: |
|
66 static QPointer<QTcpServer> IPCServer; |
|
67 |
|
68 bool m_isDemoMode; |
|
69 void RealStart(); |
|
70 QPointer<QTcpSocket> IPCSocket; |
|
71 |
|
72 private slots: |
|
73 void NewConnection(); |
|
74 void ClientDisconnect(); |
|
75 void ClientRead(); |
|
76 void StartProcessError(QProcess::ProcessError error); |
|
77 |
|
78 void tcpServerReady(); |
|
79 }; |
|
80 |
|
81 #endif // _TCPBASE_INCLUDED |