Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.73 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.Items.Wired;
  20. using Plus.HabboHotel.Rooms.Chat.Commands.Events;
  21.  
  22. namespace Plus.HabboHotel.Rooms.Chat.Commands
  23. {
  24. public class CommandManager
  25. {
  26. /// <summary>
  27. /// Command Prefix only applies to custom commands.
  28. /// </summary>
  29. private string _prefix = ":";
  30.  
  31. /// <summary>
  32. /// Commands registered for use.
  33. /// </summary>
  34. private readonly Dictionary<string, IChatCommand> _commands;
  35.  
  36. /// <summary>
  37. /// The default initializer for the CommandManager
  38. /// </summary>
  39. public CommandManager(string Prefix)
  40. {
  41. this._prefix = Prefix;
  42. this._commands = new Dictionary<string, IChatCommand>();
  43.  
  44. this.RegisterVIP();
  45. this.RegisterUser();
  46. this.RegisterModerator();
  47. this.RegisterAdministrator();
  48. }
  49.  
  50. /// <summary>
  51. /// Request the text to parse and check for commands that need to be executed.
  52. /// </summary>
  53. /// <param name="Session">Session calling this method.</param>
  54. /// <param name="Message">The message to parse.</param>
  55. /// <returns>True if parsed or false if not.</returns>
  56. public bool Parse(GameClient Session, string Message)
  57. {
  58. if (Session == null || Session.GetHabbo() == null || Session.GetHabbo().CurrentRoom == null)
  59. return false;
  60.  
  61. if (!Message.StartsWith(_prefix))
  62. return false;
  63.  
  64. if (Message == _prefix + "commands")
  65. {
  66. StringBuilder List = new StringBuilder();
  67. List.Append("These are the commands you have access to:\n");
  68. foreach (var CmdList in _commands.ToList())
  69. {
  70. if (!string.IsNullOrEmpty(CmdList.Value.PermissionRequired))
  71. {
  72. if (!Session.GetHabbo().GetPermissions().HasCommand(CmdList.Value.PermissionRequired))
  73. continue;
  74. }
  75.  
  76. List.Append(":" + CmdList.Key + " " + CmdList.Value.Parameters + " - " + CmdList.Value.Description + "\n");
  77. }
  78. Session.SendMessage(new MOTDNotificationComposer(List.ToString()));
  79. return true;
  80. }
  81.  
  82. Message = Message.Substring(1);
  83. string[] Split = Message.Split(' ');
  84.  
  85. if (Split.Length == 0)
  86. return false;
  87.  
  88. IChatCommand Cmd = null;
  89. if (_commands.TryGetValue(Split[0].ToLower(), out Cmd))
  90. {
  91. if (Session.GetHabbo().GetPermissions().HasRight("mod_tool"))
  92. this.LogCommand(Session.GetHabbo().Id, Message, Session.GetHabbo().MachineId);
  93.  
  94. if (!string.IsNullOrEmpty(Cmd.PermissionRequired))
  95. {
  96. if (!Session.GetHabbo().GetPermissions().HasCommand(Cmd.PermissionRequired))
  97. return false;
  98. }
  99.  
  100.  
  101. Session.GetHabbo().IChatCommand = Cmd;
  102. Session.GetHabbo().CurrentRoom.GetWired().TriggerEvent(WiredBoxType.TriggerUserSaysCommand, Session.GetHabbo(), this);
  103.  
  104. Cmd.Execute(Session, Session.GetHabbo().CurrentRoom, Split);
  105. return true;
  106. }
  107. return false;
  108. }
  109.  
  110. /// <summary>
  111. /// Registers the VIP set of commands.
  112. /// </summary>
  113. private void RegisterVIP()
  114. {
  115. this.Register("spull", new SuperPullCommand());
  116. this.Register("follow", new FollowCommand());
  117. this.Register("flagme", new FlagMeCommand());
  118. }
  119.  
  120. /// <summary>
  121. /// Registers the Events set of commands.
  122. /// </summary>
  123.  
  124. /// <summary>
  125. /// Registers the default set of commands.
  126. /// </summary>
  127. private void RegisterUser()
  128. {
  129. this.Register("online", new OnlineCommand()); // D
  130. this.Register("info", new InfoCommand());
  131. this.Register("pickall", new PickAllCommand());
  132. this.Register("ejectall", new EjectAllCommand());
  133. this.Register("lay", new LayCommand()); // D
  134. this.Register("sit", new SitCommand()); // D
  135. this.Register("stand", new StandCommand()); // D
  136. this.Register("mutepets", new MutePetsCommand());
  137. this.Register("mutebots", new MuteBotsCommand());
  138.  
  139. this.Register("mimic", new MimicCommand());
  140. this.Register("dance", new DanceCommand()); // D
  141. this.Register("push", new PushCommand()); // D
  142. this.Register("pull", new PullCommand()); // D
  143. this.Register("enable", new EnableCommand());
  144. this.Register("faceless", new FacelessCommand());
  145. this.Register("moonwalk", new MoonwalkCommand());
  146.  
  147. this.Register("unload", new UnloadCommand());
  148. this.Register("regenmaps", new RegenMaps());
  149. this.Register("emptyitems", new EmptyItems());
  150. this.Register("setmax", new SetMaxCommand());
  151. this.Register("setspeed", new SetSpeedCommand());
  152. this.Register("disablediagonal", new DisableDiagonalCommand());
  153.  
  154. this.Register("stats", new StatsCommand());
  155. this.Register("kickpets", new KickPetsCommand());
  156. this.Register("kickbots", new KickBotsCommand());
  157.  
  158. this.Register("room", new RoomCommand());
  159. this.Register("dnd", new DNDCommand());
  160. this.Register("disablegifts", new DisableGiftsCommand());
  161. this.Register("convertcredits", new ConvertCreditsCommand());
  162. this.Register("disablewhispers", new DisableWhispersCommand());
  163. this.Register("disablemimic", new DisableMimicCommand()); ;
  164.  
  165. this.Register("pet", new PetCommand());
  166. this.Register("spush", new SuperPushCommand());
  167. this.Register("superpush", new SuperPushCommand());
  168.  
  169. this.Register("afk", new AfkCommand());
  170. this.Register("back", new BackCommand()); // D
  171. this.Register("bans", new BanCountCommand()); // D
  172. this.Register("chatalert", new ChatAlertCommand()); // D
  173.  
  174. // Testing some commands
  175. this.Register("sellroom", new roomSellCommand());
  176. this.Register("buyroom", new roomBuyCommand());
  177. this.Register("declineoffer", new roomDeclineOffer());
  178. this.Register("acceptoffer", new roomAcceptOffer());
  179. this.Register("sex", new SexCommand());
  180. this.Register("smokeweed", new WeedCommand());
  181. this.Register("slapass", new SlapassCommand());
  182. this.Register("color", new ColorCommand());
  183.  
  184.  
  185. this.Register("hug", new HugCommand()); // D
  186. this.Register("kiss", new KissCommand()); // D
  187. this.Register("slap", new SlapCommand()); // D
  188. this.Register("badgewars", new badgeWarCommand()); // D
  189. this.Register("kickwars", new KickWarCommand()); // D
  190. this.Register("kp", new KickWarPlayerCommand()); // D
  191. this.Register("gt", new GiveTrustcommand()); // D
  192. this.Register("trusted", new TrustedCommand()); // D
  193. this.Register("21", new TwentyOneCommand()); // D
  194. this.Register("vakna", new WakeCommand()); // D
  195. this.Register("tb", new TakeBadgeCommand()); // D
  196. this.Register("wakeall", new WakeAllCommand()); // D
  197. this.Register("join", new JoinGame()); // D
  198. this.Register("youtube", new Youtube()); // D
  199. this.Register("marry", new RelationCommand());
  200. this.Register("rko", new RkoCommand());
  201. this.Register("jerkoff", new JerkOffCommand());
  202. this.Register("fartface", new FartFaceCommand());
  203. this.Register("highfive", new HighfiveCommand());
  204. this.Register("facepalm", new FacepalmCommand());
  205. this.Register("dropkick", new DropkickCommand());
  206. this.Register("cut", new CutCommand());
  207. this.Register("breakface", new BreakfaceCommand());
  208.  
  209.  
  210.  
  211. // this.Register("roomsit", new RoomSitCommand());
  212.  
  213. }
  214.  
  215. /// <summary>
  216. /// Registers the moderator set of commands.
  217. /// </summary>
  218. private void RegisterModerator()
  219. {
  220. this.Register("ban", new BanCommand());
  221. this.Register("mip", new MIPCommand());
  222. this.Register("ipban", new IPBanCommand());
  223.  
  224. this.Register("ui", new UserInfoCommand());
  225. this.Register("userinfo", new UserInfoCommand());
  226. this.Register("sa", new StaffAlertCommand());
  227. this.Register("unroommute", new RoomUnmuteCommand());
  228. this.Register("roommute", new RoomMuteCommand());
  229. this.Register("roombadge", new RoomBadgeCommand());
  230. this.Register("roomalert", new RoomAlertCommand());
  231. this.Register("roomkick", new RoomKickCommand());
  232. this.Register("mute", new MuteCommand());
  233. this.Register("smute", new MuteCommand());
  234. this.Register("unmute", new UnmuteCommand());
  235. this.Register("massbadge", new MassBadgeCommand());
  236. this.Register("massgive", new MassGiveCommand());
  237. this.Register("globalgive", new GlobalGiveCommand());
  238. this.Register("kick", new KickCommand());
  239. this.Register("skick", new KickCommand());
  240. this.Register("ha", new HotelAlertCommand());
  241. this.Register("hotelalert", new HotelAlertCommand());
  242. this.Register("hal", new HALCommand());
  243. this.Register("give", new GiveCommand());
  244. this.Register("givebadge", new GiveBadgeCommand());
  245. this.Register("dc", new DisconnectCommand());
  246. this.Register("kill", new DisconnectCommand());
  247. this.Register("disconnect", new DisconnectCommand());
  248. this.Register("alert", new AlertCommand());
  249. this.Register("tradeban", new TradeBanCommand());
  250.  
  251. this.Register("teleport", new TeleportCommand());
  252. this.Register("summon", new SummonCommand());
  253. this.Register("override", new OverrideCommand());
  254. this.Register("massenable", new MassEnableCommand());
  255. this.Register("massdance", new MassDanceCommand());
  256. this.Register("freeze", new FreezeCommand());
  257. this.Register("unfreeze", new UnFreezeCommand());
  258. this.Register("fastwalk", new FastwalkCommand());
  259. this.Register("superfastwalk", new SuperFastwalkCommand());
  260. this.Register("coords", new CoordsCommand());
  261. this.Register("alleyesonme", new AllEyesOnMeCommand());
  262. this.Register("allaroundme", new AllAroundMeCommand());
  263. this.Register("forcesit", new ForceSitCommand());
  264.  
  265. this.Register("ignorewhispers", new IgnoreWhispersCommand());
  266. this.Register("forced_effects", new DisableForcedFXCommand());
  267.  
  268. this.Register("makesay", new MakeSayCommand());
  269. this.Register("flaguser", new FlagUserCommand());
  270. this.Register("eventha", new EventAlerCommand()); // D
  271. this.Register("dicealert", new DiceAlertCommand());
  272. this.Register("takebadgestaff", new TakeBadgeStaffCommand()); // D
  273. this.Register("logmein", new LogMeInCommand()); // D
  274. this.Register("sethomeroom", new HomeroomCommand()); // D
  275. this.Register("ss", new StaffSayCommand()); // D
  276. this.Register("cmdlog", new CommandLogCommand()); // D
  277. }
  278.  
  279. /// <summary>
  280. /// Registers the administrator set of commands.
  281. /// </summary>
  282. private void RegisterAdministrator()
  283. {
  284. this.Register("bubble", new BubbleCommand());
  285. this.Register("update", new UpdateCommand());
  286. this.Register("deletegroup", new DeleteGroupCommand());
  287. this.Register("carry", new CarryCommand());
  288. this.Register("goto", new GOTOCommand());
  289.  
  290. this.Register("shutdown", new ShutdownCommand());
  291. this.Register("restart", new RestartCommand());
  292. this.Register("prison", new PrisonCommand());
  293. this.Register("unprison", new UnPrisonCommand());
  294. this.Register("officer", new OfficerCommand());
  295. this.Register("makeofficer", new MakeOfficerCommand());
  296. }
  297.  
  298. /// <summary>
  299. /// Registers a Chat Command.
  300. /// </summary>
  301. /// <param name="CommandText">Text to type for this command.</param>
  302. /// <param name="Command">The command to execute.</param>
  303. public void Register(string CommandText, IChatCommand Command)
  304. {
  305. this._commands.Add(CommandText, Command);
  306. }
  307.  
  308. public static string MergeParams(string[] Params, int Start)
  309. {
  310. var Merged = new StringBuilder();
  311. for (int i = Start; i < Params.Length; i++)
  312. {
  313. if (i > Start)
  314. Merged.Append(" ");
  315. Merged.Append(Params[i]);
  316. }
  317.  
  318. return Merged.ToString();
  319. }
  320.  
  321. public void LogCommand(int UserId, string Data, string MachineId)
  322. {
  323. using (IQueryAdapter dbClient = PlusEnvironment.GetDatabaseManager().GetQueryReactor())
  324. {
  325. dbClient.SetQuery("INSERT INTO `logs_client_staff` (`user_id`,`data_string`,`machine_id`, `timestamp`) VALUES (@UserId,@Data,@MachineId,@Timestamp)");
  326. dbClient.AddParameter("UserId", UserId);
  327. dbClient.AddParameter("Data", Data);
  328. dbClient.AddParameter("MachineId", MachineId);
  329. dbClient.AddParameter("Timestamp", PlusEnvironment.GetUnixTimestamp());
  330. dbClient.RunQuery();
  331. }
  332. }
  333.  
  334. public bool TryGetCommand(string Command, out IChatCommand IChatCommand)
  335. {
  336. return this._commands.TryGetValue(Command, out IChatCommand);
  337. }
  338. }
  339. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement