Esempio n. 1
0
        private void LeftClick(CoopMenu menu, int x, int y)
        {
            if (addServerButton != null && addServerButton.containsPoint(x, y))
            {
                Game1.playSound("bigDeSelect");

                Game1.activeClickableMenu = new TextMenu("Server name?", (serverName) =>
                {
                    Game1.activeClickableMenu = new TextMenu("IP address?", (ipAddress) =>
                    {
                        bookmarks.Bookmarks.Remove(serverName);
                        bookmarks.Bookmarks.Add(serverName, ipAddress);
                        writeData(bookmarks, "Bookmarks.json");

                        var title = new TitleMenu();
                        title.skipToTitleButtons();
                        TitleMenu.subMenu         = new CoopMenu();
                        Game1.activeClickableMenu = title;
                    });
                });
            }
        }
Esempio n. 2
0
        /// <summary>Skip the intro if the game is ready.</summary>
        /// <param name="menu">The title menu whose intro to skip.</param>
        /// <param name="currentStage">The current step in the mod logic.</param>
        /// <returns>Returns the next step in the skip logic.</returns>
        private Stage Skip(TitleMenu menu, Stage currentStage)
        {
            // wait until the game is ready
            if (Game1.currentGameTime == null)
            {
                return(currentStage);
            }

            // do nothing if a confirmation box is on-screen (e.g. multiplayer disconnect error)
            if (TitleMenu.subMenu is ConfirmationDialog)
            {
                return(Stage.None);
            }

            // main skip logic
            if (currentStage == Stage.SkipIntro)
            {
                if (Constants.TargetPlatform == GamePlatform.Android)
                {
                    // skip to title screen
                    menu.skipToTitleButtons();

                    // skip button transition
                    while (this.Helper.Reflection.GetField <bool>(menu, "isTransitioningButtons").GetValue())
                    {
                        menu.update(Game1.currentGameTime);
                    }
                }
                else
                {
                    // skip to title screen
                    menu.receiveKeyPress(Keys.Escape);
                    menu.update(Game1.currentGameTime);

                    // skip button transition
                    while (this.Helper.Reflection.GetField <int>(menu, "buttonsToShow").GetValue() < TitleMenu.numberOfButtons)
                    {
                        menu.update(Game1.currentGameTime);
                    }
                }

                // skip to next screen
                switch (this.Config.SkipTo)
                {
                case Screen.Title:
                    return(Stage.None);

                case Screen.Load:
                    // skip to load screen
                    menu.performButtonAction("Load");
                    while (TitleMenu.subMenu == null)
                    {
                        menu.update(Game1.currentGameTime);
                    }
                    return(Stage.None);

                case Screen.JoinCoop:
                case Screen.HostCoop:
                    // skip to co-op screen
                    menu.performButtonAction("Co-op");
                    while (TitleMenu.subMenu == null)
                    {
                        menu.update(Game1.currentGameTime);
                    }

                    return(this.Config.SkipTo == Screen.JoinCoop
                            ? Stage.None
                            : Stage.WaitingForConnection);
                }
            }

            // skip to host tab after connection is established
            if (currentStage == Stage.WaitingForConnection)
            {
                // not applicable
                if (this.Config.SkipTo != Screen.HostCoop || !(TitleMenu.subMenu is CoopMenu submenu))
                {
                    return(Stage.None);
                }

                // not connected yet
                if (submenu.hostTab == null)
                {
                    return(currentStage);
                }

                // select host tab
                submenu.receiveLeftClick(submenu.hostTab.bounds.X, submenu.hostTab.bounds.Y, playSound: false);
            }

            // ???
            return(Stage.None);
        }
