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); } }
public void DenyEnter(ref MyEventEnterGame msg) { var response = new MyEventEnterGameResponse(); response.Allowed = false; Peers.NetworkClient.Send(ref response, msg.SenderConnection, NetDeliveryMethod.ReliableOrdered, 0); }
// Client is joining to ME and I'm host private void OnEnterGame(ref MyEventEnterGame msg) { Log("OnEnterGame"); if (JoinMode == MyJoinMode.Open) { AllowEnter(ref msg); } else if (JoinMode == MyJoinMode.Closed) { DenyEnter(ref msg); } }
private void OnAllPeersConnected() { m_introductionTimer.Dispose(); ClearCallbacks(); // When somebody was faster, I can receive new player list MyMultiplayerPeers.Static.NetworkClient.RegisterCallback <MyEventGetPlayerListResponse>(OnGetPlayerListResponse); MyMultiplayerPeers.Static.NetworkClient.RegisterCallback <MyEventEnterGameResponse>(OnEnterGameResponse); var msg = new MyEventEnterGame(); msg.ConnectedPlayers = MyMultiplayerPeers.Static.Players.Select(s => s.UserId).ToList(); msg.PlayerInfo = new MyPlayerInfo() { DisplayName = MyClientServer.LoggedPlayer.GetDisplayName().ToString(), UserId = MyClientServer.LoggedPlayer.GetUserId(), Faction = MyMwcObjectBuilder_FactionEnum.None, PlayerId = 0, // Host will assign }; MyMultiplayerPeers.Static.SendHost(ref msg); MyMultiplayerGameplay.Log("JOIN 5. - All peers connected, entering game (#EnterGame)"); }