IsMapValid() public static method

Uses the engine function to check if a map is valid.
public static IsMapValid ( string map ) : bool
map string /// Name of the map ///
return bool
Beispiel #1
0
        /// <summary>
        /// Returns a list of all valid maps in the directory.
        /// </summary>
        /// <returns>
        /// String array of all map names <see cref="System.String[]"/>
        /// </returns>
        public static string[] LoadMapListFromDirectory()
        {
            List <string> list  = new List <string>();
            var           files = new DirectoryInfo(Path.Combine(Server.GameDirectory, "maps")).GetFiles("*.bsp");

            foreach (FileInfo fi in files)
            {
                string map = fi.Name.Substring(0, fi.Name.Length - 4);
                if (Server.IsMapValid(map))
                {
                    list.Add(map);
                }
            }
            return(list.ToArray());
        }
Beispiel #2
0
        /// <summary>
        /// Returns a list of all valid maps in the mapcycle.
        /// </summary>
        /// <returns>
        /// String array of all map names <see cref="System.String[]"/>
        /// </returns>
        public static string[] LoadMapListFromMapcycle()
        {
            StreamReader  sr   = null;
            List <string> list = new List <string>();

            try {
                string mapcyclefile = Path.Combine(Server.GameDirectory, CVar.GetStringValue("mapcyclefile"));
                sr = new StreamReader(File.Open(mapcyclefile, FileMode.Open));
                while (!sr.EndOfStream)
                {
                    string line = sr.ReadLine();
                    if (line.ToLower().EndsWith(".bsp"))
                    {
                        string map = line.Substring(0, line.Length - 4);
                        if (Server.IsMapValid(map))
                        {
                            list.Add(map);
                        }
                    }
                    else
                    {
                        if (Server.IsMapValid(line))
                        {
                            list.Add(line);
                        }
                    }
                }
                return(list.ToArray());
            } catch {
                try {
                    return(list.ToArray());
                } catch {
                    return(new string[] {});
                }
            } finally {
                if (sr != null)
                {
                    sr.Close();
                }
            }
        }