382 } |
382 } |
383 |
383 |
384 return; |
384 return; |
385 } |
385 } |
386 |
386 |
387 if (lst[0] == "ADD_TEAM") |
|
388 { |
|
389 if(lst.size() != 24) |
|
390 { |
|
391 qWarning("Net: Bad ADDTEAM message"); |
|
392 return; |
|
393 } |
|
394 QStringList tmp = lst; |
|
395 tmp.removeFirst(); |
|
396 emit AddNetTeam(tmp); |
|
397 return; |
|
398 } |
|
399 |
|
400 if (lst[0] == "REMOVE_TEAM") |
|
401 { |
|
402 if(lst.size() != 2) |
|
403 { |
|
404 qWarning("Net: Bad REMOVETEAM message"); |
|
405 return; |
|
406 } |
|
407 emit RemoveNetTeam(HWTeam(lst[1])); |
|
408 return; |
|
409 } |
|
410 |
|
411 if(lst[0] == "ROOMABANDONED") |
|
412 { |
|
413 netClientState = InLobby; |
|
414 askRoomsList(); |
|
415 emit LeftRoom(tr("Room destroyed")); |
|
416 return; |
|
417 } |
|
418 |
|
419 if(lst[0] == "KICKED") |
387 if(lst[0] == "KICKED") |
420 { |
388 { |
421 netClientState = InLobby; |
389 netClientState = InLobby; |
422 askRoomsList(); |
390 askRoomsList(); |
423 emit LeftRoom(tr("You got kicked")); |
391 emit LeftRoom(tr("You got kicked")); |
424 return; |
392 return; |
425 } |
393 } |
426 |
394 |
427 if(lst[0] == "JOINED") |
|
428 { |
|
429 if(lst.size() < 2) |
|
430 { |
|
431 qWarning("Net: Bad JOINED message"); |
|
432 return; |
|
433 } |
|
434 |
|
435 for(int i = 1; i < lst.size(); ++i) |
|
436 { |
|
437 if (lst[i] == mynick) |
|
438 { |
|
439 netClientState = InRoom; |
|
440 emit EnteredGame(); |
|
441 emit roomMaster(isChief); |
|
442 if (isChief) |
|
443 emit configAsked(); |
|
444 } |
|
445 |
|
446 emit nickAdded(lst[i], isChief && (lst[i] != mynick)); |
|
447 emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i])); |
|
448 } |
|
449 return; |
|
450 } |
|
451 |
|
452 if(lst[0] == "LOBBY:JOINED") |
395 if(lst[0] == "LOBBY:JOINED") |
453 { |
396 { |
454 if(lst.size() < 2) |
397 if(lst.size() < 2) |
455 { |
398 { |
456 qWarning("Net: Bad JOINED message"); |
399 qWarning("Net: Bad JOINED message"); |
467 } |
410 } |
468 |
411 |
469 emit nickAddedLobby(lst[i], false); |
412 emit nickAddedLobby(lst[i], false); |
470 emit chatStringLobby(lst[i], tr("%1 *** %2 has joined").arg('\x03').arg("|nick|")); |
413 emit chatStringLobby(lst[i], tr("%1 *** %2 has joined").arg('\x03').arg("|nick|")); |
471 } |
414 } |
472 return; |
|
473 } |
|
474 |
|
475 if(lst[0] == "LEFT") |
|
476 { |
|
477 if(lst.size() < 2) |
|
478 { |
|
479 qWarning("Net: Bad LEFT message"); |
|
480 return; |
|
481 } |
|
482 emit nickRemoved(lst[1]); |
|
483 if (lst.size() < 3) |
|
484 emit chatStringFromNet(tr("%1 *** %2 has left").arg('\x03').arg(lst[1])); |
|
485 else |
|
486 emit chatStringFromNet(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2])); |
|
487 return; |
415 return; |
488 } |
416 } |
489 |
417 |
490 if(lst[0] == "ROOM" && lst.size() == 10 && lst[1] == "ADD") |
418 if(lst[0] == "ROOM" && lst.size() == 10 && lst[1] == "ADD") |
491 { |
419 { |
561 handleNotice(n); |
482 handleNotice(n); |
562 |
483 |
563 return; |
484 return; |
564 } |
485 } |
565 |
486 |
566 if (lst[0] == "TEAM_ACCEPTED") |
|
567 { |
|
568 if (lst.size() != 2) |
|
569 { |
|
570 qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
571 return; |
|
572 } |
|
573 emit TeamAccepted(lst[1]); |
|
574 return; |
|
575 } |
|
576 |
|
577 |
|
578 if (lst[0] == "CFG") |
|
579 { |
|
580 if(lst.size() < 3) |
|
581 { |
|
582 qWarning("Net: Bad CFG message"); |
|
583 return; |
|
584 } |
|
585 QStringList tmp = lst; |
|
586 tmp.removeFirst(); |
|
587 tmp.removeFirst(); |
|
588 if (lst[1] == "SCHEME") |
|
589 emit netSchemeConfig(tmp); |
|
590 else |
|
591 emit paramChanged(lst[1], tmp); |
|
592 return; |
|
593 } |
|
594 |
|
595 if (lst[0] == "HH_NUM") |
|
596 { |
|
597 if (lst.size() != 3) |
|
598 { |
|
599 qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
600 return; |
|
601 } |
|
602 HWTeam tmptm(lst[1]); |
|
603 tmptm.setNumHedgehogs(lst[2].toUInt()); |
|
604 emit hhnumChanged(tmptm); |
|
605 return; |
|
606 } |
|
607 |
|
608 if (lst[0] == "TEAM_COLOR") |
|
609 { |
|
610 if (lst.size() != 3) |
|
611 { |
|
612 qWarning("Net: Bad TEAM_COLOR message"); |
|
613 return; |
|
614 } |
|
615 HWTeam tmptm(lst[1]); |
|
616 tmptm.setColor(lst[2].toInt()); |
|
617 emit teamColorChanged(tmptm); |
|
618 return; |
|
619 } |
|
620 |
|
621 if (lst[0] == "EM") |
|
622 { |
|
623 if(lst.size() < 2) |
|
624 { |
|
625 qWarning("Net: Bad EM message"); |
|
626 return; |
|
627 } |
|
628 for(int i = 1; i < lst.size(); ++i) |
|
629 { |
|
630 QByteArray em = QByteArray::fromBase64(lst[i].toAscii()); |
|
631 emit FromNet(em); |
|
632 } |
|
633 return; |
|
634 } |
|
635 |
|
636 if (lst[0] == "BYE") |
487 if (lst[0] == "BYE") |
637 { |
488 { |
638 if (lst.size() < 2) |
489 if (lst.size() < 2) |
639 { |
490 { |
640 qWarning("Net: Bad BYE message"); |
491 qWarning("Net: Bad BYE message"); |
648 Disconnect(); |
499 Disconnect(); |
649 emit disconnected(lst[1]); |
500 emit disconnected(lst[1]); |
650 return; |
501 return; |
651 } |
502 } |
652 |
503 |
653 |
|
654 if (lst[0] == "ADMIN_ACCESS") |
504 if (lst[0] == "ADMIN_ACCESS") |
655 { |
505 { |
656 emit adminAccess(true); |
506 emit adminAccess(true); |
657 return; |
507 return; |
658 } |
508 } |
659 |
509 |
660 if (lst[0] == "ROOM_CONTROL_ACCESS") |
510 |
661 { |
511 if(netClientState == InRoom) |
662 if (lst.size() < 2) |
512 { |
663 { |
513 if (lst[0] == "EM") |
664 qWarning("Net: Bad ROOM_CONTROL_ACCESS message"); |
514 { |
665 return; |
515 if(lst.size() < 2) |
666 } |
516 { |
667 isChief = (lst[1] != "0"); |
517 qWarning("Net: Bad EM message"); |
668 emit roomMaster(isChief); |
518 return; |
669 return; |
519 } |
670 } |
520 for(int i = 1; i < lst.size(); ++i) |
671 |
521 { |
672 qWarning() << "Net: Unknown message:" << lst; |
522 QByteArray em = QByteArray::fromBase64(lst[i].toAscii()); |
|
523 emit FromNet(em); |
|
524 } |
|
525 return; |
|
526 } |
|
527 |
|
528 if (lst[0] == "ADD_TEAM") |
|
529 { |
|
530 if(lst.size() != 24) |
|
531 { |
|
532 qWarning("Net: Bad ADDTEAM message"); |
|
533 return; |
|
534 } |
|
535 QStringList tmp = lst; |
|
536 tmp.removeFirst(); |
|
537 emit AddNetTeam(tmp); |
|
538 return; |
|
539 } |
|
540 |
|
541 if (lst[0] == "REMOVE_TEAM") |
|
542 { |
|
543 if(lst.size() != 2) |
|
544 { |
|
545 qWarning("Net: Bad REMOVETEAM message"); |
|
546 return; |
|
547 } |
|
548 emit RemoveNetTeam(HWTeam(lst[1])); |
|
549 return; |
|
550 } |
|
551 |
|
552 if(lst[0] == "ROOMABANDONED") |
|
553 { |
|
554 netClientState = InLobby; |
|
555 askRoomsList(); |
|
556 emit LeftRoom(tr("Room destroyed")); |
|
557 return; |
|
558 } |
|
559 |
|
560 if (lst[0] == "RUN_GAME") |
|
561 { |
|
562 netClientState = InGame; |
|
563 emit AskForRunGame(); |
|
564 return; |
|
565 } |
|
566 |
|
567 if (lst[0] == "TEAM_ACCEPTED") |
|
568 { |
|
569 if (lst.size() != 2) |
|
570 { |
|
571 qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
572 return; |
|
573 } |
|
574 emit TeamAccepted(lst[1]); |
|
575 return; |
|
576 } |
|
577 |
|
578 if (lst[0] == "CFG") |
|
579 { |
|
580 if(lst.size() < 3) |
|
581 { |
|
582 qWarning("Net: Bad CFG message"); |
|
583 return; |
|
584 } |
|
585 QStringList tmp = lst; |
|
586 tmp.removeFirst(); |
|
587 tmp.removeFirst(); |
|
588 if (lst[1] == "SCHEME") |
|
589 emit netSchemeConfig(tmp); |
|
590 else |
|
591 emit paramChanged(lst[1], tmp); |
|
592 return; |
|
593 } |
|
594 |
|
595 if (lst[0] == "HH_NUM") |
|
596 { |
|
597 if (lst.size() != 3) |
|
598 { |
|
599 qWarning("Net: Bad TEAM_ACCEPTED message"); |
|
600 return; |
|
601 } |
|
602 HWTeam tmptm(lst[1]); |
|
603 tmptm.setNumHedgehogs(lst[2].toUInt()); |
|
604 emit hhnumChanged(tmptm); |
|
605 return; |
|
606 } |
|
607 |
|
608 if (lst[0] == "TEAM_COLOR") |
|
609 { |
|
610 if (lst.size() != 3) |
|
611 { |
|
612 qWarning("Net: Bad TEAM_COLOR message"); |
|
613 return; |
|
614 } |
|
615 HWTeam tmptm(lst[1]); |
|
616 tmptm.setColor(lst[2].toInt()); |
|
617 emit teamColorChanged(tmptm); |
|
618 return; |
|
619 } |
|
620 |
|
621 if(lst[0] == "JOINED") |
|
622 { |
|
623 if(lst.size() < 2) |
|
624 { |
|
625 qWarning("Net: Bad JOINED message"); |
|
626 return; |
|
627 } |
|
628 |
|
629 for(int i = 1; i < lst.size(); ++i) |
|
630 { |
|
631 if (lst[i] == mynick) |
|
632 { |
|
633 netClientState = InRoom; |
|
634 emit EnteredGame(); |
|
635 emit roomMaster(isChief); |
|
636 if (isChief) |
|
637 emit configAsked(); |
|
638 } |
|
639 |
|
640 emit nickAdded(lst[i], isChief && (lst[i] != mynick)); |
|
641 emit chatStringFromNet(tr("%1 *** %2 has joined the room").arg('\x03').arg(lst[i])); |
|
642 } |
|
643 return; |
|
644 } |
|
645 |
|
646 if(lst[0] == "LEFT") |
|
647 { |
|
648 if(lst.size() < 2) |
|
649 { |
|
650 qWarning("Net: Bad LEFT message"); |
|
651 return; |
|
652 } |
|
653 emit nickRemoved(lst[1]); |
|
654 if (lst.size() < 3) |
|
655 emit chatStringFromNet(tr("%1 *** %2 has left").arg('\x03').arg(lst[1])); |
|
656 else |
|
657 emit chatStringFromNet(tr("%1 *** %2 has left (%3)").arg('\x03').arg(lst[1], lst[2])); |
|
658 return; |
|
659 } |
|
660 |
|
661 if (lst[0] == "ROOM_CONTROL_ACCESS") |
|
662 { |
|
663 if (lst.size() < 2) |
|
664 { |
|
665 qWarning("Net: Bad ROOM_CONTROL_ACCESS message"); |
|
666 return; |
|
667 } |
|
668 isChief = (lst[1] != "0"); |
|
669 emit roomMaster(isChief); |
|
670 return; |
|
671 } |
|
672 } |
|
673 |
|
674 qWarning() << "Net: Unknown message or wrong state:" << lst; |
673 } |
675 } |
674 |
676 |
675 void HWNewNet::onHedgehogsNumChanged(const HWTeam& team) |
677 void HWNewNet::onHedgehogsNumChanged(const HWTeam& team) |
676 { |
678 { |
677 if (isChief) |
679 if (isChief) |