SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts

Reply
 
Thread Tools Display Modes
Old 22/03/2015, 11:04 AM   #1
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,122
Reputation: 529
Default Command Blocker

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
__________________


Kar's Cops and Robbers 2020

Last edited by Threshold; 30/03/2015 at 03:41 AM.
Threshold is offline   Reply With Quote
Old 22/03/2015, 11:08 AM   #2
iFiras
Huge Clucker
 
iFiras's Avatar
 
Join Date: Oct 2013
Location: Tunisia
Posts: 487
Reputation: 38
Default Re: Command Blocker

Seems like a nice filterscript, useful, good job.
iFiras is offline   Reply With Quote
Old 22/03/2015, 11:08 AM   #3
TazmaNiax
Big Clucker
 
TazmaNiax's Avatar
 
Join Date: Apr 2014
Location: Indonesia
Posts: 134
Reputation: 8
Default Re: Command Blocker

Seems useful for bug commands xD
Btw nice filterscript
__________________
nope
TazmaNiax is offline   Reply With Quote
Old 22/03/2015, 11:24 AM   #4
JeaSon
Gangsta
 
JeaSon's Avatar
 
Join Date: Aug 2013
Location: Future
Posts: 558
Reputation: 79
Default Re: Command Blocker

nice one
__________________
Again back
JeaSon is offline   Reply With Quote
Old 22/03/2015, 12:09 PM   #5
Younes44
Gangsta
 
Younes44's Avatar
 
Join Date: Oct 2013
Posts: 763
Reputation: 78
Default Re: Command Blocker

Good Work Brother
__________________
Left SA:MP, and not avalaible anymore!!
Thanks samp for awesome moments, i enjoy!! Goodbye!
ModernFreeroam: www.mf-samp.com , IP:94.23.255.30:7777
CounterTerroristUnit: www.ctu.w4f.eu , IP:87.98.243.201:6969
xSF: www.xsfserver.com , IP: 87.98.243.201:6969
Exm: www.exmserv.me , IP: exmserv.me:7777
Underground Stunting: www.ustunting.com , IP:145.239.3.225:7777

Thanks everyone,for the awesome moments,
Regards, COD Ghosts owner.
Younes44 ,YOuNeS_Dz ,WarZ ,Bryan_ , Kaneki
Younes44 is offline   Reply With Quote
Old 22/03/2015, 04:04 PM   #6
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,885
Reputation: 1337
Default Re: Command Blocker

This should also work with YCMD did you test it?
Pottus is offline   Reply With Quote
Old 22/03/2015, 04:05 PM   #7
Karan007
Gangsta
 
Karan007's Avatar
 
Join Date: Feb 2015
Posts: 539
Reputation: 67
Default Re: Command Blocker

Great job!
Karan007 is offline   Reply With Quote
Old 22/03/2015, 06:03 PM   #8
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,122
Reputation: 529
Default Re: Command Blocker

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.
__________________


Kar's Cops and Robbers 2020
Threshold is offline   Reply With Quote
Old 22/03/2015, 06:57 PM   #9
Threshold
High-roller
 
Threshold's Avatar
 
Join Date: Nov 2012
Location: Australia
Posts: 3,122
Reputation: 529
Default Re: Command Blocker

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.
__________________


Kar's Cops and Robbers 2020
Threshold is offline   Reply With Quote
Old 24/03/2015, 09:31 AM   #10
X337
Gangsta
 
Join Date: Sep 2014
Location: Indonesia
Posts: 872
Reputation: 291
Default Re: Command Blocker

It's useful, i used this on my gamemode.
Thanks.
__________________
viva la sa-mp
X337 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is There Any Website Blocker ? Windrush Everything and Nothing 16 11/05/2013 10:21 PM
Symbol blocker Julian12345 Help Archive 6 11/06/2011 01:45 AM
[FilterScript] [FS] Flooder IP Blocker v1 Tenshi Filterscripts 8 25/05/2010 04:01 AM
[FilterScript] [FS] Command blocker Destrojer Filterscripts 2 05/01/2010 05:32 AM
teleport blocker please help? PANNA Help Archive 1 17/10/2009 09:50 PM


All times are GMT. The time now is 05:55 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.