author | displacer |
Mon, 15 Jan 2007 18:45:07 +0000 | |
changeset 339 | 7535ab6c3820 |
parent 338 | d1e75dcd285f |
child 341 | 184230eb4151 |
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; |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
30 |
class TeamSelWidget; |
315 | 31 |
|
32 |
extern char delimeter; |
|
33 |
||
34 |
class HWNewNet : public QObject |
|
35 |
{ |
|
36 |
Q_OBJECT |
|
37 |
||
38 |
public: |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
39 |
HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget); |
315 | 40 |
void Connect(const QString & hostName, quint16 port, const QString & nick); |
41 |
void Disconnect(); |
|
42 |
void JoinGame(const QString & game); |
|
43 |
void StartGame(); |
|
44 |
||
45 |
private: |
|
46 |
GameUIConfig* config; |
|
334 | 47 |
GameCFGWidget* m_pGameCFGWidget; |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
48 |
TeamSelWidget* m_pTeamSelWidget; |
315 | 49 |
|
334 | 50 |
bool isChief; |
315 | 51 |
QString mynick; |
52 |
QTcpSocket NetSocket; |
|
53 |
QString seed; |
|
54 |
||
55 |
void ConfigAsked(); |
|
56 |
void RunGame(); |
|
57 |
||
58 |
template <typename T> |
|
59 |
void SendCfgStrNet(T a) { |
|
60 |
QByteArray strmsg; |
|
328 | 61 |
strmsg.append(a); |
315 | 62 |
quint8 sz = strmsg.size(); |
63 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
64 |
QString _msg = delimeter + QString(enginemsg.toBase64()); |
|
65 |
RawSendNet(_msg); |
|
66 |
} |
|
67 |
||
68 |
template <typename T> |
|
69 |
void SendCfgStrLoc(T a) { |
|
70 |
QByteArray strmsg; |
|
71 |
strmsg.append(QString(a).toUtf8()); |
|
72 |
quint8 sz = strmsg.size(); |
|
73 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
74 |
emit FromNet(enginemsg); |
|
75 |
} |
|
76 |
||
77 |
void RawSendNet(const QString & buf); |
|
78 |
void RawSendNet(const QByteArray & buf); |
|
79 |
void ParseLine(const QByteArray & line); |
|
80 |
||
81 |
signals: |
|
82 |
void Connected(); |
|
83 |
void Disconnected(); |
|
84 |
void AddGame(const QString & chan); |
|
85 |
void EnteredGame(); |
|
86 |
void FromNet(const QByteArray & buf); |
|
87 |
void LocalCFG(const QString & team); |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
88 |
void AddNetTeam(const HWTeam&); |
315 | 89 |
|
329
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 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
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
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
|
96 |
|
315 | 97 |
public slots: |
98 |
void SendNet(const QByteArray & buf); |
|
328 | 99 |
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
|
100 |
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
|
101 |
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
|
102 |
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
|
103 |
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
|
104 |
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
|
105 |
void onFortsModeChanged(bool value); |
315 | 106 |
|
107 |
private slots: |
|
108 |
void ClientRead(); |
|
109 |
void OnConnect(); |
|
110 |
void OnDisconnect(); |
|
111 |
//void Perform(); |
|
112 |
void displayError(QAbstractSocket::SocketError socketError); |
|
113 |
//void FlushNetBuf(); |
|
114 |
}; |
|
115 |
||
116 |
#endif // _NEW_NETCLIENT_INCLUDED |