コード例 #1
0
        public GameStartingUI(Server s, Action callback)
        {
            _callback = callback;
            _server = s;

            _close_form_event = new ManualResetEvent(false);
            InitializeComponent();
        }
コード例 #2
0
        private void refreshSingleServer(Server e)
        {
            if (taskInProgress)
                return;
            List<Server> server = new List<Server>();
            server.Add(e);

            addToServerList(e);
            doNewQuery(server);
        }
コード例 #3
0
        private void onServerUpdated(Server server)
        {
            if (!taskInProgress)
                return;
            if (serverBrowserView.InvokeRequired)
            {
                onServerUpdatedCallback c = new onServerUpdatedCallback(onServerUpdated);
                this.Invoke(c, new object[] { server });
                return;
            }

            if (server.queryStatus == Server.ServerQueryStatus.Failed)
            {
                if (currentFilter.Favourites != Filter.YNA.Yes)
                    serverBrowserView.Items.Remove(server.rowItem);
                else
                    server.rowItem.BackColor = Color.OrangeRed;
                return;
            }
            else if (server.queryStatus == Server.ServerQueryStatus.TimedOut)
            {
                if (currentFilter.Favourites != Filter.YNA.Yes)
                    serverBrowserView.Items.Remove(server.rowItem);
                else
                    server.rowItem.BackColor = Color.Gray;
                return;
            }
            else if (server.queryStatus == Server.ServerQueryStatus.Successful &&
                !currentFilter.serverMatchesFilter(server, favMngr, friendMngr))
            {
                serverBrowserView.Items.Remove(server.rowItem);
            }
            else if (server.queryStatus == Server.ServerQueryStatus.Successful)
            {
                // update that individual list item
                if (server.rowItem.SubItems.Count != 9)
                {
                    server.rowItem.SubItems.Clear();
                    server.rowItem.SubItems.Add(HelperFunctions.removeColourCodes(server.serverName));
                    server.rowItem.SubItems.Add(favMngr.isFavourite(server) ? "X" : "-");
                    server.rowItem.SubItems.Add(string.Format("{0} ({1})", server.serverPing.ToString(), server.serverDvars["sv_maxPing"]));
                    server.rowItem.SubItems.Add(string.Format("{0} / {1}", server.serverNPlayers, server.serverMaxPlayers));
                    server.rowItem.SubItems.Add(HelperFunctions.gameTypeToFullname(server.serverGametype));
                    server.rowItem.SubItems.Add(HelperFunctions.mapToFullname(server.serverMap));
                    server.rowItem.SubItems.Add(server.serverMod);
                    server.rowItem.SubItems.Add(server.serverDvars["g_hardcore"].Equals("1") ? "X" : "-");
                }
                else
                {
                    server.rowItem.SubItems[1].Text = HelperFunctions.removeColourCodes(server.serverName);
                    server.rowItem.SubItems[2].Text = favMngr.isFavourite(server) ? "X" : "-";
                    server.rowItem.SubItems[3].Text = string.Format("{0} ({1})", server.serverPing.ToString(), server.serverDvars["sv_maxPing"]);
                    server.rowItem.SubItems[4].Text = string.Format("{0} / {1}", server.serverNPlayers, server.serverMaxPlayers);
                    server.rowItem.SubItems[5].Text = HelperFunctions.gameTypeToFullname(server.serverGametype);
                    server.rowItem.SubItems[6].Text = HelperFunctions.mapToFullname(server.serverMap);
                    server.rowItem.SubItems[7].Text = server.serverMod;
                    if (server.serverDvars.ContainsKey("g_hardcore"))
                        server.rowItem.SubItems[8].Text = (server.serverDvars["g_hardcore"].Equals("1") ? "X" : "-");
                    else
                        server.rowItem.SubItems[8].Text = "";
                }
            }
            if (infoDlg.currentServer == server)
                infoDlg.updateDlg(server); // if the info dlg exists, update it with the correct info

            serverBrowserView.Sort();
        }
コード例 #4
0
 private void launchGameOnAddress(Server s)
 {
     new GameStartingUI(s, new Action(serverFinishedLaunch)).startConnecting();
 }
