jlalt

Mysql Ban SystemV2

Oct 27th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 12.14 KB | None | 0 0
  1. #include a_samp
  2. #include a_mysql
  3. #include zcmd
  4.  
  5. #define red          0xFF0000AA
  6. #define COLOR_Silver 0xCACACAAA
  7.  
  8. //==================================News======================================//
  9. new banned[MAX_PLAYERS],
  10.     whatunbanip[32],
  11.     whatbanip[32],
  12.     mysql;
  13. //====================================Forwards================================//
  14. forward BanCheck(playerid);
  15. forward BanIPCheck(playerid);
  16. forward kickplayer(playerid);
  17. forward Unban(playerid);
  18. forward Unbanip(playerid);
  19. forward Banip(playerid);
  20. forward Baninfo(playerid);
  21. //============================================================================//
  22.  
  23. public OnFilterScriptInit()
  24. {
  25.     mysql_log(LOG_ERROR | LOG_WARNING | LOG_DEBUG);
  26.     mysql = mysql_connect("MYSQL_HOST", "MYSQL_USER", "MYSQL_DATABASE", "MYSQL_PASSWORD");
  27.     if(mysql_errno(mysql) != 0)
  28.     {
  29.          print("Could not connect to database!");
  30.     }
  31.     else
  32.     {
  33.         print("Successfully connected on DB ");
  34.     }
  35.     return 1;
  36. }
  37.  
  38. public OnFilterScriptExit() {
  39.     mysql_close();
  40. }
  41.  
  42. public OnPlayerConnect(playerid) {
  43.     banned[playerid] = 0;
  44.     new name1[35];
  45.     GetPlayerName(playerid,name1,sizeof(name1));
  46.     new Query[250];
  47.    
  48.     mysql_format(mysql, Query, sizeof(Query),"SELECT `banned`, `ip`, `date`, `time`, `bannedby`, `banned`, `reason` FROM `banneds` WHERE `name` = '%e' LIMIT 1", name1);
  49.     mysql_tquery(mysql, Query, "BanCheck", "i", playerid);
  50.     return 1;
  51.  }
  52.  
  53. CMD:ban(playerid,params[]) {
  54.     if(IsPlayerAdmin(playerid)) {
  55.             new strdate[128],strtime[128], tmp[256], tmp2[256], Index;      tmp = strtok(params,Index), tmp2 = strtok(params,Index);
  56.             if(!strlen(params)) return SendClientMessage(playerid, red, "USAGE: /ban [playerid] [reason]");
  57.             if(!strlen(tmp2)) return SendClientMessage(playerid, red, "ERROR: You must give a reason");
  58.             new player1, playername[MAX_PLAYER_NAME], ip[128], adminname[MAX_PLAYER_NAME], string[128];
  59.             player1 = strval(tmp);
  60.             if(IsPlayerConnected(player1) && player1 != INVALID_PLAYER_ID && player1 != playerid && !IsPlayerAdmin(player1)) {
  61.                 GetPlayerName(player1, playername, sizeof(playername)); GetPlayerName(playerid, adminname, sizeof(adminname)); GetPlayerIp(playerid,ip,sizeof(ip));
  62.                 new year,month,day,hour,minuite,second; getdate(year, month, day); gettime(hour,minuite,second);
  63.                 format(string,sizeof(string),"|- %s has been banned by Administrator %s [Reason: %s] [Date: %d/%d/%d] [Time: %d:%d] -|",playername,adminname,params[2],day,month,year,hour,minuite);
  64.                 SendClientMessageToAll(COLOR_Silver,string);
  65.                 print(string);
  66.  
  67.                 format(strdate, sizeof(strdate), "%d-%d-%d ",year,month,day);
  68.                 format(strtime,sizeof(strtime),"%d:%d:%d",hour,minuite,second);
  69.                 new Query[250];
  70.                
  71.                 format(Query, sizeof(Query), "UPDATE `banneds` SET `ip` = '%s', `date` = '%s', `time` = '%s', `bannedby` = '%s', `banned` = '%d', `reason` = '%s' WHERE `name` = '%s'", ip,strdate,strtime,adminname,1,params[2],playername);
  72.                 mysql_tquery(mysql, Query, "", "");
  73.                 format(Query, sizeof(Query),"INSERT INTO `bannedips`(`ip`) VALUES ('%s')",ip);
  74.                 mysql_tquery(mysql, Query, "", "");
  75.                
  76.                 return SetTimerEx("kickplayer", 500, false, "i", playerid);
  77.             } else return SendClientMessage(playerid, red, "Player is not connected or is yourself or is the highest level admin");
  78.     } else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
  79. }
  80. CMD:unban(playerid,params[]) {
  81.      if(IsPlayerAdmin(playerid)) {
  82.      if(isnull(params)) return SendClientMessage(playerid,-1,"Usage: /unban [playername]");
  83.      new Query[250];
  84.      format(Query, sizeof(Query), "SELECT * FROM banneds WHERE `name` = '%s'", params);
  85.      mysql_tquery(mysql, Query, "Unban", "i", playerid);
  86.      
  87.      } else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
  88.      return 1;
  89. }
  90.  
  91.  
  92. CMD:unbanip(playerid,params[]) {
  93.    if(IsPlayerAdmin(playerid)) {
  94.      if(isnull(params)) return SendClientMessage(playerid,-1,"Usage: /unbanip [ip]");
  95.      new size; size = strval(params);
  96.      if(size > 15 && size < 30) {
  97.      new Query[250];
  98.      format(Query, sizeof(Query), "SELECT * FROM bannedips WHERE `ip` = '%s'", params);
  99.      strins(whatunbanip, params, 0);
  100.      mysql_tquery(mysql, Query, "Unbanip", "i", playerid);
  101.      } else return SendClientMessage(playerid,red,"ERROR: IP is too short OR is too long");
  102.    } else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
  103.    return 1;
  104. }
  105.  
  106. CMD:banip(playerid,params[]) {
  107.    if(IsPlayerAdmin(playerid)) {
  108.      if(isnull(params)) return SendClientMessage(playerid,-1,"Usage: /banip [ip]");
  109.      new Query[250];
  110.      format(Query, sizeof(Query), "SELECT * FROM bannedips WHERE `ip` = '%s'", params);
  111.      mysql_tquery(mysql, Query, "Banip", "i", playerid);
  112.      strins(whatbanip, params, 0);
  113.    } else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
  114.    return 1;
  115. }
  116. public Banip(playerid) {
  117.    new rows, fields,string[128],Query[250];
  118.    cache_get_data(rows, fields, mysql);
  119.    if(rows)
  120.       {
  121.       whatbanip = "";
  122.       return SendClientMessage(playerid,red,"ERROR: That ip already banned");
  123.       }
  124.    if(!rows)
  125.       {
  126.        format(Query, sizeof(Query),"INSERT INTO `bannedips`(`ip`) VALUES ('%s')",whatbanip);
  127.        mysql_tquery(mysql, Query, "", "");
  128.        format(string,sizeof(string),"[IP]: %s has been successfully banned",whatbanip);
  129.        SendClientMessage(playerid,0x00FFFFAA,string);
  130.        whatbanip = "";
  131.       }
  132.    return 1;
  133. }
  134.  
  135. CMD:baninfo(playerid,params[]) {
  136.    if(IsPlayerAdmin(playerid)) {
  137.      if(isnull(params)) return SendClientMessage(playerid,-1,"Usage: /baninfo [playername]");
  138.      new Query[250];
  139.      format(Query, sizeof(Query), "SELECT * FROM banneds WHERE `name` = '%s'", params);
  140.      mysql_tquery(mysql, Query, "Baninfo", "i", playerid);
  141.  
  142.    } else return SendClientMessage(playerid,red,"ERROR: You are not a high enough level to use this command");
  143.    return 1;
  144. }
  145.      
  146. //================================Publics=====================================//
  147. public BanCheck(playerid) {
  148.     new rows, fields,ibanned[10],ifbanned;
  149.     cache_get_data(rows, fields, mysql);
  150.     if(rows)
  151.     {
  152.          cache_get_field_content(0, "banned", ibanned, mysql, 10);
  153.          ifbanned = strval(ibanned);
  154.          if(ifbanned == 1) {
  155.          new save[4][80],name1[MAX_PLAYER_NAME+1]; GetPlayerName(playerid,name1,sizeof(name1));
  156.          cache_get_field_content(0, "date", save[0], mysql, 80);
  157.          cache_get_field_content(0, "time", save[1], mysql, 80);
  158.          cache_get_field_content(0, "bannedby", save[2], mysql, 80);
  159.          cache_get_field_content(0, "reason", save[3], mysql, 80);
  160.          new str[350],content[128]; format(content,sizeof content,"%s %s",save[0],save[1]);
  161.          format(str, sizeof(str),"{C0C0C0}Your Account's currently Banned.\n\n{00FFFF}In-Game Name: {33FF33}%s\n{00FFFF}Administrator: {33FF33}%s\n{00FFFF}Date: {33FF33}%s\n{00FFFF}Reason: {33FF33}%s\n{C0C0C0}* if you think that you're banned wrongfully,\nfeel free to make unban appeal on our forum: forum",name1,save[2],content,save[3]);
  162.          ShowPlayerDialog(playerid, 801, DIALOG_STYLE_MSGBOX, "{FF0000}You Are Banned!", str, "Close","");
  163.          SetTimerEx("kickplayer", 500, false, "i", playerid);
  164.      }
  165.    }
  166.     if(!rows)
  167.     {
  168.      new Query[250],ip1[32]; GetPlayerIp(playerid,ip1,sizeof(ip1));
  169.      format(Query, sizeof(Query), "SELECT * FROM `bannedips` WHERE `ip` = '%s'", ip1);
  170.      mysql_tquery(mysql, Query, "BanIPCheck", "i", playerid);
  171.      }
  172.     return 1;
  173. }
  174.  
  175. public BanIPCheck(playerid) {
  176.        new rows, fields,string[128];
  177.        cache_get_data(rows, fields, mysql);
  178.        if(rows)
  179.         {
  180.          new name1[MAX_PLAYER_NAME]; GetPlayerName(playerid,name1,sizeof(name1));
  181.          format(string,sizeof(string),"%s has been Auto Kicked | Reason: Banned IP |",name1);
  182.          SendClientMessageToAll(COLOR_Silver,string);
  183.          SetTimerEx("kickplayer", 500, false, "i", playerid);
  184.        }
  185.        if(!rows)
  186.       {
  187.        new Query[250],datum[50],hour1,minute1,second1,year1,month1,day1,tijd[50],ip1[32];
  188.        new name1[MAX_PLAYER_NAME]; GetPlayerName(playerid,name1,sizeof(name1));
  189.        getdate(year1, month1, day1); gettime(hour1,minute1,second1); GetPlayerIp(playerid,ip1,sizeof(ip1));
  190.        format(datum, sizeof(datum), "%d-%d-%d", year1, month1, day1); format(tijd, sizeof(tijd), "%d:%d:%d", hour1, minute1, second1);
  191.        new none[15]; none = "None";
  192.        format(Query, sizeof(Query),"INSERT INTO `banneds` (name,ip,date,time,bannedby,banned,reason) VALUES ('%s','%s','%s','%s','%s','%s','%s')",name1,ip1,datum,tijd,none,none,none);
  193.        mysql_tquery(mysql, Query, "", "");
  194.    }
  195. }
  196.  
  197. public Unban(playerid) {
  198.   new rows, fields,string[128];
  199.   cache_get_data(rows, fields, mysql);
  200.   if(rows)
  201.       {
  202.        new Query[250],saving0[10],saving1[32],saving2[32],unban;
  203.        cache_get_field_content(0, "name", saving2, mysql, 32);
  204.        cache_get_field_content(0, "banned", saving0, mysql, 10);
  205.        cache_get_field_content(0, "ip", saving1, mysql, 32);
  206.        unban = strval(saving0);
  207.        if(unban == 1) {
  208.        new none[10]; none = "0";
  209.        format(Query, sizeof(Query),"UPDATE `banneds` SET `banned` = 0,`bannedby` = %s,`reason` = %s WHERE `name` = '%s'",none,none,saving2);
  210.        mysql_tquery(mysql, Query, "", "");
  211.        format(Query, 100, "DELETE FROM `bannedips` WHERE `ip` = '%s'", saving1);
  212.        mysql_tquery(mysql, Query, "", "");
  213.        format(string,sizeof(string),"%s successfully has been unbanned",saving2);
  214.        SendClientMessage(playerid,0x00FFFFAA,string);
  215.        } else return SendClientMessage(playerid,red,"ERROR: This Player is not banned");
  216.     } else return SendClientMessage(playerid,red,"ERROR: Player Name Not Exist on Database");
  217.   return 1;
  218. }
  219.  
  220. public Unbanip(playerid) {
  221.    new rows, fields,string[128];
  222.    cache_get_data(rows, fields, mysql);
  223.    if(rows)
  224.       {
  225.        new Query[250];
  226.        format(Query, 100, "DELETE FROM `bannedips` WHERE `ip` = '%s'", whatunbanip);
  227.        mysql_tquery(mysql, Query, "", "");
  228.        format(string,sizeof(string),"[IP]: %s has been successfully unbanned", whatunbanip);
  229.        SendClientMessage(playerid,0x00FFFFAA,string);
  230.        whatunbanip = "";
  231.    } else return SendClientMessage(playerid,red,"ERROR: IP Not Exist on banned ips Database"); whatunbanip = "";
  232.    return 1;
  233. }
  234.  
  235. public Baninfo(playerid) {
  236.    new rows, fields;
  237.    cache_get_data(rows, fields, mysql);
  238.    if(rows)
  239.       {
  240.        new save[5][50],save5[128],banned1,str[350],str2[80],datetime[50];
  241.        cache_get_field_content(0, "banned", save[0], mysql, 10);
  242.        banned1 = strval(save[0]);
  243.        if(banned1 == 1) {
  244.        cache_get_field_content(0, "date", save[1], mysql, 50);
  245.        cache_get_field_content(0, "time", save[2], mysql, 50);
  246.        cache_get_field_content(0, "bannedby", save[3], mysql, 50);
  247.        cache_get_field_content(0, "name", save[4], mysql, 50);
  248.        cache_get_field_content(0, "reason", save5, mysql, 128);
  249.        format(str2,sizeof(str2),"%s Ban Information",save[4]);
  250.        format(datetime,sizeof(datetime),"%s %s",save[1],save[2]);
  251.        format(str, sizeof(str),"{00FFFF}Player Name: {33FF33}%s\n\n{00FFFF}Banned By: {33FF33}%s\n\n{00FFFF}Date: {33FF33}%s\n\n{00FFFF}Reason: {33FF33}%s",save[4],save[3],datetime,save5);
  252.        ShowPlayerDialog(playerid, 801, DIALOG_STYLE_MSGBOX, str2, str, "Close","");
  253.        } else return SendClientMessage(playerid,red,"ERROR: This player is not banned");
  254.    } else return SendClientMessage(playerid,red,"ERROR: Player Name not Exist on database");
  255.    return 1;
  256. }
  257.  
  258. public kickplayer(playerid) {
  259.     return Kick(playerid);
  260. }
  261. //==================================a fuction=================================//
  262. strtok(const string[], &index)
  263. {
  264.     new length = strlen(string);
  265.     while ((index < length) && (string[index] <= ' '))
  266.     {
  267.         index++;
  268.     }
  269.  
  270.     new offset = index;
  271.     new result[20];
  272.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  273.     {
  274.         result[index - offset] = string[index];
  275.         index++;
  276.     }
  277.     result[index - offset] = EOS;
  278.     return result;
  279. }
  280. //============================================================================//
Advertisement
Add Comment
Please, Sign In to add comment