Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CommandManager.RegisterCommand(CdGuestwipe);
- static readonly CommandDescriptor CdGuestwipe = new CommandDescriptor
- {
- Name = "guestwipe",
- Category = CommandCategory.World,
- Permissions = new[] { Permission.Guestwipe },
- IsConsoleSafe = true,
- Usage = "/guestwipe",
- Help = "Wipes a map with the name 'Guest'.",
- Handler = Guestwipe
- };
- internal static void Guestwipe(Player player, Command cmd)
- {
- string guestwipe = cmd.Next();
- if (guestwipe == null)
- {
- Scheduler.NewTask(t => Server.Players.Message("&9Warning! The Guest world will be wiped in 30 seconds.")).RunOnce(TimeSpan.FromSeconds(1));
- Scheduler.NewTask(t => Server.Players.Message("&9Warning! The Guest world will be wiped in 15 seconds.")).RunOnce(TimeSpan.FromSeconds(16));
- Scheduler.NewTask(t => player.Message("&4Prepare to use /ok when notified.")).RunOnce(TimeSpan.FromSeconds(25));
- Scheduler.NewTask(t => WorldLoadHandler(player, new Command("/wload2 guestwipe guest"))).RunOnce(TimeSpan.FromSeconds(30));
- }
- }
- //wload2
- static readonly CommandDescriptor CdWorldLoad2 = new CommandDescriptor
- {
- Name = "wload2",
- Aliases = new[] { "wadd2" },
- Category = CommandCategory.World,
- IsConsoleSafe = true,
- IsHidden = true,
- Permissions = new[] { Permission.Realm },
- Usage = "/wload FileName [WorldName]",
- Help = "Using this command could get you banned",
- Handler = WorldLoad2
- };
- internal static void WorldLoad2(Player player, Command cmd)
- {
- string fileName = cmd.Next();
- string worldName = cmd.Next();
- if (worldName == null && player.World == null)
- {
- player.Message("When using /wload from console, you must specify the world name.");
- return;
- }
- if (fileName == null)
- {
- // No params given at all
- CdWorldLoad.PrintUsage(player);
- return;
- }
- string fullFileName = WorldManager.FindMapFile(player, fileName);
- if (fullFileName == null) return;
- // Loading map into current world
- if (worldName == null)
- {
- if (!cmd.IsConfirmed)
- {
- player.Confirm(cmd, "About to replace THIS MAP with \"{0}\".", fileName);
- return;
- }
- Map map;
- try
- {
- map = MapUtility.Load(fullFileName);
- }
- catch (Exception ex)
- {
- player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message);
- return;
- }
- // Loading to current world
- player.World.ChangeMap(map);
- player.World.Players.Message(player, "{0}&S loaded a new map for this world.",
- player.ClassyName);
- player.MessageNow("New map loaded for the world {0}", player.World.ClassyName);
- Logger.Log("{0} loaded new map for world \"{1}\" from {2}", LogType.UserActivity,
- player.Name, player.World.Name, fileName);
- }
- else
- {
- // Loading to some other (or new) world
- if (!World.IsValidName(worldName))
- {
- player.MessageNow("Invalid world name: \"{0}\".", worldName);
- return;
- }
- lock (WorldManager.WorldListLock)
- {
- World world = WorldManager.FindWorldExact(worldName);
- if (world != null)
- {
- // Replacing existing world's map
- if (!cmd.IsConfirmed)
- {
- player.Confirm(cmd, "About to replace map for {0}&S with \"{1}\".",
- world.ClassyName, fileName);
- return;
- }
- Map map;
- try
- {
- map = MapUtility.Load(fullFileName);
- }
- catch (Exception ex)
- {
- player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message);
- return;
- }
- try
- {
- world.ChangeMap(map);
- }
- catch (WorldOpException ex)
- {
- Logger.Log("Could not complete WorldLoad operation: {0}", LogType.Error, ex.Message);
- player.Message("&WWLoad: {0}", ex.Message);
- return;
- }
- world.Players.Message(player, "{0}&S loaded a new map for the world {1}",
- player.ClassyName, world.ClassyName);
- player.MessageNow("New map for the world {0}&S has been loaded.", world.ClassyName);
- Logger.Log("{0} loaded new map for world \"{1}\" from {2}", LogType.UserActivity,
- player.Name, world.Name, fullFileName);
- }
- else
- {
- // Adding a new world
- string targetFullFileName = Path.Combine(Paths.MapPath, worldName + ".fcm");
- if (!cmd.IsConfirmed &&
- File.Exists(targetFullFileName) && // target file already exists
- !Paths.Compare(targetFullFileName, fullFileName))
- { // and is different from sourceFile
- player.Confirm(cmd, "A map named \"{0}\" already exists, and will be overwritten with \"{1}\".",
- Path.GetFileName(targetFullFileName), Path.GetFileName(fullFileName));
- return;
- }
- try
- {
- MapUtility.Load(fullFileName);
- }
- catch (Exception ex)
- {
- player.MessageNow("Could not load \"{0}\": {1}: {2}",
- fileName, ex.GetType().Name, ex.Message);
- return;
- }
- World newWorld;
- try
- {
- newWorld = WorldManager.AddWorld(player, worldName, null, false);
- }
- catch (WorldOpException ex)
- {
- player.Message("WLoad: {0}", ex.Message);
- return;
- }
- if (newWorld != null)
- {
- newWorld.BuildSecurity.MinRank = Rank.Parse(ConfigKey.DefaultBuildRank.GetString());
- Server.Message("{0}&S created a new world named {1}",
- player.ClassyName, newWorld.ClassyName);
- Logger.Log("{0} created a new world named \"{1}\" (loaded from \"{2}\")", LogType.UserActivity,
- player.Name, worldName, fileName);
- WorldManager.SaveWorldList();
- player.MessageNow("Reminder: New world's access permission is {0}+&S, and build permission is {1}+",
- newWorld.AccessSecurity.MinRank.ClassyName,
- newWorld.BuildSecurity.MinRank.ClassyName);
- }
- else
- {
- player.MessageNow("Failed to create a new world.");
- }
- }
- }
- }
- Server.RequestGC();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement