server message handling
| 769 | // server message handling |
| 770 | // |
| 771 | static Player* addPlayer(PlayerId id, void* msg, int showMessage) { |
| 772 | int16_t team; |
| 773 | uint16_t type, wins, losses, tks; |
| 774 | float rank; |
| 775 | char callsign[CallSignLen]; |
| 776 | msg = nboUnpackUInt16(msg, type); |
| 777 | msg = nboUnpackInt16(msg, team); |
| 778 | msg = nboUnpackFloat(msg, rank); |
| 779 | msg = nboUnpackUInt16(msg, wins); |
| 780 | msg = nboUnpackUInt16(msg, losses); |
| 781 | msg = nboUnpackUInt16(msg, tks); |
| 782 | msg = nboUnpackString(msg, callsign, CallSignLen); |
| 783 | |
| 784 | // Strip any ANSI color codes |
| 785 | strncpy(callsign, stripAnsiCodes(callsign), 32); |
| 786 | |
| 787 | // id is slot, check if it's empty |
| 788 | const int i = id; |
| 789 | |
| 790 | // sanity check |
| 791 | if (i < 0) { |
| 792 | showError(TextUtils::format("Invalid player identification (%d)", i).c_str()); |
| 793 | return NULL; |
| 794 | } |
| 795 | |
| 796 | if (remotePlayers[i]) { |
| 797 | // we're not in synch with server -> help! not a good sign, but not fatal. |
| 798 | showError("Server error when adding player, player already added"); |
| 799 | return NULL; |
| 800 | } |
| 801 | |
| 802 | if (i >= curMaxPlayers) { |
| 803 | curMaxPlayers = i + 1; |
| 804 | if (World::getWorld()) { |
| 805 | World::getWorld()->setCurMaxPlayers(curMaxPlayers); |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | // add player |
| 810 | if (PlayerType(type) == TankPlayer |
| 811 | || PlayerType(type) == ComputerPlayer |
| 812 | || PlayerType(type) == ChatPlayer) { |
| 813 | remotePlayers[i] = new RemotePlayer(id, TeamColor(team), callsign, PlayerType(type)); |
| 814 | remotePlayers[i]->changeScore(rank, short(wins), short(losses), short(tks)); |
| 815 | } |
| 816 | |
| 817 | #ifdef ROBOT |
| 818 | if (PlayerType(type) == ComputerPlayer) { |
| 819 | for (int j = 0; j < numRobots; j++) { |
| 820 | if (robots[j] && !strncmp(robots[j]->getCallSign(), callsign, CallSignLen)) { |
| 821 | robots[j]->setTeam(TeamColor(team)); |
| 822 | robots[j]->changeScore(rank, wins, losses, tks); |
| 823 | break; |
| 824 | } |
| 825 | } |
| 826 | } |
| 827 | #endif |
| 828 |
no test coverage detected