|
1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2006-2008 Igor Ulyanov <iulyanov@gmail.com> |
|
4 * Copyright (c) 2008-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
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> |
|
26 #include <QMap> |
|
27 |
|
28 #include "team.h" |
|
29 #include "game.h" // for GameState |
|
30 |
|
31 class GameUIConfig; |
|
32 class GameCFGWidget; |
|
33 class TeamSelWidget; |
|
34 |
|
35 extern char delimeter; |
|
36 |
|
37 class HWNewNet : public QObject |
|
38 { |
|
39 Q_OBJECT |
|
40 |
|
41 public: |
|
42 enum ClientState { Disconnected, Connecting, Connected, InLobby, InRoom, InGame }; |
|
43 |
|
44 HWNewNet(); |
|
45 ~HWNewNet(); |
|
46 void Connect(const QString & hostName, quint16 port, const QString & nick); |
|
47 void Disconnect(); |
|
48 void SendPasswordHash(const QString & hash); |
|
49 void NewNick(const QString & nick); |
|
50 bool isRoomChief(); |
|
51 bool isInRoom(); |
|
52 ClientState clientState(); |
|
53 QString getNick(); |
|
54 QString getRoom(); |
|
55 QString getHost(); |
|
56 |
|
57 private: |
|
58 bool isChief; |
|
59 QString mynick; |
|
60 QString myroom; |
|
61 QString myhost; |
|
62 QTcpSocket NetSocket; |
|
63 QString seed; |
|
64 bool m_game_connected; |
|
65 |
|
66 template <typename T> |
|
67 void SendCfgStrNet(T a) { |
|
68 QByteArray strmsg; |
|
69 strmsg.append(a); |
|
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 |
|
85 QStringList cmdbuf; |
|
86 |
|
87 void RawSendNet(const QString & buf); |
|
88 void RawSendNet(const QByteArray & buf); |
|
89 void ParseCmd(const QStringList & lst); |
|
90 void handleNotice(int n); |
|
91 |
|
92 int loginStep; |
|
93 ClientState netClientState; |
|
94 |
|
95 signals: |
|
96 void AskForRunGame(); |
|
97 void connected(); |
|
98 void disconnected(const QString & reason); |
|
99 void Error(const QString & errmsg); |
|
100 void Warning(const QString & wrnmsg); |
|
101 void AskForPassword(const QString & nick); |
|
102 void NickTaken(const QString & nick); |
|
103 void AuthFailed(); |
|
104 void EnteredGame(); |
|
105 void LeftRoom(const QString & reason); |
|
106 void nickAdded(const QString& nick, bool notifyNick); |
|
107 void nickRemoved(const QString& nick); |
|
108 void nickAddedLobby(const QString& nick, bool notifyNick); |
|
109 void nickRemovedLobby(const QString& nick); |
|
110 void FromNet(const QByteArray & buf); |
|
111 void adminAccess(bool); |
|
112 void roomMaster(bool); |
|
113 |
|
114 void netSchemeConfig(QStringList &); |
|
115 void paramChanged(const QString & param, const QStringList & value); |
|
116 void configAsked(); |
|
117 |
|
118 void TeamAccepted(const QString&); |
|
119 void AddNetTeam(const HWTeam&); |
|
120 void RemoveNetTeam(const HWTeam&); |
|
121 void hhnumChanged(const HWTeam&); |
|
122 void teamColorChanged(const HWTeam&); |
|
123 void chatStringLobby(const QString&); |
|
124 void chatStringLobby(const QString&, const QString&); |
|
125 void chatStringFromNet(const QString&); |
|
126 void chatStringFromMe(const QString&); |
|
127 void chatStringFromMeLobby(const QString&); |
|
128 |
|
129 void roomsList(const QStringList&); |
|
130 void serverMessage(const QString &); |
|
131 void serverMessageNew(const QString &); |
|
132 void serverMessageOld(const QString &); |
|
133 void latestProtocolVar(int); |
|
134 |
|
135 void setReadyStatus(const QString & nick, bool isReady); |
|
136 void setMyReadyStatus(bool isReady); |
|
137 |
|
138 public slots: |
|
139 void ToggleReady(); |
|
140 void chatLineToNet(const QString& str); |
|
141 void chatLineToLobby(const QString& str); |
|
142 void SendTeamMessage(const QString& str); |
|
143 void SendNet(const QByteArray & buf); |
|
144 void AddTeam(const HWTeam & team); |
|
145 void RemoveTeam(const HWTeam& team); |
|
146 void onHedgehogsNumChanged(const HWTeam& team); |
|
147 void onTeamColorChanged(const HWTeam& team); |
|
148 void onParamChanged(const QString & param, const QStringList & value); |
|
149 |
|
150 void setServerMessageNew(const QString &); |
|
151 void setServerMessageOld(const QString &); |
|
152 void setLatestProtocolVar(int proto); |
|
153 void askServerVars(); |
|
154 |
|
155 void JoinRoom(const QString & room); |
|
156 void CreateRoom(const QString & room); |
|
157 void updateRoomName(const QString &); |
|
158 void askRoomsList(); |
|
159 void gameFinished(bool correcly); |
|
160 void banPlayer(const QString &); |
|
161 void kickPlayer(const QString &); |
|
162 void infoPlayer(const QString &); |
|
163 void followPlayer(const QString &); |
|
164 void startGame(); |
|
165 void toggleRestrictJoins(); |
|
166 void toggleRestrictTeamAdds(); |
|
167 void partRoom(); |
|
168 void clearAccountsCache(); |
|
169 |
|
170 private slots: |
|
171 void ClientRead(); |
|
172 void OnConnect(); |
|
173 void OnDisconnect(); |
|
174 void displayError(QAbstractSocket::SocketError socketError); |
|
175 }; |
|
176 |
|
177 #endif // _NEW_NETCLIENT_INCLUDED |