author | unc0rr |
Thu, 27 Nov 2008 15:01:12 +0000 | |
changeset 1516 | bb9fa5809c49 |
parent 1512 | 43742041c211 |
child 1526 | 18e412dd7d50 |
permissions | -rw-r--r-- |
315 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy 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(); |
|
1339 | 44 |
bool isRoomChief(); |
315 | 45 |
|
46 |
private: |
|
47 |
GameUIConfig* config; |
|
334 | 48 |
GameCFGWidget* m_pGameCFGWidget; |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
49 |
TeamSelWidget* m_pTeamSelWidget; |
315 | 50 |
|
334 | 51 |
bool isChief; |
315 | 52 |
QString mynick; |
53 |
QTcpSocket NetSocket; |
|
54 |
QString seed; |
|
383 | 55 |
bool m_game_connected; |
315 | 56 |
|
57 |
void ConfigAsked(); |
|
58 |
void RunGame(); |
|
59 |
||
60 |
template <typename T> |
|
61 |
void SendCfgStrNet(T a) { |
|
62 |
QByteArray strmsg; |
|
328 | 63 |
strmsg.append(a); |
315 | 64 |
quint8 sz = strmsg.size(); |
65 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
66 |
QString _msg = delimeter + QString(enginemsg.toBase64()); |
|
67 |
RawSendNet(_msg); |
|
68 |
} |
|
69 |
||
70 |
template <typename T> |
|
71 |
void SendCfgStrLoc(T a) { |
|
72 |
QByteArray strmsg; |
|
73 |
strmsg.append(QString(a).toUtf8()); |
|
74 |
quint8 sz = strmsg.size(); |
|
75 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
76 |
emit FromNet(enginemsg); |
|
77 |
} |
|
78 |
||
1082 | 79 |
QStringList cmdbuf; |
80 |
||
315 | 81 |
void RawSendNet(const QString & buf); |
82 |
void RawSendNet(const QByteArray & buf); |
|
1082 | 83 |
void ParseCmd(const QStringList & lst); |
1378 | 84 |
QString formatChatMsg(const QString & nick, const QString & msg); |
315 | 85 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
86 |
int loginStep; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
87 |
int netClientState; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
88 |
|
315 | 89 |
signals: |
660 | 90 |
void AskForRunGame(); |
315 | 91 |
void Connected(); |
92 |
void Disconnected(); |
|
93 |
void EnteredGame(); |
|
465 | 94 |
void nickAdded(const QString& nick); |
95 |
void nickRemoved(const QString& nick); |
|
315 | 96 |
void FromNet(const QByteArray & buf); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
97 |
void AddNetTeam(const HWTeam&); |
315 | 98 |
|
329
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 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
|
100 |
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
|
101 |
void themeChanged(const QString & theme); |
1427 | 102 |
void initHealthChanged(int health); |
103 |
void turnTimeChanged(int time); |
|
329
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 fortsModeChanged(bool value); |
1427 | 105 |
void teamsDivideChanged(bool value); |
352 | 106 |
void hhnumChanged(const HWTeam&); |
372 | 107 |
void teamColorChanged(const HWTeam&); |
1356 | 108 |
void chatStringFromNet(const QString&); |
1360 | 109 |
void chatStringFromMe(const QString&); |
703 | 110 |
void ammoChanged(const QString& name, const QString& ammo); |
1377 | 111 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
112 |
void roomsList(const QStringList&); |
1377 | 113 |
void serverMessage(const QString &); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
114 |
|
1405 | 115 |
void setReadyStatus(const QString & nick, bool isReady); |
1512
43742041c211
- Don't send 'Bad param' msg, as the only reason of it is just some lag
unc0rr
parents:
1427
diff
changeset
|
116 |
void showMessage(const QString &); |
1405 | 117 |
|
315 | 118 |
public slots: |
1404 | 119 |
void ToggleReady(); |
453 | 120 |
void chatLineToNet(const QString& str); |
315 | 121 |
void SendNet(const QByteArray & buf); |
328 | 122 |
void AddTeam(const HWTeam & team); |
347 | 123 |
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
|
124 |
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
|
125 |
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
|
126 |
void onThemeChanged(const QString & theme); |
1427 | 127 |
void onInitHealthChanged(int health); |
128 |
void onTurnTimeChanged(int time); |
|
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
129 |
void onFortsModeChanged(bool value); |
1427 | 130 |
void onTeamsDivideChanged(bool value); |
352 | 131 |
void onHedgehogsNumChanged(const HWTeam& team); |
372 | 132 |
void onTeamColorChanged(const HWTeam& team); |
703 | 133 |
void onWeaponsNameChanged(const QString& name, const QString& ammo); |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
134 |
void JoinRoom(const QString & room); |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
135 |
void CreateRoom(const QString & room); |
1315 | 136 |
void askRoomsList(); |
1344
4004e597f1bf
Clients send roundfinished message to server when the round is over
unc0rr
parents:
1339
diff
changeset
|
137 |
void gameFinished(); |
1391 | 138 |
void kickPlayer(const QString &); |
1410
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
139 |
void startGame(); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
140 |
void toggleRestrictJoins(); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
141 |
void toggleRestrictTeamAdds(); |
315 | 142 |
|
143 |
private slots: |
|
144 |
void ClientRead(); |
|
145 |
void OnConnect(); |
|
146 |
void OnDisconnect(); |
|
147 |
void displayError(QAbstractSocket::SocketError socketError); |
|
148 |
}; |
|
149 |
||
150 |
#endif // _NEW_NETCLIENT_INCLUDED |