public serverBrowserForm()
 {
     InitializeComponent();
     currentFilter = Filter.getDefaultFilter();
     serverList    = new List <Server>();
     infoDlg       = new InfoDlg(new doUpdateServer(refreshSingleServer), new JoiningCallback(onJoiningGame));
     filtersDlg    = new FiltersDlg(new onFilterChanged(filterChanged));
     favMngr       = new FavouritesMngr();
     friendMngr    = new FriendsMngr();
 }
 public serverBrowserForm()
 {
     InitializeComponent();
     currentFilter = Filter.getDefaultFilter();
     serverList = new List<Server>();
     infoDlg = new InfoDlg(new doUpdateServer(refreshSingleServer), new JoiningCallback(onJoiningGame));
     filtersDlg = new FiltersDlg(new onFilterChanged(filterChanged));
     favMngr = new FavouritesMngr();
     friendMngr = new FriendsMngr();
 }
Пример #3
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;
        }
Пример #4
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);
        }