author | unc0rr |
Thu, 09 Oct 2008 15:54:09 +0000 | |
changeset 1333 | b0b0510eb82d |
parent 1330 | 12c13ffb426f |
child 1336 | 4e88eccbe7f6 |
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 |
|
1325 | 302 |
if (lst[0] == "TEAM_ACCEPTED") { |
303 |
if (lst.size() != 2) |
|
304 |
{ |
|
305 |
qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
306 |
return; |
|
307 |
} |
|
308 |
m_pTeamSelWidget->changeTeamStatus(lst[1]); |
|
309 |
return; |
|
310 |
} |
|
354
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
311 |
|
1333
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
312 |
if (lst[0] == "MAP") { |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
313 |
if (lst.size() != 2) |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
314 |
{ |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
315 |
qWarning("Net: Bad MAP message"); |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
316 |
return; |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
317 |
} |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
318 |
emit mapChanged(lst[1]); |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
319 |
return; |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
320 |
} |
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
321 |
|
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
322 |
|
1319 | 323 |
if (lst[0] == "CONFIG_PARAM") { |
324 |
if(lst.size() < 3) |
|
325 |
{ |
|
326 |
qWarning("Net: Bad CONFIG_PARAM message"); |
|
327 |
return; |
|
328 |
} |
|
329 |
if (lst[1] == "SEED") { |
|
330 |
emit seedChanged(lst[2]); |
|
331 |
return; |
|
332 |
} |
|
333 |
if (lst[1] == "THEME") { |
|
334 |
emit themeChanged(lst[2]); |
|
335 |
return; |
|
336 |
} |
|
337 |
if (lst[1] == "HEALTH") { |
|
338 |
emit initHealthChanged(lst[2].toUInt()); |
|
339 |
return; |
|
340 |
} |
|
341 |
if (lst[1] == "TURNTIME") { |
|
342 |
emit turnTimeChanged(lst[2].toUInt()); |
|
343 |
return; |
|
344 |
} |
|
345 |
if (lst[1] == "FORTSMODE") { |
|
346 |
emit fortsModeChanged(lst[2].toInt() != 0); |
|
347 |
return; |
|
348 |
} |
|
349 |
if (lst[1] == "AMMO") { |
|
350 |
if(lst.size() < 4) return; |
|
351 |
emit ammoChanged(lst[3], lst[2]); |
|
352 |
return; |
|
353 |
} |
|
354 |
qWarning() << "Net: Unknown 'CONFIG_PARAM' message:" << lst; |
|
355 |
return; |
|
697 | 356 |
} |
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
357 |
|
1327 | 358 |
if (lst[0] == "HH_NUM") { |
359 |
if (lst.size() != 3) |
|
360 |
{ |
|
361 |
qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
362 |
return; |
|
363 |
} |
|
364 |
HWTeam tmptm(lst[1]); |
|
365 |
tmptm.numHedgehogs = lst[2].toUInt(); |
|
366 |
emit hhnumChanged(tmptm); |
|
367 |
return; |
|
368 |
} |
|
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
369 |
|
1330 | 370 |
if (lst[0] == "TEAM_COLOR") { |
371 |
if (lst.size() != 3) |
|
372 |
{ |
|
373 |
qWarning("Net: Bad TEAM_COLOR message"); |
|
374 |
return; |
|
375 |
} |
|
376 |
HWTeam tmptm(lst[1]); |
|
377 |
tmptm.teamColor = QColor(lst[2]); |
|
378 |
emit teamColorChanged(tmptm); |
|
379 |
return; |
|
380 |
} |
|
381 |
||
1310 | 382 |
if (lst[0] == "GAMEMSG") { |
573 | 383 |
if(lst.size() < 2) |
384 |
{ |
|
1310 | 385 |
qWarning("Net: Bad GAMEMSG message"); |
573 | 386 |
return; |
387 |
} |
|
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
388 |
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
|
389 |
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
|
390 |
return; |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
391 |
} |
573 | 392 |
|
1082 | 393 |
qWarning() << "Net: Unknown message:" << lst; |
315 | 394 |
} |
395 |
||
396 |
||
397 |
void HWNewNet::ConfigAsked() |
|
398 |
{ |
|
1310 | 399 |
QString map = m_pGameCFGWidget->getCurrentMap(); |
400 |
if (map.size()) |
|
401 |
onMapChanged(map); |
|
574 | 402 |
|
1310 | 403 |
onSeedChanged(m_pGameCFGWidget->getCurrentSeed()); |
404 |
onThemeChanged(m_pGameCFGWidget->getCurrentTheme()); |
|
405 |
onInitHealthChanged(m_pGameCFGWidget->getInitHealth()); |
|
406 |
onTurnTimeChanged(m_pGameCFGWidget->getTurnTime()); |
|
407 |
onFortsModeChanged(m_pGameCFGWidget->getGameFlags() & 0x1); |
|
408 |
// always initialize with default ammo (also avoiding complicated cross-class dependencies) |
|
409 |
onWeaponsNameChanged("Default", cDefaultAmmoStore->mid(10)); |
|
315 | 410 |
} |
411 |
||
412 |
void HWNewNet::RunGame() |
|
413 |
{ |
|
1310 | 414 |
emit AskForRunGame(); |
431 | 415 |
} |
416 |
||
352 | 417 |
void HWNewNet::onHedgehogsNumChanged(const HWTeam& team) |
418 |
{ |
|
1330 | 419 |
if (isChief) |
1327 | 420 |
RawSendNet(QString("HH_NUM%1%2%1%3") |
1324 | 421 |
.arg(delimeter) |
422 |
.arg(team.TeamName) |
|
1321 | 423 |
.arg(team.numHedgehogs)); |
352 | 424 |
} |
425 |
||
372 | 426 |
void HWNewNet::onTeamColorChanged(const HWTeam& team) |
427 |
{ |
|
1330 | 428 |
if (isChief) |
429 |
RawSendNet(QString("TEAM_COLOR%1%2%1%3") |
|
1324 | 430 |
.arg(delimeter) |
431 |
.arg(team.TeamName) |
|
1321 | 432 |
.arg(team.teamColor.name())); |
372 | 433 |
} |
434 |
||
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
435 |
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
|
436 |
{ |
1318 | 437 |
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
|
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 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
440 |
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
|
441 |
{ |
1333
b0b0510eb82d
- Fix a bug with chosen map (new clinet gets wrong information)
unc0rr
parents:
1330
diff
changeset
|
442 |
if (isChief) RawSendNet(QString("MAP%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
|
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 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
445 |
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
|
446 |
{ |
1318 | 447 |
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
|
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 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
450 |
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
|
451 |
{ |
1318 | 452 |
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
|
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 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
455 |
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
|
456 |
{ |
1318 | 457 |
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
|
458 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
459 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
460 |
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
|
461 |
{ |
1318 | 462 |
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
|
463 |
} |
453 | 464 |
|
703 | 465 |
void HWNewNet::onWeaponsNameChanged(const QString& name, const QString& ammo) |
697 | 466 |
{ |
1318 | 467 |
if (isChief) RawSendNet(QString("CONFIG_PARAM%1AMMO%1%2%1%3").arg(delimeter).arg(ammo).arg(name)); |
697 | 468 |
} |
469 |
||
453 | 470 |
void HWNewNet::chatLineToNet(const QString& str) |
471 |
{ |
|
472 |
if(str!="") { |
|
1322
c624b04699fb
Fix protocol implementation to conform documentation
unc0rr
parents:
1321
diff
changeset
|
473 |
RawSendNet(QString("CHAT_STRING")+delimeter+str); |
453 | 474 |
emit(chatStringFromNet(QStringList(mynick) << str)); |
475 |
} |
|
476 |
} |
|
1315 | 477 |
|
478 |
void HWNewNet::askRoomsList() |
|
479 |
{ |
|
480 |
if(netClientState != 2) |
|
481 |
{ |
|
1321 | 482 |
qWarning("Illegal try to get rooms list!"); |
1315 | 483 |
return; |
484 |
} |
|
485 |
RawSendNet(QString("LIST")); |
|
486 |
} |