Esempio n. 1
0
        static bool LoadOfflineLevel(Player p, string map)
        {
            string      propsPath = LevelInfo.PropsPath(map);
            LevelConfig cfg       = new LevelConfig();

            cfg.Load(propsPath);

            if (!cfg.LoadOnGoto)
            {
                p.Message("Level \"{0}\" cannot be loaded using %T/Goto.", map);
                return(false);
            }

            AccessController visitAccess = new LevelAccessController(cfg, map, true);
            bool             skip        = p.summonedMap != null && p.summonedMap.CaselessEq(map);
            LevelPermission  plRank      = skip ? LevelPermission.Nobody : p.Rank;

            if (!visitAccess.CheckDetailed(p, plRank))
            {
                return(false);
            }

            LevelActions.Load(p, map, false);
            Level lvl = LevelInfo.FindExact(map);

            if (lvl != null)
            {
                return(GotoLevel(p, lvl));
            }

            p.Message("Level \"{0}\" failed to be auto-loaded.", map);
            return(false);
        }
Esempio n. 2
0
        public static bool IsRealmOwner(string name, string map)
        {
            Level       lvl = null;
            LevelConfig cfg = GetConfig(map, out lvl);

            return(IsRealmOwner(map, cfg, name));
        }
Esempio n. 3
0
        internal static bool ValidateAction(Player p, string map, string action)
        {
            if (p == null)
            {
                return(true);
            }
            LevelAccessController visit, build;
            Level       lvl = null;
            LevelConfig cfg = GetConfig(map, out lvl);

            if (lvl != null)
            {
                visit = lvl.VisitAccess;
                build = lvl.BuildAccess;
            }
            else
            {
                visit = new LevelAccessController(cfg, map, true);
                build = new LevelAccessController(cfg, map, false);
            }

            if (!visit.CheckDetailed(p) || !build.CheckDetailed(p))
            {
                Player.Message(p, "Hence, you cannot {0}.", action);
                return(false);
            }
            return(true);
        }
Esempio n. 4
0
 static void LineProcessor(string key, string value, ref LevelConfig config)
 {
     if (!ConfigElement.Parse(Server.levelConfig, key, value, config))
     {
         Logger.Log(LogType.Warning, "\"{0}\" was not a recognised level property key.", key);
     }
 }
Esempio n. 5
0
        static bool LoadOfflineLevel(Player p, string name)
        {
            string      propsPath = LevelInfo.PropertiesPath(name);
            LevelConfig cfg       = new LevelConfig();

            LevelConfig.Load(propsPath, cfg);

            if (!cfg.LoadOnGoto)
            {
                Player.Message(p, "Level \"{0}\" cannot be loaded using %T/Goto.", name);
                return(false);
            }

            LevelAccessController visitAccess = new LevelAccessController(cfg, name, true);
            bool ignorePerms = p.summonedMap != null && p.summonedMap.CaselessEq(name);

            if (!visitAccess.CheckDetailed(p, ignorePerms))
            {
                return(false);
            }

            CmdLoad.LoadLevel(p, name, true);
            Level lvl = LevelInfo.FindExact(name);

            if (lvl != null)
            {
                return(GotoLevel(p, lvl));
            }

            Player.Message(p, "Level \"{0}\" failed to be auto-loaded.", name);
            return(false);
        }
Esempio n. 6
0
 public static void SaveSettings(Level lvl)
 {
     if (lvl.IsMuseum)
     {
         return;               // museums do not save properties
     }
     lock (lvl.savePropsLock) {
         string propsPath = LevelInfo.PropertiesPath(lvl.MapName);
         LevelConfig.Save(propsPath, lvl.Config, lvl.name);
     }
 }
Esempio n. 7
0
 public static void Save(string path, LevelConfig config, string lvlname)
 {
     try {
         using (StreamWriter w = new StreamWriter(path)) {
             w.WriteLine("#Level properties for " + lvlname);
             w.WriteLine("#Drown-time in seconds is [drown time] * 200 / 3 / 1000");
             ConfigElement.Serialise(Server.levelConfig, " settings", w, config);
         }
     } catch (Exception ex) {
         Logger.Log(LogType.Warning, "Failed to save level properties!");
         Logger.LogError(ex);
     }
 }
Esempio n. 8
0
        public static LevelConfig GetConfig(string map, out Level lvl)
        {
            lvl = FindExact(map);
            if (lvl != null)
            {
                return(lvl.Config);
            }

            string      propsPath = PropsPath(map);
            LevelConfig cfg       = new LevelConfig();

            cfg.Load(propsPath);
            return(cfg);
        }
