stock AntiAdv(playerid, text[]) { // Anti Adv new strR[255], is1=0, r=0; while(strlen(text[is1])) { if('0'<=text[is1]<='9') { new is2=is1+1, p=0; while(p==0) { if('0'<=text[is2]<='9'&&strlen(text[is2])) { is2++; } else { strmid(strR[r],text,is1,is2,255); if(strval(strR[r])<255) r++; is1=is2; p=1; } } } is1++; } if(r>=4) { new strMy[255]; format(strMy, sizeof(strMy), "AdmWarn: %s is attempting to Server Advertise: %s", RPN(playerid), text); SendAdminMessage(COLOR_DARKRED, 1, strMy); new pr2; for(new z=0;z<r;z++) { while((pr2=strfind(text,strR[z],true))!=-1) { for(new i=pr2,j=pr2+strlen(strR[z]);i<j;i++) { text[i]='*'; } } } return 1; } return 0; }
for(new i, j = strlen(string)); i < j; i++)
{
if('0' <= string[i] <= '9')
{
if(!sscanf(string[i], "{p<.>a<i>[4]S()[144]}"))
{
// found ip
break;
}
}
}
The best way to do this would a regular expression. But if you don't want to load another plugin, it may also work with sscanf. Perhap something like:
PHP код:
|
I basically wanted to remove the whole code, but if I remove it, I will make alot of errors when compiling because the advertsiment system is everywhere, basically almost in every chat type ex. /gov, /f, etc. I'll see what I can do with it without changing the code, but just changing the values. Thanks.
|
The best way to do this would a regular expression. But if you don't want to load another plugin, it may also work with sscanf. Perhap something like:
PHP код:
|
// ** INCLUDES
#include <a_samp>
#include <sscanf>
// ** DEFINES
// *** FUNCTIONS
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)
#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
// ** MAIN
main()
{
print("Loaded \"anti_advert.amx\".");
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerText(playerid, text[])
{
if(IsAdvertisement(text))
{
SendClientMessage(playerid, 0xFF0000FF, "Your message is considered an advertisement, please review it.");
return 0;
}
return 1;
}
// ** FUNCTIONS
forward bool:IsAdvertisement(text[]);
public bool:IsAdvertisement(text[])
{
new message[128], extract[2], element[4][4], count_1, count_2, temp, bool:number_next = false, bool:next_number = false, bool:advert = false;
strcpy(message, text, sizeof(message));
for(new i = 0, j = strlen(message); i < j; i ++)
{
switch(message[i])
{
case '0'..'9':
{
if(next_number) continue;
number_next = false;
strmid(extract, message[i], 0, 1);
strcat(element[count_1], extract);
count_2 ++;
if(count_2 == 3 || message[i + 1] == EOS)
{
strmid(extract, message[i + 1], 0, 1);
if(IsNumeric(extract))
{
element[0][0] = EOS;
element[1][0] = EOS;
element[2][0] = EOS;
element[3][0] = EOS;
count_1 = 0;
count_2 = 0;
next_number = true;
continue;
}
temp = strval(element[count_1]);
if(count_1 == 0)
{
if(temp <= 255)
{
count_1 ++;
count_2 = 0;
}
else
{
element[count_1][0] = EOS;
count_2 = 0;
next_number = true;
}
}
else
{
if(temp <= 255)
{
count_1 ++;
count_2 = 0;
}
else
{
element[0][0] = EOS;
element[1][0] = EOS;
element[2][0] = EOS;
element[3][0] = EOS;
count_1 = 0;
count_2 = 0;
next_number = true;
}
}
}
if(count_1 == 4)
{
advert = true;
break;
}
}
default:
{
next_number = false;
if(number_next) continue;
if(!isnull(element[count_1]))
{
temp = strval(element[count_1]);
if(count_1 == 0)
{
if(temp <= 255)
{
count_1 ++;
count_2 = 0;
number_next = true;
}
else
{
element[count_1][0] = EOS;
count_2 = 0;
}
}
else
{
if(temp <= 255)
{
count_1 ++;
count_2 = 0;
number_next = true;
}
else
{
element[0][0] = EOS;
element[1][0] = EOS;
element[2][0] = EOS;
element[3][0] = EOS;
count_1 = 0;
count_2 = 0;
}
}
if(count_1 == 4)
{
advert = true;
break;
}
}
}
}
}
return advert;
}
stock IsNumeric(const string[])
{
return !sscanf(string, "{d}");
}
// ** INCLUDES
#include <a_samp>
#include <regex>
// ** DEFINES
// *** FUNCTIONS
#define strcpy(%0,%1,%2) strcat((%0[0] = '\0', %0), %1, %2)
// ** MAIN
main()
{
print("Loaded \"anti_advert_regex.amx\".");
}
// ** CALLBACKS
public OnGameModeInit()
{
return 1;
}
public OnGameModeExit()
{
return 1;
}
public OnPlayerText(playerid, text[])
{
if(IsAdvertisement(text))
{
SendClientMessage(playerid, 0xFF0000FF, "Your message is considered as an advert, please review it.");
return 0;
}
return 1;
}
// ** FUNCTIONS
forward bool:IsAdvertisement(text[]);
public bool:IsAdvertisement(text[])
{
new message[128], build, expression[] = "(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.+){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)", start, end;
strcpy(message, text, sizeof(message));
for(new i = 0, j = strlen(message); i < j; i ++)
{
switch(message[i])
{
case '0'..'9': continue;
case '.': continue;
default:
{
strdel(message, i, i + 1);
strins(message, ".", i);
}
}
}
build = regex_exbuild(expression);
regex_exmatch(message, build);
regex_exsearch(message, build, start, end);
if(start >= 0) return true;
return false;
}