Exemplo n.º 1
0
        static Level ReadBackup(Player p, string map, string path, string type)
        {
            Logger.Log(LogType.Warning, "Attempting to load {1} for {0}", map, type);
            Level lvl = Level.Load(map, path);

            if (lvl != null)
            {
                return(lvl);
            }
            p.Message("&WLoading {1} of {0} failed.", map, type);
            return(null);
        }
Exemplo n.º 2
0
        void LoadMainLevel()
        {
            try {
                if (LevelInfo.ExistsOffline(level))
                {
                    mainLevel        = Level.Load(level);
                    mainLevel.unload = false;
                    if (mainLevel == null)
                    {
                        if (File.Exists(LevelInfo.LevelPath(level) + ".backup"))
                        {
                            Log("Attempting to load backup of " + level + ".");
                            File.Copy(LevelInfo.LevelPath(level) + ".backup", LevelInfo.LevelPath(level), true);
                            mainLevel = Level.Load(level);
                            if (mainLevel == null)
                            {
                                Log("BACKUP FAILED!");
                                Console.ReadLine(); return;
                            }
                        }
                        else
                        {
                            Log("mainlevel not found");
                            mainLevel = new Level(level, 128, 64, 128, "flat");
                            mainLevel.Save();
                            Level.CreateLeveldb(level);
                        }
                    }
                }
                else
                {
                    Log("mainlevel not found");
                    mainLevel = new Level(level, 128, 64, 128, "flat");
                    mainLevel.Save();
                    Level.CreateLeveldb(level);
                }
                LevelInfo.Loaded.Add(mainLevel);

                // fenderrock - Make sure the level does have a physics thread
                if (mainLevel.physThread == null)
                {
                    mainLevel.StartPhysics();
                }
            } catch (Exception e) {
                ErrorLog(e);
            }
        }
Exemplo n.º 3
0
        static Level ReadLevel(Player p, string map)
        {
            Level lvl = Level.Load(map);

            if (lvl != null)
            {
                return(lvl);
            }

            string path = LevelInfo.MapPath(map) + ".backup";

            if (!File.Exists(path))
            {
                p.Message("%WBackup of {0} does not exist.", map); return(null);
            }
            Logger.Log(LogType.Warning, "Attempting to load backup map for " + map);

            lvl = Level.Load(map, path);
            if (lvl != null)
            {
                return(lvl);
            }
            p.Message("%WLoading backup of {0} failed too.", map);

            string backupDir = LevelInfo.BackupBasePath(map);

            if (Directory.Exists(backupDir))
            {
                int latest = LevelInfo.LatestBackup(map);
                Logger.Log(LogType.Warning, "Attempting to load latest backup ({1}) of {0} instead", map, latest);

                path = LevelInfo.BackupFilePath(map, latest.ToString());
                lvl  = Level.Load(map, path);
                if (lvl == null)
                {
                    p.Message("%WLoading latest backup failed too.");
                }
            }
            else
            {
                p.Message("%WLatest backup of {0} does not exist.", map);
            }
            return(lvl);
        }
Exemplo n.º 4
0
        static Level ReadLevel(Player p, string map)
        {
            Level lvl = Level.Load(map);

            if (lvl != null)
            {
                return(lvl);
            }

            string path = LevelInfo.MapPath(map) + ".backup";

            if (!File.Exists(path))
            {
                p.Message("Level \"{0}\" does not exist", map); return(lvl);
            }
            lvl = ReadBackup(p, map, path, "backup copy");
            if (lvl != null)
            {
                return(lvl);
            }

            path = Paths.PrevMapFile(map);
            lvl  = ReadBackup(p, map, path, "previous save");
            if (lvl != null)
            {
                return(lvl);
            }

            string backupDir = LevelInfo.BackupBasePath(map);

            if (Directory.Exists(backupDir))
            {
                int latest = LevelInfo.LatestBackup(map);
                path = LevelInfo.BackupFilePath(map, latest.ToString());
                lvl  = ReadBackup(p, map, path, "latest backup");
            }
            else
            {
                p.Message("&WLatest backup of {0} does not exist.", map);
            }
            return(lvl);
        }