Lenin_Daniel

Anti incoming connection flood samp

Jul 5th, 2014
982
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.37 KB | None | 0 0
  1. #if defined REMOTE_CHAT
  2. ********************************************************************************
  3. *           ANTI INCOMING CONECCTION FLOOD 1.0 BY  DANIEL-92                   *
  4. *         Copyright © 2014 [Daniel-92 / [92]Daniel / (=Maxell=)]               *
  5. *             This file is provided as is (no warranties).                     *
  6. ********************************************************************************
  7. #endif
  8.  
  9. #include <a_samp>
  10.  
  11. //------------------------------------------------------------------------------
  12. #define JOIN_FLOD_TIME          6   //Tiempo en segundos que se tomará como incoming connection flood
  13. #define MAX_JOIN_FLOOD          10  //Máximo de joins dentro del tiempo definido arriba antes de que se aplique el baneo
  14.                                     //* Si hay 10 mensajes en la consola dentro de 6 segundos se aplica el baneao
  15. new
  16.     DB:JoinFloodDataBase,
  17.     jf_string[164],last_clear;
  18.  
  19. public OnFilterScriptInit() {
  20.     JoinFloodDataBase = db_open("JoinFloodDataBase.db");
  21.     db_query(JoinFloodDataBase,"CREATE TEMP TABLE IF NOT EXISTS Join_Flood \
  22.         (`ID` INTEGER PRIMARY KEY AUTOINCREMENT,`REMOTE_CLIENT` TEXT,`GRANULARITY` NUMERIC)"
  23.     );
  24.     last_clear = gettime()+60*5;
  25. }
  26.  
  27. public OnFilterScriptExit() {
  28.     db_close(JoinFloodDataBase);
  29. }
  30.  
  31. public OnIncomingConnection(playerid, ip_address[], port) {
  32.     format(jf_string,sizeof(jf_string),"\
  33.         SELECT COUNT(ID) AS TOTAL FROM `Join_Flood` WHERE `REMOTE_CLIENT` = '%s' \
  34.         AND `GRANULARITY`+"#JOIN_FLOD_TIME" > %d ORDER BY ID DESC LIMIT "#MAX_JOIN_FLOOD"",ip_address,gettime()
  35.     );
  36.     new DBResult:result = db_query(JoinFloodDataBase,jf_string);
  37.     db_get_field_assoc(result,"TOTAL",jf_string,sizeof(jf_string));
  38.     db_free_result(result);
  39.     if(strval(jf_string) >= MAX_JOIN_FLOOD) {
  40.         format(jf_string,sizeof jf_string,"banip %s",ip_address);   //Formateamos el comando rcon
  41.         SendRconCommand(jf_string);                                 //Mandamos el comando rcon
  42.         BlockIpAddress(ip_address,60*1000*30);                      //Bloqueamos la ip por 30 minutos (Funcion nativa de la 0.3z R2)
  43.     }
  44.     else if(gettime() > last_clear) {
  45.         db_free_result(db_query(JoinFloodDataBase,"DELETE FROM Join_Flood"));
  46.         last_clear = gettime()+60*10;
  47.     }
  48.     else {
  49.         format(jf_string,sizeof(jf_string),"INSERT INTO Join_Flood (REMOTE_CLIENT,GRANULARITY) VALUES ('%s','%d')",ip_address,gettime());
  50.         db_free_result(db_query(JoinFloodDataBase,jf_string));
  51.     }
  52.     return 1;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment