public virtual async Task SetPermissionAsync(string commandName, PermissionLevel level) { using (var db = new Database()) { var match = CommandService.Commands.FirstOrDefault(x => x.Name.Equals(commandName, System.StringComparison.OrdinalIgnoreCase) || x.Aliases.Any(a => a.Equals(commandName, System.StringComparison.OrdinalIgnoreCase))); if (match == null) { await SimpleEmbedAsync("Unknown command name.", Color.Red); return; } if (!match.Preconditions.Any(x => x is RequirePermission)) { await SimpleEmbedAsync("This command cannot have it's permission overwritten."); return; } var permission = new CommandPermission { GuildId = Context.Guild.Id, CommandName = match.Name.ToLower(), Level = level }; db.Permissions.Add(permission); if (PermissionService.PermissionCache.TryGetValue(Context.Guild.Id, out var cache)) { cache.Cache.Remove(match.Name.ToLower()); } db.SaveChanges(); await SimpleEmbedAsync($"{match.Name} permission level set to: {level}", Color.Blue); } }
public object HandleCommand(Player player, string commandName, string commandOverload, dynamic commandInputJson) { Log.Debug($"HandleCommand {commandName}"); try { Command command = null; if (Commands.ContainsKey(commandName)) { command = Commands[commandName]; } else { command = Commands.Values.FirstOrDefault(cmd => cmd.Versions.Any(version => version.Aliases != null && version.Aliases.Any(s => s == commandName))); } if (command == null) { Log.Warn($"Found no command handler for {commandName}"); return(null); } Overload overload = command.Versions.First().Overloads[commandOverload]; CommandPermission requiredPermission = (CommandPermission)Enum.Parse(typeof(CommandPermission), command.Versions.First().Permission, true); if (player.CommandPermission < requiredPermission) { Log.Debug($"Insufficient permissions. Require {requiredPermission} but player had {player.CommandPermission}"); return(null); } MethodInfo method = overload.Method; List <string> strings = new List <string>(); if (commandInputJson != null) { foreach (ParameterInfo parameter in method.GetParameters()) { if (typeof(Player).IsAssignableFrom(parameter.ParameterType)) { continue; } if (HasProperty(commandInputJson, parameter.Name)) { Log.Debug($"Parameter: {commandInputJson[ToCamelCase(parameter.Name)].ToString()}"); strings.Add(commandInputJson[ToCamelCase(parameter.Name)].ToString()); } } } return(ExecuteCommand(method, player, strings.ToArray())); } catch (Exception e) { Log.Error("Handle JSON command", e); } return(null); }
public CommandPermission GetCommandPermission(string permission) { CommandPermission p = CommandPermission.Normal; switch (permission.ToLower()) { case "normal": p = CommandPermission.Normal; break; case "halfoperator": p = CommandPermission.HalfOperator; break; case "operator": p = CommandPermission.Operator; break; case "administrator": p = CommandPermission.Administrator; break; } return(p); }
/// <summary> /// Marks a method as a parameterized Alaris sub-command. /// </summary> /// <param name="command">Alaris command.</param> /// <param name="permission">Access permission.</param> /// <param name="numParams">Number of parameters.</param> /// <param name="isParamCountUnknown">Specifies whether the parameter count for this command unknown or not.</param> public ParameterizedAlarisSubCommand(string command, CommandPermission permission = CommandPermission.Normal, int numParams = 1, bool isParamCountUnknown = false) : base(command, permission) { Command = command; Permission = permission; ParameterCount = numParams; IsParameterCountUnspecified = (isParamCountUnknown && numParams == 0); }
/// <summary> /// Default constructor, sets the CommandPermission and CommandSecurity delegates /// so that they always return true (okay) /// </summary> /// <param name="theCommand"></param> /// <param name="theFunc"></param> public CommandAndFunction(String theCommand, CommandFunction theFunc) { command = theCommand; function = theFunc; permission = delegate(MemoryStream a, StxEtxHandler b) { return(true); }; security = delegate(MemoryStream a, StxEtxHandler b) { return(true); }; }
public object HandleCommand(Player player, string cmdline) { var split = Regex.Split(cmdline, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)").Select(s => s.Trim('"')).ToArray(); string commandName = split[0].Trim('/'); string[] arguments = split.Skip(1).ToArray(); Command command = null; command = GetCommand(commandName); //if (arguments.Length > 0 && command == null) //{ // commandName = commandName + " " + arguments[0]; // arguments = arguments.Skip(1).ToArray(); // command = GetCommand(commandName); //} if (command == null) { Log.Warn($"Found no command {commandName}"); return(null); } foreach (var overload in command.Versions.First().Overloads.Values.OrderByDescending(o => o.Input.Parameters?.Length ?? 0)) { var args = arguments; if (args.Length > 0 && overload.Input.Parameters.FirstOrDefault(p => p.Name.Equals("subcommand")) != null) { string subCommand = args[0]; if (overload.Input.Parameters.FirstOrDefault(p => p.Name.Equals("subcommand") && p.EnumValues[0] == subCommand) == null) { continue; } args = args.Skip(1).ToArray(); } CommandPermission requiredPermission = (CommandPermission)Enum.Parse(typeof(CommandPermission), command.Versions.First().Permission, true); if (player.CommandPermission < requiredPermission) { Log.Debug($"Insufficient permissions. Require {requiredPermission} but player had {player.CommandPermission}"); return(null); } MethodInfo method = overload.Method; var retVal = ExecuteCommand(method, player, args); if (retVal != null) { return(retVal); } Log.Debug("No result from execution"); } return(null); }
public override void ProcessClient() { switch (Action) { case PermissionGroupAction.List: CommandPermission.ShowGroupList(Groups, MemberNames); break; } }
/// <summary> /// /// </summary> /// <param name="theCommand"></param> /// <param name="theFunc"></param> /// <param name="permissionCheck">this function is called before theCommand(); return true to indicate that the STX handler has permission to call theCommand()</param> /// <param name="securityCheck">this function is called before theCommand(); return true to indicate that the STX handler's ClientContext is secure enought to call theCommand()</param> public CommandAndFunction(String theCommand, CommandFunction theFunc, CommandPermission permissionCheck, CommandSecurity securityCheck) { command = theCommand; function = theFunc; permission = permissionCheck; security = securityCheck; }
public void SchumixRegisterHandler(string code, CommandDelegate method, CommandPermission permission = CommandPermission.Normal) { lock (Lock) { foreach (var nw in _networks) { nw.Value.SchumixRegisterHandler(code, method, permission); } } }
public void SchumixRegisterHandler(string code, CommandDelegate method, CommandPermission permission = CommandPermission.Normal) { if(sIgnoreCommand.IsIgnore(code)) return; if(CommandMethodMap.ContainsKey(code.ToLower())) CommandMethodMap[code.ToLower()].Method += method; else CommandMethodMap.Add(code.ToLower(), new CommandMethod(method, permission)); }
public override void ProcessClient() { switch (CommandAction) { case CommandActions.Level: foreach (CommandStruct command in Commands) { ChatCommandService.UpdateCommandSecurity(command); } break; case CommandActions.List: CommandPermission.ShowCommandList(Commands); break; } }
public void SchumixRegisterHandler(string code, CommandDelegate method, CommandPermission permission = CommandPermission.Normal) { if (sIgnoreCommand.IsIgnore(code)) { return; } if (CommandMethodMap.ContainsKey(code.ToLower())) { CommandMethodMap[code.ToLower()].Method += method; } else { CommandMethodMap.Add(code.ToLower(), new CommandMethod(method, permission)); } }
public object HandleCommand(Player player, string cmdline) { var split = Regex.Split(cmdline, "(?<=^[^\"]*(?:\"[^\"]*\"[^\"]*)*) (?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)").Select(s => s.Trim('"')).ToArray(); string commandName = split[0].Trim('/'); string[] arguments = split.Skip(1).ToArray(); Command command = null; if (Commands.ContainsKey(commandName)) { command = Commands[commandName]; } else { command = Commands.Values.FirstOrDefault(cmd => cmd.Versions.Any(version => version.Aliases != null && version.Aliases.Any(s => s == commandName))); } if (command == null) { return(null); } foreach (var overload in command.Versions.First().Overloads.Values) { CommandPermission requiredPermission = (CommandPermission)Enum.Parse(typeof(CommandPermission), command.Versions.First().Permission, true); if (player.CommandPermission < requiredPermission) { Log.Debug($"Insufficient permissions. Require {requiredPermission} but player had {player.CommandPermission}"); return(null); } MethodInfo method = overload.Method; var retVal = ExecuteCommand(method, player, arguments); if (retVal != null) { return(retVal); } } return(null); }
public void RegisterSchumixHook(string CommandName, string LuaName, CommandPermission permission = CommandPermission.Normal) { var func = _lua.GetFunction(typeof(CommandDelegate), LuaName); if (func.IsNull()) { return; } var handler = func as CommandDelegate; if (_RegisteredSchumix.ContainsKey(CommandName.ToLower())) { _RegisteredSchumix[CommandName.ToLower()].Method += handler; } else { _RegisteredSchumix.Add(CommandName.ToLower(), new SchumixCommandMethod(handler, permission)); } sIrcBase.SchumixRegisterHandler(CommandName, handler, permission); }
public override void ProcessClient() { switch (Action) { case PlayerPermissionAction.Level: ChatCommandService.UserSecurity = PlayerLevel; //allow cmds now ChatCommandLogic.Instance.BlockCommandExecution = false; //and stop further requests if (ChatCommandLogic.Instance.PermissionRequestTimer != null) { ChatCommandLogic.Instance.PermissionRequestTimer.Stop(); ChatCommandLogic.Instance.PermissionRequestTimer.Close(); } break; case PlayerPermissionAction.List: CommandPermission.ShowPlayerList(PlayerPermissions); break; } }
/// <summary> /// Marks a method as an Schumix command. /// </summary> /// <param name="command">The command corresponding to this method.</param> /// <param name="permission">Command's access permission</param> public SchumixCommandAttribute(string command, CommandPermission permission = CommandPermission.Normal) { Command = command.ToLower(); Permission = permission; }
public void RegisterSchumixHook(string CommandName, string LuaName, CommandPermission permission = CommandPermission.Normal) { var func = _lua.GetFunction(typeof(CommandDelegate), LuaName); if(func.IsNull()) return; var handler = func as CommandDelegate; if(_RegisteredSchumix.ContainsKey(CommandName.ToLower())) _RegisteredSchumix[CommandName.ToLower()].Method += handler; else _RegisteredSchumix.Add(CommandName.ToLower(), new SchumixCommandMethod(handler, permission)); sIrcBase.SchumixRegisterHandler(CommandName, handler, permission); }
public CommandMethod(CommandDelegate method, CommandPermission permission = CommandPermission.Normal) { Method = method; Permission = permission; }
public void SchumixRegisterHandler(string code, CommandDelegate method, CommandPermission permission = CommandPermission.Normal) { lock(Lock) { foreach(var nw in _networks) nw.Value.SchumixRegisterHandler(code, method, permission); } }
public RolePermission(int roleId, CommandPermission permissionId) { RoleId = roleId; PermissionId = permissionId; }
public SchumixCommandMethod(CommandDelegate method, CommandPermission permission = CommandPermission.Normal) { Method = method; Permission = permission; }