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