author | unc0rr |
Thu, 09 Oct 2008 13:57:18 +0000 | |
changeset 1332 | 19ff9bf7d69e |
parent 1330 | 12c13ffb426f |
child 1333 | b0b0510eb82d |
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 |
{ |
|
1327 | 90 |
QString cmd = QString("ADD_TEAM") + 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 |
{ |
|
1329 | 109 |
RawSendNet(QString("REMOVE_TEAM") + 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 |
|
1325 | 244 |
if (lst[0] == "ADD_TEAM") { |
245 |
if(lst.size() != 21) |
|
1321 | 246 |
{ |
1325 | 247 |
qWarning("Net: Bad ADDTEAM message"); |
1321 | 248 |
return; |
249 |
} |
|
250 |
QStringList tmp = lst; |
|
251 |
tmp.removeFirst(); |
|
252 |
emit AddNetTeam(tmp); |
|
253 |
return; |
|
254 |
} |
|
315 | 255 |
|
1329 | 256 |
if (lst[0] == "REMOVE_TEAM") { |
1330 | 257 |
if(lst.size() != 2) |
573 | 258 |
{ |
259 |
qWarning("Net: Bad REMOVETEAM message"); |
|
260 |
return; |
|
261 |
} |
|
1325 | 262 |
m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1])); |
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 |
|
1325 | 287 |
if(lst[0] == "LEFT") { |
1310 | 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 |
|
1325 | 297 |
if (lst[0] == "RUNGAME") { |
298 |
RunGame(); |
|
299 |
return; |
|
300 |
} |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
301 |
|
315 | 302 |
|
1325 | 303 |
if (lst[0] == "TEAM_ACCEPTED") { |
304 |
if (lst.size() != 2) |
|
305 |
{ |
|
306 |
qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
307 |
return; |
|
308 |
} |
|
309 |
m_pTeamSelWidget->changeTeamStatus(lst[1]); |
|
310 |
return; |
|
311 |
} |
|
354
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 |
} |
|
348 |
qWarning() << "Net: Unknown 'CONFIG_PARAM' message:" << lst; |
|
349 |
return; |
|
697 | 350 |
} |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
351 |
|
1327 | 352 |
if (lst[0] == "HH_NUM") { |
353 |
if (lst.size() != 3) |
|
354 |
{ |
|
355 |
qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
356 |
return; |
|
357 |
} |
|
358 |
HWTeam tmptm(lst[1]); |
|
359 |
tmptm.numHedgehogs = lst[2].toUInt(); |
|
360 |
emit hhnumChanged(tmptm); |
|
361 |
return; |
|
362 |
} |
|
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
363 |
|
1330 | 364 |
if (lst[0] == "TEAM_COLOR") { |
365 |
if (lst.size() != 3) |
|
366 |
{ |
|
367 |
qWarning("Net: Bad TEAM_COLOR message"); |
|
368 |
return; |
|
369 |
} |
|
370 |
HWTeam tmptm(lst[1]); |
|
371 |
tmptm.teamColor = QColor(lst[2]); |
|
372 |
emit teamColorChanged(tmptm); |
|
373 |
return; |
|
374 |
} |
|
375 |
||
1310 | 376 |
if (lst[0] == "GAMEMSG") { |
573 | 377 |
if(lst.size() < 2) |
378 |
{ |
|
1310 | 379 |
qWarning("Net: Bad GAMEMSG message"); |
573 | 380 |
return; |
381 |
} |
|
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
382 |
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
|
383 |
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
|
384 |
return; |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
385 |
} |
573 | 386 |
|
1082 | 387 |
qWarning() << "Net: Unknown message:" << lst; |
315 | 388 |
} |
389 |
||
390 |
||
391 |
void HWNewNet::ConfigAsked() |
|
392 |
{ |
|
1310 | 393 |
QString map = m_pGameCFGWidget->getCurrentMap(); |
394 |
if (map.size()) |
|
395 |
onMapChanged(map); |
|
574 | 396 |
|
1310 | 397 |
onSeedChanged(m_pGameCFGWidget->getCurrentSeed()); |
398 |
onThemeChanged(m_pGameCFGWidget->getCurrentTheme()); |
|
399 |
onInitHealthChanged(m_pGameCFGWidget->getInitHealth()); |
|
400 |
onTurnTimeChanged(m_pGameCFGWidget->getTurnTime()); |
|
401 |
onFortsModeChanged(m_pGameCFGWidget->getGameFlags() & 0x1); |
|
402 |
// always initialize with default ammo (also avoiding complicated cross-class dependencies) |
|
403 |
onWeaponsNameChanged("Default", cDefaultAmmoStore->mid(10)); |
|
315 | 404 |
} |
405 |
||
406 |
void HWNewNet::RunGame() |
|
407 |
{ |
|
1310 | 408 |
emit AskForRunGame(); |
431 | 409 |
} |
410 |
||
352 | 411 |
void HWNewNet::onHedgehogsNumChanged(const HWTeam& team) |
412 |
{ |
|
1330 | 413 |
if (isChief) |
1327 | 414 |
RawSendNet(QString("HH_NUM%1%2%1%3") |
1324 | 415 |
.arg(delimeter) |
416 |
.arg(team.TeamName) |
|
1321 | 417 |
.arg(team.numHedgehogs)); |
352 | 418 |
} |
419 |
||
372 | 420 |
void HWNewNet::onTeamColorChanged(const HWTeam& team) |
421 |
{ |
|
1330 | 422 |
if (isChief) |
423 |
RawSendNet(QString("TEAM_COLOR%1%2%1%3") |
|
1324 | 424 |
.arg(delimeter) |
425 |
.arg(team.TeamName) |
|
1321 | 426 |
.arg(team.teamColor.name())); |
372 | 427 |
} |
428 |
||
329
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::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
|
430 |
{ |
1318 | 431 |
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
|
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::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
|
435 |
{ |
1318 | 436 |
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
|
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::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
|
440 |
{ |
1318 | 441 |
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
|
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::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
|
445 |
{ |
1318 | 446 |
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
|
447 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
448 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
449 |
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
|
450 |
{ |
1318 | 451 |
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
|
452 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
453 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
454 |
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
|
455 |
{ |
1318 | 456 |
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
|
457 |
} |
453 | 458 |
|
703 | 459 |
void HWNewNet::onWeaponsNameChanged(const QString& name, const QString& ammo) |
697 | 460 |
{ |
1318 | 461 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1AMMO%1%2%1%3").arg(delimeter).arg(ammo).arg(name)); |
697 | 462 |
} |
463 |
||
453 | 464 |
void HWNewNet::chatLineToNet(const QString& str) |
465 |
{ |
|
466 |
if(str!="") { |
|
1322
c624b04699fb
Fix protocol implementation to conform documentation
unc0rr
parents:
1321
diff
changeset
|
467 |
RawSendNet(QString("CHAT_STRING")+delimeter+str); |
453 | 468 |
emit(chatStringFromNet(QStringList(mynick) << str)); |
469 |
} |
|
470 |
} |
|
1315 | 471 |
|
472 |
void HWNewNet::askRoomsList() |
|
473 |
{ |
|
474 |
if(netClientState != 2) |
|
475 |
{ |
|
1321 | 476 |
qWarning("Illegal try to get rooms list!"); |
1315 | 477 |
return; |
478 |
} |
|
479 |
RawSendNet(QString("LIST")); |
|
480 |
} |