| 655 | } |
| 656 | |
| 657 | void NetworkServer::OnPlayerDestroy(int dpid) |
| 658 | { |
| 659 | if (dpid == _botClient) |
| 660 | { |
| 661 | Fail("Not implemented."); |
| 662 | // new bot client must be selected |
| 663 | return; |
| 664 | } |
| 665 | |
| 666 | RString name; |
| 667 | if (dpid == _gameMaster) |
| 668 | { |
| 669 | for (int i = 0; i < _players.Size(); i++) |
| 670 | { |
| 671 | if (_players[i].dpid == _gameMaster) |
| 672 | { |
| 673 | name = _players[i].name; |
| 674 | break; |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | NetworkPlayerInfo* info = GetPlayerInfo(dpid); |
| 680 | if (info) |
| 681 | { |
| 682 | // Fire onPlayerDisconnected event before removing |
| 683 | if (GWorld && GWorld->GetGameState()) |
| 684 | { |
| 685 | GameState* gs = GWorld->GetGameState(); |
| 686 | GameValue handler = gs->VarGet("onplayerdisconnectedcode"); |
| 687 | if (handler.GetType() == GameString) |
| 688 | { |
| 689 | gs->VarSet("_id", GameValue((GameScalarType)info->dpid), false, true); |
| 690 | gs->VarSet("_name", GameValue((GameStringType)info->name), false, true); |
| 691 | gs->Execute((const char*)(GameStringType)handler); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | RString message = |
| 696 | BuildNetworkServerPlayerMessage((const char*)LocalizeString(IDS_MP_DISCONNECT), (const char*)info->name); |
| 697 | ReportNetworkServerGlobalMessage("", message); |
| 698 | |
| 699 | if (_dedicated) |
| 700 | { |
| 701 | LOG_INFO(Network, "Player {} disconnected", (const char*)info->name); |
| 702 | } |
| 703 | |
| 704 | for (int i = 0; i < _players.Size(); i++) |
| 705 | { |
| 706 | NetworkPlayerInfo& info = _players[i]; |
| 707 | if (info.dpid == dpid) |
| 708 | { |
| 709 | #if LOG_PLAYERS |
| 710 | RptF("Server: Player info removed - name %s, id %d (total %d identities, %d players)", |
| 711 | (const char*)info.name, dpid, _identities.Size(), _players.Size() - 1); |
| 712 | #endif |
| 713 | _players.Delete(i); |
| 714 | break; |
no test coverage detected