author | unc0rr |
Thu, 05 Mar 2009 14:54:02 +0000 | |
changeset 1861 | 98de5dc5fda7 |
parent 1860 | ce140b2b928a |
child 1873 | 815a3ff1fe4b |
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); |
1526
18e412dd7d50
Send QUIT message to server when netclient object is destroyed
unc0rr
parents:
1512
diff
changeset
|
42 |
~HWNewNet(); |
315 | 43 |
void Connect(const QString & hostName, quint16 port, const QString & nick); |
44 |
void Disconnect(); |
|
1339 | 45 |
bool isRoomChief(); |
1671 | 46 |
bool isInRoom(); |
315 | 47 |
|
48 |
private: |
|
49 |
GameUIConfig* config; |
|
334 | 50 |
GameCFGWidget* m_pGameCFGWidget; |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
51 |
TeamSelWidget* m_pTeamSelWidget; |
315 | 52 |
|
334 | 53 |
bool isChief; |
315 | 54 |
QString mynick; |
55 |
QTcpSocket NetSocket; |
|
56 |
QString seed; |
|
383 | 57 |
bool m_game_connected; |
315 | 58 |
|
59 |
void ConfigAsked(); |
|
60 |
void RunGame(); |
|
61 |
||
62 |
template <typename T> |
|
63 |
void SendCfgStrNet(T a) { |
|
64 |
QByteArray strmsg; |
|
328 | 65 |
strmsg.append(a); |
315 | 66 |
quint8 sz = strmsg.size(); |
67 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
68 |
QString _msg = delimeter + QString(enginemsg.toBase64()); |
|
69 |
RawSendNet(_msg); |
|
70 |
} |
|
71 |
||
72 |
template <typename T> |
|
73 |
void SendCfgStrLoc(T a) { |
|
74 |
QByteArray strmsg; |
|
75 |
strmsg.append(QString(a).toUtf8()); |
|
76 |
quint8 sz = strmsg.size(); |
|
77 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
78 |
emit FromNet(enginemsg); |
|
79 |
} |
|
80 |
||
1082 | 81 |
QStringList cmdbuf; |
82 |
||
315 | 83 |
void RawSendNet(const QString & buf); |
84 |
void RawSendNet(const QByteArray & buf); |
|
1082 | 85 |
void ParseCmd(const QStringList & lst); |
1378 | 86 |
QString formatChatMsg(const QString & nick, const QString & msg); |
315 | 87 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
88 |
int loginStep; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
89 |
int netClientState; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
90 |
|
315 | 91 |
signals: |
660 | 92 |
void AskForRunGame(); |
315 | 93 |
void Connected(); |
94 |
void Disconnected(); |
|
95 |
void EnteredGame(); |
|
1592
5ee77ee470a6
Start converting network protocol to no-disconnecting religion
unc0rr
parents:
1577
diff
changeset
|
96 |
void LeftRoom(); |
465 | 97 |
void nickAdded(const QString& nick); |
98 |
void nickRemoved(const QString& nick); |
|
1566
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1530
diff
changeset
|
99 |
void nickAddedLobby(const QString& nick); |
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1530
diff
changeset
|
100 |
void nickRemovedLobby(const QString& nick); |
315 | 101 |
void FromNet(const QByteArray & buf); |
1856
e71dbf958c87
Enable admin button when have privilege. Button does nothing yet.
unc0rr
parents:
1797
diff
changeset
|
102 |
void adminAccess(bool); |
1860 | 103 |
void roomMaster(bool); |
1856
e71dbf958c87
Enable admin button when have privilege. Button does nothing yet.
unc0rr
parents:
1797
diff
changeset
|
104 |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
105 |
void AddNetTeam(const HWTeam&); |
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 |
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
|
107 |
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
|
108 |
void themeChanged(const QString & theme); |
1427 | 109 |
void initHealthChanged(int health); |
110 |
void turnTimeChanged(int time); |
|
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1671
diff
changeset
|
111 |
void suddenDeathTurnsChanged(int turns); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1671
diff
changeset
|
112 |
void caseProbabilityChanged(int prob); |
329
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 fortsModeChanged(bool value); |
1427 | 114 |
void teamsDivideChanged(bool value); |
1530 | 115 |
void solidChanged(bool value); |
1784 | 116 |
void borderChanged(bool value); |
352 | 117 |
void hhnumChanged(const HWTeam&); |
372 | 118 |
void teamColorChanged(const HWTeam&); |
1568 | 119 |
void chatStringLobby(const QString&); |
1356 | 120 |
void chatStringFromNet(const QString&); |
1360 | 121 |
void chatStringFromMe(const QString&); |
1568 | 122 |
void chatStringFromMeLobby(const QString&); |
703 | 123 |
void ammoChanged(const QString& name, const QString& ammo); |
1797 | 124 |
void templateFilterChanged(int filter); |
1377 | 125 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
126 |
void roomsList(const QStringList&); |
1377 | 127 |
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
|
128 |
|
1405 | 129 |
void setReadyStatus(const QString & nick, bool isReady); |
1648 | 130 |
void setMyReadyStatus(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
|
131 |
void showMessage(const QString &); |
1405 | 132 |
|
315 | 133 |
public slots: |
1404 | 134 |
void ToggleReady(); |
453 | 135 |
void chatLineToNet(const QString& str); |
1568 | 136 |
void chatLineToLobby(const QString& str); |
315 | 137 |
void SendNet(const QByteArray & buf); |
328 | 138 |
void AddTeam(const HWTeam & team); |
347 | 139 |
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
|
140 |
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
|
141 |
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
|
142 |
void onThemeChanged(const QString & theme); |
1427 | 143 |
void onInitHealthChanged(int health); |
144 |
void onTurnTimeChanged(int time); |
|
1782
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1671
diff
changeset
|
145 |
void onSuddenDeathTurnsChanged(int turns); |
e7589e37a6d6
Options for bonus box probability tuning and number of turn until sudden death
unc0rr
parents:
1671
diff
changeset
|
146 |
void onCaseProbabilityChanged(int prob); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
147 |
void onFortsModeChanged(bool value); |
1427 | 148 |
void onTeamsDivideChanged(bool value); |
1530 | 149 |
void onSolidChanged(bool value); |
1784 | 150 |
void onBorderChanged(bool value); |
352 | 151 |
void onHedgehogsNumChanged(const HWTeam& team); |
372 | 152 |
void onTeamColorChanged(const HWTeam& team); |
703 | 153 |
void onWeaponsNameChanged(const QString& name, const QString& ammo); |
1797 | 154 |
void onTemplateFilterChanged(int filter); |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
155 |
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
|
156 |
void CreateRoom(const QString & room); |
1315 | 157 |
void askRoomsList(); |
1344
4004e597f1bf
Clients send roundfinished message to server when the round is over
unc0rr
parents:
1339
diff
changeset
|
158 |
void gameFinished(); |
1860 | 159 |
void banPlayer(const QString &); |
1391 | 160 |
void kickPlayer(const QString &); |
1577 | 161 |
void infoPlayer(const QString &); |
1410
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
162 |
void startGame(); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
163 |
void toggleRestrictJoins(); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
164 |
void toggleRestrictTeamAdds(); |
1592
5ee77ee470a6
Start converting network protocol to no-disconnecting religion
unc0rr
parents:
1577
diff
changeset
|
165 |
void partRoom(); |
315 | 166 |
|
167 |
private slots: |
|
168 |
void ClientRead(); |
|
169 |
void OnConnect(); |
|
170 |
void OnDisconnect(); |
|
171 |
void displayError(QAbstractSocket::SocketError socketError); |
|
172 |
}; |
|
173 |
||
174 |
#endif // _NEW_NETCLIENT_INCLUDED |