示例#1
0
        /// <summary>
        /// Called when the plugin is first loaded by IPA (either when the game starts or when the plugin is enabled if it starts disabled).
        /// [Init] methods that use a Constructor or called before regular methods like InitWithConfig.
        /// Only use [Init] with one Constructor.
        /// </summary>
        public void Init(IPALogger logger, IPA.Config.Config config)
        {
            Instance = this;
            Log      = logger;
            Config   = config.Generated <PluginConfig>();

            // Modifiers tab (in-lobby)
            LobbyConfigPanel.RegisterGameplayModifierTab();
        }
示例#2
0
        /// <summary>
        /// Called when the plugin is first loaded by IPA (either when the game starts or when the plugin is enabled if it starts disabled).
        /// [Init] methods that use a Constructor or called before regular methods like InitWithConfig.
        /// Only use [Init] with one Constructor.
        /// </summary>
        public void Init(IPALogger logger, IPA.Config.Config config)
        {
            Instance = this;
            Log      = logger;
            Config   = config.Generated <PluginConfig>();

            // Modifiers tab (in-lobby) - register needs to happen really early for now
            // (https://github.com/monkeymanboy/BeatSaberMarkupLanguage/issues/67)
            LobbyConfigPanel.RegisterGameplayModifierTab();
        }
示例#3
0
        private static async Task DoAnnounce(HostedGameData announce)
        {
            _sentUnAnnounce = false;

            if (await BSSBMasterAPI.Announce(announce))
            {
                _didAnnounce          = true;
                _lastCompleteAnnounce = announce;

                StatusText = $"Players can now join from the browser!\r\n{announce.Describe()}";
                HasErrored = false;
            }
            else
            {
                _didAnnounce          = false;
                _lastCompleteAnnounce = null;

                StatusText = $"Could not announce to master server!";
                HasErrored = true;
            }

            LobbyConfigPanel.UpdatePanelInstance();
        }
