author | unc0rr |
Sun, 05 Oct 2008 23:27:53 +0000 | |
changeset 1305 | 453882eb4467 |
parent 1302 | 4290ba4a14ca |
child 1307 | ce26e16d18ab |
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) |
|
176 |
QMessageBox::information(0, 0, lst[1]); |
|
177 |
else |
|
178 |
QMessageBox::information(0, 0, "Unknown error"); |
|
179 |
return; |
|
180 |
} |
|
315 | 181 |
|
182 |
if (lst[0] == "CONNECTED") { |
|
383 | 183 |
m_game_connected=true; |
315 | 184 |
emit Connected(); |
185 |
emit EnteredGame(); |
|
186 |
return; |
|
187 |
} |
|
188 |
||
453 | 189 |
if (lst[0] == "CHAT_STRING") { |
1082 | 190 |
if(lst.size() < 3) |
573 | 191 |
{ |
192 |
qWarning("Net: Empty CHAT_STRING message"); |
|
193 |
return; |
|
194 |
} |
|
1082 | 195 |
QStringList tmp = lst; |
196 |
tmp.removeFirst(); |
|
197 |
emit chatStringFromNet(tmp); |
|
453 | 198 |
return; |
199 |
} |
|
200 |
||
338
d1e75dcd285f
multiple teams now available per host (still alpha)
displacer
parents:
335
diff
changeset
|
201 |
if (lst[0] == "ADDTEAM:") { |
1245
d2eca4a053f5
Send hats info via net. Hats implementation complete now.
unc0rr
parents:
1189
diff
changeset
|
202 |
if(lst.size() < 22) |
574 | 203 |
{ |
204 |
qWarning("Net: Too short ADDTEAM message"); |
|
205 |
return; |
|
206 |
} |
|
1082 | 207 |
QStringList tmp = lst; |
208 |
tmp.removeFirst(); |
|
209 |
emit AddNetTeam(tmp); |
|
315 | 210 |
return; |
211 |
} |
|
212 |
||
347 | 213 |
if (lst[0] == "REMOVETEAM:") { |
573 | 214 |
if(lst.size() < 3) |
215 |
{ |
|
216 |
qWarning("Net: Bad REMOVETEAM message"); |
|
217 |
return; |
|
218 |
} |
|
352 | 219 |
m_pTeamSelWidget->removeNetTeam(HWTeam(lst[1], lst[2].toUInt())); |
347 | 220 |
return; |
221 |
} |
|
222 |
||
349 | 223 |
if(lst[0]=="SLAVE") { |
224 |
m_pGameCFGWidget->setEnabled(false); |
|
362
b28e0dd48269
hedgehogs num modification now allowed to chief client only
displacer
parents:
356
diff
changeset
|
225 |
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
|
226 |
return; |
349 | 227 |
} |
228 |
||
455 | 229 |
if(lst[0]=="JOINED") { |
573 | 230 |
if(lst.size() < 2) |
231 |
{ |
|
232 |
qWarning("Net: Bad JOINED message"); |
|
233 |
return; |
|
234 |
} |
|
465 | 235 |
emit nickAdded(lst[1]); |
455 | 236 |
return; |
237 |
} |
|
238 |
||
461 | 239 |
if(lst[0]=="LEFT") { |
573 | 240 |
if(lst.size() < 2) |
241 |
{ |
|
242 |
qWarning("Net: Bad LEFT message"); |
|
243 |
return; |
|
244 |
} |
|
465 | 245 |
emit nickRemoved(lst[1]); |
461 | 246 |
return; |
247 |
} |
|
248 |
||
315 | 249 |
if (lst[0] == "CONFIGASKED") { |
334 | 250 |
isChief=true; |
315 | 251 |
ConfigAsked(); |
252 |
return; |
|
253 |
} |
|
320 | 254 |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
255 |
if (lst[0] == "RUNGAME") { |
396 | 256 |
RunGame(); |
257 |
return; |
|
339
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
258 |
} |
7535ab6c3820
Run game message added, team and config info provided for net game
displacer
parents:
338
diff
changeset
|
259 |
|
315 | 260 |
if (lst[0] == "CONFIGURED") { |
1082 | 261 |
QStringList tmp = lst; |
262 |
tmp.removeFirst(); |
|
263 |
if(tmp.size() < 6) |
|
573 | 264 |
{ |
265 |
qWarning("Net: Bad CONFIGURED message"); |
|
266 |
return; |
|
267 |
} |
|
1082 | 268 |
emit seedChanged(tmp[0]); |
269 |
emit mapChanged(tmp[1]); |
|
270 |
emit themeChanged(tmp[2]); |
|
271 |
emit initHealthChanged(tmp[3].toUInt()); |
|
272 |
emit turnTimeChanged(tmp[4].toUInt()); |
|
273 |
emit fortsModeChanged(tmp[5].toInt() != 0); |
|
315 | 274 |
return; |
275 |
} |
|
276 |
||
354
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
277 |
if(lst[0]=="TEAM_ACCEPTED") { |
573 | 278 |
if(lst.size() < 3) |
279 |
{ |
|
280 |
qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
281 |
return; |
|
282 |
} |
|
354
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
283 |
m_networkToLocalteams.insert(lst[2].toUInt(), lst[1]); |
373 | 284 |
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
|
285 |
return; |
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
286 |
} |
60e4af0a4375
network to local teams map, addteams from server before team config bug, fixed some segfaults
displacer
parents:
352
diff
changeset
|
287 |
|
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
288 |
if (lst[0] == "CONFIG_PARAM") { |
573 | 289 |
if(lst.size() < 3) |
290 |
{ |
|
291 |
qWarning("Net: Bad CONFIG_PARAM message"); |
|
292 |
return; |
|
293 |
} |
|
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
294 |
if (lst[1] == "SEED") { |
332 | 295 |
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
|
296 |
return; |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
297 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
298 |
if (lst[1] == "MAP") { |
332 | 299 |
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
|
300 |
return; |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
301 |
} |
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] == "THEME") { |
332 | 303 |
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
|
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] == "HEALTH") { |
332 | 307 |
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
|
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] == "TURNTIME") { |
332 | 311 |
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
|
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] == "FORTSMODE") { |
332 | 315 |
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
|
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 |
} |
697 | 318 |
if (lst[1] == "AMMO") { |
703 | 319 |
if(lst.size() < 4) return; |
320 |
emit ammoChanged(lst[3], lst[2]); |
|
697 | 321 |
return; |
322 |
} |
|
401 | 323 |
QStringList hhTmpList=lst[1].split('+'); |
324 |
if (hhTmpList[0] == "TEAM_COLOR") { |
|
325 |
HWTeam tmptm(hhTmpList[1], hhTmpList[2].toUInt()); |
|
326 |
if(m_networkToLocalteams.find(hhTmpList[2].toUInt())!=m_networkToLocalteams.end()) { |
|
327 |
tmptm=HWTeam(hhTmpList[1]); // local team should be changed |
|
372 | 328 |
} |
401 | 329 |
tmptm.teamColor=QColor(lst[2]); |
372 | 330 |
emit teamColorChanged(tmptm); |
331 |
return; |
|
332 |
} |
|
401 | 333 |
if (hhTmpList[0] == "HHNUM") { |
399 | 334 |
HWTeam tmptm(hhTmpList[1], hhTmpList[2].toUInt()); |
335 |
if(m_networkToLocalteams.find(hhTmpList[2].toUInt())!=m_networkToLocalteams.end()) { |
|
336 |
tmptm=HWTeam(hhTmpList[1]); // local team should be changed |
|
337 |
} |
|
338 |
tmptm.numHedgehogs=lst[2].toUInt(); |
|
339 |
emit hhnumChanged(tmptm); |
|
340 |
return; |
|
341 |
} |
|
1082 | 342 |
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
|
343 |
return; |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
344 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
345 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
346 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
347 |
// 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
|
348 |
// "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
|
349 |
if (lst[0] == "GAMEMSG:") { |
573 | 350 |
if(lst.size() < 2) |
351 |
{ |
|
352 |
qWarning("Net: Bad LEFT message"); |
|
353 |
return; |
|
354 |
} |
|
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
355 |
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
|
356 |
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
|
357 |
return; |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
358 |
} |
573 | 359 |
|
1082 | 360 |
qWarning() << "Net: Unknown message:" << lst; |
315 | 361 |
} |
362 |
||
363 |
||
364 |
void HWNewNet::ConfigAsked() |
|
365 |
{ |
|
574 | 366 |
QString map = m_pGameCFGWidget->getCurrentMap(); |
367 |
if (map.size()) |
|
368 |
onMapChanged(map); |
|
369 |
||
335 | 370 |
onSeedChanged(m_pGameCFGWidget->getCurrentSeed()); |
371 |
onThemeChanged(m_pGameCFGWidget->getCurrentTheme()); |
|
372 |
onInitHealthChanged(m_pGameCFGWidget->getInitHealth()); |
|
373 |
onTurnTimeChanged(m_pGameCFGWidget->getTurnTime()); |
|
444 | 374 |
onFortsModeChanged(m_pGameCFGWidget->getGameFlags() & 0x1); |
697 | 375 |
// always initialize with default ammo (also avoiding complicated cross-class dependencies) |
703 | 376 |
onWeaponsNameChanged("Default", cDefaultAmmoStore->mid(10)); |
315 | 377 |
} |
378 |
||
379 |
void HWNewNet::RunGame() |
|
380 |
{ |
|
660 | 381 |
emit AskForRunGame(); |
431 | 382 |
} |
383 |
||
352 | 384 |
void HWNewNet::onHedgehogsNumChanged(const HWTeam& team) |
385 |
{ |
|
455 | 386 |
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
|
387 |
.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
|
388 |
.arg(team.numHedgehogs)); |
352 | 389 |
} |
390 |
||
372 | 391 |
void HWNewNet::onTeamColorChanged(const HWTeam& team) |
392 |
{ |
|
401 | 393 |
RawSendNet(QString("CONFIG_PARAM%1TEAM_COLOR+%2+%3%1%4").arg(delimeter).arg(team.TeamName)\ |
372 | 394 |
.arg(team.getNetID() ? team.getNetID() : m_networkToLocalteams.key(team.TeamName))\ |
395 |
.arg(team.teamColor.name())); |
|
396 |
} |
|
397 |
||
329
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
398 |
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
|
399 |
{ |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
400 |
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
|
401 |
} |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
402 |
|
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
403 |
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
|
404 |
{ |
4c3aad46baa5
Send game parameters by net... Currently it leads to infinite loop, flooding traffic with messages about changes
unc0rr
parents:
322
diff
changeset
|
405 |
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
|
406 |
} |
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 |
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
|
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 |
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
|
411 |
} |
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 |
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
|
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 |
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
|
416 |
} |
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 |
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
|
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 |
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
|
421 |
} |
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 |
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
|
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 |
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
|
426 |
} |
453 | 427 |
|
703 | 428 |
void HWNewNet::onWeaponsNameChanged(const QString& name, const QString& ammo) |
697 | 429 |
{ |
703 | 430 |
RawSendNet(QString("CONFIG_PARAM%1AMMO%1%2%1%3").arg(delimeter).arg(ammo).arg(name)); |
697 | 431 |
} |
432 |
||
453 | 433 |
void HWNewNet::chatLineToNet(const QString& str) |
434 |
{ |
|
435 |
if(str!="") { |
|
436 |
RawSendNet(QString("CHAT_STRING")+delimeter+mynick+delimeter+str); |
|
437 |
emit(chatStringFromNet(QStringList(mynick) << str)); |
|
438 |
} |
|
439 |
} |