Advertisement
Guest User

guestwipe

a guest
Sep 18th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.68 KB | None | 0 0
  1. CommandManager.RegisterCommand(CdGuestwipe);
  2.  
  3.  
  4. static readonly CommandDescriptor CdGuestwipe = new CommandDescriptor
  5. {
  6. Name = "guestwipe",
  7.  
  8. Category = CommandCategory.World,
  9. Permissions = new[] { Permission.Guestwipe },
  10. IsConsoleSafe = true,
  11. Usage = "/guestwipe",
  12. Help = "Wipes a map with the name 'Guest'.",
  13. Handler = Guestwipe
  14. };
  15.  
  16. internal static void Guestwipe(Player player, Command cmd)
  17. {
  18. string guestwipe = cmd.Next();
  19. if (guestwipe == null)
  20. {
  21. Scheduler.NewTask(t => Server.Players.Message("&9Warning! The Guest world will be wiped in 30 seconds.")).RunOnce(TimeSpan.FromSeconds(1));
  22. Scheduler.NewTask(t => Server.Players.Message("&9Warning! The Guest world will be wiped in 15 seconds.")).RunOnce(TimeSpan.FromSeconds(16));
  23. Scheduler.NewTask(t => player.Message("&4Prepare to use /ok when notified.")).RunOnce(TimeSpan.FromSeconds(25));
  24. Scheduler.NewTask(t => WorldLoadHandler(player, new Command("/wload2 guestwipe guest"))).RunOnce(TimeSpan.FromSeconds(30));
  25. }
  26. }
  27.  
  28.  
  29. //wload2
  30.  
  31.  
  32.  
  33. static readonly CommandDescriptor CdWorldLoad2 = new CommandDescriptor
  34. {
  35. Name = "wload2",
  36. Aliases = new[] { "wadd2" },
  37. Category = CommandCategory.World,
  38. IsConsoleSafe = true,
  39. IsHidden = true,
  40. Permissions = new[] { Permission.Realm },
  41. Usage = "/wload FileName [WorldName]",
  42. Help = "Using this command could get you banned",
  43. Handler = WorldLoad2
  44. };
  45.  
  46.  
  47. internal static void WorldLoad2(Player player, Command cmd)
  48. {
  49. string fileName = cmd.Next();
  50. string worldName = cmd.Next();
  51.  
  52. if (worldName == null && player.World == null)
  53. {
  54. player.Message("When using /wload from console, you must specify the world name.");
  55. return;
  56. }
  57.  
  58. if (fileName == null)
  59. {
  60. // No params given at all
  61. CdWorldLoad.PrintUsage(player);
  62. return;
  63. }
  64.  
  65. string fullFileName = WorldManager.FindMapFile(player, fileName);
  66. if (fullFileName == null) return;
  67.  
  68. // Loading map into current world
  69. if (worldName == null)
  70. {
  71. if (!cmd.IsConfirmed)
  72. {
  73. player.Confirm(cmd, "About to replace THIS MAP with \"{0}\".", fileName);
  74. return;
  75. }
  76. Map map;
  77. try
  78. {
  79. map = MapUtility.Load(fullFileName);
  80. }
  81. catch (Exception ex)
  82. {
  83. player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message);
  84. return;
  85. }
  86.  
  87. // Loading to current world
  88. player.World.ChangeMap(map);
  89. player.World.Players.Message(player, "{0}&S loaded a new map for this world.",
  90. player.ClassyName);
  91. player.MessageNow("New map loaded for the world {0}", player.World.ClassyName);
  92.  
  93. Logger.Log("{0} loaded new map for world \"{1}\" from {2}", LogType.UserActivity,
  94. player.Name, player.World.Name, fileName);
  95.  
  96.  
  97. }
  98. else
  99. {
  100. // Loading to some other (or new) world
  101. if (!World.IsValidName(worldName))
  102. {
  103. player.MessageNow("Invalid world name: \"{0}\".", worldName);
  104. return;
  105. }
  106.  
  107. lock (WorldManager.WorldListLock)
  108. {
  109. World world = WorldManager.FindWorldExact(worldName);
  110. if (world != null)
  111. {
  112. // Replacing existing world's map
  113. if (!cmd.IsConfirmed)
  114. {
  115. player.Confirm(cmd, "About to replace map for {0}&S with \"{1}\".",
  116. world.ClassyName, fileName);
  117. return;
  118. }
  119.  
  120. Map map;
  121. try
  122. {
  123. map = MapUtility.Load(fullFileName);
  124. }
  125. catch (Exception ex)
  126. {
  127. player.MessageNow("Could not load specified file: {0}: {1}", ex.GetType().Name, ex.Message);
  128. return;
  129. }
  130.  
  131. try
  132. {
  133. world.ChangeMap(map);
  134. }
  135. catch (WorldOpException ex)
  136. {
  137. Logger.Log("Could not complete WorldLoad operation: {0}", LogType.Error, ex.Message);
  138. player.Message("&WWLoad: {0}", ex.Message);
  139. return;
  140. }
  141.  
  142. world.Players.Message(player, "{0}&S loaded a new map for the world {1}",
  143. player.ClassyName, world.ClassyName);
  144. player.MessageNow("New map for the world {0}&S has been loaded.", world.ClassyName);
  145. Logger.Log("{0} loaded new map for world \"{1}\" from {2}", LogType.UserActivity,
  146. player.Name, world.Name, fullFileName);
  147.  
  148. }
  149. else
  150. {
  151. // Adding a new world
  152. string targetFullFileName = Path.Combine(Paths.MapPath, worldName + ".fcm");
  153. if (!cmd.IsConfirmed &&
  154. File.Exists(targetFullFileName) && // target file already exists
  155. !Paths.Compare(targetFullFileName, fullFileName))
  156. { // and is different from sourceFile
  157. player.Confirm(cmd, "A map named \"{0}\" already exists, and will be overwritten with \"{1}\".",
  158. Path.GetFileName(targetFullFileName), Path.GetFileName(fullFileName));
  159. return;
  160. }
  161.  
  162. try
  163. {
  164. MapUtility.Load(fullFileName);
  165. }
  166. catch (Exception ex)
  167. {
  168. player.MessageNow("Could not load \"{0}\": {1}: {2}",
  169. fileName, ex.GetType().Name, ex.Message);
  170. return;
  171. }
  172.  
  173. World newWorld;
  174. try
  175. {
  176. newWorld = WorldManager.AddWorld(player, worldName, null, false);
  177. }
  178. catch (WorldOpException ex)
  179. {
  180. player.Message("WLoad: {0}", ex.Message);
  181. return;
  182. }
  183.  
  184. if (newWorld != null)
  185. {
  186. newWorld.BuildSecurity.MinRank = Rank.Parse(ConfigKey.DefaultBuildRank.GetString());
  187. Server.Message("{0}&S created a new world named {1}",
  188. player.ClassyName, newWorld.ClassyName);
  189. Logger.Log("{0} created a new world named \"{1}\" (loaded from \"{2}\")", LogType.UserActivity,
  190. player.Name, worldName, fileName);
  191. WorldManager.SaveWorldList();
  192. player.MessageNow("Reminder: New world's access permission is {0}+&S, and build permission is {1}+",
  193. newWorld.AccessSecurity.MinRank.ClassyName,
  194. newWorld.BuildSecurity.MinRank.ClassyName);
  195. }
  196. else
  197. {
  198. player.MessageNow("Failed to create a new world.");
  199. }
  200. }
  201. }
  202. }
  203.  
  204. Server.RequestGC();
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement