Ejemplo n.º 1
0
 private async void OnServerNameChange(string newValue)
 {
     Plugin.Config.CustomGameName = newValue;
     newValue = MpSession.GetHostGameName();    // this will read CustomGameName but fall back to a default name if left empty
     Plugin.Config.CustomGameName = newValue;
     _serverNameSetting.EnterPressed(newValue); // this will update both keyboard text & button face text
 }
Ejemplo n.º 2
0
        private void UpdateFilterButton()
        {
            var nextLabel = new StringBuilder();

            // Current constraints list
            if (!String.IsNullOrEmpty(_searchQuery))
            {
                nextLabel.Append($"Search: \"{_searchQuery}\"");
            }
            else
            {
                nextLabel.Append("All servers");
            }

            // No MpEx?
            if (!MpSession.GetLocalPlayerHasMultiplayerExtensions())
            {
                nextLabel.Append(", no modded games");
            }

            // (X results)
            var resultCount = HostedGameBrowser.TotalResultCount;
            var resultUnit  = resultCount == 1 ? "result" : "results";

            nextLabel.Append($" ({resultCount} {resultUnit})");

            // Apply
            _filterButtonLabel.SetText(nextLabel.ToString());
        }
        public static async Task <ServerBrowseResult> Browse(int offset, HostedGameFilters filters)
        {
            var queryString = HttpUtility.ParseQueryString("");

            if (MpLocalPlayer.Platform.HasValue)
            {
                queryString.Add("platform", MpLocalPlayer.PlatformId);
            }

            if (offset > 0)
            {
                queryString.Add("offset", offset.ToString());
            }

            if (!MpSession.GetLocalPlayerHasMultiplayerExtensions())
            {
                queryString.Add("vanilla", "1");
            }

            if (!String.IsNullOrEmpty(filters.TextSearch))
            {
                queryString.Add("query", filters.TextSearch);
            }

            if (filters.HideFullGames)
            {
                queryString.Add("filterFull", "1");
            }

            if (filters.HideInProgressGames)
            {
                queryString.Add("filterInProgress", "1");
            }

            if (filters.HideModdedGames)
            {
                queryString.Add("filterModded", "1");
            }

            var response = await PerformWebRequest("GET", $"/browse?{queryString}");

            if (response == null)
            {
                Plugin.Log?.Warn($"Browse failed, did not get a valid response");
                return(null);
            }

            try
            {
                var contentStr = await response.Content.ReadAsStringAsync();

                return(ServerBrowseResult.FromJson(contentStr));
            }
            catch (Exception ex)
            {
                Plugin.Log?.Warn($"Error parsing browser response: {ex}");
                return(null);
            }
        }
        private static HostedGameData GenerateAnnounce()
        {
            var sessionManager   = MpSession.SessionManager;
            var localPlayer      = sessionManager.localPlayer;
            var connectedPlayers = sessionManager.connectedPlayers;

            if (_mpExVersion == null)
            {
                _mpExVersion = MpExHelper.GetInstalledVersion();

                if (_mpExVersion != null)
                {
                    Plugin.Log?.Info($"Detected MultiplayerExtensions, version {_mpExVersion}");
                }
            }

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

            lobbyAnnounce.Players = new List <HostedGamePlayer>();
            lobbyAnnounce.Players.Add(new HostedGamePlayer()
            {
                SortIndex = localPlayer.sortIndex,
                UserId    = localPlayer.userId,
                UserName  = localPlayer.userName,
                IsHost    = localPlayer.isConnectionOwner,
                Latency   = localPlayer.currentLatency
            });
            foreach (var connectedPlayer in connectedPlayers)
            {
                lobbyAnnounce.Players.Add(new HostedGamePlayer()
                {
                    SortIndex = connectedPlayer.sortIndex,
                    UserId    = connectedPlayer.userId,
                    UserName  = connectedPlayer.userName,
                    IsHost    = connectedPlayer.isConnectionOwner,
                    Latency   = connectedPlayer.currentLatency
                });
            }

            return(lobbyAnnounce);
        }
