Пример #1
0
 static void DoReload(Player p, Level lvl)
 {
     Player[] players = PlayerInfo.Online.Items;
     foreach (Player pl in players)
     {
         if (pl.level == lvl)
         {
             LevelActions.ReloadFor(p, pl, true);
         }
     }
     Server.DoGC();
 }
Пример #2
0
 static void DoReload(Player p, Level lvl)
 {
     Player[] players = PlayerInfo.Online.Items;
     foreach (Player pl in players)
     {
         if (pl.level.name.CaselessEq(lvl.name))
         {
             LevelActions.ReloadMap(p, pl, true);
         }
     }
     GC.Collect();
     GC.WaitForPendingFinalizers();
 }
Пример #3
0
 public override void Use(Player p, string message, CommandData data)
 {
     if (message.Length == 0)
     {
         Help(p); return;
     }
     string[] args = message.SplitSpaces();
     if (args.Length > 2)
     {
         Help(p); return;
     }
     LevelActions.Load(p, args[0], true);
 }
Пример #4
0
        public override void Use(Player p, string message)
        {
            string[] args = message.Split(' ');
            if (args.Length < 4)
            {
                Help(p); return;
            }
            Level lvl = LevelInfo.FindMatches(p, args[0]);

            if (lvl == null)
            {
                return;
            }

            ushort x, y, z;

            if (!UInt16.TryParse(args[1], out x) || !UInt16.TryParse(args[2], out y) || !UInt16.TryParse(args[3], out z))
            {
                Player.Message(p, "Invalid dimensions."); return;
            }

            if (!MapGen.OkayAxis(x))
            {
                Player.Message(p, "width must be divisible by 16, and >= 16"); return;
            }
            if (!MapGen.OkayAxis(y))
            {
                Player.Message(p, "height must be divisible by 16, and >= 16"); return;
            }
            if (!MapGen.OkayAxis(z))
            {
                Player.Message(p, "length must be divisible by 16, and >= 16."); return;
            }
            if (!CmdNewLvl.CheckMapSize(p, x, y, z))
            {
                return;
            }

            bool confirmed = args.Length > 4 && args[4].CaselessEq("confirm");

            if (!confirmed && (x < lvl.Width || y < lvl.Height || z < lvl.Length))
            {
                Player.Message(p, "New level dimensions are smaller than the current dimensions, &cyou will lose blocks%S.");
                Player.Message(p, "Type %T/resizelvl {0} {1} {2} {3} confirm %Sif you're sure.", args[0], x, y, z);
                return;
            }

            Level newLvl = ResizeLevel(lvl, x, y, z);

            LevelActions.Replace(lvl, newLvl);
        }
Пример #5
0
        public override void Use(Player p, string message, CommandData data)
        {
            IGame game = IGame.GameOn(p.level);

            if (game != null)
            {
                p.Message("You can only reload levels outside of a game."); return;
            }
            if (!Hacks.CanUseNoclip(p))
            {
                p.Message("You cannot use &T/Reload &Son this map."); return;
            }
            if (CheckSuper(p, message, "player or level name"))
            {
                return;
            }
            if (message.Length == 0)
            {
                message = p.name;
            }
            string[] parts = message.SplitSpaces();

            if (!parts[0].CaselessEq("all"))
            {
                PlayerActions.ReloadMap(p);
                p.Message("&bMap reloaded");
            }
            else
            {
                Level lvl = p.level;
                if (parts.Length == 2)
                {
                    lvl = Matcher.FindLevels(p, parts[1]);
                    if (lvl == null)
                    {
                        return;
                    }
                }
                else if (p.IsSuper)
                {
                    SuperRequiresArgs(name + " all", p, "level name"); return;
                }

                if (!CheckExtraPerm(p, data, 1))
                {
                    return;
                }
                LevelActions.ReloadAll(lvl, p, true);
            }
            Server.DoGC();
        }
