using HISP.Player; using System; using System.Collections.Generic; using System.Globalization; namespace HISP.Game.Chat { public class CommandRegister { private static List registeredComamnds = new List(); public static CommandRegister[] RegisteredCommands { get { return registeredComamnds.ToArray(); } } private Func commandCallback; public bool CmdRequiresAdmin; public bool CmdRequiresMod; public char CmdLetter; public string CmdName; public string CmdUsage; public CommandRegister(char cmdLetter, string cmdName, string cmdUsage, Func cmdCallback, bool cmdRequiresAdmin, bool cmdRequiresMod) { this.CmdLetter = cmdLetter; this.CmdName = cmdName.ToUpper(CultureInfo.InvariantCulture).Trim(); this.CmdUsage = cmdUsage; this.CmdRequiresMod = cmdRequiresMod; this.CmdRequiresAdmin = cmdRequiresAdmin; this.commandCallback = cmdCallback; registeredComamnds.Add(this); } public bool HasPermission(User user) { if (CmdRequiresAdmin && !(user.Administrator)) return false; if (CmdRequiresMod && !(user.Moderator || user.Administrator)) return false; return true; } public bool Execute(string message, string[] args, User user) { if(HasPermission(user)) return commandCallback(message, args, user); return false; } } }