public override void Load(bool startup)
        {
            Command.Register(new CmdReloadEffects());
            Command.Register(new CmdEffect());
            Command.Register(new CmdSpawner());

            rnd = new Random();
            LoadEffects();
            DefineEffectsAll();

            playerEffects = PlayerExtList.Load("extra/playereffects.txt");

            OnPlayerMoveEvent.Register(OnPlayerMove, Priority.Low);
            OnPlayerFinishConnectingEvent.Register(OnPlayerFinishConnecting, Priority.Low);
            OnLevelLoadedEvent.Register(OnLevelLoaded, Priority.Low);
            OnLevelUnloadEvent.Register(OnLevelUnload, Priority.Low);
            OnLevelDeletedEvent.Register(OnLevelDeleted, Priority.Low);
            OnLevelCopiedEvent.Register(OnLevelCopied, Priority.Low);
            OnLevelRenamedEvent.Register(OnLevelRenamed, Priority.Low);

            SpawnersFile.cache = new ThreadSafeCache();
            if (!Directory.Exists(SpawnersFile.spawnerDirectory))
            {
                Directory.CreateDirectory(SpawnersFile.spawnerDirectory);
            }
            Level[] levels = LevelInfo.Loaded.Items;
            foreach (Level level in levels)
            {
                SpawnersFile.Load(level);
            }
            spawnerAccum = 0;
            ActivateSpawners();
        }
        public override void Unload(bool shutdown)
        {
            Command.Unregister(Command.Find("ReloadEffects"));
            Command.Unregister(Command.Find("Effect"));
            Command.Unregister(Command.Find("Spawner"));

            OnPlayerFinishConnectingEvent.Unregister(OnPlayerFinishConnecting);
            OnLevelLoadedEvent.Unregister(OnLevelLoaded);
            OnLevelUnloadEvent.Unregister(OnLevelUnload);
            OnLevelDeletedEvent.Unregister(OnLevelDeleted);
            OnLevelCopiedEvent.Unregister(OnLevelCopied);
            OnLevelRenamedEvent.Unregister(OnLevelRenamed);

            spawnersAtLevel.Clear();
            instance.Cancel(tickSpawners);
        }
Exemple #3
0
        /*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);
        }