author | unc0rr |
Sun, 06 Jul 2008 20:02:42 +0000 | |
changeset 1056 | bb33a634a4b0 |
parent 883 | 07a568ba44e0 |
child 1066 | 1f1b3686a2b0 |
permissions | -rw-r--r-- |
315 | 1 |
/* |
2 |
* Hedgewars, a worms-like game |
|
883 | 3 |
* Copyright (c) 2006-2008 Ulyanov Igor <iulyanov@gmail.com> |
315 | 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> |
|
354
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
25 |
#include <QMap> |
315 | 26 |
|
27 |
#include "team.h" |
|
448 | 28 |
#include "game.h" // for GameState |
315 | 29 |
|
30 |
class GameUIConfig; |
|
334 | 31 |
class GameCFGWidget; |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
32 |
class TeamSelWidget; |
315 | 33 |
|
34 |
extern char delimeter; |
|
35 |
||
36 |
class HWNewNet : public QObject |
|
37 |
{ |
|
38 |
Q_OBJECT |
|
39 |
||
40 |
public: |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
41 |
HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget); |
315 | 42 |
void Connect(const QString & hostName, quint16 port, const QString & nick); |
43 |
void Disconnect(); |
|
44 |
void JoinGame(const QString & game); |
|
45 |
void StartGame(); |
|
46 |
||
47 |
private: |
|
48 |
GameUIConfig* config; |
|
334 | 49 |
GameCFGWidget* m_pGameCFGWidget; |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
50 |
TeamSelWidget* m_pTeamSelWidget; |
315 | 51 |
|
334 | 52 |
bool isChief; |
315 | 53 |
QString mynick; |
54 |
QTcpSocket NetSocket; |
|
55 |
QString seed; |
|
383 | 56 |
bool m_game_connected; |
315 | 57 |
|
354
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
58 |
QMap<unsigned int, QString> m_networkToLocalteams; // key is netID, value is local team name |
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
59 |
|
315 | 60 |
void ConfigAsked(); |
61 |
void RunGame(); |
|
62 |
||
63 |
template <typename T> |
|
64 |
void SendCfgStrNet(T a) { |
|
65 |
QByteArray strmsg; |
|
328 | 66 |
strmsg.append(a); |
315 | 67 |
quint8 sz = strmsg.size(); |
68 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
69 |
QString _msg = delimeter + QString(enginemsg.toBase64()); |
|
70 |
RawSendNet(_msg); |
|
71 |
} |
|
72 |
||
73 |
template <typename T> |
|
74 |
void SendCfgStrLoc(T a) { |
|
75 |
QByteArray strmsg; |
|
76 |
strmsg.append(QString(a).toUtf8()); |
|
77 |
quint8 sz = strmsg.size(); |
|
78 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
79 |
emit FromNet(enginemsg); |
|
80 |
} |
|
81 |
||
82 |
void RawSendNet(const QString & buf); |
|
83 |
void RawSendNet(const QByteArray & buf); |
|
84 |
void ParseLine(const QByteArray & line); |
|
85 |
||
86 |
signals: |
|
660 | 87 |
void AskForRunGame(); |
315 | 88 |
void Connected(); |
89 |
void Disconnected(); |
|
90 |
void EnteredGame(); |
|
465 | 91 |
void nickAdded(const QString& nick); |
92 |
void nickRemoved(const QString& nick); |
|
315 | 93 |
void FromNet(const QByteArray & buf); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
94 |
void AddNetTeam(const HWTeam&); |
315 | 95 |
|
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
96 |
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
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
void fortsModeChanged(bool value); |
352 | 102 |
void hhnumChanged(const HWTeam&); |
372 | 103 |
void teamColorChanged(const HWTeam&); |
453 | 104 |
void chatStringFromNet(const QStringList&); |
703 | 105 |
void ammoChanged(const QString& name, const QString& ammo); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
106 |
|
315 | 107 |
public slots: |
453 | 108 |
void chatLineToNet(const QString& str); |
315 | 109 |
void SendNet(const QByteArray & buf); |
328 | 110 |
void AddTeam(const HWTeam & team); |
347 | 111 |
void RemoveTeam(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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
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
|
117 |
void onFortsModeChanged(bool value); |
352 | 118 |
void onHedgehogsNumChanged(const HWTeam& team); |
372 | 119 |
void onTeamColorChanged(const HWTeam& team); |
703 | 120 |
void onWeaponsNameChanged(const QString& name, const QString& ammo); |
315 | 121 |
|
122 |
private slots: |
|
123 |
void ClientRead(); |
|
124 |
void OnConnect(); |
|
125 |
void OnDisconnect(); |
|
126 |
//void Perform(); |
|
127 |
void displayError(QAbstractSocket::SocketError socketError); |
|
128 |
//void FlushNetBuf(); |
|
129 |
}; |
|
130 |
||
131 |
#endif // _NEW_NETCLIENT_INCLUDED |