Advertisement
Wojtek96

Untitled

May 5th, 2013
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. //Anti Bot System
  2. #include "a_samp.inc"
  3. new var[MAX_PLAYERS] = {-1,...}, warns[MAX_PLAYERS] = {0,...}, bool:npc[MAX_PLAYERS] = {false,...}, MAX_PLAYERS_ = MAX_PLAYERS;
  4. public OnFilterScriptInit()
  5. {
  6. SendRconCommand("reloadbans");
  7. print("Anti Bot Started");
  8. return 1;
  9. }
  10. public OnPlayerConnect(playerid)
  11. {
  12. if(CountIP(GetIP(playerid)) >= 4) return BanAll(playerid), 0;
  13. MAX_PLAYERS_ = playerid > MAX_PLAYERS_ ? playerid : GetHighestID(),
  14. npc[playerid] = bool:IsPlayerNPC(playerid),
  15. var[playerid] = SetTimerEx("BSS",2500,false,"i",playerid),
  16. warns[playerid] = 0;
  17. return 1;
  18. }
  19. public OnPlayerDisconnect(playerid, reason)
  20. {
  21. MAX_PLAYERS_ = GetHighestID(playerid);
  22. if(npc[playerid]) npc[playerid] = false;
  23. if(var[playerid] != -1)
  24. {
  25. KillTimer(var[playerid]);
  26. var[playerid] = -1;
  27. }
  28. warns[playerid] = 0;
  29. return 1;
  30. }
  31. stock CountIP(ip[])
  32. {
  33. new c = 0;
  34. for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i) && !strcmp(GetIP(i),ip)) c++;
  35. return c;
  36. }
  37. forward BSS(playerid);
  38. public BSS(playerid)
  39. {
  40. new i = GetPlayerPing(playerid);
  41. if(i <= 0 || i >= 70000)
  42. {
  43. if(warns[playerid] >= 1) BanAll(playerid);
  44. else warns[playerid]++, var[playerid] = SetTimerEx("BSS",1500,false,"i",playerid);
  45. }
  46. return 0;
  47. }
  48. stock GetIP(playerid)
  49. {
  50. new ip[16];
  51. GetPlayerIp(playerid,ip,sizeof(ip));
  52. return ip;
  53. }
  54. stock BanAll(playerid)
  55. {
  56. new ip[32];
  57. GetPlayerIp(playerid,ip,sizeof(ip));
  58. for(new i = 0, p = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i) && !npc[i])
  59. {
  60. p = GetPlayerPing(i);
  61. if(i == playerid || !strcmp(ip,GetIP(i)) || p <= 0 || p >= 70000)
  62. {
  63. BanEx(i,"Bot");
  64. if(var[i] != -1)
  65. {
  66. KillTimer(var[i]);
  67. var[i] = -1;
  68. }
  69. }
  70. }
  71. format(ip,sizeof(ip),"banip %s",ip);
  72. return SendRconCommand(ip);
  73. }
  74. stock GetHighestID(exceptof = INVALID_PLAYER_ID)
  75. {
  76. new h = 0;
  77. for(new i = 0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i) && i != exceptof && i > h) h = i;
  78. return h;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement