예제 #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;
            }
        }
예제 #2
0
파일: Level.cs 프로젝트: ProtheanGod/KingMC
        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();
        }
예제 #3
0
        public void LoadMap(string name)
        {
            if (String.IsNullOrEmpty(name) || !HasMap(name)) return;

            name = name.ToLower();
            Level oldMap = null;
            if (active && map != null) oldMap = map;
            Command.all.Find("load").Use(null, name);
            map = Level.Find(name);

            if (map != null)
            {
                mapSettings = LoadMapSettings(name);
                mapData = GenerateMapData(mapSettings);

                map.setPhysics(mapData.destroy ? 2 : 1);
                map.motd = "Lava Survival: " + map.name.Capitalize();
                map.overload = 1000000;
                map.unload = false;
                map.loadOnGoto = false;
                Level.SaveSettings(map);
            }
            
            if (active && map != null)
            {
                sendingPlayers = true;
                try
                {
                    Player.players.ForEach(delegate(Player pl)
                    {
                        if (pl.level == oldMap)
                        {
                            if (sendAfkMain && Server.afkset.Contains(pl.name)) Command.all.Find("main").Use(pl, "");
                            else Command.all.Find("goto").Use(pl, map.name);
                        }
                    });
                    if (OnMapChange != null)
                        OnMapChange(oldMap, map);
                    oldMap.Unload(true, false);
                }
                catch { }
                sendingPlayers = false;

                StartRound();
            }
        }
예제 #4
0
        //givenName is safe against SQL injections, it gets checked in CmdLoad.cs
        public static Level Load(string givenName, byte phys)
        {
            if (LevelLoad != null)
            {
                LevelLoad(givenName);
            }
            OnLevelLoadEvent.Call(givenName);
            if (cancelload)
            {
                cancelload = false;
                return(null);
            }
            CreateLeveldb(givenName);

            string path = LevelInfo.LevelPath(givenName);

            if (File.Exists(path))
            {
                try
                {
                    Level level = LvlFile.Load(givenName, path);
                    level.setPhysics(phys);
                    level.backedup = true;

                    using (DataTable ZoneDB = Database.fillData("SELECT * FROM `Zone" + givenName + "`"))
                    {
                        Zone Zn;
                        for (int i = 0; i < ZoneDB.Rows.Count; ++i)
                        {
                            DataRow row = ZoneDB.Rows[i];
                            Zn.smallX = ushort.Parse(row["SmallX"].ToString());
                            Zn.smallY = ushort.Parse(row["SmallY"].ToString());
                            Zn.smallZ = ushort.Parse(row["SmallZ"].ToString());
                            Zn.bigX   = ushort.Parse(row["BigX"].ToString());
                            Zn.bigY   = ushort.Parse(row["BigY"].ToString());
                            Zn.bigZ   = ushort.Parse(row["BigZ"].ToString());
                            Zn.Owner  = row["Owner"].ToString();
                            level.ZoneList.Add(Zn);
                        }
                    }

                    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();
                    //level.physChecker.Elapsed += delegate
                    //{
                    //    if (!level.physicssate && level.physics > 0)
                    //        level.StartPhysics();
                    //};
                    //level.physChecker.Start();

                    try
                    {
                        DataTable foundDB = Database.fillData("SELECT * FROM `Portals" + givenName + "`");

                        for (int i = 0; i < foundDB.Rows.Count; ++i)
                        {
                            DataRow row = foundDB.Rows[i];
                            if (
                                !Block.portal(level.GetTile(ushort.Parse(row["EntryX"].ToString()),
                                                            ushort.Parse(row["EntryY"].ToString()),
                                                            ushort.Parse(row["EntryZ"].ToString()))))
                            {
                                Database.executeQuery("DELETE FROM `Portals" + givenName + "` WHERE EntryX=" +
                                                      row["EntryX"] + " AND EntryY=" +
                                                      row["EntryY"] + " AND EntryZ=" +
                                                      row["EntryZ"]);
                            }
                        }
                        foundDB = Database.fillData("SELECT * FROM `Messages" + givenName + "`");

                        for (int i = 0; i < foundDB.Rows.Count; ++i)
                        {
                            DataRow row = foundDB.Rows[i];
                            if (
                                !Block.mb(level.GetTile(ushort.Parse(row["X"].ToString()),
                                                        ushort.Parse(row["Y"].ToString()),
                                                        ushort.Parse(row["Z"].ToString()))))
                            {
                                //givenName is safe against SQL injections, it gets checked in CmdLoad.cs
                                Database.executeQuery("DELETE FROM `Messages" + givenName + "` WHERE X=" +
                                                      row["X"] + " AND Y=" + row["Y"] +
                                                      " AND Z=" + row["Z"]);
                            }
                        }
                        foundDB.Dispose();
                    } catch (Exception e) {
                        Server.ErrorLog(e);
                    }

                    try {
                        string propsPath = LevelInfo.GetPropertiesPath(level.name);
                        if (propsPath != null)
                        {
                            LvlProperties.Load(level, propsPath);
                        }
                        else
                        {
                            Server.s.Log(".properties file for level " + level.name + " was not found.");
                        }
                        LvlProperties.LoadEnv(level, level.name);
                    } catch (Exception e) {
                        Server.ErrorLog(e);
                    }

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

                    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);
                }
            }
            Server.s.Log("ERROR loading level.");
            return(null);
        }
예제 #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);
            }
        }