PDA

View Full Version : Detecting a cmd and the value, zcmd issue


Omirrow
12/06/2017, 06:17 PM
Hey there,

I have tried a lot of options to fix this problem but I couldn't find a valid solution. I use zcmd in a gamemode and I scripted an anti spam recently, it works fine but the thing is I'd like to skip a few commands, keep them out of the anti spam script.

I can skip them like that;


new lastcmd[MAX_PLAYERS];

public OnPlayerCommandPerformed(playerid,cmdtext[],success)
{
if(!success) return 1;
if(success)
{
lastcmd[playerid]=gettime();
}
return 1;
}

public OnPlayerCommandReceived(playerid, cmdtext[])
{
if(strcmp(cmdtext, "/xx", false))
{
if(lastcmd[playerid]!=0 && gettime()-lastcmd[playerid] <= 3)
{
SendClientMessage(playerid,-1,"stop spamming");
return 0;
}
}
return 1;
}


With this code, we prevent the anti spam system to keep "/xx" command out of spam but the thing is, my /xx command has a value, it works like '/xx [texthere]'

So the output at the end is something like that "/xx hello" so, how can I block this ? Using a similar code as above?

EDIT: If you wonder the command;

CMD:xx(playerid, params[])
{
if(isnull(params)) return SendClientMessage(playerid,-1,"/xx [text]");
return 1;
}

Basically something like that, I get params from the cmd and use it somewhere else.

Omirrow
12/06/2017, 10:06 PM
I still need help.

BigETI
13/06/2017, 06:15 AM
If you write inside a "command function", you already know its name. For the parameters search for "string scan format"

Omirrow
13/06/2017, 07:31 PM
If you write inside a "command function", you already know its name. For the parameters search for "string scan format"

Well, how can I use a command's parameter in OnPlayerCommandReceived public? How do I detect it, can you expand your answer a little bit more?

An example would be great.

Freedom.
13/06/2017, 08:00 PM
deleted

Omirrow
14/06/2017, 04:00 PM
I still need help, how can I detect a cmd with it's parameters?

Omirrow
17/06/2017, 10:16 PM
I couldn't find a way to get it working, still need help.

Konstantinos
17/06/2017, 10:28 PM
strcmp has a length option which is optional.


if(strcmp(cmdtext, "/xx") && strcmp(cmdtext, "/xx ", true, 4))

Omirrow
19/06/2017, 07:27 PM
strcmp has a length option which is optional.


if(strcmp(cmdtext, "/xx") && strcmp(cmdtext, "/xx ", true, 4))


strcmp(cmdtext, "/xx ", true, 4)

What does actually this do? I mean, what if it's longer than 4 characters, my command's output is usually something like that: "/xx hello people, this is a channel that you can talk like that." So, in this situation, should I put an estimated length?

JasonRiggs
19/06/2017, 07:55 PM
Mind showing us your anti-spam system?

jlalt
19/06/2017, 08:08 PM
Use strfind and check if value is not 0


public OnPlayerCommandReceived(playerid, cmdtext[])
{
if(strfind(cmdtext, "/xx", false) != 0)
{
if(lastcmd[playerid]!=0 && gettime()-lastcmd[playerid] <= 3)
{
SendClientMessage(playerid,-1,"stop spamming");
return 0;
}
}
return 1;
}

Konstantinos
20/06/2017, 08:41 AM
strcmp(cmdtext, "/xx ", true, 4)

What does actually this do? I mean, what if it's longer than 4 characters, my command's output is usually something like that: "/xx hello people, this is a channel that you can talk like that." So, in this situation, should I put an estimated length?

It only compares the first 4 characters "/xx hello people, this is a channel that you can talk like that." and ignores the params part.

@jlalt: strfind returns -1 if not found.

Omirrow
20/06/2017, 12:23 PM
It only compares the first 4 characters "/xx hello people, this is a channel that you can talk like that." and ignores the params part.

@jlalt: strfind returns -1 if not found.

So, how can I detect it automatically and compare those strings? /xx is a chat channel so I'd like to keep it out of anti-spam script, I'd like to let people spam this chat but be able to spam important commands which has MySQL queries and such.

jlalt
20/06/2017, 10:52 PM
It only compares the first 4 characters "/xx hello people, this is a channel that you can talk like that." and ignores the params part.

@jlalt: strfind returns -1 if not found.

Already told him to check if strfind value is not 0 like if there was /xx it will return its pos if its 0 anti spam will be prevent if its -1 anti spam will execute and also if its > 0 anti spam will execute too.

DavidBilla
21/06/2017, 04:17 AM
I guess strlen could be useful here

if(strlen(cmdtext)>4)

Sew_Sumi
21/06/2017, 07:15 AM
I'd be checking before the command, so that any command is blacklisted via them spamming, via one line in the first section of that callback.

Omirrow
21/06/2017, 04:38 PM
I'd be checking before the command, so that any command is blacklisted via them spamming, via one line in the first section of that callback.

Well, seems like that's what I'm going to do. I just wanted to ask and maybe learn if it's possible to detect the message that comes after /xx but I coudln't get my answer, I'll be checking spam before cmds, I'll add it manually.