author | unc0rr |
Wed, 08 Oct 2008 18:46:02 +0000 | |
changeset 1324 | 4b48ae1f0f53 |
parent 1322 | c624b04699fb |
child 1325 | c8994d47f41d |
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 |
#include <QMessageBox> |
|
1189
f66cdbbfc4b6
Fix compile under Ubuntu (why it compiles everywhere else?)
unc0rr
parents:
1083
diff
changeset
|
20 |
#include <QDebug> |
315 | 21 |
|
697 | 22 |
#include "hwconsts.h" |
315 | 23 |
#include "newnetclient.h" |
24 |
#include "proto.h" |
|
25 |
#include "gameuiconfig.h" |
|
26 |
#include "game.h" |
|
334 | 27 |
#include "gamecfgwidget.h" |
347 | 28 |
#include "teamselect.h" |
315 | 29 |
|
1082 | 30 |
char delimeter='\n'; |
315 | 31 |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
32 |
HWNewNet::HWNewNet(GameUIConfig * config, GameCFGWidget* pGameCFGWidget, TeamSelWidget* pTeamSelWidget) : |
334 | 33 |
config(config), |
34 |
m_pGameCFGWidget(pGameCFGWidget), |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
35 |
m_pTeamSelWidget(pTeamSelWidget), |
383 | 36 |
isChief(false), |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
37 |
m_game_connected(false), |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
38 |
loginStep(0), |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
39 |
netClientState(0) |
315 | 40 |
{ |
41 |
connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
|
42 |
connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect())); |
|
43 |
connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect())); |
|
44 |
connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, |
|
45 |
SLOT(displayError(QAbstractSocket::SocketError))); |
|
46 |
} |
|
47 |
||
48 |
void HWNewNet::Connect(const QString & hostName, quint16 port, const QString & nick) |
|
49 |
{ |
|
655
e58a77556878
- Temporary set delimiter to *, as \t seems to be endline now in Qt
unc0rr
parents:
574
diff
changeset
|
50 |
mynick = nick; |
315 | 51 |
NetSocket.connectToHost(hostName, port); |
52 |
} |
|
53 |
||
54 |
void HWNewNet::Disconnect() |
|
55 |
{ |
|
1311 | 56 |
m_game_connected = false; |
383 | 57 |
NetSocket.disconnectFromHost(); |
315 | 58 |
} |
59 |
||
1082 | 60 |
void HWNewNet::CreateRoom(const QString & room) |
315 | 61 |
{ |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
62 |
if(netClientState != 2) |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
63 |
{ |
1321 | 64 |
qWarning("Illegal try to create room!"); |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
65 |
return; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
66 |
} |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
67 |
|
1082 | 68 |
RawSendNet(QString("CREATE%1%2").arg(delimeter).arg(room)); |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
69 |
isChief = true; |
1082 | 70 |
} |
71 |
||
72 |
void HWNewNet::JoinRoom(const QString & room) |
|
73 |
{ |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
74 |
if(netClientState != 2) |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
75 |
{ |
1321 | 76 |
qWarning("Illegal try to join room!"); |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
77 |
return; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
78 |
} |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
79 |
|
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
80 |
loginStep++; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
81 |
|
1082 | 82 |
RawSendNet(QString("JOIN%1%2").arg(delimeter).arg(room)); |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
83 |
m_pGameCFGWidget->setEnabled(false); |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
84 |
m_pTeamSelWidget->setNonInteractive(); |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
85 |
isChief = false; |
315 | 86 |
} |
87 |
||
88 |
void HWNewNet::AddTeam(const HWTeam & team) |
|
89 |
{ |
|
1311 | 90 |
QString cmd = QString("ADDTEAM") + delimeter + |
382
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
373
diff
changeset
|
91 |
team.TeamName + delimeter + |
e7220e48ead1
colors changing config fully working (still need disabling in slaves)
displacer
parents:
373
diff
changeset
|
92 |
team.teamColor.name() + delimeter + |
443
eec37eb7f5db
fort, grave and difficulty information for net team
displacer
parents:
431
diff
changeset
|
93 |
team.Grave + delimeter + |
eec37eb7f5db
fort, grave and difficulty information for net team
displacer
parents:
431
diff
changeset
|
94 |
team.Fort + delimeter + |
1245
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
95 |
QString::number(team.difficulty); |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
96 |
|
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
97 |
for(int i = 0; i < 8; ++i) |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
98 |
{ |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
99 |
cmd.append(delimeter); |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
100 |
cmd.append(team.HHName[i]); |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
101 |
cmd.append(delimeter); |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
102 |
cmd.append(team.HHHat[i]); |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
103 |
} |
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
104 |
RawSendNet(cmd); |
315 | 105 |
} |
106 |
||
347 | 107 |
void HWNewNet::RemoveTeam(const HWTeam & team) |
108 |
{ |
|
1311 | 109 |
RawSendNet(QString("REMOVETEAM") + delimeter + team.TeamName); |
347 | 110 |
} |
111 |
||
1311 | 112 |
void HWNewNet::Ready() |
315 | 113 |
{ |
1311 | 114 |
RawSendNet(QString("READY")); |
315 | 115 |
} |
116 |
||
117 |
void HWNewNet::SendNet(const QByteArray & buf) |
|
118 |
{ |
|
119 |
QString msg = QString(buf.toBase64()); |
|
120 |
||
1311 | 121 |
RawSendNet(QString("GAMEMSG%1%2").arg(delimeter).arg(msg)); |
315 | 122 |
} |
123 |
||
124 |
void HWNewNet::RawSendNet(const QString & str) |
|
125 |
{ |
|
126 |
RawSendNet(str.toUtf8()); |
|
127 |
} |
|
128 |
||
129 |
void HWNewNet::RawSendNet(const QByteArray & buf) |
|
130 |
{ |
|
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
131 |
qDebug() << "Client: " << QString(buf).split("\n"); |
315 | 132 |
NetSocket.write(buf); |
1082 | 133 |
NetSocket.write("\n\n", 2); |
315 | 134 |
} |
135 |
||
136 |
void HWNewNet::ClientRead() |
|
137 |
{ |
|
1082 | 138 |
while (NetSocket.canReadLine()) { |
139 |
QString s = QString::fromUtf8(NetSocket.readLine().trimmed()); |
|
140 |
||
141 |
if (s.size() == 0) { |
|
142 |
ParseCmd(cmdbuf); |
|
143 |
cmdbuf.clear(); |
|
144 |
} else |
|
145 |
cmdbuf << s; |
|
146 |
} |
|
315 | 147 |
} |
148 |
||
149 |
void HWNewNet::OnConnect() |
|
150 |
{ |
|
1310 | 151 |
RawSendNet(QString("NICK%1%2").arg(delimeter).arg(mynick)); |
152 |
RawSendNet(QString("PROTO%1%2").arg(delimeter).arg(*cProtoVer)); |
|
315 | 153 |
} |
154 |
||
155 |
void HWNewNet::OnDisconnect() |
|
156 |
{ |
|
338
d1e75dcd285f
multiple teams now available per host (still alpha)
displacer
parents:
335
diff
changeset
|
157 |
//emit ChangeInTeams(QStringList()); |
383 | 158 |
if(m_game_connected) emit Disconnected(); |
159 |
m_game_connected=false; |
|
315 | 160 |
} |
161 |
||
162 |
void HWNewNet::displayError(QAbstractSocket::SocketError socketError) |
|
163 |
{ |
|
1302 | 164 |
switch (socketError) { |
165 |
case QAbstractSocket::RemoteHostClosedError: |
|
166 |
break; |
|
167 |
case QAbstractSocket::HostNotFoundError: |
|
168 |
QMessageBox::information(0, tr("Error"), |
|
169 |
tr("The host was not found. Please check the host name and port settings.")); |
|
170 |
break; |
|
171 |
case QAbstractSocket::ConnectionRefusedError: |
|
172 |
QMessageBox::information(0, tr("Error"), |
|
173 |
tr("Connection refused")); |
|
174 |
break; |
|
175 |
default: |
|
176 |
QMessageBox::information(0, tr("Error"), |
|
177 |
NetSocket.errorString()); |
|
178 |
} |
|
315 | 179 |
} |
180 |
||
1082 | 181 |
void HWNewNet::ParseCmd(const QStringList & lst) |
315 | 182 |
{ |
1305 | 183 |
qDebug() << "Server: " << lst; |
184 |
||
185 |
if(!lst.size()) |
|
186 |
{ |
|
187 |
qWarning("Net client: Bad message"); |
|
188 |
return; |
|
189 |
} |
|
320 | 190 |
|
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
191 |
if ((lst[0] == "NICK") || (lst[0] == "PROTO")) |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
192 |
{ |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
193 |
loginStep++; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
194 |
if (loginStep == 2) |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
195 |
{ |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
196 |
netClientState = 2; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
197 |
RawSendNet(QString("LIST")); |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
198 |
} |
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
199 |
return ; |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
200 |
} |
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
201 |
|
1305 | 202 |
if (lst[0] == "ERROR") { |
203 |
if (lst.size() == 2) |
|
1307 | 204 |
QMessageBox::information(0, 0, "Error: " + lst[1]); |
1305 | 205 |
else |
206 |
QMessageBox::information(0, 0, "Unknown error"); |
|
207 |
return; |
|
208 |
} |
|
315 | 209 |
|
1307 | 210 |
if (lst[0] == "WARNING") { |
211 |
if (lst.size() == 2) |
|
212 |
QMessageBox::information(0, 0, "Warning: " + lst[1]); |
|
213 |
else |
|
214 |
QMessageBox::information(0, 0, "Unknown warning"); |
|
215 |
return; |
|
216 |
} |
|
217 |
||
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
218 |
if (lst[0] == "CONNECTED") { |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
219 |
netClientState = 1; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
220 |
m_game_connected = true; |
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
221 |
emit Connected(); |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
222 |
return; |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
223 |
} |
315 | 224 |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
225 |
if (lst[0] == "ROOMS") { |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
226 |
QStringList tmp = lst; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
227 |
tmp.removeFirst(); |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
228 |
emit roomsList(tmp); |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
229 |
return; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
230 |
} |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
231 |
|
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
232 |
if (lst[0] == "CHAT_STRING") { |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
233 |
if(lst.size() < 3) |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
234 |
{ |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
235 |
qWarning("Net: Empty CHAT_STRING message"); |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
236 |
return; |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
237 |
} |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
238 |
QStringList tmp = lst; |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
239 |
tmp.removeFirst(); |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
240 |
emit chatStringFromNet(tmp); |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
241 |
return; |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
242 |
} |
453 | 243 |
|
1321 | 244 |
if (lst[0] == "ADDTEAM") { |
245 |
if(lst.size() < 22) |
|
246 |
{ |
|
247 |
qWarning("Net: Too short ADDTEAM message"); |
|
248 |
return; |
|
249 |
} |
|
250 |
QStringList tmp = lst; |
|
251 |
tmp.removeFirst(); |
|
252 |
emit AddNetTeam(tmp); |
|
253 |
return; |
|
254 |
} |
|
315 | 255 |
|
1321 | 256 |
if (lst[0] == "REMOVETEAM") { |
573 | 257 |
if(lst.size() < 3) |
258 |
{ |
|
259 |
qWarning("Net: Bad REMOVETEAM message"); |
|
260 |
return; |
|
261 |
} |
|
352 | 262 |
m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1], lst[2].toUInt())); |
347 | 263 |
return; |
264 |
} |
|
265 |
||
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
266 |
if(lst[0]=="JOINED") { |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
267 |
if(lst.size() < 2) |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
268 |
{ |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
269 |
qWarning("Net: Bad JOINED message"); |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
270 |
return; |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
271 |
} |
1311 | 272 |
|
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
273 |
for(int i = 1; i < lst.size(); ++i) |
1311 | 274 |
{ |
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
275 |
if (lst[i] == mynick) |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
276 |
{ |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
277 |
netClientState = 3; |
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
278 |
emit EnteredGame(); |
1316 | 279 |
if (isChief) |
280 |
ConfigAsked(); |
|
1313
f4c54e9e1b8c
- Introduce a bit of state miachine in client code (should be more robust and verbosive now)
unc0rr
parents:
1311
diff
changeset
|
281 |
} |
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
282 |
emit nickAdded(lst[i]); |
1311 | 283 |
} |
1308
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
284 |
return; |
d5dcd6cfa5e2
Fix another server failure (when second client in room disconnects)
unc0rr
parents:
1307
diff
changeset
|
285 |
} |
455 | 286 |
|
1310 | 287 |
if(lst[0]=="LEFT") { |
288 |
if(lst.size() < 2) |
|
289 |
{ |
|
290 |
qWarning("Net: Bad LEFT message"); |
|
291 |
return; |
|
292 |
} |
|
293 |
emit nickRemoved(lst[1]); |
|
294 |
return; |
|
295 |
} |
|
461 | 296 |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
297 |
if (lst[0] == "RUNGAME") { |
396 | 298 |
RunGame(); |
299 |
return; |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
300 |
} |
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
301 |
|
315 | 302 |
|
354
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
303 |
if(lst[0]=="TEAM_ACCEPTED") { |
573 | 304 |
if(lst.size() < 3) |
305 |
{ |
|
306 |
qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
307 |
return; |
|
308 |
} |
|
373 | 309 |
m_pTeamSelWidget->changeTeamStatus(lst[1]); |
354
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
310 |
return; |
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
311 |
} |
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
312 |
|
1319 | 313 |
if (lst[0] == "CONFIG_PARAM") { |
314 |
if(lst.size() < 3) |
|
315 |
{ |
|
316 |
qWarning("Net: Bad CONFIG_PARAM message"); |
|
317 |
return; |
|
318 |
} |
|
319 |
if (lst[1] == "SEED") { |
|
320 |
emit seedChanged(lst[2]); |
|
321 |
return; |
|
322 |
} |
|
323 |
if (lst[1] == "MAP") { |
|
324 |
emit mapChanged(lst[2]); |
|
325 |
return; |
|
326 |
} |
|
327 |
if (lst[1] == "THEME") { |
|
328 |
emit themeChanged(lst[2]); |
|
329 |
return; |
|
330 |
} |
|
331 |
if (lst[1] == "HEALTH") { |
|
332 |
emit initHealthChanged(lst[2].toUInt()); |
|
333 |
return; |
|
334 |
} |
|
335 |
if (lst[1] == "TURNTIME") { |
|
336 |
emit turnTimeChanged(lst[2].toUInt()); |
|
337 |
return; |
|
338 |
} |
|
339 |
if (lst[1] == "FORTSMODE") { |
|
340 |
emit fortsModeChanged(lst[2].toInt() != 0); |
|
341 |
return; |
|
342 |
} |
|
343 |
if (lst[1] == "AMMO") { |
|
344 |
if(lst.size() < 4) return; |
|
345 |
emit ammoChanged(lst[3], lst[2]); |
|
346 |
return; |
|
347 |
} |
|
1324 | 348 |
QStringList hhTmpList = lst[1].split('+'); |
1319 | 349 |
if (hhTmpList[0] == "TEAM_COLOR") { |
1324 | 350 |
HWTeam tmptm(hhTmpList[1]); |
351 |
tmptm.teamColor = QColor(lst[2]); |
|
1319 | 352 |
emit teamColorChanged(tmptm); |
353 |
return; |
|
354 |
} |
|
355 |
if (hhTmpList[0] == "HHNUM") { |
|
1324 | 356 |
HWTeam tmptm(hhTmpList[1]); |
357 |
tmptm.numHedgehogs = lst[2].toUInt(); |
|
1319 | 358 |
emit hhnumChanged(tmptm); |
359 |
return; |
|
360 |
} |
|
361 |
qWarning() << "Net: Unknown 'CONFIG_PARAM' message:" << lst; |
|
362 |
return; |
|
697 | 363 |
} |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
364 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
365 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
366 |
// should be kinda game states, which don't allow "GAMEMSG:" at configure step, |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
367 |
// "CONNECTED" at round phase, etc. |
1310 | 368 |
if (lst[0] == "GAMEMSG") { |
573 | 369 |
if(lst.size() < 2) |
370 |
{ |
|
1310 | 371 |
qWarning("Net: Bad GAMEMSG message"); |
573 | 372 |
return; |
373 |
} |
|
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
374 |
QByteArray em = QByteArray::fromBase64(lst[1].toAscii()); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
375 |
emit FromNet(em); |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
376 |
return; |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
377 |
} |
573 | 378 |
|
1082 | 379 |
qWarning() << "Net: Unknown message:" << lst; |
315 | 380 |
} |
381 |
||
382 |
||
383 |
void HWNewNet::ConfigAsked() |
|
384 |
{ |
|
1310 | 385 |
QString map = m_pGameCFGWidget->getCurrentMap(); |
386 |
if (map.size()) |
|
387 |
onMapChanged(map); |
|
574 | 388 |
|
1310 | 389 |
onSeedChanged(m_pGameCFGWidget->getCurrentSeed()); |
390 |
onThemeChanged(m_pGameCFGWidget->getCurrentTheme()); |
|
391 |
onInitHealthChanged(m_pGameCFGWidget->getInitHealth()); |
|
392 |
onTurnTimeChanged(m_pGameCFGWidget->getTurnTime()); |
|
393 |
onFortsModeChanged(m_pGameCFGWidget->getGameFlags() & 0x1); |
|
394 |
// always initialize with default ammo (also avoiding complicated cross-class dependencies) |
|
395 |
onWeaponsNameChanged("Default", cDefaultAmmoStore->mid(10)); |
|
315 | 396 |
} |
397 |
||
398 |
void HWNewNet::RunGame() |
|
399 |
{ |
|
1310 | 400 |
emit AskForRunGame(); |
431 | 401 |
} |
402 |
||
352 | 403 |
void HWNewNet::onHedgehogsNumChanged(const HWTeam& team) |
404 |
{ |
|
1324 | 405 |
RawSendNet(QString("HHNUM%1%2%1%3") |
406 |
.arg(delimeter) |
|
407 |
.arg(team.TeamName) |
|
1321 | 408 |
.arg(team.numHedgehogs)); |
352 | 409 |
} |
410 |
||
372 | 411 |
void HWNewNet::onTeamColorChanged(const HWTeam& team) |
412 |
{ |
|
1324 | 413 |
RawSendNet(QString("CONFIG_PARAM%1TEAM_COLOR%1%2%1%3") |
414 |
.arg(delimeter) |
|
415 |
.arg(team.TeamName) |
|
1321 | 416 |
.arg(team.teamColor.name())); |
372 | 417 |
} |
418 |
||
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
419 |
void HWNewNet::onSeedChanged(const QString & seed) |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
420 |
{ |
1318 | 421 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1SEED%1%2").arg(delimeter).arg(seed)); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
422 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
423 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
424 |
void HWNewNet::onMapChanged(const QString & map) |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
425 |
{ |
1318 | 426 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1MAP%1%2").arg(delimeter).arg(map)); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
427 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
428 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
429 |
void HWNewNet::onThemeChanged(const QString & theme) |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
430 |
{ |
1318 | 431 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1THEME%1%2").arg(delimeter).arg(theme)); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
432 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
433 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
434 |
void HWNewNet::onInitHealthChanged(quint32 health) |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
435 |
{ |
1318 | 436 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1HEALTH%1%2").arg(delimeter).arg(health)); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
437 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
438 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
439 |
void HWNewNet::onTurnTimeChanged(quint32 time) |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
440 |
{ |
1318 | 441 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1TURNTIME%1%2").arg(delimeter).arg(time)); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
442 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
443 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
444 |
void HWNewNet::onFortsModeChanged(bool value) |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
445 |
{ |
1318 | 446 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1FORTSMODE%1%2").arg(delimeter).arg(value)); |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
447 |
} |
453 | 448 |
|
703 | 449 |
void HWNewNet::onWeaponsNameChanged(const QString& name, const QString& ammo) |
697 | 450 |
{ |
1318 | 451 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1AMMO%1%2%1%3").arg(delimeter).arg(ammo).arg(name)); |
697 | 452 |
} |
453 |
||
453 | 454 |
void HWNewNet::chatLineToNet(const QString& str) |
455 |
{ |
|
456 |
if(str!="") { |
|
1322
c624b04699fb
Fix protocol implementation to conform documentation
unc0rr
parents:
1321
diff
changeset
|
457 |
RawSendNet(QString("CHAT_STRING")+delimeter+str); |
453 | 458 |
emit(chatStringFromNet(QStringList(mynick) << str)); |
459 |
} |
|
460 |
} |
|
1315 | 461 |
|
462 |
void HWNewNet::askRoomsList() |
|
463 |
{ |
|
464 |
if(netClientState != 2) |
|
465 |
{ |
|
1321 | 466 |
qWarning("Illegal try to get rooms list!"); |
1315 | 467 |
return; |
468 |
} |
|
469 |
RawSendNet(QString("LIST")); |
|
470 |
} |