Exemple #1
0
        static Level GetMuseum(string name, string path)
        {
            Player[] players = PlayerInfo.Online.Items;
            // Since museums are essentially readonly anyways, try to reuse
            //  blocks/CustomBlocks from existing museum to reduce memory usage
            // Lock the search and import so this happens even when
            //  connections occur in quick succession.
            lock (museum_lock) {
                foreach (Player pl in players)
                {
                    Level lvl = pl.level;
                    if (!lvl.IsMuseum || lvl.name != name)
                    {
                        continue;
                    }

                    Level clone = new Level();
                    clone.blocks       = lvl.blocks;
                    clone.CustomBlocks = lvl.CustomBlocks;

                    // Just in case museum was unloaded a split second before
                    if (clone.blocks == null || clone.CustomBlocks == null)
                    {
                        break;
                    }

                    clone.Init(name, lvl.Width, lvl.Height, lvl.Length);
                    return(clone);
                }

                return(IMapImporter.Read(path, name, false));
            }
        }
Exemple #2
0
        static void Import(Player p, string url, string map)
        {
            p.Message("downloading");

            byte[] data = HttpUtil.DownloadData(url, p);
            if (data == null)
            {
                return;
            }

            IMapImporter importer = GetImporter(Path.GetExtension(url).ToLower());

            if (importer == null)
            {
                string formats = IMapImporter.Formats.Join(imp => imp.Extension);
                p.Message("%WNo {0} file with that name could be parsed.", formats);
                return;
            }

            if (LevelInfo.MapExists(map))
            {
                p.Message("%WMap {0} already exists. Rename the file to something else before importing",
                          Path.GetFileNameWithoutExtension(map));
                return;
            }

            Level lvl;

            try {
                Stream stream = new MemoryStream(data);
                lvl = importer.Read(stream, map, true);

                MCGalaxy.Commands.World.CmdOverseer.SetPerms(p, lvl);

                try {
                    lvl.Save(true);
                } finally {
                    lvl.Dispose();
                    Server.DoGC();
                }
            } catch (Exception ex) {
                Logger.LogError("Error importing map", ex);
                p.Message("%WImporting map {0} failed. See error logs.", map);
                return;
            }

            string msg = string.Format("{0}%S imported level {1}", p.ColoredName, lvl.ColoredName);

            Chat.MessageGlobal(msg);
        }
        bool DoRestore(Player p, Vec3S32[] marks, object state, BlockID block)
        {
            string path   = (string)state;
            Level  source = IMapImporter.Read(path, "templevel", false);

            RestoreSelectionDrawOp op = new RestoreSelectionDrawOp();

            op.Source = source;
            if (DrawOpPerformer.Do(op, null, p, marks))
            {
                return(false);
            }

            // Not high enough draw limit
            source.Dispose();
            return(false);
        }
Exemple #4
0
 void Import(Player p, string path, string name, IMapImporter importer)
 {
     try {
         Level lvl = importer.Read(path + importer.Extension, name, true);
         try {
             lvl.Save(true);
         } finally {
             lvl.Dispose();
             GC.Collect();
             GC.WaitForPendingFinalizers();
         }
     } catch (Exception ex) {
         Server.ErrorLog(ex);
         Player.Message(p, "The map conversion failed.");
         return;
     }
     Player.Message(p, "Converted map!");
     //CmdLoad.LoadLevel(p, name); pls
 }
Exemple #5
0
 void Import(Player p, string path, string name, IMapImporter importer)
 {
     if (LevelInfo.MapExists(name))
     {
         p.Message("%WMap {0} already exists. Try renaming the file to something else before importing.", name);
         return;
     }
     try {
         Level lvl = importer.Read(path + importer.Extension, name, true);
         try {
             lvl.Save(true);
         } finally {
             lvl.Dispose();
             Server.DoGC();
         }
     } catch (Exception ex) {
         Logger.LogError("Error importing map", ex);
         p.Message("The map conversion failed.");
         return;
     }
     p.Message("Converted map!");
 }
Exemple #6
0
        static void Import(Player p, IMapImporter importer, Stream src, string map)
        {
            if (LevelInfo.MapExists(map))
            {
                p.Message("&WMap {0} already exists. Rename the file to something else before importing", map);
                return;
            }

            try {
                Level lvl = importer.Read(src, map, true);
                try {
                    lvl.Save(true);
                } finally {
                    lvl.Dispose();
                    Server.DoGC();
                }
            } catch (Exception ex) {
                Logger.LogError("Error importing map " + map, ex);
                p.Message("&WImporting map {0} failed. See error logs.", map);
                return;
            }
            p.Message("Successfully imported map {0}!", map);
        }
Exemple #7
0
        public static Level Load(string name, string path)
        {
            bool cancel = false;

            OnLevelLoadEvent.Call(name, path, ref cancel);
            if (cancel)
            {
                return(null);
            }

            if (!File.Exists(path))
            {
                Logger.Log(LogType.Warning, "Attempted to load level {0}, but {1} does not exist.", name, path);
                return(null);
            }

            try {
                Level lvl = IMapImporter.Read(path, name, 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);
            }
        }