author | unc0rr |
Mon, 10 Jan 2011 18:14:05 +0300 | |
branch | server_refactor |
changeset 4573 | 7e3be7d7eeda |
parent 3697 | d5b30d6373fc |
child 4879 | 55f939e2c19c |
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(); |
2821 | 47 |
int getClientState(); |
48 |
QString getNick(); |
|
49 |
QString getRoom(); |
|
50 |
QString getHost(); |
|
3697 | 51 |
|
315 | 52 |
private: |
53 |
GameUIConfig* config; |
|
334 | 54 |
GameCFGWidget* m_pGameCFGWidget; |
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
55 |
TeamSelWidget* m_pTeamSelWidget; |
315 | 56 |
|
334 | 57 |
bool isChief; |
315 | 58 |
QString mynick; |
2821 | 59 |
QString myroom; |
60 |
QString myhost; |
|
315 | 61 |
QTcpSocket NetSocket; |
62 |
QString seed; |
|
383 | 63 |
bool m_game_connected; |
315 | 64 |
|
65 |
template <typename T> |
|
66 |
void SendCfgStrNet(T a) { |
|
67 |
QByteArray strmsg; |
|
328 | 68 |
strmsg.append(a); |
315 | 69 |
quint8 sz = strmsg.size(); |
70 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
71 |
QString _msg = delimeter + QString(enginemsg.toBase64()); |
|
72 |
RawSendNet(_msg); |
|
73 |
} |
|
74 |
||
75 |
template <typename T> |
|
76 |
void SendCfgStrLoc(T a) { |
|
77 |
QByteArray strmsg; |
|
78 |
strmsg.append(QString(a).toUtf8()); |
|
79 |
quint8 sz = strmsg.size(); |
|
80 |
QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
81 |
emit FromNet(enginemsg); |
|
82 |
} |
|
83 |
||
1082 | 84 |
QStringList cmdbuf; |
85 |
||
315 | 86 |
void RawSendNet(const QString & buf); |
87 |
void RawSendNet(const QByteArray & buf); |
|
1082 | 88 |
void ParseCmd(const QStringList & lst); |
315 | 89 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
90 |
int loginStep; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
91 |
int netClientState; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
92 |
|
315 | 93 |
signals: |
660 | 94 |
void AskForRunGame(); |
315 | 95 |
void Connected(); |
96 |
void Disconnected(); |
|
97 |
void EnteredGame(); |
|
1592
5ee77ee470a6
Start converting network protocol to no-disconnecting religion
unc0rr
parents:
1577
diff
changeset
|
98 |
void LeftRoom(); |
2777 | 99 |
void nickAdded(const QString& nick, bool notifyNick); |
465 | 100 |
void nickRemoved(const QString& nick); |
2777 | 101 |
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
|
102 |
void nickRemovedLobby(const QString& nick); |
315 | 103 |
void FromNet(const QByteArray & buf); |
1856
e71dbf958c87
Enable admin button when have privilege. Button does nothing yet.
unc0rr
parents:
1797
diff
changeset
|
104 |
void adminAccess(bool); |
1860 | 105 |
void roomMaster(bool); |
1856
e71dbf958c87
Enable admin button when have privilege. Button does nothing yet.
unc0rr
parents:
1797
diff
changeset
|
106 |
|
1899
5763f46d7486
Sync schemes config over net should work now (untested)
unc0rr
parents:
1875
diff
changeset
|
107 |
void netSchemeConfig(QStringList &); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1860
diff
changeset
|
108 |
void paramChanged(const QString & param, const QStringList & value); |
1875 | 109 |
void configAsked(); |
110 |
||
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
111 |
void AddNetTeam(const HWTeam&); |
352 | 112 |
void hhnumChanged(const HWTeam&); |
372 | 113 |
void teamColorChanged(const HWTeam&); |
1568 | 114 |
void chatStringLobby(const QString&); |
1356 | 115 |
void chatStringFromNet(const QString&); |
1360 | 116 |
void chatStringFromMe(const QString&); |
1568 | 117 |
void chatStringFromMeLobby(const QString&); |
1377 | 118 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
119 |
void roomsList(const QStringList&); |
1377 | 120 |
void serverMessage(const QString &); |
3283 | 121 |
void serverMessageNew(const QString &); |
122 |
void serverMessageOld(const QString &); |
|
123 |
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
|
124 |
|
1405 | 125 |
void setReadyStatus(const QString & nick, bool isReady); |
1648 | 126 |
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
|
127 |
void showMessage(const QString &); |
1405 | 128 |
|
315 | 129 |
public slots: |
1404 | 130 |
void ToggleReady(); |
453 | 131 |
void chatLineToNet(const QString& str); |
1568 | 132 |
void chatLineToLobby(const QString& str); |
2403 | 133 |
void SendTeamMessage(const QString& str); |
315 | 134 |
void SendNet(const QByteArray & buf); |
328 | 135 |
void AddTeam(const HWTeam & team); |
347 | 136 |
void RemoveTeam(const HWTeam& team); |
352 | 137 |
void onHedgehogsNumChanged(const HWTeam& team); |
372 | 138 |
void onTeamColorChanged(const HWTeam& team); |
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1860
diff
changeset
|
139 |
void onParamChanged(const QString & param, const QStringList & value); |
2377 | 140 |
|
3283 | 141 |
void setServerMessageNew(const QString &); |
142 |
void setServerMessageOld(const QString &); |
|
143 |
void setLatestProtocolVar(int proto); |
|
144 |
void askServerVars(); |
|
1873
815a3ff1fe4b
Start refactoring some things. Frontend becomes temporarily unusable for network game
unc0rr
parents:
1860
diff
changeset
|
145 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
146 |
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
|
147 |
void CreateRoom(const QString & room); |
1315 | 148 |
void askRoomsList(); |
1344
4004e597f1bf
Clients send roundfinished message to server when the round is over
unc0rr
parents:
1339
diff
changeset
|
149 |
void gameFinished(); |
1860 | 150 |
void banPlayer(const QString &); |
1391 | 151 |
void kickPlayer(const QString &); |
1577 | 152 |
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
|
153 |
void followPlayer(const QString &); |
1410
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
154 |
void startGame(); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
155 |
void toggleRestrictJoins(); |
eece43296890
Send appropriate messages to server on control menu actions
unc0rr
parents:
1405
diff
changeset
|
156 |
void toggleRestrictTeamAdds(); |
1592
5ee77ee470a6
Start converting network protocol to no-disconnecting religion
unc0rr
parents:
1577
diff
changeset
|
157 |
void partRoom(); |
2155
d897222d3339
Implement ability for server admin to clear accounts cache
unc0rr
parents:
1925
diff
changeset
|
158 |
void clearAccountsCache(); |
315 | 159 |
|
160 |
private slots: |
|
161 |
void ClientRead(); |
|
162 |
void OnConnect(); |
|
163 |
void OnDisconnect(); |
|
164 |
void displayError(QAbstractSocket::SocketError socketError); |
|
165 |
}; |
|
166 |
||
167 |
#endif // _NEW_NETCLIENT_INCLUDED |