示例#4
0
        public static void HandleUpdate()
        {
#pragma warning disable CS4014
            var sessionManager = MpSession.SessionManager;

            if (sessionManager == null ||
                !MpLobbyConnectionTypePatch.IsPartyMultiplayer ||
                !MpLobbyConnectionTypePatch.IsPartyHost ||
                !MpLobbyStatePatch.IsValidMpState)
            {
                // We are not in a party lobby, or we are not the host
                // Make sure any previous host announcements by us are cancelled and bail
                StatusText = "You must be the host of a custom multiplayer game.";
                HasErrored = true;

                UnAnnounce();

                LobbyConfigPanel.UpdatePanelInstance();
                return;
            }

            if (Plugin.Config.LobbyAnnounceToggle)
            {
                // Toggle is on, ensure state is synced
                if (!_didSetLocalPlayerState.HasValue || _didSetLocalPlayerState.Value == false)
                {
                    _didSetLocalPlayerState = true;
                    sessionManager.SetLocalPlayerState("lobbyannounce", true); // NB: this calls another update
                }
            }
            else
            {
                // Toggle is off, ensure state is synced & do not proceed with announce
                StatusText = "Lobby announces are toggled off.";
                HasErrored = true;

                UnAnnounce();

                if (!_didSetLocalPlayerState.HasValue || _didSetLocalPlayerState.Value == true)
                {
                    _didSetLocalPlayerState = false;
                    sessionManager.SetLocalPlayerState("lobbyannounce", false); // NB: this calls another update
                }

                LobbyConfigPanel.UpdatePanelInstance();
                return;
            }

            if (String.IsNullOrEmpty(_lobbyCode) || !sessionManager.isConnectionOwner ||
                sessionManager.localPlayer == null || !sessionManager.isConnected ||
                sessionManager.maxPlayerCount == 1)
            {
                // We do not (yet) have the Server Code, or we're at an in-between state where things aren't ready yet
                StatusText = "Can't send announcement (invalid lobby state).";
                HasErrored = true;

                UnAnnounce();

                LobbyConfigPanel.UpdatePanelInstance();
                return;
            }

            string finalGameName = $"{sessionManager.localPlayer.userName}'s game";

            if (!String.IsNullOrEmpty(_customGameName))
            {
                finalGameName = _customGameName;
            }
            else if (!String.IsNullOrEmpty(Plugin.Config.CustomGameName))
            {
                finalGameName = Plugin.Config.CustomGameName;
            }

            var lobbyAnnounce = new HostedGameData()
            {
                ServerCode       = _lobbyCode,
                GameName         = finalGameName,
                OwnerId          = sessionManager.localPlayer.userId,
                OwnerName        = sessionManager.localPlayer.userName,
                PlayerCount      = MpSession.GetPlayerCount(),
                PlayerLimit      = MpSession.GetPlayerLimit(),
                IsModded         = sessionManager.localPlayer.HasState("modded") && sessionManager.localPlayer.HasState("customsongs"),
                LobbyState       = MpLobbyStatePatch.LobbyState,
                LevelId          = _level?.levelID,
                SongName         = _level?.songName,
                SongAuthor       = _level?.songAuthorName,
                Difficulty       = _difficulty,
                Platform         = Plugin.PlatformId,
                MasterServerHost = MpConnect.LastUsedMasterServer != null ? MpConnect.LastUsedMasterServer.hostName : null,
                MasterServerPort = MpConnect.LastUsedMasterServer != null ? MpConnect.LastUsedMasterServer.port : MpConnect.DEFAULT_MASTER_PORT
            };

            StatusText = "Announcing your game to the world...\r\n" + lobbyAnnounce.Describe();
            HasErrored = false;

            LobbyConfigPanel.UpdatePanelInstance();

            DoAnnounce(lobbyAnnounce);
#pragma warning restore CS4014
        }
        public static void HandleUpdate()
        {
            var sessionManager = MpSession.SessionManager;

            if (sessionManager == null ||
                !MpLobbyConnectionTypePatch.IsPartyMultiplayer ||
                !MpLobbyConnectionTypePatch.IsPartyHost ||
                !MpLobbyStatePatch.IsValidMpState)
            {
                // We are not in a party lobby, or we are not the host
                // Make sure any previous host announcements by us are cancelled and bail
                StatusText = "You must be the host of a custom multiplayer game.";
                HasErrored = true;

                UnAnnounce();

                LobbyConfigPanel.UpdatePanelInstance();
                return;
            }

            if (Plugin.Config.LobbyAnnounceToggle)
            {
                // Toggle is on, ensure state is synced
                if (!_didSetLocalPlayerState.HasValue || _didSetLocalPlayerState.Value == false)
                {
                    _didSetLocalPlayerState = true;
                    sessionManager.SetLocalPlayerState("lobbyannounce", true); // NB: this calls another update
                }
            }
            else
            {
                // Toggle is off, ensure state is synced & do not proceed with announce
                StatusText = "Lobby announces are toggled off.";
                HasErrored = true;

                UnAnnounce();

                if (!_didSetLocalPlayerState.HasValue || _didSetLocalPlayerState.Value == true)
                {
                    _didSetLocalPlayerState = false;
                    sessionManager.SetLocalPlayerState("lobbyannounce", false); // NB: this calls another update
                }

                LobbyConfigPanel.UpdatePanelInstance();
                return;
            }

            if (String.IsNullOrEmpty(_lobbyCode) || !sessionManager.isConnectionOwner ||
                sessionManager.localPlayer == null || !sessionManager.isConnected ||
                sessionManager.maxPlayerCount == 1)
            {
                // We do not (yet) have the Server Code, or we're at an in-between state where things aren't ready yet
                StatusText = "Can't send announcement (invalid lobby state).";
                HasErrored = true;

                UnAnnounce();

                LobbyConfigPanel.UpdatePanelInstance();
                return;
            }

            var lobbyAnnounce = GenerateAnnounce();

            StatusText = "Announcing your game to the world...\r\n" + lobbyAnnounce.Describe();
            HasErrored = false;

            LobbyConfigPanel.UpdatePanelInstance();

            DoAnnounce(lobbyAnnounce);
        }