Ejemplo n.º 5
0
        public static async Task <ServerBrowseResult> Browse(int offset, string searchQuery, bool filterFull = false, bool filterInProgress = false, bool filterModded = false)
        {
            var queryString = HttpUtility.ParseQueryString("");

            if (Plugin.PlatformId != Plugin.PLATFORM_UNKNOWN)
            {
                queryString.Add("platform", Plugin.PlatformId);
            }

            if (offset > 0)
            {
                queryString.Add("offset", offset.ToString());
            }

            if (!MpSession.GetLocalPlayerHasMultiplayerExtensions())
            {
                queryString.Add("vanilla", "1");
            }

            if (!String.IsNullOrEmpty(searchQuery))
            {
                queryString.Add("query", searchQuery);
            }

            if (filterFull)
            {
                queryString.Add("filterFull", "1");
            }

            if (filterInProgress)
            {
                queryString.Add("filterInProgress", "1");
            }

            if (filterModded)
            {
                queryString.Add("filterModded", "1");
            }

            var response = await PerformWebRequest("GET", $"/browse?{queryString}");

            if (response == null)
            {
                Plugin.Log?.Warn($"Browse failed, did not get a valid response");
                return(null);
            }

            try
            {
                var contentStr = await response.Content.ReadAsStringAsync();

                return(ServerBrowseResult.FromJson(contentStr));
            }
            catch (Exception ex)
            {
                Plugin.Log?.Warn($"Error parsing browser response: {ex}");
                return(null);
            }
        }
Ejemplo n.º 6
0
        private void OnLateMenuSceneLoadedFresh(ScenesTransitionSetupDataSO obj)
        {
            // Bind multiplayer session events
            MpSession.SetUp();
            MpModeSelection.SetUp();

            // UI setup
            PluginUi.SetUp();

            // Initial state update
            GameStateManager.HandleUpdate();
        }
Ejemplo n.º 7
0
        public void OnApplicationQuit()
        {
            Log?.Debug("OnApplicationQuit");

            // Cancel update timer
            UpdateTimer.Stop();

            // Clean up events
            BSEvents.lateMenuSceneLoadedFresh -= OnLateMenuSceneLoadedFresh;
            MpSession.TearDown();

            // Try to cancel any host announcements we may have had
            GameStateManager.UnAnnounce();
        }
Ejemplo n.º 8
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
        }
        private void LobbyBrowser_OnUpdate()
        {
            GameList.data.Clear();
            CancelImageLoading();

            if (!String.IsNullOrEmpty(HostedGameBrowser.ServerMessage))
            {
                ServerMessageText.text    = HostedGameBrowser.ServerMessage;
                ServerMessageText.enabled = true;
            }
            else
            {
                ServerMessageText.enabled = false;
            }

            if (!HostedGameBrowser.ConnectionOk)
            {
                StatusText.text  = "Failed to get server list";
                StatusText.color = Color.red;
            }
            else if (!HostedGameBrowser.AnyResultsOnPage)
            {
                if (HostedGameBrowser.TotalResultCount == 0)
                {
                    if (IsSearching)
                    {
                        StatusText.text = "No servers found matching your search";
                    }
                    else
                    {
                        StatusText.text = "Sorry, no servers found";
                    }
                }
                else
                {
                    StatusText.text = "This page is empty";
                    RefreshButtonClick(); // this is awkward so force a refresh
                }

                StatusText.color = Color.red;
            }
            else
            {
                StatusText.text = $"Found {HostedGameBrowser.TotalResultCount} "
                                  + (HostedGameBrowser.TotalResultCount == 1 ? "server" : "servers")
                                  + $" (Page {HostedGameBrowser.PageIndex + 1} of {HostedGameBrowser.TotalPageCount})";

                StatusText.color = Color.green;

                if (IsSearching)
                {
                    StatusText.text += " (Filtered)";
                }

                foreach (var lobby in HostedGameBrowser.LobbiesOnPage)
                {
                    GameList.data.Add(new HostedGameCellData(_imageLoadCancellation, CellUpdateCallback, lobby));
                }
            }

            if (!MpSession.GetLocalPlayerHasMultiplayerExtensions())
            {
                StatusText.text += "\r\nMultiplayerExtensions not detected, hiding modded games";
                StatusText.color = Color.yellow;
                FilterModdedButton.interactable = false;
            }

            AfterCellsCreated();

            RefreshButton.interactable = true;

            SearchButton.interactable = (IsSearching || HostedGameBrowser.AnyResultsOnPage);
            SearchButton.SetButtonText(IsSearching ? "<color=#32CD32>Search</color>" : "Search");

            PageUpButton.interactable   = HostedGameBrowser.PageIndex > 0;
            PageDownButton.interactable = HostedGameBrowser.PageIndex < HostedGameBrowser.TotalPageCount - 1;
        }