Advertisement
ZrnecX

Untitled

Jun 14th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. //Maintenance Mode
  2. //By Tresdni (aka DxMonkey)
  3. //Last Update: 07/26/2015
  4.  
  5. using System;
  6. using System.Collections.Generic;
  7.  
  8. using Server.Commands;
  9. using Server.Gumps;
  10. using Server.Network;
  11.  
  12. namespace Server.Maintenance
  13. {
  14. public class MaintenanceMode
  15. {
  16. private static bool m_Enabled;
  17.  
  18. public static void Initialize()
  19. {
  20. EventSink.Login += EventSink_Login;
  21. CommandSystem.Register("maintenancemode", AccessLevel.Administrator, new CommandEventHandler(MaintenanceMode_OnCommand));
  22. CommandSystem.Register("mm", AccessLevel.Administrator, new CommandEventHandler(MaintenanceMode_OnCommand));
  23. }
  24.  
  25. private static void EventSink_Login(LoginEventArgs args)
  26. {
  27. Mobile m = args.Mobile;
  28.  
  29. if (!m_Enabled || m.AccessLevel >= AccessLevel.Counselor)
  30. {
  31. return;
  32. }
  33.  
  34. Timer.DelayCall(TimeSpan.FromSeconds(2.0), new TimerStateCallback(Disconnect), m);
  35. }
  36.  
  37. private static void MaintenanceMode_OnCommand(CommandEventArgs e)
  38. {
  39. if (m_Enabled)
  40. {
  41. m_Enabled = false;
  42. e.Mobile.SendMessage("Maintenance mode disabled. Players may now log in.");
  43. }
  44. else
  45. {
  46. m_Enabled = true;
  47. e.Mobile.SendMessage("Maintenance mode enabled. Players can no longer log in during this time.");
  48. List<NetState> states = NetState.Instances;
  49.  
  50. foreach (NetState t in states)
  51. {
  52. if (t != null && t.Running && t.Mobile.AccessLevel < AccessLevel.Counselor)
  53. {
  54. t.Mobile.SendGump(new MaintenanceModeGump());
  55. t.Dispose(true);
  56. }
  57. }
  58. }
  59. }
  60.  
  61. private static void Disconnect(object state)
  62. {
  63. Mobile m = (Mobile)state;
  64.  
  65. if (m.NetState == null || !m.NetState.Running)
  66. {
  67. return;
  68. }
  69.  
  70. m.SendGump(new MaintenanceModeGump());
  71. m.NetState.Dispose(true);
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement