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); } }
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); } }
//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); } }