|
1 /* |
|
2 * Hedgewars, a worms-like game |
|
3 * Copyright (c) 2006 Ulyanov Igor <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 _NEW_NETCLIENT_INCLUDED |
|
20 #define _NEW_NETCLIENT_INCLUDED |
|
21 |
|
22 #include <QObject> |
|
23 #include <QString> |
|
24 #include <QTcpSocket> |
|
25 |
|
26 #include "team.h" |
|
27 |
|
28 class GameUIConfig; |
|
29 |
|
30 extern char delimeter; |
|
31 |
|
32 class HWNewNet : public QObject |
|
33 { |
|
34 Q_OBJECT |
|
35 |
|
36 public: |
|
37 HWNewNet(GameUIConfig * config); |
|
38 void Connect(const QString & hostName, quint16 port, const QString & nick); |
|
39 void Disconnect(); |
|
40 void JoinGame(const QString & game); |
|
41 void AddTeam(const HWTeam & team); |
|
42 void StartGame(); |
|
43 |
|
44 private: |
|
45 GameUIConfig* config; |
|
46 |
|
47 QString mynick; |
|
48 QTcpSocket NetSocket; |
|
49 QString seed; |
|
50 |
|
51 void ConfigAsked(); |
|
52 void RunGame(); |
|
53 |
|
54 template <typename T> |
|
55 void SendCfgStrNet(T a) { |
|
56 QByteArray strmsg; |
|
57 strmsg.append(a); |
|
58 quint8 sz = strmsg.size(); |
|
59 QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
60 QString _msg = delimeter + QString(enginemsg.toBase64()); |
|
61 RawSendNet(_msg); |
|
62 } |
|
63 |
|
64 template <typename T> |
|
65 void SendCfgStrLoc(T a) { |
|
66 QByteArray strmsg; |
|
67 strmsg.append(QString(a).toUtf8()); |
|
68 quint8 sz = strmsg.size(); |
|
69 QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
70 emit FromNet(enginemsg); |
|
71 } |
|
72 |
|
73 void RawSendNet(const QString & buf); |
|
74 void RawSendNet(const QByteArray & buf); |
|
75 void ParseLine(const QByteArray & line); |
|
76 |
|
77 signals: |
|
78 void Connected(); |
|
79 void Disconnected(); |
|
80 void AddGame(const QString & chan); |
|
81 void EnteredGame(); |
|
82 void FromNet(const QByteArray & buf); |
|
83 void LocalCFG(const QString & team); |
|
84 void ChangeInTeams(const QStringList & teams); |
|
85 |
|
86 public slots: |
|
87 void SendNet(const QByteArray & buf); |
|
88 |
|
89 private slots: |
|
90 void ClientRead(); |
|
91 void OnConnect(); |
|
92 void OnDisconnect(); |
|
93 //void Perform(); |
|
94 void displayError(QAbstractSocket::SocketError socketError); |
|
95 //void FlushNetBuf(); |
|
96 }; |
|
97 |
|
98 #endif // _NEW_NETCLIENT_INCLUDED |