315
|
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 StartGame();
|
|
42 |
|
|
43 |
private:
|
|
44 |
GameUIConfig* config;
|
|
45 |
|
|
46 |
QString mynick;
|
|
47 |
QTcpSocket NetSocket;
|
|
48 |
QString seed;
|
|
49 |
|
|
50 |
void ConfigAsked();
|
|
51 |
void RunGame();
|
|
52 |
|
|
53 |
template <typename T>
|
|
54 |
void SendCfgStrNet(T a) {
|
|
55 |
QByteArray strmsg;
|
328
|
56 |
strmsg.append(a);
|
315
|
57 |
quint8 sz = strmsg.size();
|
|
58 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg;
|
|
59 |
QString _msg = delimeter + QString(enginemsg.toBase64());
|
|
60 |
RawSendNet(_msg);
|
|
61 |
}
|
|
62 |
|
|
63 |
template <typename T>
|
|
64 |
void SendCfgStrLoc(T a) {
|
|
65 |
QByteArray strmsg;
|
|
66 |
strmsg.append(QString(a).toUtf8());
|
|
67 |
quint8 sz = strmsg.size();
|
|
68 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg;
|
|
69 |
emit FromNet(enginemsg);
|
|
70 |
}
|
|
71 |
|
|
72 |
void RawSendNet(const QString & buf);
|
|
73 |
void RawSendNet(const QByteArray & buf);
|
|
74 |
void ParseLine(const QByteArray & line);
|
|
75 |
|
|
76 |
signals:
|
|
77 |
void Connected();
|
|
78 |
void Disconnected();
|
|
79 |
void AddGame(const QString & chan);
|
|
80 |
void EnteredGame();
|
|
81 |
void FromNet(const QByteArray & buf);
|
|
82 |
void LocalCFG(const QString & team);
|
|
83 |
void ChangeInTeams(const QStringList & teams);
|
|
84 |
|
|
85 |
public slots:
|
|
86 |
void SendNet(const QByteArray & buf);
|
328
|
87 |
void AddTeam(const HWTeam & team);
|
315
|
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
|