Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.69 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using System.Collections.Generic;
  5.  
  6. using Plus.Utilities;
  7. using Plus.HabboHotel.Rooms;
  8. using Plus.HabboHotel.GameClients;
  9.  
  10. using Plus.HabboHotel.Rooms.Chat.Commands.User;
  11. using Plus.HabboHotel.Rooms.Chat.Commands.User.Fun;
  12. using Plus.HabboHotel.Rooms.Chat.Commands.Moderator;
  13. using Plus.HabboHotel.Rooms.Chat.Commands.Moderator.Fun;
  14. using Plus.HabboHotel.Rooms.Chat.Commands.Administrator;
  15.  
  16. using Plus.Communication.Packets.Outgoing.Rooms.Chat;
  17. using Plus.Communication.Packets.Outgoing.Notifications;
  18. using Plus.Database.Interfaces;
  19. using Plus.HabboHotel.Rooms.Chat.Commands.Events;
  20. using Plus.HabboHotel.Items.Wired;
  21.  
  22.  
  23. namespace Plus.HabboHotel.Rooms.Chat.Commands
  24. {
  25. public class CommandManager
  26. {
  27. /// <summary>
  28. /// Command Prefix only applies to custom commands.
  29. /// </summary>
  30. private string _prefix = ":";
  31.  
  32. /// <summary>
  33. /// Commands registered for use.
  34. /// </summary>
  35. private readonly Dictionary<string, IChatCommand> _commands;
  36.  
  37. /// <summary>
  38. /// The default initializer for the CommandManager
  39. /// </summary>
  40. public CommandManager(string Prefix)
  41. {
  42. this._prefix = Prefix;
  43. this._commands = new Dictionary<string, IChatCommand>();
  44.  
  45. this.RegisterVIP();
  46. this.RegisterUser();
  47. this.RegisterEvents();
  48. this.RegisterModerator();
  49. this.RegisterAdministrator();
  50. }
  51.  
  52. /// <summary>
  53. /// Request the text to parse and check for commands that need to be executed.
  54. /// </summary>
  55. /// <param name="Session">Session calling this method.</param>
  56. /// <param name="Message">The message to parse.</param>
  57. /// <returns>True if parsed or false if not.</returns>
  58. public bool Parse(GameClient Session, string Message)
  59. {
  60. if (Session == null || Session.GetHabbo() == null || Session.GetHabbo().CurrentRoom == null)
  61. return false;
  62.  
  63. if (!Message.StartsWith(_prefix))
  64. return false;
  65.  
  66. if (Message == _prefix + "comandos")
  67. {
  68. StringBuilder List = new StringBuilder();
  69. List.Append("Esta é a lista de comandos que você tem disponível:\r\n");
  70. foreach (var CmdList in _commands.ToList())
  71. {
  72. if (!string.IsNullOrEmpty(CmdList.Value.PermissionRequired))
  73. {
  74. if (!Session.GetHabbo().GetPermissions().HasCommand(CmdList.Value.PermissionRequired))
  75. continue;
  76. }
  77.  
  78. List.Append(":" + CmdList.Key + " " + CmdList.Value.Parameters + " - " + CmdList.Value.Description + "\r\n");
  79. }
  80. Session.SendMessage(new MOTDNotificationComposer(List.ToString()));
  81. return true;
  82. }
  83.  
  84. Message = Message.Substring(1);
  85. string[] Split = Message.Split(' ');
  86.  
  87. if (Split.Length == 0)
  88. return false;
  89.  
  90. IChatCommand Cmd = null;
  91. if (_commands.TryGetValue(Split[0].ToLower(), out Cmd))
  92. {
  93. if (Session.GetHabbo().GetPermissions().HasRight("mod_tool"))
  94. this.LogCommand(Session.GetHabbo().Id, Message, Session.GetHabbo().MachineId);
  95.  
  96. if (!string.IsNullOrEmpty(Cmd.PermissionRequired))
  97. {
  98. if (!Session.GetHabbo().GetPermissions().HasCommand(Cmd.PermissionRequired))
  99. return false;
  100. }
  101.  
  102.  
  103. Session.GetHabbo().IChatCommand = Cmd;
  104. Session.GetHabbo().CurrentRoom.GetWired().TriggerEvent(WiredBoxType.TriggerUserSaysCommand, Session.GetHabbo(), this);
  105.  
  106. Cmd.Execute(Session, Session.GetHabbo().CurrentRoom, Split);
  107. return true;
  108. }
  109. return false;
  110. }
  111.  
  112. /// <summary>
  113. /// Registers the VIP set of commands.
  114. /// </summary>
  115. private void RegisterVIP()
  116. {
  117. this.Register("spull", new SuperPullCommand());
  118. }
  119.  
  120. /// <summary>
  121. /// Registers the Events set of commands.
  122. /// </summary>
  123. private void RegisterEvents()
  124. {
  125. this.Register("eha", new EventAlertCommand());
  126. this.Register("eventalert", new EventAlertCommand());
  127. }
  128.  
  129. /// <summary>
  130. /// Registers the default set of commands.
  131. /// </summary>
  132. private void RegisterUser()
  133. {
  134. this.Register("about", new InfoCommand());
  135. this.Register("pickall", new PickAllCommand());
  136. this.Register("ejectall", new EjectAllCommand());
  137. this.Register("lay", new LayCommand());
  138. this.Register("sit", new SitCommand());
  139. this.Register("stand", new StandCommand());
  140. this.Register("mutepets", new MutePetsCommand());
  141. this.Register("mutebots", new MuteBotsCommand());
  142.  
  143. this.Register("copy", new MimicCommand());
  144. this.Register("dance", new DanceCommand());
  145. this.Register("push", new PushCommand());
  146. this.Register("pull", new PullCommand());
  147. this.Register("enable", new EnableCommand());
  148. this.Register("follow", new FollowCommand());
  149. this.Register("faceless", new FacelessCommand());
  150. this.Register("moonwalk", new MoonwalkCommand());
  151.  
  152. this.Register("unload", new UnloadCommand());
  153. this.Register("regenmaps", new RegenMaps());
  154. this.Register("empty", new EmptyItems());
  155. this.Register("setmax", new SetMaxCommand());
  156. this.Register("setspeed", new SetSpeedCommand());
  157. this.Register("disablediagonal", new DisableDiagonalCommand());
  158. this.Register("flagme", new FlagMeCommand());
  159.  
  160. this.Register("stats", new StatsCommand());
  161. this.Register("kickpets", new KickPetsCommand());
  162. this.Register("kickbots", new KickBotsCommand());
  163.  
  164. this.Register("room", new RoomCommand());
  165. this.Register("dnd", new DNDCommand());
  166. this.Register("disablegifts", new DisableGiftsCommand());
  167. this.Register("convertcredits", new ConvertCreditsCommand());
  168. this.Register("disablewhispers", new DisableWhispersCommand());
  169. this.Register("disablemimic", new DisableMimicCommand()); ;
  170.  
  171. this.Register("pet", new PetCommand());
  172. this.Register("spush", new SuperPushCommand());
  173. this.Register("superpush", new SuperPushCommand());
  174.  
  175. }
  176.  
  177. /// <summary>
  178. /// Registers the moderator set of commands.
  179. /// </summary>
  180. private void RegisterModerator()
  181. {
  182. this.Register("ban", new BanCommand());
  183. this.Register("mip", new MIPCommand());
  184. this.Register("ipban", new IPBanCommand());
  185.  
  186.  
  187. this.Register("ui", new UserInfoCommand());
  188. this.Register("userinfo", new UserInfoCommand());
  189. this.Register("sa", new StaffAlertCommand());
  190. this.Register("roomunmute", new RoomUnmuteCommand());
  191. this.Register("roommute", new RoomMuteCommand());
  192. this.Register("roombadge", new RoomBadgeCommand());
  193. this.Register("roomalert", new RoomAlertCommand());
  194. this.Register("roomkick", new RoomKickCommand());
  195. this.Register("mute", new MuteCommand());
  196. this.Register("smute", new MuteCommand());
  197. this.Register("unmute", new UnmuteCommand());
  198. this.Register("massbadge", new MassBadgeCommand());
  199. this.Register("kick", new KickCommand());
  200. this.Register("skick", new KickCommand());
  201. this.Register("ha", new HotelAlertCommand());
  202. this.Register("hotelalert", new HotelAlertCommand());
  203. this.Register("hal", new HALCommand());
  204. this.Register("give", new GiveCommand());
  205. this.Register("givebadge", new GiveBadgeCommand());
  206. this.Register("dc", new DisconnectCommand());
  207. this.Register("kill", new DisconnectCommand());
  208. this.Register("disconnect", new DisconnectCommand());
  209. this.Register("alert", new AlertCommand());
  210. this.Register("tradeban", new TradeBanCommand());
  211.  
  212. this.Register("teleport", new TeleportCommand());
  213. this.Register("summon", new SummonCommand());
  214. this.Register("override", new OverrideCommand());
  215. this.Register("massenable", new MassEnableCommand());
  216. this.Register("massdance", new MassDanceCommand());
  217. this.Register("freeze", new FreezeCommand());
  218. this.Register("unfreeze", new UnFreezeCommand());
  219. this.Register("fastwalk", new FastwalkCommand());
  220. this.Register("superfastwalk", new SuperFastwalkCommand());
  221. this.Register("coords", new CoordsCommand());
  222. this.Register("alleyesonme", new AllEyesOnMeCommand());
  223. this.Register("allaroundme", new AllAroundMeCommand());
  224. this.Register("forcesit", new ForceSitCommand());
  225.  
  226. this.Register("ignorewhispers", new IgnoreWhispersCommand());
  227. this.Register("forced_effects", new DisableForcedFXCommand());
  228.  
  229. this.Register("makesay", new MakeSayCommand());
  230. this.Register("flaguser", new FlagUserCommand());
  231. }
  232.  
  233. /// <summary>
  234. /// Registers the administrator set of commands.
  235. /// </summary>
  236. private void RegisterAdministrator()
  237. {
  238. this.Register("bubble", new BubbleCommand());
  239. this.Register("update", new UpdateCommand());
  240. this.Register("deletegroup", new DeleteGroupCommand());
  241. this.Register("handitem", new CarryCommand());
  242. this.Register("goto", new GOTOCommand());
  243. }
  244.  
  245. /// <summary>
  246. /// Registers a Chat Command.
  247. /// </summary>
  248. /// <param name="CommandText">Text to type for this command.</param>
  249. /// <param name="Command">The command to execute.</param>
  250. public void Register(string CommandText, IChatCommand Command)
  251. {
  252. this._commands.Add(CommandText, Command);
  253. }
  254.  
  255. public static string MergeParams(string[] Params, int Start)
  256. {
  257. var Merged = new StringBuilder();
  258. for (int i = Start; i < Params.Length; i++)
  259. {
  260. if (i > Start)
  261. Merged.Append(" ");
  262. Merged.Append(Params[i]);
  263. }
  264.  
  265. return Merged.ToString();
  266. }
  267.  
  268. public void LogCommand(int UserId, string Data, string MachineId)
  269. {
  270. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  271. {
  272. dbClient.SetQuery("INSERT INTO `logs_client_staff` (`user_id`,`data_string`,`machine_id`, `timestamp`) VALUES (@UserId,@Data,@MachineId,@Timestamp)");
  273. dbClient.AddParameter("UserId", UserId);
  274. dbClient.AddParameter("Data", Data);
  275. dbClient.AddParameter("MachineId", MachineId);
  276. dbClient.AddParameter("Timestamp", PlusEnvironment.GetUnixTimestamp());
  277. dbClient.RunQuery();
  278. }
  279. }
  280.  
  281. public bool TryGetCommand(string Command, out IChatCommand IChatCommand)
  282. {
  283. return this._commands.TryGetValue(Command, out IChatCommand);
  284. }
  285. }
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement