These are chat archives for ikkentim/SampSharp

2nd
Jul 2015
Marco Acierno
@marcoacierno
Jul 02 2015 12:31
Ok convertffs seems very good
Marco Acierno
@marcoacierno
Jul 02 2015 13:33
Anyway, issue #123 is about adding the possibility to provide a custom usage format message?
Tim Potze
@ikkentim
Jul 02 2015 13:35
That's already possible, issue #123 is about a custom "permissions denied" message.
The command controller allows for custom usage messages
Tim Potze
@ikkentim
Jul 02 2015 13:35
I was faster ? :)
Florian van Dillen
@fvandillen
Jul 02 2015 13:35
Damn you Tim :smile:
Tim Potze
@ikkentim
Jul 02 2015 13:36
They were different links anyways :sparkles:
Marco Acierno
@marcoacierno
Jul 02 2015 13:57
oh ok :v
Marco Acierno
@marcoacierno
Jul 02 2015 16:24
My current implementation is to create another attribute PermissionCheckFailed added to the method which checks if the user has the ability to do so
but if we want to reuse the method and display another message this would be a problem
so maybe add another attribute in the Command like PermissionDeniedMessage?
but at the same time reuse the message message will be a nightmare if the user will need to change it (but he could use a constant variable, anyway)
Tim Potze
@ikkentim
Jul 02 2015 16:26
Sounds like a plan :+1:
Marco Acierno
@marcoacierno
Jul 02 2015 16:27
Like this
    [PermissionCheckFailed(Message = "You must be command!")]
    public static bool TestCommandPermission(GtaPlayer player)
    {
        return player.IsAdmin;
    }
Tim Potze
@ikkentim
Jul 02 2015 16:29
Yes, then this would also include the check which should be used.
Possibly it would be nice to create an interface IPermissionChecker { bool Check(GtaPlayer player); } with possibly some more options related to failure messages. Then this could be passed as a parameter in this attribute.
Marco Acierno
@marcoacierno
Jul 02 2015 16:36
something like
interface IPermissionChecker { bool Check(GtaPlayer player); }
Tim Potze
@ikkentim
Jul 02 2015 16:36
Yes.
Marco Acierno
@marcoacierno
Jul 02 2015 16:37
public class AdminCommandChecker : IPermissionChecker { bool Check(GtaPlayer player) { return player.IsAdmin; } }
and maybe a string GetMessage
then in the Command attribute
PermissionCheck = AdminCommandChecker.class (C# equivalent I don't know, I will search)
Tim Potze
@ikkentim
Jul 02 2015 16:37
 public interface IPermissionChecker
{
    string Message { get; }
    bool Check(GtaPlayer player);
}
Marco Acierno
@marcoacierno
Jul 02 2015 16:37
in this way users can put the check code somewhere else
yeah
Tim Potze
@ikkentim
Jul 02 2015 16:39
[PermissionCheck(typeof(MyChecker))]
Marco Acierno
@marcoacierno
Jul 02 2015 16:39
in the command method
Tim Potze
@ikkentim
Jul 02 2015 16:40
Yes.
Marco Acierno
@marcoacierno
Jul 02 2015 16:43
since every info about the permission check will be inside the class MyChecker, why we need another attribute? just because we don't want to clutter Command attribute? We just need the class to initialize
Tim Potze
@ikkentim
Jul 02 2015 16:43
Good question.
Might indeed want to put it in CommandAttribute.
Marco Acierno
@marcoacierno
Jul 02 2015 16:45
yeah, since we already have it too. PermissionCheckMethod will just become PermissionCheck with a different type
Tim Potze
@ikkentim
Jul 02 2015 16:45
Indeed
Florian van Dillen
@fvandillen
Jul 02 2015 16:48
I hear great stuff in the works!
Marco Acierno
@marcoacierno
Jul 02 2015 18:19
check this commit rrev/SampSharp@581805d
Tim Potze
@ikkentim
Jul 02 2015 20:02
:+1:
Nice one
Marco Acierno
@marcoacierno
Jul 02 2015 20:49
ok I created the PR #124