Amaroq7 / SPMod

SourcePawn Scripting Engine for Half-Life 1 based games
GNU General Public License v3.0
27 stars 12 forks source link

Command manager #13

Closed Amaroq7 closed 6 years ago

Amaroq7 commented 6 years ago

Description

We should be able to create commands.

There could be natives responsible for creating only console commands (not in say).

typeset CmdCallback
{
    // For client cmd
    function PluginReturn (int client);
    // for srv cmd
    function PluginReturn ();
}
// Client console
RegisterClCmd(const char[] cmd, CmdCallback func, int flags = 0, const char[] info = "")
// Server console
RegisterSrvCmd(const char[] cmd, CmdCallback func, const char[] info = "")

For say we would have forward which is executed on "say" and "say_team" commands.

//1st variant
forward PluginReturn OnSayCommand(int client, bool say_team)
//2nd variant (argv would store first argument of say command, f.e. for "say /test" argv param would store "/test")
forward PluginReturn OnSayCommand(int client, const char[] argv, bool say_team)

Example of registering say command

//1st variant
public PluginReturn OnSayCommand(int client, bool say_team)
{
    char argv[32];
    CmdGetArgv(1, argv, sizeof(argv)); //Not existent native for now
    if (!StrCmp(argv, "/test"))
    {
        SomeCmdCallback(client);
        return PluginStop;
    }
    return PluginContinue;
}

//2nd variant
public PluginReturn OnSayCommand(int client, const char[] argv, bool say_team)
{
    if (!StrCmp(argv, "/test"))
    {
        SomeCmdCallback(client);
        return PluginStop;
    }
    return PluginContinue;
}

Commands permissions

In amxx we have to check permissions manually by executing cmd_access in command callback. I think it would be better to check them in SPMod and execute command callback whenever client has right permissions.

How do we replicate the issue?

n/a

Expected behavior (i.e. solution)

We should be able to register commands.

Other Comments

Any thoughts on this?