Пример #6
0
        public override void Use(Player p, string message, CommandData data)
        {
            string[] args = message.SplitSpaces();
            if (args.Length != 2)
            {
                Help(p); return;
            }

            Level lvl = Matcher.FindLevels(p, args[0]);

            if (lvl == null)
            {
                return;
            }
            string newMap = args[1].ToLower();

            if (!Formatter.ValidMapName(p, newMap))
            {
                return;
            }

            if (LevelInfo.MapExists(newMap))
            {
                p.Message("Level already exists."); return;
            }
            if (lvl == Server.mainLevel)
            {
                p.Message("Cannot rename the main level."); return;
            }
            if (!LevelInfo.Check(p, data.Rank, lvl, "rename this level"))
            {
                return;
            }

            List <Player> players = lvl.getPlayers();

            lvl.Unload();

            LevelActions.Rename(lvl.name, newMap);
            LevelActions.Load(p, newMap, true);
            Chat.MessageGlobal("Renamed {0} to {1}", lvl.name, newMap);
            // Move all the old players to the renamed map
            foreach (Player pl in players)
            {
                PlayerActions.ChangeMap(pl, newMap);
            }
        }
Пример #7
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                Help(p); return;
            }
            string[] args = message.ToLower().SplitSpaces();
            if (args.Length < 2)
            {
                p.Message("You did not specify the destination level name."); return;
            }

            string src = args[0];

            src = Matcher.FindMaps(p, src);
            if (src == null)
            {
                return;
            }
            if (!LevelInfo.Check(p, data.Rank, src, "copy this map"))
            {
                return;
            }

            string dst = args[1];

            if (!Formatter.ValidName(p, dst, "level"))
            {
                return;
            }
            if (LevelInfo.MapExists(dst))
            {
                p.Message("Level \"" + dst + "\" already exists."); return;
            }

            try {
                LevelActions.CopyLevel(src, dst);
            } catch (IOException) {
                p.Message("Level %W" + dst + " %Salready exists!"); return;
            }

            Level       ignored;
            LevelConfig cfg = LevelInfo.GetConfig(src, out ignored);

            p.Message("Level {0} %Shas been copied to {1}", cfg.Color + src, cfg.Color + dst);
        }
Пример #8
0
 void Start()
 {
     LevelActions = FindObjectOfType <LevelActions>();
     visual       = gameObject.GetComponentInChildren <TileVisuals>();
     // ShowFront(0.1f);
     Delay(1);
     Delay(X * 0.1f);
     Animate(AnimationWithCallback.Create(
                 Animation.Create(UpdateRotation, Easings.Functions.QuadraticEaseInOut, 1.0f, 0, 180.0f),
                 null,
                 () =>
     {
         visual.backColor = colorSchema[0];
         visual.backIcon  = TileIcon.Blank;
     }
                 ));
 }
Пример #9
0
        public static bool DoResize(Player p, string[] args)
        {
            Level lvl = Matcher.FindLevels(p, args[0]);

            if (lvl == null)
            {
                return(true);
            }
            if (!LevelInfo.ValidateAction(p, lvl.name, "resize this level"))
            {
                return(false);
            }

            ushort x = 0, y = 0, z = 0;

            if (!CmdNewLvl.CheckMapAxis(p, args[1], "Width", ref x))
            {
                return(false);
            }
            if (!CmdNewLvl.CheckMapAxis(p, args[2], "Height", ref y))
            {
                return(false);
            }
            if (!CmdNewLvl.CheckMapAxis(p, args[3], "Length", ref z))
            {
                return(false);
            }
            if (!CmdNewLvl.CheckMapVolume(p, x, y, z))
            {
                return(true);
            }

            bool confirmed = args.Length > 4 && args[4].CaselessEq("confirm");

            if (!confirmed && (x < lvl.Width || y < lvl.Height || z < lvl.Length))
            {
                Player.Message(p, "New level dimensions are smaller than the current dimensions, &cyou will lose blocks%S.");
                return(false);
            }

            Level newLvl = ResizeLevel(lvl, x, y, z);

            LevelActions.Replace(lvl, newLvl);
            return(true);
        }
