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 HWNewNet(); |
|
43 ~HWNewNet(); |
|
44 void Connect(const QString & hostName, quint16 port, const QString & nick); |
|
45 void Disconnect(); |
|
46 void SendPasswordHash(const QString & hash); |
|
47 void NewNick(const QString & nick); |
|
48 bool isRoomChief(); |
|
49 bool isInRoom(); |
|
50 int getClientState(); |
|
51 QString getNick(); |
|
52 QString getRoom(); |
|
53 QString getHost(); |
|
54 |
|
55 private: |
|
56 bool isChief; |
|
57 QString mynick; |
|
58 QString myroom; |
|
59 QString myhost; |
|
60 QTcpSocket NetSocket; |
|
61 QString seed; |
|
62 bool m_game_connected; |
|
63 |
|
64 template <typename T> |
|
65 void SendCfgStrNet(T a) { |
|
66 QByteArray strmsg; |
|
67 strmsg.append(a); |
|
68 quint8 sz = strmsg.size(); |
|
69 QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
70 QString _msg = delimeter + QString(enginemsg.toBase64()); |
|
71 RawSendNet(_msg); |
|
72 } |
|
73 |
|
74 template <typename T> |
|
75 void SendCfgStrLoc(T a) { |
|
76 QByteArray strmsg; |
|
77 strmsg.append(QString(a).toUtf8()); |
|
78 quint8 sz = strmsg.size(); |
|
79 QByteArray enginemsg = QByteArray((char *)&sz, 1) + strmsg; |
|
80 emit FromNet(enginemsg); |
|
81 } |
|
82 |
|
83 QStringList cmdbuf; |
|
84 |
|
85 void RawSendNet(const QString & buf); |
|
86 void RawSendNet(const QByteArray & buf); |
|
87 void ParseCmd(const QStringList & lst); |
|
88 void handleNotice(int n); |
|
89 |
|
90 int loginStep; |
|
91 int netClientState; |
|
92 |
|
93 signals: |
|
94 void AskForRunGame(); |
|
95 void Connected(); |
|
96 void Disconnected(const QString & reason); |
|
97 void Error(const QString & errmsg); |
|
98 void Warning(const QString & wrnmsg); |
|
99 void AskForPassword(const QString & nick); |
|
100 void NickTaken(const QString & nick); |
|
101 void AuthFailed(); |
|
102 void EnteredGame(); |
|
103 void LeftRoom(const QString & reason); |
|
104 void nickAdded(const QString& nick, bool notifyNick); |
|
105 void nickRemoved(const QString& nick); |
|
106 void nickAddedLobby(const QString& nick, bool notifyNick); |
|
107 void nickRemovedLobby(const QString& nick); |
|
108 void FromNet(const QByteArray & buf); |
|
109 void adminAccess(bool); |
|
110 void roomMaster(bool); |
|
111 |
|
112 void netSchemeConfig(QStringList &); |
|
113 void paramChanged(const QString & param, const QStringList & value); |
|
114 void configAsked(); |
|
115 |
|
116 void TeamAccepted(const QString&); |
|
117 void AddNetTeam(const HWTeam&); |
|
118 void RemoveNetTeam(const HWTeam&); |
|
119 void hhnumChanged(const HWTeam&); |
|
120 void teamColorChanged(const HWTeam&); |
|
121 void chatStringLobby(const QString&); |
|
122 void chatStringLobby(const QString&, const QString&); |
|
123 void chatStringFromNet(const QString&); |
|
124 void chatStringFromMe(const QString&); |
|
125 void chatStringFromMeLobby(const QString&); |
|
126 |
|
127 void roomsList(const QStringList&); |
|
128 void serverMessage(const QString &); |
|
129 void serverMessageNew(const QString &); |
|
130 void serverMessageOld(const QString &); |
|
131 void latestProtocolVar(int); |
|
132 |
|
133 void setReadyStatus(const QString & nick, bool isReady); |
|
134 void setMyReadyStatus(bool isReady); |
|
135 |
|
136 public slots: |
|
137 void ToggleReady(); |
|
138 void chatLineToNet(const QString& str); |
|
139 void chatLineToLobby(const QString& str); |
|
140 void SendTeamMessage(const QString& str); |
|
141 void SendNet(const QByteArray & buf); |
|
142 void AddTeam(const HWTeam & team); |
|
143 void RemoveTeam(const HWTeam& team); |
|
144 void onHedgehogsNumChanged(const HWTeam& team); |
|
145 void onTeamColorChanged(const HWTeam& team); |
|
146 void onParamChanged(const QString & param, const QStringList & value); |
|
147 |
|
148 void setServerMessageNew(const QString &); |
|
149 void setServerMessageOld(const QString &); |
|
150 void setLatestProtocolVar(int proto); |
|
151 void askServerVars(); |
|
152 |
|
153 void JoinRoom(const QString & room); |
|
154 void CreateRoom(const QString & room); |
|
155 void updateRoomName(const QString &); |
|
156 void askRoomsList(); |
|
157 void gameFinished(bool correcly); |
|
158 void banPlayer(const QString &); |
|
159 void kickPlayer(const QString &); |
|
160 void infoPlayer(const QString &); |
|
161 void followPlayer(const QString &); |
|
162 void startGame(); |
|
163 void toggleRestrictJoins(); |
|
164 void toggleRestrictTeamAdds(); |
|
165 void partRoom(); |
|
166 void clearAccountsCache(); |
|
167 |
|
168 private slots: |
|
169 void ClientRead(); |
|
170 void OnConnect(); |
|
171 void OnDisconnect(); |
|
172 void displayError(QAbstractSocket::SocketError socketError); |
|
173 }; |
|
174 |
|
175 #endif // _NEW_NETCLIENT_INCLUDED |
|