Ejemplo n.º 1
0
        public static void Replace(Level old, Level lvl)
        {
            LevelDB.SaveBlockDB(old);
            LevelInfo.Loaded.Remove(old);
            LevelInfo.Loaded.Add(lvl);

            old.setPhysics(0);
            old.ClearPhysics();
            lvl.StartPhysics();

            Player[] players = PlayerInfo.Online.Items;
            foreach (Player pl in players)
            {
                if (pl.level != old)
                {
                    continue;
                }
                pl.level = lvl;
                ReloadMap(null, pl, false);
            }

            old.Unload(true, false);
            if (old == Server.mainLevel)
            {
                Server.mainLevel = lvl;
            }
        }
Ejemplo n.º 2
0
        public static Level Load(string name, string path)
        {
            OnLevelLoadEvent.Call(name);
            if (cancelload)
            {
                cancelload = false; return(null);
            }

            if (!File.Exists(path))
            {
                Logger.Log(LogType.Warning, "Attempted to load {0}, but the level file does not exist.", name);
                return(null);
            }

            try {
                Level lvl = IMapImporter.Formats[0].Read(path, name, true);
                lvl.backedup = true;
                LoadMetadata(lvl);
                BotsFile.Load(lvl);

                object locker = ThreadSafeCache.DBCache.GetLocker(name);
                lock (locker) {
                    LevelDB.LoadZones(lvl, name);
                    LevelDB.LoadPortals(lvl, name);
                    LevelDB.LoadMessages(lvl, name);
                }

                Logger.Log(LogType.SystemActivity, "Level \"{0}\" loaded.", lvl.name);
                OnLevelLoadedEvent.Call(lvl);
                return(lvl);
            } catch (Exception ex) {
                Logger.LogError("Error loading map from " + path, ex);
                return(null);
            }
        }
Ejemplo n.º 3
0
        public static Level Load(string name, string path)
        {
            OnLevelLoadEvent.Call(name);
            if (cancelload)
            {
                cancelload = false; return(null);
            }

            if (!File.Exists(path))
            {
                Logger.Log(LogType.Warning, "Attempted to load {0}, but the level file does not exist.", name);
                return(null);
            }

            try {
                Level lvl = IMapImporter.Formats[0].Read(path, name, true);
                lvl.backedup = true;

                lvl.Config.JailX    = (ushort)(lvl.spawnx * 32);
                lvl.Config.JailY    = (ushort)(lvl.spawny * 32);
                lvl.Config.JailZ    = (ushort)(lvl.spawnz * 32);
                lvl.Config.jailrotx = lvl.rotx;
                lvl.Config.jailroty = lvl.roty;

                LoadMetadata(lvl);
                MCGalaxy.Bots.BotsFile.Load(lvl);

                object locker = ThreadSafeCache.DBCache.GetLocker(name);
                lock (locker) {
                    LevelDB.LoadZones(lvl, name);
                    LevelDB.LoadPortals(lvl, name);
                    LevelDB.LoadMessages(lvl, name);
                }

                Logger.Log(LogType.SystemActivity, "Level \"{0}\" loaded.", lvl.name);
                OnLevelLoadedEvent.Call(lvl);
                return(lvl);
            } catch (Exception ex) {
                Logger.LogError(ex);
                return(null);
            }
        }
Ejemplo n.º 4
0
 public void SaveBlockDBChanges()
 {
     lock (dbLock) LevelDB.SaveBlockDB(this);
 }
Ejemplo n.º 5
0
        public static Level Load(string name, byte phys)
        {
            if (LevelLoad != null)
            {
                LevelLoad(name);
            }
            OnLevelLoadEvent.Call(name);
            if (cancelload)
            {
                cancelload = false; return(null);
            }

            string path = LevelInfo.LevelPath(name);

            if (!File.Exists(path))
            {
                Server.s.Log("Attempted to load " + name + ", but the level file does not exist.");
                return(null);
            }

            try {
                Level level = IMapImporter.Formats[0].Read(path, name, true);
                level.setPhysics(phys);
                level.backedup = true;

                level.jailx    = (ushort)(level.spawnx * 32);
                level.jaily    = (ushort)(level.spawny * 32);
                level.jailz    = (ushort)(level.spawnz * 32);
                level.jailrotx = level.rotx;
                level.jailroty = level.roty;
                level.StartPhysics();

                try {
                    string propsPath = LevelInfo.FindPropertiesFile(level.name);
                    if (propsPath != null)
                    {
                        LvlProperties.Load(level, propsPath);
                    }
                    else
                    {
                        Server.s.Log(".properties file for level " + level.name + " was not found.");
                    }
                    // Backwards compatibility for older levels which had .env files.
                    LvlProperties.LoadEnv(level);
                } catch (Exception e) {
                    Server.ErrorLog(e);
                }
                level.BlockDB.Used = level.UseBlockDB;

                BlockDefinition[] defs = BlockDefinition.Load(false, level);
                for (int i = 0; i < defs.Length; i++)
                {
                    if (defs[i] == null)
                    {
                        continue;
                    }
                    level.CustomBlockDefs[i]  = defs[i];
                    level.CustomBlockProps[i] = new BlockProps((byte)i);
                }
                BlockProps.Load("lvl_" + level.name, level.CustomBlockProps);
                Bots.BotsFile.LoadBots(level);

                object locker = ThreadSafeCache.DBCache.Get(name);
                lock (locker) {
                    LevelDB.LoadZones(level, name);
                    LevelDB.LoadPortals(level, name);
                    LevelDB.LoadMessages(level, name);
                }

                Server.s.Log(string.Format("Level \"{0}\" loaded.", level.name));
                if (LevelLoaded != null)
                {
                    LevelLoaded(level);
                }
                OnLevelLoadedEvent.Call(level);
                return(level);
            } catch (Exception ex) {
                Server.ErrorLog(ex);
                return(null);
            }
        }