Пример #10
0
        public override void Use(Player p, string message)
        {
            string[] args = message.Split(' ');
            if (args.Length != 2)
            {
                Help(p); return;
            }

            Level lvl = LevelInfo.FindMatches(p, args[0]);

            if (lvl == null)
            {
                return;
            }
            string newName = args[1].ToLower();

            if (!Formatter.ValidName(p, newName, "level"))
            {
                return;
            }

            if (LevelInfo.ExistsOffline(newName))
            {
                Player.Message(p, "Level already exists."); return;
            }
            if (lvl == Server.mainLevel)
            {
                Player.Message(p, "Cannot rename the main level."); return;
            }

            List <Player> players = lvl.getPlayers();

            lvl.Unload();

            LevelActions.Rename(lvl.name, newName);
            CmdLoad.LoadLevel(p, newName);
            Chat.MessageAll("Renamed {0} to {1}", lvl.name, newName);
            // Move all the old players to the renamed map
            foreach (Player pl in players)
            {
                PlayerActions.ChangeMap(pl, newName);
            }
        }
Пример #11
0
        static void DoRestore(Level lvl, string backup)
        {
            lock (lvl.saveLock) {
                File.Copy(LevelInfo.BackupFilePath(lvl.name, backup), LevelInfo.MapPath(lvl.name), true);
                lvl.SaveChanges = false;
            }

            Level restore = Level.Load(lvl.name);

            if (restore != null)
            {
                LevelActions.Replace(lvl, restore);
            }
            else
            {
                Logger.Log(LogType.Warning, "Restore nulled");
                File.Copy(LevelInfo.MapPath(lvl.name) + ".backup", LevelInfo.MapPath(lvl.name), true);
            }
        }
Пример #12
0
        static void DoRestore(Level lvl, string backup)
        {
            lock (lvl.saveLock) {
                File.Copy(LevelInfo.BackupPath(lvl.name, backup), LevelInfo.LevelPath(lvl.name), true);
                lvl.saveLevel = false;
            }

            Level restore = Level.Load(lvl.name);

            if (restore != null)
            {
                LevelActions.Replace(lvl, restore);
            }
            else
            {
                Server.s.Log("Restore nulled");
                File.Copy(LevelInfo.LevelPath(lvl.name) + ".backup", LevelInfo.LevelPath(lvl.name), true);
            }
        }
Пример #13
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (CheckSuper(p, message, "level name"))
            {
                return;
            }
            IGame game = IGame.GameOn(p.level);

            if (message.Length == 0)
            {
                if (game != null)
                {
                    p.Message("You cannot use &T/Reload &Swhile a game is running");
                }
                else if (!Hacks.CanUseNoclip(p))
                {
                    p.Message("You cannot use &T/Reload &Son this level");
                }
                else
                {
                    PlayerActions.ReloadMap(p);
                    p.Message("&bMap reloaded");
                }
                return;
            }

            if (!CheckExtraPerm(p, data, 1))
            {
                return;
            }
            Level lvl = p.level;

            if (!message.CaselessEq("all"))
            {
                lvl = Matcher.FindLevels(p, message);
                if (lvl == null)
                {
                    return;
                }
            }
            LevelActions.ReloadAll(lvl, p, true);
        }
Пример #14
0
        static void DeleteMap(Player p, string value)
        {
            if (value.Length > 0)
            {
                p.Message("To delete your current map, type %T/os map delete");
                return;
            }

            string map = p.level.name;

            p.Message("Created backup.");
            if (LevelActions.Delete(map))
            {
                p.Message("Map " + map + " was removed.");
            }
            else
            {
                p.Message(LevelActions.DeleteFailedMessage);
            }
        }
Пример #15
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (CheckSuper(p, message, "player or level name"))
            {
                return;
            }
            if (message.Length == 0)
            {
                message = p.name;
            }
            string[] parts = message.SplitSpaces();

            if (!parts[0].CaselessEq("all"))
            {
                PlayerActions.ReloadMap(p);
                p.Message("&bMap reloaded");
            }
            else
            {
                Level lvl = p.level;
                if (parts.Length == 2)
                {
                    lvl = Matcher.FindLevels(p, parts[1]);
                    if (lvl == null)
                    {
                        return;
                    }
                }
                else if (p.IsSuper)
                {
                    SuperRequiresArgs(name + " all", p, "level name"); return;
                }

                if (!CheckExtraPerm(p, data, 1))
                {
                    return;
                }
                LevelActions.ReloadAll(lvl, p, true);
            }
            Server.DoGC();
        }
Пример #16
0
        protected virtual void ContinueOnSameMap()
        {
            Map.Message("Continuing " + GameName + " on the same map");
            Level old = Level.Load(Map.MapName);

            if (old == null)
            {
                Map.Message("&WCannot reset changes to map"); return;
            }
            if (old.Width != Map.Width || old.Height != Map.Height || old.Length != Map.Length)
            {
                Map.Message("&WCannot reset changes to map"); return;
            }

            // Try to reset changes made to this map, if possible
            // TODO: do this in a nicer way
            Map.blocks       = old.blocks;
            Map.CustomBlocks = old.CustomBlocks;
            LevelActions.ReloadAll(Map, Player.Console, false);
            Map.Message("Reset map to latest backup");
        }
Пример #17
0
        public static bool DoResize(Player p, string[] args, CommandData data, out bool needConfirm)
        {
            needConfirm = false;
            Level lvl = Matcher.FindLevels(p, args[0]);

            if (lvl == null)
            {
                return(true);
            }
            if (!LevelInfo.Check(p, data.Rank, lvl, "resize this level"))
            {
                return(false);
            }

            ushort x = 0, y = 0, z = 0;

            if (!CmdNewLvl.GetDimensions(p, args, 1, ref x, ref y, ref z))
            {
                return(false);
            }

            bool confirmed = args.Length > 4 && args[4].CaselessEq("confirm");

            if (!confirmed && (x < lvl.Width || y < lvl.Height || z < lvl.Length))
            {
                p.Message("New level dimensions are smaller than the current dimensions, %Wyou will lose blocks%S.");
                needConfirm = true;
                return(false);
            }

            Level resized = ResizeLevel(lvl, x, y, z);

            if (resized == null)
            {
                p.Message("%WError resizing map."); return(false);
            }
            LevelActions.Replace(lvl, resized);
            return(true);
        }
Пример #18
0
        public override void Use(Player p, string message)
        {
            if (message == "")
            {
                Help(p); return;
            }
            string[] args = message.ToLower().Split(' ');
            if (args.Length < 2)
            {
                Player.Message(p, "You did not specify the destination level name."); return;
            }

            string src = args[0], dst = args[1];

            if (p != null && !p.group.CanExecute("newlvl"))
            {
                Player.Message(p, "You cannot use /copylvl as you cannot use /newlvl."); return;
            }
            src = LevelInfo.FindMapMatches(p, src);
            if (src == null)
            {
                return;
            }
            if (!Formatter.ValidName(p, dst, "level"))
            {
                return;
            }
            if (LevelInfo.ExistsOffline(dst))
            {
                Player.Message(p, "The level \"" + dst + "\" already exists."); return;
            }

            try {
                LevelActions.CopyLevel(src, dst);
            } catch (System.IO.IOException) {
                Player.Message(p, "The level &c" + dst + " %Salready exists!"); return;
            }
            Player.Message(p, "The level &a" + src + " %Shas been copied to &a" + dst + ".");
        }
Пример #19
0
        public void GenerateMap(Player p, int width, int height, int length)
        {
            Level lvl = CountdownMapGen.Generate(width, height, length);
            Level cur = LevelInfo.FindExact("countdown");

            if (cur != null)
            {
                LevelActions.Replace(cur, lvl);
            }
            else
            {
                LevelInfo.Add(lvl);
            }

            lvl.Save();
            Map = lvl;

            const string format = "Generated map ({0}x{1}x{2}), sending you to it..";

            p.Message(format, width, height, length);
            PlayerActions.ChangeMap(p, "countdown");
        }
Пример #20
0
        static void DeleteMap(Player p, string value)
        {
            byte mapNum = 0;

            if (value == "")
            {
                Player.Message(p, "To delete one of your maps, type %T/os map delete [map number]");
            }
            else if (value == "1")
            {
                string map = FirstMapName(p);
                if (!LevelInfo.ExistsOffline(map))
                {
                    Player.Message(p, "You don't have a map with that map number."); return;
                }

                Player.Message(p, "Created backup.");
                LevelActions.Delete(map);
                Player.Message(p, "Map 1 has been removed.");
            }
            else if (byte.TryParse(value, out mapNum))
            {
                string map = p.name.ToLower() + value;
                if (!LevelInfo.ExistsOffline(map))
                {
                    Player.Message(p, "You don't have a map with that map number."); return;
                }

                Player.Message(p, "Created backup.");
                LevelActions.Delete(map);
                Player.Message(p, "Map " + value + " has been removed.");
            }
            else
            {
                Player.MessageLines(p, mapHelp);
            }
        }
Пример #21
0
        public override void Use(Player p, string message)
        {
            if (message == "" || message.Split(' ').Length > 1)
            {
                Help(p); return;
            }
            if (!Formatter.ValidName(p, message, "level"))
            {
                return;
            }
            string map = LevelInfo.FindMapMatches(p, message);

            if (map == null)
            {
                return;
            }

            Level lvl = LevelInfo.FindExact(map);

            if (lvl != null && p != null && lvl.permissionbuild > p.Rank)
            {
                Player.Message(p, "%cYou can't delete levels with a perbuild rank higher than yours!"); return;
            }
            if (lvl == Server.mainLevel)
            {
                Player.Message(p, "Cannot delete the main level."); return;
            }

            LevelPermission perbuild = GetPerBuildPermission(map);

            if (p != null && perbuild > p.Rank)
            {
                Player.Message(p, "%cYou can't delete levels with a perbuild rank higher than yours!"); return;
            }
            Player.Message(p, "Created backup.");
            LevelActions.Delete(map.ToLower());
        }
Пример #22
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                Help(p); return;
            }
            string[] args = message.ToLower().SplitSpaces();
            if (args.Length < 2)
            {
                p.Message("You did not specify the destination level name."); return;
            }
            LevelConfig cfg;

            string src = Matcher.FindMaps(p, args[0]);

            if (src == null)
            {
                return;
            }
            if (!LevelInfo.Check(p, data.Rank, src, "copy this map", out cfg))
            {
                return;
            }

            string dst = args[1];

            if (!Formatter.ValidMapName(p, dst))
            {
                return;
            }

            if (!LevelActions.Copy(p, src, dst))
            {
                return;
            }
            Chat.MessageGlobal("Level {0} %Swas copied to {1}", cfg.Color + src, cfg.Color + dst);
        }
Пример #23
0
        protected virtual bool SetMap(string map)
        {
            Picker.QueuedMap = null;
            Level next = LevelInfo.FindExact(map);

            if (next == null)
            {
                next = LevelActions.Load(Player.Console, map, false);
            }
            if (next == null)
            {
                return(false);
            }

            Map             = next;
            Map.SaveChanges = false;

            if (GetConfig().SetMainLevel)
            {
                Server.SetMainLevel(Map);
            }
            UpdateMapConfig();
            return(true);
        }
