author | nemo |
Fri, 25 Mar 2011 19:25:50 -0400 | |
changeset 5049 | 96e51a62fb7f |
parent 4976 | 088d40d8aba2 |
child 5126 | 50803f3403a5 |
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: |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
42 |
HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget); |
1526
18e412dd7d50
Send QUIT message to server when netclient object is destroyed
unc0rr
parents:
1512
diff
changeset
|
43 |
~HWNewNet(); |
315 | 44 |
void Connect(const QString & hostName, quint16 port, const QString & nick); |
45 |
void Disconnect(); |
|
1339 | 46 |
bool isRoomChief(); |
1671 | 47 |
bool isInRoom(); |
2821 | 48 |
int getClientState(); |
49 |
QString getNick(); |
|
50 |
QString getRoom(); |
|
51 |
QString getHost(); |
|
3697 | 52 |
|
315 | 53 |
private: |
54 |
GameUIConfig* config; |
|
334 | 55 |
GameCFGWidget* m_pGameCFGWidget; |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
56 |
TeamSelWidget* m_pTeamSelWidget; |
315 | 57 |
|
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; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
93 |
int netClientState; |
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(); |
315 | 97 |
void Connected(); |
98 |
void Disconnected(); |
|
99 |
void EnteredGame(); |
|
1592
5ee77ee470a6
Start converting network protocol to no-disconnecting religion
unc0rr
parents:
1577
diff
changeset
|
100 |
void LeftRoom(); |
2777 | 101 |
void nickAdded(const QString& nick, bool notifyNick); |
465 | 102 |
void nickRemoved(const QString& nick); |
2777 | 103 |
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
|
104 |
void nickRemovedLobby(const QString& nick); |
315 | 105 |
void FromNet(const QByteArray & buf); |
1856
e71dbf958c87
Enable admin button when have privilege. Button does nothing yet.
unc0rr
parents:
1797
diff
changeset
|
106 |
void adminAccess(bool); |
1860 | 107 |
void roomMaster(bool); |
1856
e71dbf958c87
Enable admin button when have privilege. Button does nothing yet.
unc0rr
parents:
1797
diff
changeset
|
108 |
|
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1875
diff
changeset
|
109 |
void netSchemeConfig(QStringList &); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1860
diff
changeset
|
110 |
void paramChanged(const QString & param, const QStringList & value); |
1875 | 111 |
void configAsked(); |
112 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
113 |
void AddNetTeam(const HWTeam&); |
352 | 114 |
void hhnumChanged(const HWTeam&); |
372 | 115 |
void teamColorChanged(const HWTeam&); |
1568 | 116 |
void chatStringLobby(const QString&); |
4897
11598e7aa7e6
make names in chats clickable. still color adjustments needed; and testing
sheepluva
parents:
4879
diff
changeset
|
117 |
void chatStringLobby(const QString&, const QString&); |
1356 | 118 |
void chatStringFromNet(const QString&); |
1360 | 119 |
void chatStringFromMe(const QString&); |
1568 | 120 |
void chatStringFromMeLobby(const QString&); |
1377 | 121 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
122 |
void roomsList(const QStringList&); |
1377 | 123 |
void serverMessage(const QString &); |
3283 | 124 |
void serverMessageNew(const QString &); |
125 |
void serverMessageOld(const QString &); |
|
126 |
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
|
127 |
|
1405 | 128 |
void setReadyStatus(const QString & nick, bool isReady); |
1648 | 129 |
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
|
130 |
void showMessage(const QString &); |
1405 | 131 |
|
315 | 132 |
public slots: |
1404 | 133 |
void ToggleReady(); |
453 | 134 |
void chatLineToNet(const QString& str); |
1568 | 135 |
void chatLineToLobby(const QString& str); |
2403 | 136 |
void SendTeamMessage(const QString& str); |
315 | 137 |
void SendNet(const QByteArray & buf); |
328 | 138 |
void AddTeam(const HWTeam & team); |
347 | 139 |
void RemoveTeam(const HWTeam& team); |
352 | 140 |
void onHedgehogsNumChanged(const HWTeam& team); |
372 | 141 |
void onTeamColorChanged(const HWTeam& team); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1860
diff
changeset
|
142 |
void onParamChanged(const QString & param, const QStringList & value); |
2377 | 143 |
|
3283 | 144 |
void setServerMessageNew(const QString &); |
145 |
void setServerMessageOld(const QString &); |
|
146 |
void setLatestProtocolVar(int proto); |
|
147 |
void askServerVars(); |
|
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1860
diff
changeset
|
148 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
149 |
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
|
150 |
void CreateRoom(const QString & room); |
1315 | 151 |
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
|
152 |
void gameFinished(bool correcly); |
1860 | 153 |
void banPlayer(const QString &); |
1391 | 154 |
void kickPlayer(const QString &); |
1577 | 155 |
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
|
156 |
void followPlayer(const QString &); |
1410
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
157 |
void startGame(); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
158 |
void toggleRestrictJoins(); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
159 |
void toggleRestrictTeamAdds(); |
1592
5ee77ee470a6
Start converting network protocol to no-disconnecting religion
unc0rr
parents:
1577
diff
changeset
|
160 |
void partRoom(); |
2155
d897222d3339
Implement ability for server admin to clear accounts cache
unc0rr
parents:
1925
diff
changeset
|
161 |
void clearAccountsCache(); |
315 | 162 |
|
163 |
private slots: |
|
164 |
void ClientRead(); |
|
165 |
void OnConnect(); |
|
166 |
void OnDisconnect(); |
|
4879
55f939e2c19c
Ask for another nickname on collision. Works only with new server.
unc0rr
parents:
3697
diff
changeset
|
167 |
void displayError(QAbstractSocket::SocketError socketError); |
315 | 168 |
}; |
169 |
||
170 |
#endif // _NEW_NETCLIENT_INCLUDED |