Esempio n. 1
0
        private static bool JoinGameTest(Lobby lobby)
        {
            if (!lobby.IsValid)
                return false;

            if (lobby.GetLobbyType() == LobbyTypeEnum.FriendsOnly && !MySteam.API.Friends.HasFriend(lobby.GetOwner()))
            {
                MyGuiSandbox.Show(MyCommonTexts.OnlyFriendsCanJoinThisGame);
                return false;
            }
            if (!MyMultiplayerLobby.IsLobbyCorrectVersion(lobby))
            {
                var formatString = MyTexts.GetString(MyCommonTexts.MultiplayerError_IncorrectVersion);
                var myVersion = MyBuildNumbers.ConvertBuildNumberFromIntToString(MyFinalBuildConstants.APP_VERSION);
                var serverVersion = MyBuildNumbers.ConvertBuildNumberFromIntToString(MyMultiplayerLobby.GetLobbyAppVersion(lobby));
                MyGuiSandbox.Show(new StringBuilder(String.Format(formatString, myVersion, serverVersion)));
                return false;
            }
            if (MyFakes.ENABLE_MP_DATA_HASHES && !MyMultiplayerLobby.HasSameData(lobby))
            {
                MyGuiSandbox.Show(MyCommonTexts.MultiplayerError_DifferentData);
                MySandboxGame.Log.WriteLine("Different game data when connecting to server. Local hash: " + MyDataIntegrityChecker.GetHashBase64() + ", server hash: " + MyMultiplayerLobby.GetDataHash(lobby));
                return false;
            }
            return true;
        }
Esempio n. 2
0
        internal MyMultiplayerLobby(Lobby lobby, MySyncLayer syncLayer)
            : base(syncLayer, new EndpointId(Sync.MyId))
        {
            Lobby = lobby;
            ServerId = Lobby.GetOwner();

            SyncLayer.RegisterClientEvents(this);

            HostName = MySteam.UserName;
           
            Debug.Assert(IsServer, "Wrong object created");

            MySteam.API.Matchmaking.LobbyChatUpdate += Matchmaking_LobbyChatUpdate;
            MySteam.API.Matchmaking.LobbyChatMsg += Matchmaking_LobbyChatMsg;
            ClientLeft += MyMultiplayerLobby_ClientLeft;
            AcceptMemberSessions();
        }
