Advertisement
Guest User

Pesticide

a guest
Mar 6th, 2011
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 11.97 KB | None | 0 0
  1. #define pesticide_version "1.0.0"
  2.  
  3. /*
  4.  
  5.    -------------------------------------------------------------------------------------
  6.     The ©Pesticide Blacklist is a project by André "DeathOnaStick" Brandenburger
  7.    
  8.     By using and/or compiling this script you are aware of...
  9.         ...that you are not allowed to use this script for illegal purposes
  10.         ...that you are not allowed to ban innocent people when using this script
  11.         ...that you are not allowed to connect to the URLs manually, except blacklist.pytalhost.net/index.php
  12.         ...that you are not allowed to change this script, neither by adding or changing something, nor by adding codelines
  13.        
  14.     If you do not agree, you are neither allowed to compile this script, nor allowed to use it.
  15.    
  16.     Thank you for your understanding.
  17.    
  18.     Have Fun!
  19.  
  20.    -------------------------------------------------------------------------------------
  21.    
  22. */
  23.  
  24.  
  25.  
  26.  
  27.  
  28. /* ~ Settings ~ */
  29.  
  30. #define ForceVerification
  31.  
  32. #define ECHO_DATA
  33.  
  34. /* ~ */
  35.  
  36.  
  37. #include <a_samp>
  38. #include <a_http>
  39. #include <pesticide>
  40.  
  41. #pragma unused pesticide_Ban
  42. #pragma unused pesticide_BanEx
  43.  
  44. #define COLOR_RED 0xAA3333AA
  45. #define COLOR_YELLOW 0xFFFF00AA
  46. #define COLOR_ORANGE 0xFF9900AA
  47. #define COLOR_GREEN 0x33AA33AA
  48. #define COLOR_LIGHTBLUE 0x33CCFFAA
  49. #define COLOR_WHITE 0xFFFFFFAA
  50. #define COLOR_SYSTEM 0xEFEFF7AA
  51.  
  52. /* Macros */
  53.  
  54. #define PingServer();\
  55.     pingvar=GetTickCount();\
  56.     new PingAccess[100];\
  57.     format(PingAccess, sizeof(PingAccess), "%s/pesticide.php?ping=1", pbServer);\
  58.     HTTP(707, HTTP_GET, PingAccess, "", "OnPingResponse");
  59.  
  60. #define Verify(%0);\
  61.     new pIP[16];\
  62.     GetPlayerIp(%0, pIP, sizeof(pIP));\
  63.     new submitString[25+sizeof(pbServer)+sizeof(pIP)];\
  64.     format(submitString, sizeof(submitString), "%s/pesticide.php?IP=%s",pbServer, pIP);\
  65.     HTTP(%0, HTTP_GET, submitString, "", "UserVerification");
  66.  
  67.  
  68. #define SendBlacklistRequest(%0);\
  69.     new submitString[100+MAX_PLAYER_NAME+2];\
  70.     new PName[MAX_PLAYER_NAME];\
  71.     GetPlayerName(%0, PName, sizeof(PName));\
  72.     new PIP[16];\
  73.     GetPlayerIp(%0, PIP, sizeof(PIP));\
  74.     format(submitString, sizeof(submitString), "%s/pesticide.php?name=%s&IP=%s", pbServer, PName, PIP);\
  75.     HTTP((85+%0), HTTP_GET, submitString, "", "ResponseOnRequest");
  76. /* ~ */
  77.  
  78. new pingvar=0;
  79.  
  80. new bool:connected=false;
  81.  
  82. new pbServer[50]="blacklist.pytalhost.net";
  83.  
  84. new pingtimerid;
  85.  
  86. forward OnPingResponse(index, response_code, data[]);
  87. forward UserVerification(index, response_code, data[]);
  88. forward ResponseOnRequest(index, response_code, data[]);
  89. forward pesticide_force(playerid);
  90. forward pesticide_ping();
  91. forward pb_Ban(playerid, bool:ex, reason[]);
  92.  
  93. public pb_Ban(playerid, bool:ex, reason[]){
  94.     SendBlacklistRequest(playerid);
  95. }
  96.  
  97. public OnPingResponse(index, response_code, data[])
  98. {
  99.     #if defined ECHO_DATA
  100.     printf("%s",data);
  101.     #endif
  102.     if(response_code!=200)
  103.     {
  104.         printf("#ERROR %i: Client could not connect to pb-Server.", response_code);
  105.         printf("#ERROR %i: #-> Cannot access to Pesticide-Database.", response_code);
  106.         connected=false;
  107.         KillTimer(pingtimerid);
  108.         pingtimerid=SetTimer("pesticide_Ping", 10*60*1000, false);
  109.     }
  110.     else
  111.     {
  112.         new entries=0, newestvers[10];
  113.         sscanf(data, "p|isz", entries, newestvers);
  114.        
  115.         new v1, v2, v3;
  116.         sscanf(newestvers, "p.iii", v1,v2,v3);
  117.        
  118.         new pseuv1,pseuv2,pseuv3;
  119.         sscanf(pesticide_version, "p.iii", pseuv1,pseuv2,pseuv3);
  120.        
  121.         printf("#You are using Pesticide v.%s. Newest version: v.%i.%i.%i.", pesticide_version, v1,v2,v3);
  122.         if(v1>pseuv1)
  123.         {
  124.             print("#Warning: Extremely important changes have been done with the newest version of (c)Pesticide!");
  125.             print("#Warning: Please visit forum.sa-mp.com and search for pesticide \n#Warning: to find the download-link to the newest version.");
  126.             print("#Warning: Alternatively you could also visit blacklist.pytalhost.com.");
  127.             printf("%c", 7);
  128.         }
  129.         else if(v2>pseuv2)
  130.         {
  131.             print("#Warning: Major changes have been done with the newest version of (c)Pesticide.");
  132.             print("#Warning: Please visit forum.sa-mp.com and search for pesticide \n#Warning: to find the download-link to the newest version.");
  133.             print("#Warning: Alternatively you could also visit blacklist.pytalhost.com.");
  134.         }
  135.         else
  136.         {
  137.             if((v3<=pseuv3&&v2<=pseuv2&&v1<=pseuv1)||(v2<=pseuv2&&v1<=pseuv1)||(v1<=pseuv1))
  138.             {
  139.                 print("#Your version of Pesticide is up to date.");
  140.             }
  141.             printf("#Pesticide: Database pinged with %i entries. Ping: %i",entries, GetTickCount()-pingvar);
  142.             if(connected==false)
  143.             {
  144.                 for(new i=0, tx=GetMaxPlayers(); i<=tx; i++)if(IsPlayerConnected(i))if(!IsPlayerNPC(i))
  145.                 {
  146.                     Verify(i);
  147.                 }
  148.                 connected=true;
  149.                 KillTimer(pingtimerid);
  150.                 pingtimerid=SetTimer("pesticide_Ping", 45*60*1000, false);
  151.             }
  152.         }
  153.     }
  154.     return 1;
  155. }
  156.  
  157. public UserVerification(index, response_code, data[])
  158. {
  159.     #if defined ECHO_DATA
  160.     printf("%s",data);
  161.     #endif
  162.     if(response_code==200)
  163.     {
  164.         if(connected==false)
  165.         {
  166.             for(new i=0, tx=GetMaxPlayers(); i<=tx; i++)if(IsPlayerConnected(i))if(!IsPlayerNPC(i))if(i!=index)
  167.             {
  168.                 Verify(i);
  169.             }
  170.             connected=true;
  171.         }
  172.         new amount, day, month, year;
  173.         if (sscanf(data, "p|iiii", amount, day, month, year))
  174.         {
  175.             SendClientMessage(index, COLOR_SYSTEM, "This server is {C8400B}protected {EFEFF7}by Pesticide.");
  176.             SendClientMessage(index, COLOR_SYSTEM, "Your connection information has been {33AA33}verified{EFEFF7}.");
  177.             SetPVarInt(index, "pesticide_uservalid", 1);
  178.             return 1;
  179.         }
  180.         else
  181.         {
  182.             new tday, tmonth, tyear, Sum, BDays=1;
  183.             getdate(tyear, tmonth, tday);
  184.             Sum=CalculateDaysBetweenDates(day,month,year,tday,tmonth,tyear);
  185.             while(amount>0){
  186.                 BDays*=3;
  187.                 amount--;
  188.             }
  189.             if(BDays<=Sum)
  190.             {
  191.                 SendClientMessage(index, COLOR_SYSTEM, "This server is {33AA33}protected {EFEFF7}by Pesticide.");
  192.                 SendClientMessage(index, COLOR_SYSTEM, "Your connection information has been {33AA33}verified{EFEFF7}.");
  193.                 SetPVarInt(index, "pesticide_uservalid", 1);
  194.                 return 1;
  195.             }
  196.             else
  197.             {
  198.                 SendClientMessage(index, COLOR_SYSTEM, "This server is {33AA33}protected {EFEFF7}by Pesticide.");
  199.                 SendClientMessage(index, COLOR_SYSTEM, "Your connection information is {E31515}verified as banned{EFEFF7}.");
  200.                 SendClientMessage(index, COLOR_SYSTEM, "You are {4F4F4F}blacklisted{EFEFF7} from all (c){E31515}Pesticide{E31515}-Servers.");
  201.                 new pIP[16];
  202.                 GetPlayerIp(index, pIP, sizeof(pIP));
  203.                 printf("#Pesticide: Database-entry of %s verified by pb-Server. Connection rejected. ", pIP);
  204.                 return Kick(index);
  205.             }
  206.         }
  207.     }
  208.     else
  209.     {
  210.         SendClientMessage(index, COLOR_SYSTEM, "This server is {33AA33}protected {EFEFF7}by (c){E31515}Pesticide{E31515}.");
  211.         SendClientMessage(index, COLOR_SYSTEM, "The (c){E31515}Pesticide{EFEFF7}-Blacklist is currently {E31515}offline{EFEFF7}.");
  212.         connected=false;
  213.         return 1;
  214.     }
  215. }
  216.  
  217. public ResponseOnRequest(index, response_code, data[])
  218. {
  219.     #if defined ECHO_DATA
  220.     printf("%s",data);
  221.     #endif
  222.     if(response_code==200)
  223.     {
  224.         if(strfind(data, "LREACHED")!=-1){print("#Pesticide: You have reached your blacklist limit.");print("#Pesticide: You can try again next hour.");}
  225.         else if(strfind(data, "SINVALID")!=-1){print("#Pesticide: Your server has been marked as invalid.");print("#Pesticide: You cannot blacklist players anymore.\n#Pesticide: Connection rejected.");}
  226.         else if(strfind(data, "1")!=-1)print("#Pesticide: Successfully sent a blacklist-request to Server.");
  227.         else printf("Unknown Error: %s", data);
  228.     }
  229.     return 1;
  230. }
  231.  
  232. public pesticide_ping()
  233. {
  234.     PingServer();
  235. }
  236.  
  237. public pesticide_force(playerid)
  238. {
  239.     if(GetPVarInt(playerid, "pesticide_uservalid")!=1)
  240.     {
  241.         print("#!Pesticide: User-Verification timed out. Connection rejected. ~!!!~");
  242.         SendClientMessage(playerid, COLOR_RED, "Warning: Verification timed out. Connection rejected.");
  243.         return Kick(playerid);
  244.     }
  245.     else return 1;
  246. }
  247.  
  248. public OnPlayerConnect(playerid)
  249. {
  250.     #if defined ForceVerification
  251.     if(connected==true)
  252.     {
  253.         SetPVarInt(playerid, "pesticide_timerid", SetTimerEx("pesticide_force", 3*60*1000, false, "i", playerid));
  254.     }
  255.     #endif
  256.     Verify(playerid);
  257. }
  258.  
  259. public OnPlayerDisconnect(playerid)
  260. {
  261.     KillTimer(GetPVarInt(playerid, "pesticide_timerid"));
  262. }
  263.  
  264. public OnFilterScriptInit()
  265. {
  266.     print("\n\
  267.     =========================(c)Pesticide==========================\n= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n\
  268.     ## (c)Pesticide-Filterscript and Database [FS LOADED]        ##\n\
  269.    ## by André \"DeathOnaStick\" Brandenburger                    ##\n= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\n\
  270.     ===============================================================\n");
  271.     PingServer();
  272.     return 1;
  273. }
  274.  
  275.  
  276.  
  277.  
  278.  
  279.  
  280.  
  281.  
  282.  
  283.  
  284.  
  285. sscanf(string[], format[], {Float,_}:...)
  286. {
  287. #if defined isnull
  288. if (isnull(string))
  289. #else
  290. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  291. #endif
  292. {return format[0];}
  293. #pragma tabsize 4
  294. new formatPos = 0,stringPos = 0,paramPos = 2,paramCount = numargs(),delim = ' ';while (string[stringPos] && string[stringPos] <= ' '){stringPos++;}
  295. while (paramPos < paramCount && string[stringPos]){
  296. switch (format[formatPos++]){case '\0':{return 0;}case 'i', 'd':{
  297. new neg = 1,num = 0,ch = string[stringPos];if (ch == '-'){neg = -1;ch = string[++stringPos];}
  298. do{stringPos++;if ('0' <= ch <= '9'){num = (num * 10) + (ch - '0');}else {return -1;}}
  299. while ((ch = string[stringPos]) > ' ' && ch != delim);setarg(paramPos, 0, num * neg);}case 'h', 'x':{
  300. new num = 0,ch = string[stringPos];do{stringPos++;switch (ch){case 'x', 'X':{num = 0;continue;}case '0' .. '9':{num = (num << 4) | (ch - '0');}case 'a' .. 'f':{num = (num << 4) | (ch - ('a' - 10));}case 'A' .. 'F':{num = (num << 4) | (ch - ('A' - 10));}default:{return -1;}}}while ((ch = string[stringPos]) > ' ' && ch != delim);
  301. setarg(paramPos, 0, num);}case 'c':{setarg(paramPos, 0, string[stringPos++]);}case 'f':{
  302. new changestr[16], changepos = 0, strpos = stringPos;while(changepos < 16 && string[strpos] && string[strpos] != delim){
  303. changestr[changepos++] = string[strpos++];}changestr[changepos] = '\0';setarg(paramPos,0,_:floatstr(changestr));}case 'p':{delim = format[formatPos++];continue;}case '\'':{
  304. new end = formatPos - 1,ch;while ((ch = format[++end]) && ch != '\'') {}if (!ch){
  305. return -1;}format[end] = '\0';if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1){
  306. if (format[end + 1]){return -1;}
  307. return 0;}format[end] = '\'';stringPos = ch + (end - formatPos);formatPos = end + 1;}case 'u':{
  308. new end = stringPos - 1,id = 0,bool:num = true,ch;while ((ch = string[++end]) && ch != delim){if (num){if ('0' <= ch <= '9'){id = (id * 10) + (ch - '0');}else{num = false;}}}
  309. if (num && IsPlayerConnected(id)){setarg(paramPos, 0, id);}else{
  310. #if !defined foreach
  311. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  312. #define __SSCANF_FOREACH__
  313. #endif
  314. string[end] = '\0';num = false;new name[MAX_PLAYER_NAME];id = end - stringPos;foreach (Player, playerid){GetPlayerName(playerid, name, sizeof (name));if (!strcmp(name, string[stringPos], true, id)){
  315. setarg(paramPos, 0, playerid);num = true;break;}}if (!num){
  316. setarg(paramPos, 0, INVALID_PLAYER_ID);}string[end] = ch;
  317. #if defined __SSCANF_FOREACH__
  318. #undef foreach
  319. #undef __SSCANF_FOREACH__
  320. #endif
  321. }stringPos = end;}case 's', 'z':{
  322. new i = 0,ch;if (format[formatPos]){
  323. while ((ch = string[stringPos++]) && ch != delim){
  324. setarg(paramPos, i++, ch);}if (!i){return -1;}}else{while ((ch = string[stringPos++])){
  325. setarg(paramPos, i++, ch);}}stringPos--;setarg(paramPos, i, '\0');}default:{continue;}}
  326. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' '){stringPos++;}
  327. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' ')){
  328. stringPos++;}paramPos++;}do{if ((delim = format[formatPos++]) > ' '){
  329. if (delim == '\''){while ((delim = format[formatPos++]) && delim != '\'') {}}else if (delim != 'z'){return delim;}}}
  330. while (delim > ' ');return 0;}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement