[FilterScript] Command Blocker
#1

COMMAND BLOCKER V1.2

This is pretty much just a simple dynamic command blocker that I made up after seeing a small thread. I had nothing to do and I thought people could probably make use of this...

The filterscript requires RCON access by default, and the color and text of the error message if a command is blocked can be changed by editing the macros for 'BLOCKED_COMMAND_MSG' and 'BLOCKED_COMMAND_COLOR'. This filterscript is optimal for people using ZCMD, YCMD and DCMD within their scripts already. This does not necessarily have to be a filterscript either, it can easily be added to your gamemode, assuming there are no conflicts between variable names and/or command processors.

This system also has an optional '/blocklist' command which will list all blocked commands either within a dialog or a series of client messages. (Depending on whether you have set LIST_USE_DIALOG to true or false)
The list command is enabled and does not use dialogs by default. To disable to blocklist command, you can simply change 'LIST_COMMAND' to false or delete the entire command from the filterscript itself. The value of LIST_USE_DIALOG does not matter if you have LIST_COMMAND disabled. The dialogid for the list command is 14653 by default, but can be changed in the ShowPlayerDialog line.


Pastebin:
http://pastebin.com/1dxZQF2H


pawn Code:
#include <a_samp>

#define LIST_COMMAND            true
#define LIST_USE_DIALOG         false

#define COMMAND_BLOCKED_MSG     "This command has been blocked, you cannot use it."
#define COMMAND_BLOCKED_COLOR   0xFF0000FF
#define MAX_COMMAND_BLOCKED     25

new BlockedCommand[MAX_COMMAND_BLOCKED][25];

public OnPlayerCommandText(playerid, cmdtext[])
{
    new bool:CMD_BLOCKED = false;
    for(new i = 0; i < MAX_COMMAND_BLOCKED; i++)
    {
        if(BlockedCommand[i][0] == '\0') continue;
        if(cmdtext[0] == '/')
        {
            if(!strcmp(BlockedCommand[i], cmdtext[1], true)) CMD_BLOCKED = true;
        }
        else if(!strcmp(BlockedCommand[i], cmdtext, true)) CMD_BLOCKED = true;
        else continue;
    }
    if(CMD_BLOCKED) return SendClientMessage(playerid, COMMAND_BLOCKED_COLOR, COMMAND_BLOCKED_MSG);

    #if LIST_COMMAND == true
        if(!strcmp(cmdtext, "/blocklist", true))
        {
            if(!IsPlayerAdmin(playerid)) return 0;
            #if LIST_USE_DIALOG == true
                new fstr[600], str[30];
                for(new i = 0; i < sizeof(BlockedComand); i++)
                {
                    if(BlockedCommand[i][0] == '\0') continue;
                    format(str, sizeof(str), "/%s\n", BlockedCommand[i]);
                    strcat(fstr, str);
                }
                ShowPlayerDialog(playerid, 14653, DIALOG_STYLE_MSGBOX, "Blocked Commands", fstr, "Okay", "");
            #else
                new str[30];
                SendClientMessage(playerid, 0xFF0000FF, "Blocked Commands:");
                for(new i = 0; i < MAX_COMMAND_BLOCKED; i++)
                {
                    if(BlockedCommand[i][0] == '\0') continue;
                    format(str, sizeof(str), "/%s", BlockedCommand[i]);
                    SendClientMessage(playerid, -1, str);
                }
            #endif
            return 1;
        }
    #endif

    new split = strfind(cmdtext, " ", true), command[60];
    if(split != -1)
    {
        strmid(command, cmdtext, 0, split);
        strdel(cmdtext, 0, split + 1);
    }
    else format(command, sizeof(command), "%s", cmdtext);

    if(!strcmp(command, "/blockcommand", true) || !strcmp(command, "/blockcmd", true))
    {
        if(!IsPlayerAdmin(playerid)) return 0;
        if(split == -1) return SendClientMessage(playerid, -1, "USAGE: /blockcommand [command]");
        if(cmdtext[0] == '/') strdel(cmdtext, 0, 1);
        new slotfree = -1;
        for(new i = 0; i < MAX_COMMAND_BLOCKED; i++)
        {
            if(BlockedCommand[i][0] == '\0') slotfree = i;
            else if(!strcmp(BlockedCommand[i], cmdtext, true)) return SendClientMessage(playerid, -1, "This command is already blocked. Use '/unblockcommand [command]' to unblock it.");
            if(slotfree != -1) continue;
        }
        if(slotfree == -1) return SendClientMessage(playerid, -1, "You have reached the maximum limit of blocked commands. Please unblock some before proceeding.");
        format(BlockedCommand[slotfree], 25, "%s", cmdtext);
        SendClientMessage(playerid, -1, "SUCCESS: Command Blocked successfully.");
        return 1;
    }

    if(!strcmp(command, "/unblockcommand", true) || !strcmp(command, "/unblockcmd", true))
    {
        if(!IsPlayerAdmin(playerid)) return 0;
        if(split == -1) return SendClientMessage(playerid, -1, "USAGE: /unblockcommand [command]");
        if(cmdtext[0] == '/') strdel(cmdtext, 0, 1);
        new slotfree = -1;
        for(new i = 0; i < MAX_COMMAND_BLOCKED; i++)
        {
            if(!strcmp(BlockedCommand[i], cmdtext, true) && BlockedCommand[i][0] != '\0')
            {
                slotfree = i;
                break;
            }
        }
        if(slotfree == -1) return SendClientMessage(playerid, -1, "This command is not blocked. Use '/blockcommand [command]' to block it.");
        strdel(BlockedCommand[slotfree], 0, strlen(BlockedCommand[slotfree]));
        SendClientMessage(playerid, -1, "SUCCESS: Command Unblocked successfully.");
        return 1;
    }
    return 0;
}
This would definitely be much easier with MySQL, but because I am so fortunately new at MySQL, I am not capable of doing that just yet. Feel free to help me 'upgrade' or improve this script by posting recommendations below. Again, this was very rushed and I've gone quite a long while without sleep at this point, so forgive me if I make some stupid errors, but the script works fine as it is.

Code:
=== COMMAND BLOCKER CHANGELOG - (Updated 30/03/2015 05:40 UTC) ===

Version 1.2   [30/03/2015]
----------
- Added optional "/blocklist" command to display all currently blocked commands
http://pastebin.com/1dxZQF2H

Version 1.1   [22/03/2015]
----------
- Edited callback to suit any command processor, including ZCMD and YCMD. (Thanks to Pottus)
- Removed requirement for ZCMD and SSCANF
http://pastebin.com/PMqn17Zz

Version 1.0   [22/03/2015]
----------
- Original filterscript
http://pastebin.com/Rz34ZfUP
Reply
#2

Seems like a nice filterscript, useful, good job.
Reply
#3

Seems useful for bug commands xD
Btw nice filterscript
Reply
#4

nice one
Reply
#5

Good Work Brother
Reply
#6

This should also work with YCMD did you test it?
Reply
#7

Great job!
Reply
#8

Quote:
Originally Posted by Pottus
View Post
This should also work with YCMD did you test it?
Actually, good point. I only considered ZCMD's 'OnCommandPerformed' for this one.

I'll definitely look into making it a generic filterscript.
Reply
#9

Updated.
Code:
Version 1.1   [22/03/2015]
----------
- Edited callback to suit any command processor, including ZCMD and YCMD. (Thanks to Pottus)
- Removed requirement for ZCMD and SSCANF
http://pastebin.com/PMqn17Zz
EDIT:

And thanks to all for your kind words.
Reply
#10

It's useful, i used this on my gamemode.
Thanks.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)