Пример #24
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0 || message.SplitSpaces().Length > 1)
            {
                Help(p); return;
            }
            string      map = Matcher.FindMaps(p, message);
            LevelConfig cfg;

            if (map == null)
            {
                return;
            }
            if (!LevelInfo.Check(p, data.Rank, map, "delete this map", out cfg))
            {
                return;
            }

            if (!LevelActions.Delete(p, map))
            {
                return;
            }
            Chat.MessageGlobal("Level {0} &Swas deleted", cfg.Color + map);
        }
        static void HandleGoto(Player p, string map, string ignored)
        {
            byte mapNum = 0;

            if (map.Length == 0)
            {
                map = "1";
            }

            if (!byte.TryParse(map, out mapNum))
            {
                p.MessageLines(gotoHelp); return;
            }
            map = GetLevelName(p, mapNum);

            if (LevelInfo.FindExact(map) == null)
            {
                LevelActions.Load(p, map, !Server.Config.AutoLoadMaps);
            }
            if (LevelInfo.FindExact(map) != null)
            {
                PlayerActions.ChangeMap(p, map);
            }
        }
Пример #26
0
 static void DoReload(Player p, Level lvl)
 {
     LevelActions.ReloadAll(lvl, p, true);
     Server.DoGC();
 }
Пример #27
0
        public override void Use(Player p, string message, CommandData data)
        {
            if (message.Length == 0)
            {
                LevelInfo.OutputBackups(p, p.level.MapName); return;
            }

            string[] args      = message.ToLower().SplitSpaces();
            string   mapArg    = args.Length > 1 ? args[0] : p.level.MapName;
            string   backupArg = args.Length > 1 ? args[1] : args[0];

            string path;

            if (backupArg == currentFlag)
            {
                path = LevelInfo.MapPath(mapArg);
                if (!LevelInfo.MapExists(mapArg))
                {
                    if (Directory.Exists(LevelInfo.BackupBasePath(mapArg)))
                    {
                        p.Message("&WLevel \"{0}\" does not currently exist, &Showever:", mapArg);
                        LevelInfo.OutputBackups(p, mapArg);
                    }
                    else
                    {
                        p.Message("&WLevel \"{0}\" does not exist and no backups could be found.", mapArg);
                    }
                    return;
                }
            }
            else
            {
                if (!Directory.Exists(LevelInfo.BackupBasePath(mapArg)))
                {
                    p.Message("Level \"{0}\" has no backups.", mapArg); return;
                }
                if (backupArg == latestFlag)
                {
                    int latest = LevelInfo.LatestBackup(mapArg);
                    if (latest == 0)
                    {
                        p.Message("&WLevel \"{0}\" does not have any numbered backups, " +
                                  "so the latest backup could not be determined.", mapArg);
                        return;
                    }
                    backupArg = latest.ToString();
                }
                path = LevelInfo.BackupFilePath(mapArg, backupArg);
            }
            if (!File.Exists(path))
            {
                p.Message("Backup \"{0}\" for {1} could not be found.", backupArg, mapArg); return;
            }

            string formattedMuseumName;

            if (backupArg == currentFlag)
            {
                formattedMuseumName = "&cMuseum &S(" + mapArg + ")";
            }
            else
            {
                formattedMuseumName = "&cMuseum &S(" + mapArg + " " + backupArg + ")";
            }

            if (p.level.name.CaselessEq(formattedMuseumName))
            {
                p.Message("You are already in this museum."); return;
            }
            if (Interlocked.CompareExchange(ref p.LoadingMuseum, 1, 0) == 1)
            {
                p.Message("You are already loading a museum level."); return;
            }

            try {
                Level lvl = LevelActions.LoadMuseum(p, formattedMuseumName, mapArg, path);
                PlayerActions.ChangeMap(p, lvl);
            } finally {
                Interlocked.Exchange(ref p.LoadingMuseum, 0);
            }
        }