Example #1
0
        /// <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);
        }
Example #2
0
        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();
            }
        }
Example #3
0
        /// <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);
        }
        public override void Use(Player p, string message)
        {
            string[] args = message.SplitSpaces(2);
            string   src  = args[0].ToLower();
            string   dst  = args.Length > 1 ? args[1].ToLower() : src;

            if (message.Length == 0)
            {
                Help(p); return;
            }
            if (!Formatter.ValidMapName(p, src))
            {
                return;
            }
            if (!Formatter.ValidMapName(p, dst))
            {
                return;
            }

            string path = Path.Combine(oldServer, LevelInfo.MapPath(src));

            if (!File.Exists(path))
            {
                p.Message("%WLevel {0} does not exist on old server.", src); return;
            }
            if (LevelInfo.MapExists(dst))
            {
                p.Message("%WLevel {0} already exists on new server.", dst); return;
            }

            File.Copy(path, LevelInfo.MapPath(dst), true);
            CopyProperties(src, dst);
            CopyBlockDefs(src, dst);
            CopyBlockProps(src, dst);
            ExportPortals(p, src, dst);
            ExportMessages(p, src, dst);
            p.Message("Successfully imported level {0} as {1}", src, dst);
        }