Esempio n. 9
0
        public static bool IsRealmOwner(string map, LevelConfig cfg, string name)
        {
            string[] owners = cfg.RealmOwner.SplitComma();
            if (owners.Length > 0)
            {
                foreach (string owner in owners)
                {
                    if (owner.CaselessEq(name))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            // For backwards compatibility, treat name+XYZ map names as belonging to name+
            // If no + though, don't use because otherwise people can register accounts and claim maps
            return(Server.Config.ClassicubeAccountPlus && map.CaselessStarts(name));
        }
Esempio n. 10
0
        internal static bool Check(Player p, LevelPermission plRank, string map, string action)
        {
            if (p.IsConsole)
            {
                return(true);
            }
            Level lvl; LevelConfig cfg = GetConfig(map, out lvl);

            if (lvl != null)
            {
                return(Check(p, plRank, lvl, action));
            }

            LevelAccessController visit = new LevelAccessController(cfg, map, true);
            LevelAccessController build = new LevelAccessController(cfg, map, false);

            if (!visit.CheckDetailed(p, plRank) || !build.CheckDetailed(p, plRank))
            {
                p.Message("Hence, you cannot {0}.", action); return(false);
            }
            return(true);
        }
Esempio n. 11
0
        public static bool IsRealmOwner(string name, string map)
        {
            Level       lvl = null;
            LevelConfig cfg = GetConfig(map, out lvl);

            string[] owners = cfg.RealmOwner.Replace(" ", "").Split(',');

            if (owners.Length > 0 && owners[0].Length > 0)
            {
                foreach (string owner in owners)
                {
                    if (owner.CaselessEq(name))
                    {
                        return(true);
                    }
                }
                return(false);
            }

            // For backwards compatibility, treat name+XYZ map names as belonging to name+
            // If no + though, don't use because otherwise people can register accounts and claim maps
            return(ServerConfig.ClassicubeAccountPlus && map.CaselessStarts(name));
        }
Esempio n. 12
0
        public static void OutputBackups(Player p, string map, LevelConfig cfg)
        {
            map = map.ToLower();
            string root = LevelInfo.BackupBasePath(map);
            string name = cfg.Color + map;

            if (!Directory.Exists(root))
            {
                p.Message(name + " &Shas no backups yet"); return;
            }

            string[] backups = Directory.GetDirectories(root);
            p.Message(name + " &Shas &b" + backups.Length + " &Sbackups");
            int           count  = 0;
            StringBuilder custom = new StringBuilder();

            foreach (string path in backups)
            {
                string restore = LevelInfo.BackupNameFrom(path);
                int    num;
                if (int.TryParse(restore, out num))
                {
                    continue;
                }

                count++;
                custom.Append(", " + restore);
            }

            if (count == 0)
            {
                return;
            }
            p.Message("&b" + count + " &Sof these are custom-named restores:");
            p.Message(custom.ToString(2, custom.Length - 2));
        }
Esempio n. 13
0
        public static void LoadMetadata(Level lvl)
        {
            try {
                string propsPath    = LevelInfo.PropertiesPath(lvl.MapName);
                bool   propsExisted = LevelConfig.Load(propsPath, lvl.Config);

                if (propsExisted)
                {
                    lvl.setPhysics(lvl.Config.Physics);
                }
                else
                {
                    Logger.Log(LogType.ConsoleMessage, ".properties file for level {0} was not found.", lvl.MapName);
                }

                // Backwards compatibility for older levels which had .env files.
                string envPath = "levels/level properties/" + lvl.MapName + ".env";
                LevelConfig.Load(envPath, lvl.Config);
            } catch (Exception e) {
                Logger.LogError(e);
            }
            lvl.BlockDB.Cache.Enabled = lvl.Config.UseBlockDB;

            BlockDefinition[] defs = BlockDefinition.Load(false, lvl);
            for (int i = 0; i < defs.Length; i++)
            {
                if (defs[i] == null)
                {
                    continue;
                }
                lvl.UpdateCustomBlock((byte)i, defs[i]);
            }

            lvl.UpdateBlockProps();
            lvl.UpdateBlockHandlers();
        }
Esempio n. 14
0
 public LevelAccessController(LevelConfig cfg, string levelName, bool isVisit)
 {
     this.cfg     = cfg;
     this.lvlName = levelName;
     this.isVisit = isVisit;
 }
Esempio n. 15
0
 public static bool Load(string path, LevelConfig config)
 {
     return(PropertiesFile.Read(path, ref config, LineProcessor));
 }
Esempio n. 16
0
 public LevelAccessController(Level lvl, bool isVisit)
 {
     this.lvl = lvl;
     this.cfg = lvl.Config;
     IsVisit  = isVisit;
 }