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