SampSharp icon indicating copy to clipboard operation
SampSharp copied to clipboard

fix(ecs): Make commands case-insensitive

Open DevD4v3 opened this issue 1 year ago • 6 comments

Resolves #439

DevD4v3 avatar Aug 25 '24 20:08 DevD4v3

This would make all commands case-insensitive instead of allowing commands to be case-insensitive. Might be good to make it a configuration option on EcsBuilder

ikkentim avatar Mar 01 '25 20:03 ikkentim

@ikkentim This is the expected behavior. All SA-MP server commands are case-insensitive. In my opinion, this should not be a configuration option. This should be the default behavior, otherwise the Principle of least astonishment would be violated.

PD: I have updated the title of the PR, it is a fix rather than a feature.

DevD4v3 avatar Mar 16 '25 12:03 DevD4v3

@ikkentim This is the expected behavior. All SA-MP server commands are case-insensitive. In my opinion, this should not be a configuration option. This should be the default behavior, otherwise the Principle of least astonishment would be violated.

When you use OnPlayerCommandText, it's up to you to decide how to handle the command text, including case sensitive, isn't it? Even strcmp accepts such a parameter. Command processors and the fact that it is a de facto standard is another matter

bssth avatar Mar 16 '25 12:03 bssth

In my opinion (...) This should be the default behavior

You counter your own point here, besides, it would be a breaking change due to behavioral changes in existing systems

ikkentim avatar Mar 16 '25 12:03 ikkentim

Yes, it is a breaking change, but it is worth it, and even if we use a configuration option, it also introduces a breaking change, because we would have to inject an EcsOptions class in the CommandServiceBase constructor.

PD: To merge this PR, tell me specifically what I need to modify.

DevD4v3 avatar Mar 16 '25 13:03 DevD4v3

the easiest way would be a simple extension on IEcsBuilder.

public static class CommandEcsBuilderExtensions
{
    // note: default values in parameters reflect the default
    // todo: xml doc block
    public static IEcsBuilder ConfigureCommandService(this IEcsBuilder builder, bool ignoreCase = false) 
    {
        var commandService = builder.Services.GetRequiredService<ICommandService>();
        commandService.IgnoreCase = ignoreCase; // todo: add property to service
        return builder;
    }
}

might also want to use a method instead of a property for IgnoreCase in the command service, since it needs to recreate the commands dictionary with a different key comparator.

ikkentim avatar Mar 17 '25 12:03 ikkentim