author | koda |
Sat, 08 Oct 2011 00:04:18 +0200 | |
changeset 6093 | 42c9ac754460 |
parent 6060 | fdfc01419815 |
child 6616 | f77bb02b669f |
permissions | -rw-r--r-- |
315 | 1 |
/* |
1066 | 2 |
* Hedgewars, a free turn based strategy game |
4976 | 3 |
* Copyright (c) 2006-2008 Igor Ulyanov <iulyanov@gmail.com> |
4 |
* Copyright (c) 2008-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
315 | 5 |
* |
6 |
* This program is free software; you can redistribute it and/or modify |
|
7 |
* it under the terms of the GNU General Public License as published by |
|
8 |
* the Free Software Foundation; version 2 of the License |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
18 |
*/ |
|
19 |
||
20 |
#ifndef _NEW_NETCLIENT_INCLUDED |
|
21 |
#define _NEW_NETCLIENT_INCLUDED |
|
22 |
||
23 |
#include <QObject> |
|
24 |
#include <QString> |
|
25 |
#include <QTcpSocket> |
|
354
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
26 |
#include <QMap> |
315 | 27 |
|
28 |
#include "team.h" |
|
448 | 29 |
#include "game.h" // for GameState |
315 | 30 |
|
31 |
class GameUIConfig; |
|
334 | 32 |
class GameCFGWidget; |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
33 |
class TeamSelWidget; |
315 | 34 |
|
35 |
extern char delimeter; |
|
36 |
||
37 |
class HWNewNet : public QObject |
|
38 |
{ |
|
39 |
Q_OBJECT |
|
40 |
||
41 |
public: |
|
6036 | 42 |
enum ClientState { Disconnected, Connecting, Connected, InLobby, InRoom, InGame }; |
43 |
||
5998
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5126
diff
changeset
|
44 |
HWNewNet(); |
1526
18e412dd7d50
Send QUIT message to server when netclient object is destroyed
unc0rr
parents:
1512
diff
changeset
|
45 |
~HWNewNet(); |
315 | 46 |
void Connect(const QString & hostName, quint16 port, const QString & nick); |
47 |
void Disconnect(); |
|
5998
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5126
diff
changeset
|
48 |
void SendPasswordHash(const QString & hash); |
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5126
diff
changeset
|
49 |
void NewNick(const QString & nick); |
1339 | 50 |
bool isRoomChief(); |
1671 | 51 |
bool isInRoom(); |
6036 | 52 |
ClientState clientState(); |
2821 | 53 |
QString getNick(); |
54 |
QString getRoom(); |
|
55 |
QString getHost(); |
|
3697 | 56 |
|
315 | 57 |
private: |
334 | 58 |
bool isChief; |
315 | 59 |
QString mynick; |
2821 | 60 |
QString myroom; |
61 |
QString myhost; |
|
315 | 62 |
QTcpSocket NetSocket; |
63 |
QString seed; |
|
383 | 64 |
bool m_game_connected; |
315 | 65 |
|
66 |
template <typename T> |
|
67 |
void SendCfgStrNet(T a) { |
|
68 |
QByteArray strmsg; |
|
328 | 69 |
strmsg.append(a); |
315 | 70 |
quint8 sz = strmsg.size(); |
71 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
72 |
QString _msg = delimeter + QString(enginemsg.toBase64()); |
|
73 |
RawSendNet(_msg); |
|
74 |
} |
|
75 |
||
76 |
template <typename T> |
|
77 |
void SendCfgStrLoc(T a) { |
|
78 |
QByteArray strmsg; |
|
79 |
strmsg.append(QString(a).toUtf8()); |
|
80 |
quint8 sz = strmsg.size(); |
|
81 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
82 |
emit FromNet(enginemsg); |
|
83 |
} |
|
84 |
||
1082 | 85 |
QStringList cmdbuf; |
86 |
||
315 | 87 |
void RawSendNet(const QString & buf); |
88 |
void RawSendNet(const QByteArray & buf); |
|
1082 | 89 |
void ParseCmd(const QStringList & lst); |
4879
55f939e2c19c
Ask for another nickname on collision. Works only with new server.
unc0rr
parents:
3697
diff
changeset
|
90 |
void handleNotice(int n); |
315 | 91 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
92 |
int loginStep; |
6036 | 93 |
ClientState netClientState; |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
94 |
|
315 | 95 |
signals: |
660 | 96 |
void AskForRunGame(); |
6036 | 97 |
void connected(); |
98 |
void disconnected(const QString & reason); |
|
5998
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5126
diff
changeset
|
99 |
void Error(const QString & errmsg); |
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5126
diff
changeset
|
100 |
void Warning(const QString & wrnmsg); |
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5126
diff
changeset
|
101 |
void AskForPassword(const QString & nick); |
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5126
diff
changeset
|
102 |
void NickTaken(const QString & nick); |
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5126
diff
changeset
|
103 |
void AuthFailed(); |
315 | 104 |
void EnteredGame(); |
5998
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5126
diff
changeset
|
105 |
void LeftRoom(const QString & reason); |
2777 | 106 |
void nickAdded(const QString& nick, bool notifyNick); |
465 | 107 |
void nickRemoved(const QString& nick); |
2777 | 108 |
void nickAddedLobby(const QString& nick, bool notifyNick); |
1566
6b63c75fdc68
Start work on lobby: add/remove nick from the list on join/quit
unc0rr
parents:
1530
diff
changeset
|
109 |
void nickRemovedLobby(const QString& nick); |
315 | 110 |
void FromNet(const QByteArray & buf); |
1856
e71dbf958c87
Enable admin button when have privilege. Button does nothing yet.
unc0rr
parents:
1797
diff
changeset
|
111 |
void adminAccess(bool); |
1860 | 112 |
void roomMaster(bool); |
1856
e71dbf958c87
Enable admin button when have privilege. Button does nothing yet.
unc0rr
parents:
1797
diff
changeset
|
113 |
|
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1875
diff
changeset
|
114 |
void netSchemeConfig(QStringList &); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1860
diff
changeset
|
115 |
void paramChanged(const QString & param, const QStringList & value); |
1875 | 116 |
void configAsked(); |
117 |
||
5998
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5126
diff
changeset
|
118 |
void TeamAccepted(const QString&); |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
119 |
void AddNetTeam(const HWTeam&); |
5998
e8f44e9433f0
many many netclient/frondent changes (just the beginning though):
sheepluva
parents:
5126
diff
changeset
|
120 |
void RemoveNetTeam(const HWTeam&); |
352 | 121 |
void hhnumChanged(const HWTeam&); |
372 | 122 |
void teamColorChanged(const HWTeam&); |
1568 | 123 |
void chatStringLobby(const QString&); |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4879
diff
changeset
|
124 |
void chatStringLobby(const QString&, const QString&); |
1356 | 125 |
void chatStringFromNet(const QString&); |
1360 | 126 |
void chatStringFromMe(const QString&); |
1568 | 127 |
void chatStringFromMeLobby(const QString&); |
1377 | 128 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
129 |
void roomsList(const QStringList&); |
1377 | 130 |
void serverMessage(const QString &); |
3283 | 131 |
void serverMessageNew(const QString &); |
132 |
void serverMessageOld(const QString &); |
|
133 |
void latestProtocolVar(int); |
|
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
328
diff
changeset
|
134 |
|
1405 | 135 |
void setReadyStatus(const QString & nick, bool isReady); |
1648 | 136 |
void setMyReadyStatus(bool isReady); |
1405 | 137 |
|
315 | 138 |
public slots: |
1404 | 139 |
void ToggleReady(); |
453 | 140 |
void chatLineToNet(const QString& str); |
1568 | 141 |
void chatLineToLobby(const QString& str); |
2403 | 142 |
void SendTeamMessage(const QString& str); |
315 | 143 |
void SendNet(const QByteArray & buf); |
328 | 144 |
void AddTeam(const HWTeam & team); |
347 | 145 |
void RemoveTeam(const HWTeam& team); |
352 | 146 |
void onHedgehogsNumChanged(const HWTeam& team); |
372 | 147 |
void onTeamColorChanged(const HWTeam& team); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1860
diff
changeset
|
148 |
void onParamChanged(const QString & param, const QStringList & value); |
2377 | 149 |
|
3283 | 150 |
void setServerMessageNew(const QString &); |
151 |
void setServerMessageOld(const QString &); |
|
152 |
void setLatestProtocolVar(int proto); |
|
153 |
void askServerVars(); |
|
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1860
diff
changeset
|
154 |
|
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); |
5126 | 157 |
void updateRoomName(const QString &); |
1315 | 158 |
void askRoomsList(); |
4908
99d6797b7ff4
Frontend sends ROUNDFINISHED with information about whether the round was played till end (will be needed for stats)
unc0rr
parents:
4897
diff
changeset
|
159 |
void gameFinished(bool correcly); |
1860 | 160 |
void banPlayer(const QString &); |
1391 | 161 |
void kickPlayer(const QString &); |
1577 | 162 |
void infoPlayer(const QString &); |
2706
935b7d618cf0
sheepluva's patch to add a "follow" command to server and frontend, in order to stalk people and join them in their rooms
koda
parents:
2405
diff
changeset
|
163 |
void followPlayer(const QString &); |
1410
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
164 |
void startGame(); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
165 |
void toggleRestrictJoins(); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
166 |
void toggleRestrictTeamAdds(); |
1592
5ee77ee470a6
Start converting network protocol to no-disconnecting religion
unc0rr
parents:
1577
diff
changeset
|
167 |
void partRoom(); |
2155
d897222d3339
Implement ability for server admin to clear accounts cache
unc0rr
parents:
1925
diff
changeset
|
168 |
void clearAccountsCache(); |
315 | 169 |
|
170 |
private slots: |
|
171 |
void ClientRead(); |
|
172 |
void OnConnect(); |
|
173 |
void OnDisconnect(); |
|
4879
55f939e2c19c
Ask for another nickname on collision. Works only with new server.
unc0rr
parents:
3697
diff
changeset
|
174 |
void displayError(QAbstractSocket::SocketError socketError); |
315 | 175 |
}; |
176 |
||
177 |
#endif // _NEW_NETCLIENT_INCLUDED |