Ejemplo n.º 1
0
        public BrowserMenu(int x, int y, int width, int height, List <CSteamID> servers, IClickableMenu fallBackMenu) : base(x, y, width, 17 * 2 + ((height - 17 * 2) / BrowserSlot.height - 1) * BrowserSlot.height, true)
        {
            if (Game1.viewport.Height - base.height <= 150)
            {
                base.height -= BrowserSlot.height;
            }

            exitFunction = delegate
            {
                Game1.activeClickableMenu = fallBackMenu;
            };

            int i = 0;

            foreach (var steamID in servers)
            {
                var slot = new BrowserSlot(xPositionOnScreen + 15, yPositionOnScreen + 17 + i * BrowserSlot.height, width - 30, 0, 0, "0",
                                           "Loading...", $"Server ID {steamID}");
                slots.Add(steamID, slot);

                i++;
            }

            showFullServersCheckbox       = new Checkbox(xPositionOnScreen + 23, yPositionOnScreen + base.height + 27, "Show full", ModEntry.SearchOptions.ShowFullServers);
            showPasswordProtectedCheckbox = new Checkbox(xPositionOnScreen + 23, yPositionOnScreen + base.height + 27 + 40 + 12, "Show password protected", ModEntry.SearchOptions.ShowPasswordProtectedSerers);
            showNoEmptyCabinsCheckbox     = new Checkbox(xPositionOnScreen + 260, yPositionOnScreen + base.height + 27, "Show full cabins", ModEntry.SearchOptions.ShowFullCabinServers);

            searchButton  = new ClickableTextureComponent(new Rectangle(xPositionOnScreen + width - 185, yPositionOnScreen + base.height + 46, 14 * 4, 15 * 4), Game1.mouseCursors, new Rectangle(208, 321, 14, 15), 4f, true);
            refreshButton = new ClickableTextureComponent(new Rectangle(xPositionOnScreen + width - 107, yPositionOnScreen + base.height + 41, 18 * 4, 18 * 4), ModEntry.RefreshTexture, new Rectangle(0, 0, 18, 18), 4f, true);


            forwardButton = new ClickableTextureComponent(new Rectangle(xPositionOnScreen + width - 28, yPositionOnScreen + base.height - 16, 48, 44), Game1.mouseCursors, new Rectangle(365, 495, 12, 11), 4f, false);
            backButton    = new ClickableTextureComponent(new Rectangle(xPositionOnScreen - 24, yPositionOnScreen + base.height - 16, 48, 44), Game1.mouseCursors, new Rectangle(352, 495, 12, 11), 4f, false);
        }
Ejemplo n.º 2
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();
                        }
                    },