MCPcopy Create free account
hub / github.com/BohemiaInteractive/CWR / OnPlayerDestroy

Method OnPlayerDestroy

engine/Poseidon/Network/NetworkServerIntegrity.cpp:657–880  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

OnServerPlayerDeleteFunction · 0.80

Calls 15

LocalizeStringFunction · 0.85
IsDedicatedServerFunction · 0.85
GetClientMethod · 0.80
GameValueClass · 0.50
SizeMethod · 0.45
GetGameStateMethod · 0.45
VarGetMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected