static void CopyBlockDefs(string src, string dst) { string path = null; path = Path.Combine(oldServer, BlockDefinition.GlobalPath); BlockDefinition[] defs = BlockDefinition.Load(path); path = Path.Combine(oldServer, Paths.MapBlockDefs(src)); // Local/Level custom blocks override global ones if (File.Exists(path)) { BlockDefinition[] localDefs = BlockDefinition.Load(path); for (int i = 0; i < localDefs.Length; i++) { if (localDefs[i] == null || string.IsNullOrEmpty(localDefs[i].Name)) { continue; } defs[i] = localDefs[i]; } } // If block was original classic/CPE block on old server, but is now a custom block on new server // then make a block definition to prevent textures looking wrong (e.g. for Glass) for (int i = 0; i < Block.CpeCount; i++) { if (defs[i] == null && BlockDefinition.GlobalDefs[i] != null) { defs[i] = DefaultSet.MakeCustomBlock((BlockID)i); } } defs[0] = null; BlockDefinition.Save(false, defs, Paths.MapBlockDefs(dst)); }
public static void LoadMetadata(Level lvl) { 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; try { string propsPath = LevelInfo.PropsPath(lvl.MapName); bool propsExisted = lvl.Config.Load(propsPath); 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"; lvl.Config.Load(envPath); } catch (Exception e) { Logger.LogError(e); } lvl.BlockDB.Cache.Enabled = lvl.Config.UseBlockDB; BlockDefinition[] defs = BlockDefinition.Load(false, lvl.MapName); for (int b = 0; b < defs.Length; b++) { if (defs[b] == null) { continue; } lvl.UpdateCustomBlock((BlockID)b, defs[b]); } lvl.UpdateBlockProps(); lvl.UpdateBlockHandlers(); }
public static void LoadMetadata(Level lvl) { 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; try { string propsPath = LevelInfo.PropsPath(lvl.MapName); if (lvl.Config.Load(propsPath)) { lvl.SetPhysics(lvl.Config.Physics); } else { Logger.Log(LogType.ConsoleMessage, ".properties file for level {0} was not found.", lvl.MapName); } } catch (Exception e) { Logger.LogError(e); } lvl.BlockDB.Cache.Enabled = lvl.Config.UseBlockDB; string blockDefsPath = Paths.MapBlockDefs(lvl.MapName); BlockDefinition[] defs = BlockDefinition.Load(blockDefsPath); for (int b = 0; b < defs.Length; b++) { if (defs[b] == null) { continue; } lvl.UpdateCustomBlock((BlockID)b, defs[b]); } lvl.UpdateBlockProps(); lvl.UpdateBlockHandlers(); }
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(); }
//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); }
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); } }