1 /* |
|
2 * Hedgewars, a free turn based strategy game |
|
3 * Copyright (c) 2006-2008 Igor Ulyanov <iulyanov@gmail.com> |
|
4 * Copyright (c) 2008-2011 Andrey Korotaev <unC0Rr@gmail.com> |
|
5 * |
|
6 * This program is free software; you can redistribute it and/or modify |
|
7 * it under the terms of the GNU General Public License as published by |
|
8 * the Free Software Foundation; version 2 of the License |
|
9 * |
|
10 * This program is distributed in the hope that it will be useful, |
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 * GNU General Public License for more details. |
|
14 * |
|
15 * You should have received a copy of the GNU General Public License |
|
16 * along with this program; if not, write to the Free Software |
|
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
18 */ |
|
19 |
|
20 #include <QDebug> |
|
21 #include <QInputDialog> |
|
22 #include <QCryptographicHash> |
|
23 |
|
24 #include "hwconsts.h" |
|
25 #include "newnetclient.h" |
|
26 #include "proto.h" |
|
27 #include "game.h" |
|
28 #include "misc.h" |
|
29 /* only to get the ignoreList from the chat widget */ |
|
30 #include "hwform.h" |
|
31 #include "pageroomslist.h" |
|
32 #include "chatwidget.h" |
|
33 |
|
34 char delimeter='\n'; |
|
35 |
|
36 HWNewNet::HWNewNet() : |
|
37 isChief(false), |
|
38 m_game_connected(false), |
|
39 loginStep(0), |
|
40 netClientState(Disconnected) |
|
41 { |
|
42 // socket stuff |
|
43 connect(&NetSocket, SIGNAL(readyRead()), this, SLOT(ClientRead())); |
|
44 connect(&NetSocket, SIGNAL(connected()), this, SLOT(OnConnect())); |
|
45 connect(&NetSocket, SIGNAL(disconnected()), this, SLOT(OnDisconnect())); |
|
46 connect(&NetSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, |
|
47 SLOT(displayError(QAbstractSocket::SocketError))); |
|
48 } |
|
49 |
|
50 HWNewNet::~HWNewNet() |
|
51 { |
|
52 if (m_game_connected) |
|
53 { |
|
54 RawSendNet(QString("QUIT%1%2").arg(delimeter).arg("User quit")); |
|
55 emit disconnected(tr("User quit")); |
|
56 } |
|
57 NetSocket.flush(); |
|
58 } |
|
59 |
|
60 void HWNewNet::Connect(const QString & hostName, quint16 port, const QString & nick) |
|
61 { |
|
62 netClientState = Connecting; |
|
63 mynick = nick; |
|
64 myhost = hostName + QString(":%1").arg(port); |
|
65 NetSocket.connectToHost(hostName, port); |
|
66 } |
|
67 |
|
68 void HWNewNet::Disconnect() |
|
69 { |
|
70 if (m_game_connected) |
|
71 RawSendNet(QString("QUIT%1%2").arg(delimeter).arg("User quit")); |
|
72 m_game_connected = false; |
|
73 |
|
74 NetSocket.disconnectFromHost(); |
|
75 } |
|
76 |
|
77 void HWNewNet::CreateRoom(const QString & room) |
|
78 { |
|
79 if(netClientState != InLobby) |
|
80 { |
|
81 qWarning("Illegal try to create room!"); |
|
82 return; |
|
83 } |
|
84 |
|
85 myroom = room; |
|
86 |
|
87 RawSendNet(QString("CREATE_ROOM%1%2").arg(delimeter).arg(room)); |
|
88 isChief = true; |
|
89 } |
|
90 |
|
91 void HWNewNet::JoinRoom(const QString & room) |
|
92 { |
|
93 if(netClientState != InLobby) |
|
94 { |
|
95 qWarning("Illegal try to join room!"); |
|
96 return; |
|
97 } |
|
98 |
|
99 myroom = room; |
|
100 |
|
101 RawSendNet(QString("JOIN_ROOM%1%2").arg(delimeter).arg(room)); |
|
102 isChief = false; |
|
103 } |
|
104 |
|
105 void HWNewNet::AddTeam(const HWTeam & team) |
|
106 { |
|
107 QString cmd = QString("ADD_TEAM") + delimeter + |
|
108 team.name() + delimeter + |
|
109 team.color().name() + delimeter + |
|
110 team.grave() + delimeter + |
|
111 team.fort() + delimeter + |
|
112 team.voicepack() + delimeter + |
|
113 team.flag() + delimeter + |
|
114 QString::number(team.difficulty()); |
|
115 |
|
116 for(int i = 0; i < HEDGEHOGS_PER_TEAM; ++i) |
|
117 { |
|
118 cmd.append(delimeter); |
|
119 cmd.append(team.hedgehog(i).Name); |
|
120 cmd.append(delimeter); |
|
121 cmd.append(team.hedgehog(i).Hat); |
|
122 } |
|
123 RawSendNet(cmd); |
|
124 } |
|
125 |
|
126 void HWNewNet::RemoveTeam(const HWTeam & team) |
|
127 { |
|
128 RawSendNet(QString("REMOVE_TEAM") + delimeter + team.name()); |
|
129 } |
|
130 |
|
131 void HWNewNet::NewNick(const QString & nick) |
|
132 { |
|
133 RawSendNet(QString("NICK%1%2").arg(delimeter).arg(nick)); |
|
134 } |
|
135 |
|
136 void HWNewNet::ToggleReady() |
|
137 { |
|
138 RawSendNet(QString("TOGGLE_READY")); |
|
139 } |
|
140 |
|
141 void HWNewNet::SendNet(const QByteArray & buf) |
|
142 { |
|
143 QString msg = QString(buf.toBase64()); |
|
144 |
|
145 RawSendNet(QString("EM%1%2").arg(delimeter).arg(msg)); |
|
146 } |
|
147 |
|
148 void HWNewNet::RawSendNet(const QString & str) |
|
149 { |
|
150 RawSendNet(str.toUtf8()); |
|
151 } |
|
152 |
|
153 void HWNewNet::RawSendNet(const QByteArray & buf) |
|
154 { |
|
155 qDebug() << "Client: " << QString(buf).split("\n"); |
|
156 NetSocket.write(buf); |
|
157 NetSocket.write("\n\n", 2); |
|
158 } |
|
159 |
|
160 void HWNewNet::ClientRead() |
|
161 { |
|
162 while (NetSocket.canReadLine()) { |
|
163 QString s = QString::fromUtf8(NetSocket.readLine()); |
|
164 if (s.endsWith('\n')) s.chop(1); |
|
165 |
|
166 if (s.size() == 0) { |
|
167 ParseCmd(cmdbuf); |
|
168 cmdbuf.clear(); |
|
169 } else |
|
170 cmdbuf << s; |
|
171 } |
|
172 } |
|
173 |
|
174 void HWNewNet::OnConnect() |
|
175 { |
|
176 netClientState = Connected; |
|
177 } |
|
178 |
|
179 void HWNewNet::OnDisconnect() |
|
180 { |
|
181 netClientState = Disconnected; |
|
182 if(m_game_connected) emit disconnected(""); |
|
183 m_game_connected = false; |
|
184 } |
|
185 |
|
186 void HWNewNet::displayError(QAbstractSocket::SocketError socketError) |
|
187 { |
|
188 m_game_connected = false; |
|
189 |
|
190 switch (socketError) { |
|
191 case QAbstractSocket::RemoteHostClosedError: |
|
192 break; |
|
193 case QAbstractSocket::HostNotFoundError: |
|
194 emit disconnected(tr("The host was not found. Please check the host name and port settings.")); |
|
195 break; |
|
196 case QAbstractSocket::ConnectionRefusedError: |
|
197 emit disconnected(tr("Connection refused")); |
|
198 break; |
|
199 default: |
|
200 emit disconnected(NetSocket.errorString()); |
|
201 } |
|
202 } |
|
203 |
|
204 void HWNewNet::SendPasswordHash(const QString & hash) |
|
205 { |
|
206 RawSendNet(QString("PASSWORD%1%2").arg(delimeter).arg(hash)); |
|
207 } |
|
208 |
|
209 void HWNewNet::ParseCmd(const QStringList & lst) |
|
210 { |
|
211 qDebug() << "Server: " << lst; |
|
212 |
|
213 if(!lst.size()) |
|
214 { |
|
215 qWarning("Net client: Bad message"); |
|
216 return; |
|
217 } |
|
218 |
|
219 if (lst[0] == "NICK") |
|
220 { |
|
221 mynick = lst[1]; |
|
222 return ; |
|
223 } |
|
224 |
|
225 if (lst[0] == "PROTO") |
|
226 return ; |
|
227 |
|
228 if (lst[0] == "ERROR") { |
|
229 if (lst.size() == 2) |
|
230 emit Error(lst[1]); |
|
231 else |
|
232 emit Error("Unknown error"); |
|
233 return; |
|
234 } |
|
235 |
|
236 if (lst[0] == "WARNING") { |
|
237 if (lst.size() == 2) |
|
238 emit Warning(lst[1]); |
|
239 else |
|
240 emit Warning("Unknown warning"); |
|
241 return; |
|
242 } |
|
243 |
|
244 if (lst[0] == "CONNECTED") { |
|
245 if(lst.size() < 3 || lst[2].toInt() < cMinServerVersion) |
|
246 { |
|
247 // TODO: Warn user, disconnect |
|
248 qWarning() << "Server too old"; |
|
249 } |
|
250 |
|
251 RawSendNet(QString("NICK%1%2").arg(delimeter).arg(mynick)); |
|
252 RawSendNet(QString("PROTO%1%2").arg(delimeter).arg(*cProtoVer)); |
|
253 netClientState = Connected; |
|
254 m_game_connected = true; |
|
255 emit adminAccess(false); |
|
256 return; |
|
257 } |
|
258 |
|
259 if (lst[0] == "PING") { |
|
260 if (lst.size() > 1) |
|
261 RawSendNet(QString("PONG%1%2").arg(delimeter).arg(lst[1])); |
|
262 else |
|
263 RawSendNet(QString("PONG")); |
|
264 return; |
|
265 } |
|
266 |
|
267 if (lst[0] == "ROOMS") { |
|
268 QStringList tmp = lst; |
|
269 tmp.removeFirst(); |
|
270 emit roomsList(tmp); |
|
271 return; |
|
272 } |
|
273 |
|
274 if (lst[0] == "SERVER_MESSAGE") { |
|
275 if(lst.size() < 2) |
|
276 { |
|
277 qWarning("Net: Empty SERVERMESSAGE message"); |
|
278 return; |
|
279 } |
|
280 emit serverMessage(lst[1]); |
|
281 return; |
|
282 } |
|
283 |
|
284 if (lst[0] == "CHAT") { |
|
285 if(lst.size() < 3) |
|
286 { |
|
287 qWarning("Net: Empty CHAT message"); |
|
288 return; |
|
289 } |
|
290 if (netClientState == InLobby) |
|
291 emit chatStringLobby(lst[1], HWProto::formatChatMsgForFrontend(lst[2])); |
|
292 else |
|
293 emit chatStringFromNet(HWProto::formatChatMsg(lst[1], lst[2])); |
|
294 return; |
|
295 } |
|
296 |
|
297 if (lst[0] == "INFO") { |
|
298 if(lst.size() < 5) |
|
299 { |
|
300 qWarning("Net: Malformed INFO message"); |
|
301 return; |
|
302 } |
|
303 QStringList tmp = lst; |
|
304 tmp.removeFirst(); |
|
305 if (netClientState == InLobby) |
|
306 emit chatStringLobby(tmp.join("\n").prepend('\x01')); |
|
307 else |
|
308 emit chatStringFromNet(tmp.join("\n").prepend('\x01')); |
|
309 return; |
|
310 } |
|
311 |
|
312 if (lst[0] == "SERVER_VARS") { |
|
313 QStringList tmp = lst; |
|
314 tmp.removeFirst(); |
|
315 while (tmp.size() >= 2) |
|
316 { |
|
317 if(tmp[0] == "MOTD_NEW") emit serverMessageNew(tmp[1]); |
|
318 else if(tmp[0] == "MOTD_OLD") emit serverMessageOld(tmp[1]); |
|
319 else if(tmp[0] == "LATEST_PROTO") emit latestProtocolVar(tmp[1].toInt()); |
|
320 |
|
321 tmp.removeFirst(); |
|
322 tmp.removeFirst(); |
|
323 } |
|
324 return; |
|
325 } |
|
326 |
|
327 if (lst[0] == "CLIENT_FLAGS") |
|
328 { |
|
329 if(lst.size() < 3 || lst[1].size() < 2) |
|
330 { |
|
331 qWarning("Net: Malformed CLIENT_FLAGS message"); |
|
332 return; |
|
333 } |
|
334 |
|
335 QString flags = lst[1]; |
|
336 bool setFlag = flags[0] == '+'; |
|
337 |
|
338 while(flags.size() > 1) |
|
339 { |
|
340 flags.remove(0, 1); |
|
341 char c = flags[0].toAscii(); |
|
342 |
|
343 switch(c) |
|
344 { |
|
345 case 'r': |
|
346 { |
|
347 for(int i = 2; i < lst.size(); ++i) |
|
348 { |
|
349 if (lst[i] == mynick) |
|
350 emit setMyReadyStatus(setFlag); |
|
351 emit setReadyStatus(lst[i], setFlag); |
|
352 } |
|
353 } |
|
354 } |
|
355 } |
|
356 |
|
357 return; |
|
358 } |
|
359 |
|
360 if (lst[0] == "ADD_TEAM") { |
|
361 if(lst.size() != 24) |
|
362 { |
|
363 qWarning("Net: Bad ADDTEAM message"); |
|
364 return; |
|
365 } |
|
366 QStringList tmp = lst; |
|
367 tmp.removeFirst(); |
|
368 emit AddNetTeam(tmp); |
|
369 return; |
|
370 } |
|
371 |
|
372 if (lst[0] == "REMOVE_TEAM") { |
|
373 if(lst.size() != 2) |
|
374 { |
|
375 qWarning("Net: Bad REMOVETEAM message"); |
|
376 return; |
|
377 } |
|
378 emit RemoveNetTeam(HWTeam(lst[1])); |
|
379 return; |
|
380 } |
|
381 |
|
382 if(lst[0] == "ROOMABANDONED") { |
|
383 netClientState = InLobby; |
|
384 emit LeftRoom(tr("Room destroyed")); |
|
385 return; |
|
386 } |
|
387 |
|
388 if(lst[0] == "KICKED") { |
|
389 netClientState = InLobby; |
|
390 emit LeftRoom(tr("You got kicked")); |
|
391 return; |
|
392 } |
|
393 |
|
394 if(lst[0] == "JOINED") { |
|
395 if(lst.size() < 2) |
|
396 { |
|
397 qWarning("Net: Bad JOINED message"); |
|
398 return; |
|
399 } |
|
400 |
|
401 for(int i = 1; i < lst.size(); ++i) |
|
402 { |
|
403 if (lst[i] == mynick) |
|
404 { |
|
405 netClientState = InRoom; |
|
406 emit EnteredGame(); |
|
407 emit roomMaster(isChief); |
|
408 if (isChief) |
|
409 emit configAsked(); |
|
410 } |
|
411 |
|
412 emit nickAdded(lst[i], isChief && (lst[i] != mynick)); |
|
413 emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i])); |
|
414 } |
|
415 return; |
|
416 } |
|
417 |
|
418 if(lst[0] == "LOBBY:JOINED") { |
|
419 if(lst.size() < 2) |
|
420 { |
|
421 qWarning("Net: Bad JOINED message"); |
|
422 return; |
|
423 } |
|
424 |
|
425 for(int i = 1; i < lst.size(); ++i) |
|
426 { |
|
427 if (lst[i] == mynick) |
|
428 { |
|
429 netClientState = InLobby; |
|
430 RawSendNet(QString("LIST")); |
|
431 emit connected(); |
|
432 } |
|
433 |
|
434 emit nickAddedLobby(lst[i], false); |
|
435 emit chatStringLobby(lst[i], tr("%1 *** %2 has joined").arg('\x03').arg("|nick|")); |
|
436 } |
|
437 return; |
|
438 } |
|
439 |
|
440 if(lst[0] == "LEFT") { |
|
441 if(lst.size() < 2) |
|
442 { |
|
443 qWarning("Net: Bad LEFT message"); |
|
444 return; |
|
445 } |
|
446 emit nickRemoved(lst[1]); |
|
447 if (lst.size() < 3) |
|
448 emit chatStringFromNet(tr("%1 *** %2 has left").arg('\x03').arg(lst[1])); |
|
449 else |
|
450 emit chatStringFromNet(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2])); |
|
451 return; |
|
452 } |
|
453 |
|
454 if(lst[0] == "ROOM") { |
|
455 if(lst.size() < 2) |
|
456 { |
|
457 qWarning("Net: Bad ROOM message"); |
|
458 return; |
|
459 } |
|
460 RawSendNet(QString("LIST")); |
|
461 return; |
|
462 } |
|
463 |
|
464 if(lst[0] == "LOBBY:LEFT") { |
|
465 if(lst.size() < 2) |
|
466 { |
|
467 qWarning("Net: Bad LOBBY:LEFT message"); |
|
468 return; |
|
469 } |
|
470 emit nickRemovedLobby(lst[1]); |
|
471 if (lst.size() < 3) |
|
472 emit chatStringLobby(tr("%1 *** %2 has left").arg('\x03').arg(lst[1])); |
|
473 else |
|
474 emit chatStringLobby(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2])); |
|
475 return; |
|
476 } |
|
477 |
|
478 if (lst[0] == "RUN_GAME") { |
|
479 netClientState = InGame; |
|
480 emit AskForRunGame(); |
|
481 return; |
|
482 } |
|
483 |
|
484 if (lst[0] == "ASKPASSWORD") { |
|
485 emit AskForPassword(mynick); |
|
486 return; |
|
487 } |
|
488 |
|
489 if (lst[0] == "NOTICE") { |
|
490 if(lst.size() < 2) |
|
491 { |
|
492 qWarning("Net: Bad NOTICE message"); |
|
493 return; |
|
494 } |
|
495 |
|
496 bool ok; |
|
497 int n = lst[1].toInt(&ok); |
|
498 if(!ok) |
|
499 { |
|
500 qWarning("Net: Bad NOTICE message"); |
|
501 return; |
|
502 } |
|
503 |
|
504 handleNotice(n); |
|
505 |
|
506 return; |
|
507 } |
|
508 |
|
509 if (lst[0] == "TEAM_ACCEPTED") { |
|
510 if (lst.size() != 2) |
|
511 { |
|
512 qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
513 return; |
|
514 } |
|
515 emit TeamAccepted(lst[1]); |
|
516 return; |
|
517 } |
|
518 |
|
519 |
|
520 if (lst[0] == "CFG") { |
|
521 if(lst.size() < 3) |
|
522 { |
|
523 qWarning("Net: Bad CFG message"); |
|
524 return; |
|
525 } |
|
526 QStringList tmp = lst; |
|
527 tmp.removeFirst(); |
|
528 tmp.removeFirst(); |
|
529 if (lst[1] == "SCHEME") |
|
530 emit netSchemeConfig(tmp); |
|
531 else |
|
532 emit paramChanged(lst[1], tmp); |
|
533 return; |
|
534 } |
|
535 |
|
536 if (lst[0] == "HH_NUM") { |
|
537 if (lst.size() != 3) |
|
538 { |
|
539 qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
540 return; |
|
541 } |
|
542 HWTeam tmptm(lst[1]); |
|
543 tmptm.setNumHedgehogs(lst[2].toUInt()); |
|
544 emit hhnumChanged(tmptm); |
|
545 return; |
|
546 } |
|
547 |
|
548 if (lst[0] == "TEAM_COLOR") { |
|
549 if (lst.size() != 3) |
|
550 { |
|
551 qWarning("Net: Bad TEAM_COLOR message"); |
|
552 return; |
|
553 } |
|
554 HWTeam tmptm(lst[1]); |
|
555 tmptm.setColor(QColor(lst[2])); |
|
556 emit teamColorChanged(tmptm); |
|
557 return; |
|
558 } |
|
559 |
|
560 if (lst[0] == "EM") { |
|
561 if(lst.size() < 2) |
|
562 { |
|
563 qWarning("Net: Bad EM message"); |
|
564 return; |
|
565 } |
|
566 for(int i = 1; i < lst.size(); ++i) |
|
567 { |
|
568 QByteArray em = QByteArray::fromBase64(lst[i].toAscii()); |
|
569 emit FromNet(em); |
|
570 } |
|
571 return; |
|
572 } |
|
573 |
|
574 if (lst[0] == "BYE") { |
|
575 if (lst.size() < 2) |
|
576 { |
|
577 qWarning("Net: Bad BYE message"); |
|
578 return; |
|
579 } |
|
580 if (lst[1] == "Authentication failed") |
|
581 { |
|
582 emit AuthFailed(); |
|
583 } |
|
584 m_game_connected = false; |
|
585 Disconnect(); |
|
586 emit disconnected(lst[1]); |
|
587 return; |
|
588 } |
|
589 |
|
590 |
|
591 if (lst[0] == "ADMIN_ACCESS") { |
|
592 emit adminAccess(true); |
|
593 return; |
|
594 } |
|
595 |
|
596 if (lst[0] == "ROOM_CONTROL_ACCESS") { |
|
597 if (lst.size() < 2) |
|
598 { |
|
599 qWarning("Net: Bad ROOM_CONTROL_ACCESS message"); |
|
600 return; |
|
601 } |
|
602 isChief = (lst[1] != "0"); |
|
603 emit roomMaster(isChief); |
|
604 return; |
|
605 } |
|
606 |
|
607 qWarning() << "Net: Unknown message:" << lst; |
|
608 } |
|
609 |
|
610 void HWNewNet::onHedgehogsNumChanged(const HWTeam& team) |
|
611 { |
|
612 if (isChief) |
|
613 RawSendNet(QString("HH_NUM%1%2%1%3") |
|
614 .arg(delimeter) |
|
615 .arg(team.name()) |
|
616 .arg(team.numHedgehogs())); |
|
617 } |
|
618 |
|
619 void HWNewNet::onTeamColorChanged(const HWTeam& team) |
|
620 { |
|
621 if (isChief) |
|
622 RawSendNet(QString("TEAM_COLOR%1%2%1%3") |
|
623 .arg(delimeter) |
|
624 .arg(team.name()) |
|
625 .arg(team.color().name())); |
|
626 } |
|
627 |
|
628 void HWNewNet::onParamChanged(const QString & param, const QStringList & value) |
|
629 { |
|
630 if (isChief) |
|
631 RawSendNet( |
|
632 QString("CFG%1%2%1%3") |
|
633 .arg(delimeter) |
|
634 .arg(param) |
|
635 .arg(value.join(QString(delimeter))) |
|
636 ); |
|
637 } |
|
638 |
|
639 void HWNewNet::chatLineToNet(const QString& str) |
|
640 { |
|
641 if(str != "") { |
|
642 RawSendNet(QString("CHAT") + delimeter + str); |
|
643 emit(chatStringFromMe(HWProto::formatChatMsg(mynick, str))); |
|
644 } |
|
645 } |
|
646 |
|
647 void HWNewNet::chatLineToLobby(const QString& str) |
|
648 { |
|
649 if(str != "") { |
|
650 RawSendNet(QString("CHAT") + delimeter + str); |
|
651 emit(chatStringFromMeLobby(HWProto::formatChatMsg(mynick, str))); |
|
652 } |
|
653 } |
|
654 |
|
655 void HWNewNet::SendTeamMessage(const QString& str) |
|
656 { |
|
657 RawSendNet(QString("TEAMCHAT") + delimeter + str); |
|
658 } |
|
659 |
|
660 void HWNewNet::askRoomsList() |
|
661 { |
|
662 if(netClientState != InLobby) |
|
663 { |
|
664 qWarning("Illegal try to get rooms list!"); |
|
665 return; |
|
666 } |
|
667 RawSendNet(QString("LIST")); |
|
668 } |
|
669 |
|
670 HWNewNet::ClientState HWNewNet::clientState() |
|
671 { |
|
672 return netClientState; |
|
673 } |
|
674 |
|
675 QString HWNewNet::getNick() |
|
676 { |
|
677 return mynick; |
|
678 } |
|
679 |
|
680 QString HWNewNet::getRoom() |
|
681 { |
|
682 return myroom; |
|
683 } |
|
684 |
|
685 QString HWNewNet::getHost() |
|
686 { |
|
687 return myhost; |
|
688 } |
|
689 |
|
690 bool HWNewNet::isRoomChief() |
|
691 { |
|
692 return isChief; |
|
693 } |
|
694 |
|
695 void HWNewNet::gameFinished(bool correctly) |
|
696 { |
|
697 if (netClientState == InGame) netClientState = InRoom; |
|
698 RawSendNet(QString("ROUNDFINISHED%1%2").arg(delimeter).arg(correctly ? "1" : "0")); |
|
699 } |
|
700 |
|
701 void HWNewNet::banPlayer(const QString & nick) |
|
702 { |
|
703 RawSendNet(QString("BAN%1%2").arg(delimeter).arg(nick)); |
|
704 } |
|
705 |
|
706 void HWNewNet::kickPlayer(const QString & nick) |
|
707 { |
|
708 RawSendNet(QString("KICK%1%2").arg(delimeter).arg(nick)); |
|
709 } |
|
710 |
|
711 void HWNewNet::infoPlayer(const QString & nick) |
|
712 { |
|
713 RawSendNet(QString("INFO%1%2").arg(delimeter).arg(nick)); |
|
714 } |
|
715 |
|
716 void HWNewNet::followPlayer(const QString & nick) |
|
717 { |
|
718 if (!isInRoom()) { |
|
719 RawSendNet(QString("FOLLOW%1%2").arg(delimeter).arg(nick)); |
|
720 isChief = false; |
|
721 } |
|
722 } |
|
723 |
|
724 void HWNewNet::startGame() |
|
725 { |
|
726 RawSendNet(QString("START_GAME")); |
|
727 } |
|
728 |
|
729 void HWNewNet::updateRoomName(const QString & name) |
|
730 { |
|
731 RawSendNet(QString("ROOM_NAME%1%2").arg(delimeter).arg(name)); |
|
732 } |
|
733 |
|
734 |
|
735 void HWNewNet::toggleRestrictJoins() |
|
736 { |
|
737 RawSendNet(QString("TOGGLE_RESTRICT_JOINS")); |
|
738 } |
|
739 |
|
740 void HWNewNet::toggleRestrictTeamAdds() |
|
741 { |
|
742 RawSendNet(QString("TOGGLE_RESTRICT_TEAMS")); |
|
743 } |
|
744 |
|
745 void HWNewNet::clearAccountsCache() |
|
746 { |
|
747 RawSendNet(QString("CLEAR_ACCOUNTS_CACHE")); |
|
748 } |
|
749 |
|
750 void HWNewNet::partRoom() |
|
751 { |
|
752 netClientState = InLobby; |
|
753 RawSendNet(QString("PART")); |
|
754 } |
|
755 |
|
756 bool HWNewNet::isInRoom() |
|
757 { |
|
758 return netClientState >= InRoom; |
|
759 } |
|
760 |
|
761 void HWNewNet::setServerMessageNew(const QString & msg) |
|
762 { |
|
763 RawSendNet(QString("SET_SERVER_VAR%1MOTD_NEW%1%2").arg(delimeter).arg(msg)); |
|
764 } |
|
765 |
|
766 void HWNewNet::setServerMessageOld(const QString & msg) |
|
767 { |
|
768 RawSendNet(QString("SET_SERVER_VAR%1MOTD_OLD%1%2").arg(delimeter).arg(msg)); |
|
769 } |
|
770 |
|
771 void HWNewNet::setLatestProtocolVar(int proto) |
|
772 { |
|
773 RawSendNet(QString("SET_SERVER_VAR%1LATEST_PROTO%1%2").arg(delimeter).arg(proto)); |
|
774 } |
|
775 |
|
776 void HWNewNet::askServerVars() |
|
777 { |
|
778 RawSendNet(QString("GET_SERVER_VAR")); |
|
779 } |
|
780 |
|
781 void HWNewNet::handleNotice(int n) |
|
782 { |
|
783 switch(n) |
|
784 { |
|
785 case 0: |
|
786 { |
|
787 emit NickTaken(mynick); |
|
788 break; |
|
789 } |
|
790 } |
|
791 } |
|