Esempio n. 3
0
        internal MyMultiplayerLobby(Lobby lobby, MySyncLayer syncLayer)
            : base(syncLayer)
        {
            Lobby = lobby;
            ServerId = Lobby.GetOwner();

            SyncLayer.RegisterClientEvents(this);

            if (IsServer)
            {
                HostName = MySteam.UserName;
            }
            else
            {
                SyncLayer.TransportLayer.IsBuffering = true;
            }
            MySteam.API.Matchmaking.LobbyChatUpdate += Matchmaking_LobbyChatUpdate;
            MySteam.API.Matchmaking.LobbyChatMsg += Matchmaking_LobbyChatMsg;
            ClientLeft += MyMultiplayerLobby_ClientLeft;
            AcceptMemberSessions();
        }
        internal MyMultiplayerLobbyClient(Lobby lobby, MySyncLayer syncLayer)
            : base(syncLayer)
        {
            Lobby = lobby;
            ServerId = Lobby.GetOwner();

            SyncLayer.RegisterClientEvents(this);

            if (IsServer)
            {
                HostName = MySteam.UserName;
            }
            else
            {
                SyncLayer.TransportLayer.IsBuffering = true;
                
                SetReplicationLayer(new MyReplicationClient(this, new MyClientState()));
                syncLayer.TransportLayer.Register(MyMessageId.SERVER_DATA, ReplicationLayer.ProcessServerData);
                syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_CREATE, ReplicationLayer.ProcessReplicationCreate);
                syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_DESTROY, ReplicationLayer.ProcessReplicationDestroy);
                syncLayer.TransportLayer.Register(MyMessageId.SERVER_STATE_SYNC, ReplicationLayer.ProcessStateSync);
                syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent);
            }

            Debug.Assert(!IsServer, "Wrong object created");
            SyncLayer.RegisterMessageImmediate<AllMembersDataMsg>(OnAllMembersData, MyMessagePermissions.ToServer|MyMessagePermissions.FromServer);

            MySteam.API.Matchmaking.LobbyChatUpdate += Matchmaking_LobbyChatUpdate;
            MySteam.API.Matchmaking.LobbyChatMsg += Matchmaking_LobbyChatMsg;
            ClientLeft += MyMultiplayerLobby_ClientLeft;
            AcceptMemberSessions();
        }
        protected void Matchmaking_LobbyDataUpdate(bool success, Lobby lobby, ulong memberOrLobby)
        {
            if (!success)
                return;

            var newOwnerId = lobby.GetOwner();
            var oldOwnerRow = m_playersTable.Find((row) => (row.GetCell(GameAdminColumn).Text.Length == GAME_OWNER_MARKER.Length));
            var newOwnerRow = m_playersTable.Find((row) => ((ulong)row.UserData) == newOwnerId);
            Debug.Assert(oldOwnerRow != null);
            Debug.Assert(newOwnerRow != null);
            if (oldOwnerRow != null) oldOwnerRow.GetCell(GameAdminColumn).Text.Clear();
            if (newOwnerRow != null) newOwnerRow.GetCell(GameAdminColumn).Text.Clear().Append(GAME_OWNER_MARKER);

            var lobbyType = lobby.GetLobbyType();
            m_lobbyTypeCombo.SelectItemByKey((int)lobbyType, sendEvent: false);
            MySession.Static.Settings.OnlineMode = GetOnlineMode(lobbyType);

            UpdateButtonsEnabledState();

            if (!Sync.IsServer)
            {
                m_maxPlayersSlider.ValueChanged = null;
                MySession.Static.Settings.MaxPlayers = (short)MyMultiplayer.Static.MemberLimit;
                m_maxPlayersSlider.Value = MySession.Static.MaxPlayers;
                m_maxPlayersSlider.ValueChanged = MaxPlayersSlider_Changed;
            }
        }
        internal MyMultiplayerLobby(Lobby lobby, MySyncLayer syncLayer)
            : base(syncLayer)
        {
            Lobby = lobby;
            ServerId = Lobby.GetOwner();

            SyncLayer.RegisterClientEvents(this);

            if (IsServer)
            {
                HostName = MySteam.UserName;
            }
            else
            {
                SyncLayer.TransportLayer.IsBuffering = true;
            }

            Debug.Assert(IsServer, "Wrong object created");
            SyncLayer.RegisterMessageImmediate<AllMembersDataMsg>(OnAllMembersData, MyMessagePermissions.ToServer|MyMessagePermissions.FromServer);

            MySteam.API.Matchmaking.LobbyChatUpdate += Matchmaking_LobbyChatUpdate;
            MySteam.API.Matchmaking.LobbyChatMsg += Matchmaking_LobbyChatMsg;
            ClientLeft += MyMultiplayerLobby_ClientLeft;
            AcceptMemberSessions();
        }
        internal MyMultiplayerLobbyClient(Lobby lobby, MySyncLayer syncLayer)
            : base(syncLayer)
        {
            Lobby = lobby;
            ServerId = Lobby.GetOwner();

            SyncLayer.RegisterClientEvents(this);


            SyncLayer.TransportLayer.IsBuffering = true;

            SetReplicationLayer(new MyReplicationClient(this, CreateClientState()));
            syncLayer.TransportLayer.Register(MyMessageId.SERVER_DATA, ReplicationLayer.ProcessServerData);
            syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_CREATE, ReplicationLayer.ProcessReplicationCreate);
            syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_DESTROY, ReplicationLayer.ProcessReplicationDestroy);
            syncLayer.TransportLayer.Register(MyMessageId.SERVER_STATE_SYNC, ReplicationLayer.ProcessStateSync);
            syncLayer.TransportLayer.Register(MyMessageId.RPC, ReplicationLayer.ProcessEvent);
            syncLayer.TransportLayer.Register(MyMessageId.REPLICATION_STREAM_BEGIN, ReplicationLayer.ProcessReplicationCreateBegin);

            Debug.Assert(!IsServer, "Wrong object created");

            MySteam.API.Matchmaking.LobbyChatUpdate += Matchmaking_LobbyChatUpdate;
            MySteam.API.Matchmaking.LobbyChatMsg += Matchmaking_LobbyChatMsg;
            ClientLeft += MyMultiplayerLobby_ClientLeft;
            AcceptMemberSessions();
        }