コード例 #5
0
        private void addToServerList(Server server)
        {
            if (serverList.Contains(server))
                if (server.rowItem != null)
                    if (serverBrowserView.Items.Contains(server.rowItem))
                        return;

            if (serverBrowserView.InvokeRequired)
            {
                addToServerListCallback s = new addToServerListCallback(addToServerList);
                this.Invoke(s, new object[] { server });
                return;
            }

            serverList.Add(server);
            server.ServerUpdated += new ServerUpdated(onServerUpdated);

            ListViewItem lvi = serverBrowserView.Items.Add(server.ServerAddress.ToString());
            if (server.queryStatus != Server.ServerQueryStatus.NothingYet &&
                server.queryStatus != Server.ServerQueryStatus.Failed &&
                server.queryStatus != Server.ServerQueryStatus.TimedOut)
            {
                lvi.SubItems.Add(HelperFunctions.removeColourCodes(server.serverName));
                lvi.SubItems.Add(favMngr.isFavourite(server) ? "X" : "-");
                lvi.SubItems.Add(string.Format("{0} ({1})", server.serverPing.ToString(), server.serverDvars["sv_maxPing"]));
                lvi.SubItems.Add(string.Format("{0} / {1}", server.serverNPlayers, server.serverMaxPlayers));
                lvi.SubItems.Add(HelperFunctions.gameTypeToFullname(server.serverGametype));
                lvi.SubItems.Add(HelperFunctions.mapToFullname(server.serverMap));
                lvi.SubItems.Add(server.serverMod);
                lvi.SubItems.Add(server.serverDvars["g_hardcore"].Equals("1") ? "X" : "-");
            }
            else // not queried yet, so we just add it as a blank server :<
            {
                lvi.SubItems.Add("--");
                lvi.SubItems.Add(favMngr.isFavourite(server) ? "X" : "-");
                lvi.SubItems.Add("--");
                lvi.SubItems.Add("--");
                lvi.SubItems.Add("--");
                lvi.SubItems.Add("--");
                lvi.SubItems.Add("--");
                lvi.SubItems.Add("--");
            }

            server.rowItem = lvi;
        }
コード例 #6
0
        public bool serverMatchesFilter(Server s, FavouritesMngr favMngr, FriendsMngr frndMngr)
        {
            bool b = frndMngr.friendInServer(s.ServerAddress);
            if (!(friends == YNA.All || // let it through if the filter == All
                (b && friends == YNA.Yes) || // let it through if the server contains a friend and set to Yes 
                (!b && friends == YNA.No))) // let it through if the server contains a friend and set to No
                return false;

            if (!(full == YNA.All || // let it through if the filter == All
                (s.serverNPlayers == s.serverMaxPlayers && full == YNA.Yes) || // let it through if it's full and set to Yes 
                (s.serverNPlayers != s.serverMaxPlayers && full == YNA.No))) // let it through if it isn't full and set to No
                return false;
            if (!(empty == YNA.All || // let it through if the filter == All
                (s.serverNPlayers == 0 && empty == YNA.Yes) || // let it through if it's empty and set to Yes 
                (s.serverNPlayers != 0 && empty == YNA.No))) // let it through if it isn't empty and set to No
                return false;
            if (!(hardcore == YNA.All || // let it through if the filter == All
                (s.serverDvars["g_hardcore"].Equals("1") && hardcore == YNA.Yes) || // let it through if it's hardcore and set to Yes 
                (s.serverDvars["g_hardcore"].Equals("0") && hardcore == YNA.No))) // let it through if it isn't hardcore and set to No
                return false;
            try
            {
                if (!(secure == YNA.All || // let it through if the filter == All
                    (float.Parse(s.serverDvars["shortversion"]) >= 0.3 && secure == YNA.Yes) || // let it through if it's secure and set to Yes 
                    (float.Parse(s.serverDvars["shortversion"]) < 0.3 && secure == YNA.No))) // let it through if it isn't secure and set to No
                    return false;
            }
            catch { if (!s.serverDvars.ContainsKey("shortversion") && secure != YNA.All) { return false; } } // shortversion was invalid! :(
            try
            {
                if (!(pingLowerThanMax == YNA.All || // let it through if the filter == All
                    (int.Parse(s.serverDvars["sv_maxPing"]) > s.serverPing && pingLowerThanMax == YNA.Yes) || // let it through if it's low enough and set to Yes 
                    (int.Parse(s.serverDvars["sv_maxPing"]) <= s.serverPing && pingLowerThanMax == YNA.No))) // let it through if it isn't low enough and set to No
                    return false;
            }
            catch { return false; } // sv_maxPing was invalid! :(
            if (!(favourites == YNA.All || // let it through if the filter == All
                (favMngr.isFavourite(s) && favourites == YNA.Yes) || // let it through if it's a favourite and set to Yes 
                (!favMngr.isFavourite(s) && favourites == YNA.No))) // let it through if it isn't a favourite and set to No
                return false;
            if (!(mods == YNA.All || // let it through if the filter == All
                (s.serverDvars.ContainsKey("fs_game") && mods == YNA.Yes) || // let it through if it's got a mod and set to Yes 
                (!s.serverDvars.ContainsKey("fs_game") && mods == YNA.No))) // let it through if it isn't modded and set to No
                return false;

            if (!(string.IsNullOrEmpty(name) || // let it through if the search == null
                (s.serverName.Contains(name) && !string.IsNullOrEmpty(name)))) // let it through if it contains a portion of the search and isn't null
                return false;
            if (!(string.IsNullOrEmpty(map) || // let it through if the search == null
                (s.serverMap.Contains(map) && !string.IsNullOrEmpty(map)))) // let it through if it contains a portion of the search and isn't null
                return false;
            if (!(string.IsNullOrEmpty(gametype) || // let it through if the search == null
                (s.serverGametype.Contains(gametype) && !string.IsNullOrEmpty(gametype)))) // let it through if it contains a portion of the search and isn't null
                return false;

            /*if (!string.IsNullOrEmpty(buddy)) // let it through if it contains a portion of the search and isn't null
            {
                bool found = false; // we have to do it like this because there is no way to skip the return statement after the loop
                foreach (Player p in s.serverPlayerList)
                {
                    if (p.name.ToLower().Equals(buddy.ToLower()))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                    return false;
            }*/

            if (!(string.IsNullOrEmpty(mod) || // let it through if the search == null
                (s.serverMod.Contains(mod) && !string.IsNullOrEmpty(mod)))) // let it through if it contains a portion of the search and isn't null
                return false;
            return true;
        }
