public void Goto(string warp, Player p) { Warp wp = Find(warp); if (wp == null) { return; } Level lvl = LevelInfo.FindExact(wp.lvlname); if (p.level != lvl) { PlayerActions.ChangeMap(p, lvl); } if (p.level.name.CaselessEq(wp.lvlname)) { p.SendPos(Entities.SelfID, wp.x, wp.y, wp.z, wp.rotx, wp.roty); Player.Message(p, "Sent you to waypoint/warp"); } else { Player.Message(p, "Unable to send you to the warp as the map it is on is not loaded."); } }
/// <summary> Sets the main level of the server that new players spawn in. </summary> /// <returns> true if main level was changed, false if not /// (same map as current main, or given map doesn't exist).</returns> public static bool SetMainLevel(string mapName) { if (mapName.CaselessEq(ServerConfig.MainLevel)) { return(false); } Level oldMain = mainLevel; Level lvl = LevelInfo.FindExact(mapName); if (lvl == null) { lvl = CmdLoad.LoadLevel(null, mapName); } if (lvl == null) { return(false); } oldMain.Config.AutoUnload = true; mainLevel = lvl; mainLevel.Config.AutoUnload = false; ServerConfig.MainLevel = mapName; return(true); }
/// <summary> Deletes the .lvl (and related) files and database tables. Unloads level if it is loaded. </summary> public static bool Delete(string map) { Level lvl = LevelInfo.FindExact(map); if (lvl != null && !lvl.Unload()) { return(false); } if (!Directory.Exists("levels/deleted")) { Directory.CreateDirectory("levels/deleted"); } if (File.Exists(LevelInfo.DeletedPath(map))) { int num = 0; while (File.Exists(LevelInfo.DeletedPath(map + num))) { num++; } File.Move(LevelInfo.MapPath(map), LevelInfo.DeletedPath(map + num)); } else { File.Move(LevelInfo.MapPath(map), LevelInfo.DeletedPath(map)); } DoAll(map, "", action_delete); DeleteDatabaseTables(map); BlockDBFile.DeleteBackingFile(map); return(true); }
static void AutoLoadLineProcessor(string key, string value) { key = key.ToLower(); if (value == "") { value = "0"; } if (key != mainLevel.name) { Command.all.Find("load").Use(null, key + " " + value); Level l = LevelInfo.FindExact(key); } else { try { int temp = int.Parse(value); if (temp >= 0 && temp <= 3) { mainLevel.setPhysics(temp); } } catch { s.Log("Physics variable invalid"); } } }
static bool LoadOfflineLevel(Player p, string map) { string propsPath = LevelInfo.PropsPath(map); LevelConfig cfg = new LevelConfig(); cfg.Load(propsPath); if (!cfg.LoadOnGoto) { p.Message("Level \"{0}\" cannot be loaded using %T/Goto.", map); return(false); } AccessController visitAccess = new LevelAccessController(cfg, map, true); bool skip = p.summonedMap != null && p.summonedMap.CaselessEq(map); LevelPermission plRank = skip ? LevelPermission.Nobody : p.Rank; if (!visitAccess.CheckDetailed(p, plRank)) { return(false); } LevelActions.Load(p, map, false); Level lvl = LevelInfo.FindExact(map); if (lvl != null) { return(GotoLevel(p, lvl)); } p.Message("Level \"{0}\" failed to be auto-loaded.", map); return(false); }
static bool LoadOfflineLevel(Player p, string name) { string propsPath = LevelInfo.PropertiesPath(name); LevelConfig cfg = new LevelConfig(); LevelConfig.Load(propsPath, cfg); if (!cfg.LoadOnGoto) { Player.Message(p, "Level \"{0}\" cannot be loaded using %T/Goto.", name); return(false); } LevelAccessController visitAccess = new LevelAccessController(cfg, name, true); bool ignorePerms = p.summonedMap != null && p.summonedMap.CaselessEq(name); if (!visitAccess.CheckDetailed(p, ignorePerms)) { return(false); } CmdLoad.LoadLevel(p, name, true); Level lvl = LevelInfo.FindExact(name); if (lvl != null) { return(GotoLevel(p, lvl)); } Player.Message(p, "Level \"{0}\" failed to be auto-loaded.", name); return(false); }
/// <summary> Renames the given map and associated metadata. Does not unload. </summary> /// <remarks> Backups are NOT renamed. </remarks> public static bool Rename(Player p, string src, string dst) { if (LevelInfo.MapExists(dst)) { p.Message("&WLevel \"{0}\" already exists.", dst); return(false); } Level lvl = LevelInfo.FindExact(src); if (lvl == Server.mainLevel) { p.Message("Cannot rename the main level."); return(false); } List <Player> players = null; if (lvl != null) { players = lvl.getPlayers(); } if (lvl != null && !lvl.Unload()) { p.Message("Unable to rename the level, because it could not be unloaded. " + "A game may currently be running on it."); return(false); } File.Move(LevelInfo.MapPath(src), LevelInfo.MapPath(dst)); DoAll(src, dst, action_move); // TODO: Should we move backups still try { //MoveBackups(src, dst); } catch { } RenameDatabaseTables(p, src, dst); BlockDBFile.MoveBackingFile(src, dst); OnLevelRenamedEvent.Call(src, dst); if (players == null) { return(true); } // Move all the old players to the renamed map Load(p, dst, false); foreach (Player pl in players) { PlayerActions.ChangeMap(pl, dst); } return(true); }
static bool LoadOfflineLevel(Player p, string name, bool ignorePerms) { if (!Level.CheckLoadOnGoto(name)) { Player.Message(p, "Level \"{0}\" cannot be loaded using /goto.", name); return(false); } CmdLoad.LoadLevel(p, name, "0", true); Level lvl = LevelInfo.FindExact(name); if (lvl != null) { return(GotoLevel(p, lvl, ignorePerms)); } Player.Message(p, "Level \"{0}\" failed to be auto-loaded.", name); return(false); }
/*static void MoveBackups(string src, string dst) { * string srcBase = LevelInfo.BackupBasePath(src); * string dstBase = LevelInfo.BackupBasePath(dst); * if (!Directory.Exists(srcBase)) return; * Directory.CreateDirectory(dstBase); * * string[] backups = Directory.GetDirectories(srcBase); * for (int i = 0; i < backups.Length; i++) { * string name = LevelInfo.BackupNameFrom(backups[i]); * string srcFile = LevelInfo.BackupFilePath(src, name); * string dstFile = LevelInfo.BackupFilePath(dst, name); * string dstDir = LevelInfo.BackupDirPath(dst, name); * * Directory.CreateDirectory(dstDir); * File.Move(srcFile, dstFile); * Directory.Delete(backups[i]); * } * Directory.Delete(srcBase); * }*/ /// <summary> Deletes a map and associated metadata. </summary> public static bool Delete(Player p, string map) { Level lvl = LevelInfo.FindExact(map); if (lvl == Server.mainLevel) { p.Message("Cannot delete the main level."); return(false); } if (lvl != null && !lvl.Unload()) { p.Message("Unable to delete the level, because it could not be unloaded. " + "A game may currently be running on it."); return(false); } p.Message("Created backup."); if (!Directory.Exists("levels/deleted")) { Directory.CreateDirectory("levels/deleted"); } if (File.Exists(Paths.DeletedMapFile(map))) { int num = 0; while (File.Exists(Paths.DeletedMapFile(map + num))) { num++; } File.Move(LevelInfo.MapPath(map), Paths.DeletedMapFile(map + num)); } else { File.Move(LevelInfo.MapPath(map), Paths.DeletedMapFile(map)); } DoAll(map, "", action_delete); DeleteDatabaseTables(map); BlockDBFile.DeleteBackingFile(map); OnLevelDeletedEvent.Call(map); return(true); }
/// <summary> Deletes the .lvl (and related) files and database tables. /// Unloads a level (if present) which exactly matches name. </summary> public static void Delete(string name) { Level lvl = LevelInfo.FindExact(name); if (lvl != null) { lvl.Unload(); } if (!Directory.Exists("levels/deleted")) { Directory.CreateDirectory("levels/deleted"); } if (File.Exists("levels/deleted/" + name + ".lvl")) { int num = 0; while (File.Exists("levels/deleted/" + name + num + ".lvl")) { num++; } File.Move(LevelInfo.LevelPath(name), "levels/deleted/" + name + num + ".lvl"); } else { File.Move(LevelInfo.LevelPath(name), "levels/deleted/" + name + ".lvl"); } try { File.Delete("levels/level properties/" + name + ".properties"); } catch { } try { File.Delete("levels/level properties/" + name); } catch { } try { if (File.Exists("blockdefs/lvl_" + name + ".json")) { File.Delete("blockdefs/lvl_" + name + ".json"); } } catch {} BotsFile.DeleteBots(name); DeleteDatabaseTables(name); BlockDBFile.DeleteBackingFile(name); }
public static Level Load(Player p, string map, bool announce) { map = map.ToLower(); if (!LevelInfo.MapExists(map)) { p.Message("Level \"{0}\" does not exist", map); return(null); } Level cur = LevelInfo.FindExact(map); if (cur != null) { p.Message("%WLevel {0} %Wis already loaded.", cur.ColoredName); return(null); } try { Level lvl = ReadLevel(p, map); if (lvl == null || !lvl.CanJoin(p)) { return(null); } cur = LevelInfo.FindExact(map); if (cur != null) { p.Message("%WLevel {0} %Wis already loaded.", cur.ColoredName); return(null); } LevelInfo.Add(lvl); if (!announce) { return(lvl); } string autoloadMsg = "Level " + lvl.ColoredName + " %Sloaded."; Chat.Message(ChatScope.All, autoloadMsg, null, Chat.FilterVisible(p)); return(lvl); } finally { Server.DoGC(); } }
static bool GotoMap(Player p, string name, bool ignorePerms) { Level lvl = LevelInfo.FindExact(name); if (lvl != null) { return(GotoLevel(p, lvl, ignorePerms)); } if (Server.AutoLoad) { // First try exactly matching unloaded levels if (LevelInfo.ExistsOffline(name)) { return(LoadOfflineLevel(p, name, ignorePerms)); } lvl = LevelInfo.Find(name); if (lvl != null) { return(GotoLevel(p, lvl, ignorePerms)); } string matches = LevelInfo.FindMapMatches(p, name); if (matches == null) { return(false); } return(LoadOfflineLevel(p, matches, ignorePerms)); } else { lvl = LevelInfo.Find(name); if (lvl == null) { Player.Message(p, "There is no level \"{0}\" loaded. Did you mean..", name); Command.all.Find("search").Use(p, "levels " + name); return(false); } return(GotoLevel(p, lvl, ignorePerms)); } }
/// <summary> Copies a map and related metadata. </summary> /// <remarks> Backups and BlockDB are NOT copied. </remarks> public static bool Copy(Player p, string src, string dst) { if (LevelInfo.MapExists(dst)) { p.Message("&WLevel \"{0}\" already exists.", dst); return(false); } // Make sure any changes to live map are saved first Level lvl = LevelInfo.FindExact(src); if (lvl != null && !lvl.Save(true)) { p.Message("&WUnable to save {0}! Some recent block changes may not be copied.", src); } File.Copy(LevelInfo.MapPath(src), LevelInfo.MapPath(dst)); DoAll(src, dst, action_copy); CopyDatabaseTables(src, dst); OnLevelCopiedEvent.Call(src, dst); return(true); }
/// <summary> Deletes the .lvl (and related) files and database tables. Unloads level if it is loaded. </summary> public static bool Delete(string name) { Level lvl = LevelInfo.FindExact(name); if (lvl != null && !lvl.Unload()) { return(false); } if (!Directory.Exists("levels/deleted")) { Directory.CreateDirectory("levels/deleted"); } if (File.Exists(LevelInfo.DeletedPath(name))) { int num = 0; while (File.Exists(LevelInfo.DeletedPath(name + num))) { num++; } File.Move(LevelInfo.MapPath(name), LevelInfo.DeletedPath(name + num)); } else { File.Move(LevelInfo.MapPath(name), LevelInfo.DeletedPath(name)); } DeleteIfExists(LevelInfo.MapPath(name) + ".backup"); DeleteIfExists("levels/level properties/" + name); DeleteIfExists("levels/level properties/" + name + ".properties"); DeleteIfExists("blockdefs/lvl_" + name + ".json"); DeleteIfExists("blockprops/lvl_" + name + ".txt"); DeleteIfExists(BotsFile.BotsPath(name)); DeleteDatabaseTables(name); BlockDBFile.DeleteBackingFile(name); return(true); }
public static bool SetMainLevel(string map) { string main = mainLevel != null ? mainLevel.name : Server.Config.MainLevel; if (map.CaselessEq(main)) { return(false); } Level lvl = LevelInfo.FindExact(map); if (lvl == null) { lvl = LevelActions.Load(Player.Console, map, false); } if (lvl == null) { return(false); } SetMainLevel(lvl); return(true); }
static bool GotoMap(Player p, string name) { Level lvl = LevelInfo.FindExact(name); if (lvl != null) { return(GotoLevel(p, lvl)); } if (Server.Config.AutoLoadMaps) { string map = Matcher.FindMaps(p, name); if (map == null) { return(false); } lvl = LevelInfo.FindExact(map); if (lvl != null) { return(GotoLevel(p, lvl)); } return(LoadOfflineLevel(p, map)); } else { lvl = Matcher.FindLevels(p, name); if (lvl == null) { p.Message("There is no level \"{0}\" loaded. Did you mean..", name); Command.Find("Search").Use(p, "levels " + name); return(false); } return(GotoLevel(p, lvl)); } }
public static Level FindExact(string name) { return(LevelInfo.FindExact(name)); }