public static void LogPlayerList(ref MyEventGetPlayerListResponse msg)
 {
     for (int i = 0; i < msg.PlayerList.Count; i++)
     {
         var p = msg.PlayerList[i];
         Log(String.Format("PlayerList[0] {0}, UserId: {3}, PlayerId: {2}, Faction: {1}", p.DisplayName, MyFactionConstants.GetFactionProperties(p.Faction).Name, p.PlayerId, p.UserId));
     }
 }
        private void SendPlayerList(NetConnection connection)
        {
            var response = new MyEventGetPlayerListResponse();

            response.PlayerList = new List <MyPlayerInfo>(MyMultiplayerPeers.Static.Players.Select(s => RemotePlayerToInfo(s)));

            var me = new MyPlayerInfo()
            {
                DisplayName = MyClientServer.LoggedPlayer.GetDisplayName().ToString(),
                Faction     = MySession.Static.Player.Faction,
                PlayerId    = MyEntityIdentifier.CurrentPlayerId,
                UserId      = MyClientServer.LoggedPlayer.GetUserId(),
            };

            response.PlayerList.Add(me);

            LogPlayerList(ref response);

            Peers.NetworkClient.Send(ref response, connection, NetDeliveryMethod.ReliableOrdered, 0);
        }
        void OnGetPlayerListResponse(ref MyEventGetPlayerListResponse msg)
        {
            MyMultiplayerGameplay.LogPlayerList(ref msg);

            // Disconnect from players (connection to host is not dropped)
            foreach (var player in MyMultiplayerPeers.Static.Players)
            {
                if (player.UserId != MyMultiplayerPeers.Static.HostUserId)
                {
                    player.Connection.Disconnect(String.Empty);
                }
            }
            MyMultiplayerPeers.Static.Players.Clear();

            // Start connecting players again
            foreach (var playerInfo in msg.PlayerList)
            {
                var playerRemote = new MyPlayerRemote(new StringBuilder(playerInfo.DisplayName), playerInfo.UserId, playerInfo.PlayerId);
                if (playerRemote.UserId == MyMultiplayerPeers.Static.HostUserId)
                {
                    playerRemote.Connection  = msg.SenderConnection;
                    msg.SenderConnection.Tag = playerRemote;
                }
                MyMultiplayerPeers.Static.Players.Add(playerRemote);
            }

            MyMultiplayerGameplay.Log("JOIN 4.a - Player list received (#OnGetPlayerListResponse)");

            m_natIntroduction = new MyNatIntroduction(MyMultiplayerPeers.Static.NetworkClient);
            m_natIntroduction.SetRequiredPlayers(MyMultiplayerPeers.Static.Players);

            ClearCallbacks();

            var userListCopy = MyMultiplayerPeers.Static.Players.Where(s => s != null).Select(s => s.UserId).ToList();

            StartClientIntroductionTimer(userListCopy);
            RequestPlayerIntroduction(userListCopy, false);
            UpdateLobby();
        }