Esempio n. 3
0
        async Task DelayForLobbyData(CSteamID steamID, GalaxyID galaxyID, int serverI, Func <CSteamID, BrowserSlot> getServerSlot, Action <CSteamID> removeSlot)
        {
            var mm = GalaxyInstance.Matchmaking();

            BrowserSlot slot = null;

            for (int i = 0; i < 20; i++)
            {
                slot = getServerSlot(steamID);
                if (slot == null)
                {
                    await Task.Delay(500);
                }
                else
                {
                    Console.WriteLine("Got slot ID");
                    break;
                }
            }

            if (slot == null)
            {
                Console.WriteLine($"Failed to find slot for {steamID}");
                return;
            }

            for (int i = 0; i < 10; i++)
            {
                string getData(string key) => mm.GetLobbyData(galaxyID, key);

                string farmName = getData("farmName");

                if (string.IsNullOrEmpty(farmName))
                {
                    Console.WriteLine($"Get lobby data fail number {i}");
                    await Task.Delay(1000);

                    continue;
                }

                string serverMessage        = getData("serverMessage");
                string numberOfPlayers      = getData("numberOfPlayers");
                string numberOfPlayerSlots  = getData("numberOfPlayerSlots");
                string freeCabins           = getData("freeCabins");
                string requiredMods         = getData("requiredMods");
                string serversInstalledMods = getData("serverMods");
                string password             = getData("password");

                string passwordYesNo = string.IsNullOrEmpty(password) ? "No" : "Yes";
                Monitor.Log($"Server {serverI} - '{farmName}'\nPlayers online = {numberOfPlayers}. Total slots = {numberOfPlayerSlots}. Empty cabins = {freeCabins}.\nPassword protected = {passwordYesNo}.\nRequired mods = {requiredMods}\nServer's installed mods = {serversInstalledMods}\n\nServer message:\n{serverMessage}\n", LogLevel.Info);

                slot.FarmName          = farmName;
                slot.ServerDescription = serverMessage;
                int intPlayersOnline = int.TryParse(numberOfPlayers, out int x) ? x : -1;
                slot.PlayersOnline = intPlayersOnline;
                int intPlayerSlots = int.TryParse(numberOfPlayerSlots, out int y) ? y : -1;
                slot.PlayerSlots          = intPlayerSlots;
                slot.CabinCountText       = freeCabins;
                slot.ShowPasswordLockIcon = !string.IsNullOrEmpty(password);

                var sq = SearchOptions.SearchQuery.ToLower();

                if (
                    (!SearchOptions.ShowPasswordProtectedSerers && !string.IsNullOrEmpty(password))
                    ||
                    (!SearchOptions.ShowFullServers && intPlayersOnline == intPlayerSlots)
                    ||
                    (!SearchOptions.ShowFullCabinServers && freeCabins == "0" || freeCabins == "-1")
                    ||
                    (!string.IsNullOrWhiteSpace(sq) && !farmName.ToLower().Contains(sq) && !serverMessage.Contains(sq))
                    )
                {
                    removeSlot(steamID);
                    return;
                }

                slot.CallBack = delegate
                {
                    var browswer = Game1.activeClickableMenu;

                    Game1.activeClickableMenu = new ServerPage(25, 25, Game1.viewport.Width - 25 * 2, Game1.viewport.Height - 25 * 2, requiredMods, serversInstalledMods, delegate
                    {
                        var browser = Game1.activeClickableMenu;

                        void connect()
                        {
                            Console.WriteLine($"Connecting to steam server {steamID}");

                            //JoinLobby only works if you are at the title screen
                            var title = new TitleMenu();
                            title.skipToTitleButtons();
                            Game1.activeClickableMenu = title;

                            try
                            {
                                SteamMatchmaking.JoinLobby(steamID);
                                lastLobbyJoined = steamID;
                            }
                            catch (Exception e)
                            {
                                Monitor.Log("Error while connecting to server: " + e.Message, LogLevel.Error);
                            }
                        }

                        if (!string.IsNullOrEmpty(password))
                        {
                            Console.WriteLine("Showing password box");
                            Game1.activeClickableMenu = new TextMenu("Please enter this server's password", true, (passwordInput) =>
                            {
                                if (password != passwordInput)
                                {
                                    Console.WriteLine("Entered wrong password");
                                    Game1.activeClickableMenu = browser;
                                    return;
                                }
                                else
                                {
                                    connect();
                                }
                            }, () => Game1.activeClickableMenu = browser);
                        }
                        else
                        {
                            connect();
                        }
                    },
Esempio n. 4
0
        private void OnReceiveSteamServers(LobbyMatchList_t x, bool bIOFailure)
        {
            if (bIOFailure)
            {
                Monitor.Log("IO Failure!", LogLevel.Error);
                return;
            }

            Console.WriteLine($"STEAM RECEIVE SERVER LIST, COUNT={x.m_nLobbiesMatching}");

            if (lastLobbyJoined.m_SteamID != 0)
            {
                Console.WriteLine("Disconnecting from last joined lobby");

                try
                {
                    GalaxyInstance.Matchmaking().LeaveLobby(GalaxyIDFromSteamID(lastLobbyJoined));
                }
                catch (Exception)
                {
                    Console.WriteLine("  was not connected to any lobby");
                }
            }

            List <CSteamID> servers = new List <CSteamID>();

            BrowserMenu browser = null;

            int serverI = 0;

            while (true)
            {
                CSteamID steamID = SteamMatchmaking.GetLobbyByIndex(serverI);
                if (!steamID.IsValid() || steamID.m_SteamID == 0)
                {
                    break;
                }

                Console.WriteLine($"DISCOVERED SERVERID={steamID.m_SteamID}");

                var galaxyID = GalaxyIDFromSteamID(steamID);

                Console.WriteLine($"Received galaxy ID = {galaxyID?.ToString() ?? "NULL"}");

                if (galaxyID != null)
                {
                    servers.Add(steamID);

                    var mm = GalaxyInstance.Matchmaking();

                    var unkown = mm.RequestLobbyData(galaxyID);
                    Console.WriteLine($"Request lobby data output = {unkown}");

                    Task task = DelayForLobbyData(steamID, galaxyID, serverI, id => browser?.GetSlot(id), id => browser?.RemoveSlot(id));
                }

                serverI++;
            }
            if (servers.Count == 0)
            {
                Monitor.Log("Couldn't find any servers!", LogLevel.Info);
            }

            var blankTitle = new TitleMenu();

            blankTitle.skipToTitleButtons();
            TitleMenu.subMenu = new CoopMenu();

            //Game1.viewport.Height - 50 * 2
            browser = new BrowserMenu(25, 25, Game1.viewport.Width - 25 * 2, Game1.viewport.Height, servers, blankTitle);
            Game1.activeClickableMenu = browser;
        }