author | unc0rr |
Sun, 14 Jan 2007 21:17:35 +0000 | |
changeset 336 | 82d654db133d |
parent 334 | 85eacbd9827f |
child 338 | d1e75dcd285f |
permissions | -rw-r--r-- |
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; |
|
334 | 29 |
class GameCFGWidget; |
315 | 30 |
|
31 |
extern char delimeter; |
|
32 |
||
33 |
class HWNewNet : public QObject |
|
34 |
{ |
|
35 |
Q_OBJECT |
|
36 |
||
37 |
public: |
|
334 | 38 |
HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget); |
315 | 39 |
void Connect(const QString & hostName, quint16 port, const QString & nick); |
40 |
void Disconnect(); |
|
41 |
void JoinGame(const QString & game); |
|
42 |
void StartGame(); |
|
43 |
||
44 |
private: |
|
45 |
GameUIConfig* config; |
|
334 | 46 |
GameCFGWidget* m_pGameCFGWidget; |
315 | 47 |
|
334 | 48 |
bool isChief; |
315 | 49 |
QString mynick; |
50 |
QTcpSocket NetSocket; |
|
51 |
QString seed; |
|
52 |
||
53 |
void ConfigAsked(); |
|
54 |
void RunGame(); |
|
55 |
||
56 |
template <typename T> |
|
57 |
void SendCfgStrNet(T a) { |
|
58 |
QByteArray strmsg; |
|
328 | 59 |
strmsg.append(a); |
315 | 60 |
quint8 sz = strmsg.size(); |
61 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
62 |
QString _msg = delimeter + QString(enginemsg.toBase64()); |
|
63 |
RawSendNet(_msg); |
|
64 |
} |
|
65 |
||
66 |
template <typename T> |
|
67 |
void SendCfgStrLoc(T a) { |
|
68 |
QByteArray strmsg; |
|
69 |
strmsg.append(QString(a).toUtf8()); |
|
70 |
quint8 sz = strmsg.size(); |
|
71 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
72 |
emit FromNet(enginemsg); |
|
73 |
} |
|
74 |
||
75 |
void RawSendNet(const QString & buf); |
|
76 |
void RawSendNet(const QByteArray & buf); |
|
77 |
void ParseLine(const QByteArray & line); |
|
78 |
||
79 |
signals: |
|
80 |
void Connected(); |
|
81 |
void Disconnected(); |
|
82 |
void AddGame(const QString & chan); |
|
83 |
void EnteredGame(); |
|
84 |
void FromNet(const QByteArray & buf); |
|
85 |
void LocalCFG(const QString & team); |
|
86 |
void ChangeInTeams(const QStringList & teams); |
|
87 |
||
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
88 |
void seedChanged(const QString & seed); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
89 |
void mapChanged(const QString & map); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
90 |
void themeChanged(const QString & theme); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
91 |
void initHealthChanged(quint32 health); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
92 |
void turnTimeChanged(quint32 time); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
93 |
void fortsModeChanged(bool value); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
94 |
|
315 | 95 |
public slots: |
96 |
void SendNet(const QByteArray & buf); |
|
328 | 97 |
void AddTeam(const HWTeam & team); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
98 |
void onSeedChanged(const QString & seed); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
99 |
void onMapChanged(const QString & map); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
100 |
void onThemeChanged(const QString & theme); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
101 |
void onInitHealthChanged(quint32 health); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
102 |
void onTurnTimeChanged(quint32 time); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
103 |
void onFortsModeChanged(bool value); |
315 | 104 |
|
105 |
private slots: |
|
106 |
void ClientRead(); |
|
107 |
void OnConnect(); |
|
108 |
void OnDisconnect(); |
|
109 |
//void Perform(); |
|
110 |
void displayError(QAbstractSocket::SocketError socketError); |
|
111 |
//void FlushNetBuf(); |
|
112 |
}; |
|
113 |
||
114 |
#endif // _NEW_NETCLIENT_INCLUDED |