コード例 #7
0
        public void updateDlg(Server server)
        {
            playerListView.Items.Clear();
            if (server.queryStatus == Server.ServerQueryStatus.Successful)
            {
                serverInfoView.Text = "";
                int startLen = 0;
                string info;
                info = string.Format("Server Name: \t{0}", HelperFunctions.removeColourCodes(server.serverName));
                serverInfoView.Text = info;

                serverInfoView.SelectionStart = startLen;
                serverInfoView.SelectionLength = "Server Name: ".Length;
                serverInfoView.SelectionFont = new Font("Calibri", 11F, FontStyle.Bold, GraphicsUnit.Point);

                // TODO: Fix the positioning of the colour codes :/

                startLen = serverInfoView.TextLength;
                info = "\n\nAddress: \t" + server.ServerAddress.ToString();
                serverInfoView.AppendText(info);

                serverInfoView.SelectionStart = startLen;
                serverInfoView.SelectionLength = "Address: ".Length;
                serverInfoView.SelectionFont = new Font("Calibri", 11F, FontStyle.Bold, GraphicsUnit.Point);

                /*
                serverInfoView.SelectionStart = startLen;
                serverInfoView.SelectionLength = info.Length;
                serverInfoView.SelectionColor = Color.White;
                */

                startLen = serverInfoView.TextLength;
                info = string.Format("\nPlayers: \t{0}/{1}", server.serverNPlayers, server.serverMaxPlayers);
                serverInfoView.AppendText(info);
                serverInfoView.SelectionStart = startLen;
                serverInfoView.SelectionLength = "Players: ".Length;
                serverInfoView.SelectionFont = new Font("Calibri", 11F, FontStyle.Bold, GraphicsUnit.Point);


                startLen = serverInfoView.TextLength;
                info = "\nGameType: \t" + HelperFunctions.gameTypeToFullname(server.serverGametype);
                serverInfoView.AppendText(info);
                serverInfoView.SelectionStart = startLen;
                serverInfoView.SelectionLength = "GameType: ".Length;
                serverInfoView.SelectionFont = new Font("Calibri", 11F, FontStyle.Bold, GraphicsUnit.Point);

                startLen = serverInfoView.TextLength;
                info = "\nMap: \t\t" + HelperFunctions.mapToFullname(server.serverMap);
                serverInfoView.AppendText(info);
                serverInfoView.SelectionStart = startLen;
                serverInfoView.SelectionLength = "Map: ".Length;
                serverInfoView.SelectionFont = new Font("Calibri", 11F, FontStyle.Bold, GraphicsUnit.Point);

                startLen = serverInfoView.TextLength;
                info = "\nMod: \t\t" + server.serverMod;
                serverInfoView.AppendText(info);
                serverInfoView.SelectionStart = startLen;
                serverInfoView.SelectionLength = "Mod: ".Length;
                serverInfoView.SelectionFont = new Font("Calibri", 11F, FontStyle.Bold, GraphicsUnit.Point);

                playerListView.Items.Clear();
                foreach (Player p in server.serverPlayerList)
                {
                    ListViewItem lvi = playerListView.Items.Add(HelperFunctions.removeColourCodes(p.name));
                    lvi.SubItems.Add(p.score.ToString());
                    lvi.SubItems.Add(p.ping.ToString());
                }
                this.Text = HelperFunctions.removeColourCodes(server.serverName);
                singleServerRefreshButton.Enabled = true;
                singleServerJoinButton.Enabled = true;
            }
            else
            {
                if (server.queryStatus == Server.ServerQueryStatus.TimedOut)
                    serverInfoView.Text = "Server timed out...";
                else if (server.queryStatus == Server.ServerQueryStatus.NothingYet)
                    serverInfoView.Text = "Server is being queried...";
                else
                    serverInfoView.Text = "Server query failed...";
                singleServerRefreshButton.Enabled = false;
                singleServerJoinButton.Enabled = false;
            }
            currentServer = server;
            copyIP.Enabled = true;
            copyIP.ForeColor = SystemColors.ControlText;
        }
コード例 #8
0
 public bool isFavourite(Server s)
 {
     return (getFavourites().Contains(s));
 }