public void JoinGame(MyGameInfo gameInfo, string password, GameJoinedHandler onGameJoined, Action onGameEnterDisallowed, Action onDownloadingSector) { MyMultiplayerPeers.Static.Restart(); m_introductionTimer.Dispose(); m_hostTimer.Dispose(); MyMultiplayerPeers.Static.HostUserId = -1; m_game = gameInfo; m_gameJoinedAction = onGameJoined; m_gameDownloadingSector = onDownloadingSector; m_gameEnterDisallowedAction = onGameEnterDisallowed; MyMultiplayerPeers.Static.NetworkClient.ClearCallbacks(); MyMultiplayerPeers.Static.DisconnectExceptServer(); MyMultiplayerPeers.Static.Players.Clear(); MyEventJoinGame joinRequest = new MyEventJoinGame(); joinRequest.GameId = gameInfo.GameId; joinRequest.Password = password; SetCallback <MyEventJoinGameResponse>(OnJoinGameResponse); MyMultiplayerPeers.Static.NetworkClient.RegisterCallback <MyEventLoginResponse>(OnLoginResponse); MyMultiplayerPeers.Static.NetworkClient.NatIntroductionSuccess = NetworkClient_NatIntroductionSuccess; m_natIntroduction = new MyNatIntroduction(MyMultiplayerPeers.Static.NetworkClient); MyMultiplayerPeers.Static.NetworkClient.PeerConnected += new Action <NetConnection>(NetworkClient_PeerConnected); MyMultiplayerPeers.Static.SendServer(ref joinRequest); MyMultiplayerGameplay.Log("JOIN 1. - Join game"); }
private void UpdateLobby() { if (m_natIntroduction != null && m_natIntroduction.IsAllConnected()) { OnAllPeersConnected(); m_natIntroduction = null; } }
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(); }