private void AddPlayer(MyPlayerRemote player, bool isFaction = false)
 {
     AddPlayer(player.GetDisplayName(), (int)(player.Connection.AverageRoundtripTime * 1000), player.Statistics.Deaths, player.Statistics.PlayersKilled, (byte)player.PlayerId, player.Faction, isFaction);
 }
 private MyPlayerInfo RemotePlayerToInfo(MyPlayerRemote player)
 {
     return new MyPlayerInfo()
     {
         DisplayName = player.GetDisplayName().ToString(),
         PlayerId = player.PlayerId,
         UserId = player.UserId,
         Faction = player.Faction,
     };
 }
        public void AllowEnter(ref MyEventEnterGame msg)
        {
            var playerList = msg.ConnectedPlayers;
            bool allConnected = MyMultiplayerPeers.Static.Players.All(s => playerList.Contains(s.UserId));
            if (allConnected)
            {
                // Generate game user id and send back
                var response = new MyEventEnterGameResponse();
                response.Allowed = true;
                response.PlayerId = GeneratePlayerId();

                var newPlayer = new MyPlayerRemote(new StringBuilder(msg.PlayerInfo.DisplayName), msg.PlayerInfo.UserId, response.PlayerId);
                newPlayer.Connection = msg.SenderConnection;
                msg.SenderConnection.Tag = newPlayer;
                newPlayer.Faction = MyMwcObjectBuilder_FactionEnum.None;

                MyMultiplayerPeers.Static.Players.Add(newPlayer);

                Peers.NetworkClient.Send(ref response, msg.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0);
            }
            else
            {
                SendPlayerList(msg.SenderConnection);
            }
        }
        void OnNewPlayer(ref MyEventNewPlayer msg)
        {
            Log("OnNewPlayer");

            if (NewPlayer != null)
            {
                NewPlayer();
            }

            if (IsHost)
            {
                SendCheckpoint(msg.SenderConnection);

                var playerLeftMsg = new MyEventPlayerStateChanged();
                playerLeftMsg.UserId = msg.PlayerInfo.UserId;
                playerLeftMsg.NewState = MyMultiplayerStateEnum.Playing;
                Peers.SendServer(ref playerLeftMsg);

                UpdateMission();
            }
            else
            {
                var player = new MyPlayerRemote(new StringBuilder(msg.PlayerInfo.DisplayName), msg.PlayerInfo.UserId, msg.PlayerInfo.PlayerId);
                player.Connection = msg.SenderConnection;
                player.Connection.Tag = player;
                Peers.Players.Add(player);
                Notify(MyTextsWrapperEnum.MP_XHasJoined, msg.PlayerInfo.DisplayName);
            }
            LogPlayers();
        }
        void DisplayKillNotification(MyPlayerRemote deadPlayer, byte? killerId)
        {
            MyPlayerRemote killer;

            if (killerId == MyEntityIdentifier.CurrentPlayerId)
            {
                Notify(Localization.MyTextsWrapperEnum.MP_YouHaveKilledX, deadPlayer.GetDisplayName());
            }
            else if (killerId == deadPlayer.PlayerId)
            {
                // Until entity ids fixed
                //Notify(Localization.MyTextsWrapperEnum.MP_XKilledHimself, deadPlayer.GetDisplayName());
                Notify(Localization.MyTextsWrapperEnum.MP_XKilled, deadPlayer.GetDisplayName());
            }
            else if (killerId.HasValue && killerId != 0 && Peers.TryGetPlayer(killerId.Value, out killer))
            {
                Notify(Localization.MyTextsWrapperEnum.MP_XHasBeenKilledByY, deadPlayer.GetDisplayName(), killer.GetDisplayName());
            }
            else
            {
                Notify(Localization.MyTextsWrapperEnum.MP_XKilled, deadPlayer.GetDisplayName());
            }
        }
        void OnPeerDied(MyPlayerRemote deadPlayer, byte? killerId)
        {
            deadPlayer.Ship.SetAfterburner(false);
            deadPlayer.Ship = null;

            if (IsHost)
            {
                ClearLocks(deadPlayer.PlayerId);
            }

            if (killerId == MyEntityIdentifier.CurrentPlayerId)
            {
                PlayerStatistics.PlayersKilled++;
                UpdateStats();
            }

            DisplayKillNotification(deadPlayer, killerId);
        }