Guest User

bBans System

a guest
Feb 7th, 2016
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 8.36 KB | None | 0 0
  1. /*
  2.             Title:               bBan - Effective temporary/permanent ban system
  3.             Author:              biker122
  4.             Description:         bBan offers server owners to ban players
  5.                                  temporarily (or) permanently on day basis.
  6.                                  The system uses timestamps to check the ban
  7.                                  expiry time. It works on MySQL which is a
  8.                                  fastest way to send and recieve data.
  9.  
  10.             Credits:             biker122        - Scripting
  11.                                  BlueG           - MySQL (R38) Plugin
  12.                                  TimestampToDate - Jochemd
  13.                                  Y_Less          - sscanf(2)
  14.                                  Zeex            - zcmd
  15.  
  16. */
  17.  
  18. //=================================[Include(s)]===============================//
  19. #include <a_samp>
  20. #include <a_mysql>
  21. #include <sscanf2>
  22. #include <TimestampToDate>
  23. #include <zcmd>
  24.  
  25. //============================[MySQL Configuration]===========================//
  26. #define MySQL_Host                                                  "localhost"
  27. #define MySQL_User                                                  "root"
  28. #define MySQL_Pass                                                  ""
  29. #define MySQL_Data                                                  "bBan"
  30.  
  31. #define Bans_Table                                                  "Bans"
  32.  
  33. new MySQL; // Connection Handler
  34. new gQuery[640];
  35.  
  36. //===========================[Dialogs & Definitions]==========================//
  37. #define DIALOG_BANINFO                                              ( 800 )
  38. #define DIALOG_BANCHECK                                             ( 801 )
  39.  
  40. //
  41. #define MAX_BAN_REASON                                              ( 28 )
  42.  
  43. // Colours
  44. #define GREY                                                        "{C0C4C4}"
  45. #define ORANGE                                                      "{F75A05}"
  46. #define RED                                                         "{FF0000}"
  47.  
  48. //============================================================================//
  49.  
  50. public OnFilterScriptInit()
  51. {
  52.     MySQL = mysql_connect(MySQL_Host, MySQL_User, MySQL_Data, MySQL_Pass);
  53.     mysql_log(LOG_ALL);
  54.  
  55.     switch(mysql_errno(MySQL))
  56.     {
  57.         case 0: print("bBan System: MySQL connection to "MySQL_Host" successful.");
  58.         default: print("bBan System: MySQL connection to "MySQL_Host" failed.");
  59.     }
  60.     return 1;
  61. }
  62.  
  63. public OnFilterScriptExit()
  64. {
  65.     mysql_close(MySQL);
  66.     print("bBan System: Ban system has been unloaded. MySQL connection has been terminated.");
  67.     return 1;
  68. }
  69.  
  70. public OnPlayerConnect(playerid)
  71. {
  72.     Check_Ban(playerid);
  73.     return 1;
  74. }
  75.  
  76. //================================[Command(s)]================================//
  77. CMD:ban(playerid, params[])
  78. {
  79.     new reason[30], ban_id, ban_admin[MAX_PLAYER_NAME], ban_user[MAX_PLAYER_NAME], ban_time, str[512];
  80.     new expiry;
  81.     new d, m, y, h, mi, s;
  82.     if(sscanf(params, "us[30]i", ban_id, reason, ban_time)) return SendClientMessage(playerid, -1, ""RED"jBans{FFFFFF}: Insufficient/Invalid parameters! (/ban (player name/id) (ban reason) (ban time [in days] (ban time 0 = permanent))");
  83.     if(strlen(reason) > 30) return SendClientMessage(playerid, -1, ""RED"jBans{FFFFFF}: STRING ERROR! Reason must not exceed 30 characters!");
  84.     if(!IsPlayerConnected(ban_id)) return SendClientMessage(playerid, -1, ""RED"jBans{FFFFFF}: PLAYER ERROR! Invalid player specified!");
  85.  
  86.     GetPlayerName(playerid, ban_user, sizeof ban_user), GetPlayerName(playerid, ban_admin, sizeof ban_admin);
  87.     expiry = gettime() + (60*60*24*ban_time);
  88.     mysql_format(MySQL, gQuery, sizeof gQuery, "INSERT INTO `"Bans_Table"` (ban_user, ban_admin, ban_reason, ban_time) VALUES ('%e', '%e', '%e', '%i')", ban_user, ban_admin, reason, expiry);
  89.     mysql_tquery(MySQL, gQuery, "", "");
  90.  
  91.     format(str, sizeof str, ""RED"jBans{FFFFFF}: Administrator has banned %s(%i)! [Reason: %s] [Ban Time: %i day(s)]", ban_user, ban_id, reason, ban_time);
  92.     SendClientMessageToAll(-1, str);
  93.  
  94.     if(ban_time == 0)
  95.     {
  96.         format(str, sizeof(str), ""ORANGE"You are banned from the server!\nBan Time: "GREY"Permanent\n"ORANGE"Admin who banned you: "GREY"%s\n"ORANGE"Reason: "GREY"%s\n!", ban_admin, reason);
  97.         ShowPlayerDialog(ban_id, DIALOG_BANINFO, DIALOG_STYLE_MSGBOX, ""RED"You are banned!", str, "BUSTED", "GET_REKT");
  98.         SetTimerEx("KickPlayer", 500, false, "i", ban_id);
  99.     }
  100.     else if(ban_time > 0)
  101.     {
  102.         TimestampToDate(expiry , y , m, d, h, mi, s, 0, 0);
  103.         format(str, sizeof(str), ""ORANGE"You are banned from the server!\nBan Expire: "GREY"%i/%i/%i [DD/MM/YY] | %i:%i\n"ORANGE"Admin who banned you: "GREY"%s\n"ORANGE"Reason: "GREY"%s\n", d, m, y, h, mi, ban_admin, reason);
  104.         ShowPlayerDialog(ban_id, DIALOG_BANINFO, DIALOG_STYLE_MSGBOX, ""RED"You are banned!", str, "BUSTED", "GET_REKT");
  105.         SetTimerEx("KickPlayer", 500, false, "i", ban_id);
  106.     }
  107.     return 1;
  108. }
  109.  
  110. CMD:unban(playerid, params[])
  111. {
  112.     new unban_user[MAX_PLAYER_NAME];
  113.     if(sscanf(params, "s[24]", unban_user)) return SendClientMessage(playerid, -1, ""RED"jBans{FFFFFF}: Insufficient/Invalid parameter! (/unban (banned username)");
  114.  
  115.     mysql_format(MySQL, gQuery, 256, "SELECT * FROM `"Bans_Table"` WHERE `ban_name` = '%e' LIMIT 1", unban_user);
  116.     mysql_tquery(MySQL, gQuery, "Safe_Unban", "is[24]", playerid, unban_user);
  117.     return 1;
  118. }
  119.  
  120. //================================[Function(s)]===============================//
  121.  
  122. forward KickPlayer(playerid);
  123. public KickPlayer(playerid)
  124. {
  125.     Kick(playerid);
  126.     return 1;
  127. }
  128.  
  129. forward Safe_Unban(playerid, user[]);
  130. public Safe_Unban(playerid, user[])
  131. {
  132.     new rows, fields;
  133.     cache_get_data(rows, fields);
  134.  
  135.     switch(rows)
  136.     {
  137.         case 0:
  138.         {
  139.             SendClientMessage(playerid, -1, ""RED"jBans{FFFFFF}: ERROR! There is no ban issued under the given username!");
  140.         }
  141.         case 1:
  142.         {
  143.             mysql_format(MySQL, gQuery, 256, "DELETE FROM `"Bans_Table"` WHERE `ban_name` = '%e'", user);
  144.             mysql_tquery(MySQL, gQuery, "", "");
  145.  
  146.             new str[128];
  147.             format(str, sizeof str, ""RED"jBans{FFFFFF}: Administrator has unbanned %s!", user);
  148.             SendClientMessageToAll(-1, str);
  149.             SendClientMessage(playerid, -1, ""RED"jBans{FFFFFF}: You've successfully unbanned the give username!");
  150.         }
  151.     }
  152.     return 1;
  153. }
  154.  
  155. forward Check_Ban(playerid);
  156. public Check_Ban(playerid)
  157. {
  158.     new pName[MAX_PLAYER_NAME];
  159.     GetPlayerName(playerid, pName, sizeof pName);
  160.     mysql_format(MySQL, gQuery, sizeof(gQuery), "SELECT * FROM `"Bans_Table"` WHERE `ban_name` = '%e' LIMIT 1", pName);
  161.     mysql_tquery(MySQL, gQuery, "Safe_Checkban", "i", playerid);
  162.     return 1;
  163. }
  164.  
  165. forward Safe_Checkban(playerid);
  166. public Safe_Checkban(playerid)
  167. {
  168.     new rows, fields, pName[MAX_PLAYER_NAME];
  169.     GetPlayerName(playerid, pName, sizeof pName);
  170.     cache_get_data(rows, fields);
  171.     switch(rows)
  172.     {
  173.         case 1:
  174.         {
  175.             new time_left, admin[24], reason[30], y, m, d, h, mi, s;
  176.             cache_get_field_content(0, "ban_admin", admin, MySQL, 24);
  177.             cache_get_field_content(0, "ban_reason", reason, MySQL, 30);
  178.             time_left = cache_get_field_content_int(0, "ban_time", MySQL);
  179.  
  180.             if(time_left == 0)
  181.             {
  182.                 new str1[400];
  183.                 format(str1, sizeof(str1), ""ORANGE"You are banned from the server!\nBan Time: "GREY"Permanent\n"ORANGE"Admin who banned you: "GREY"%s\n"ORANGE"Reason: "GREY"%s\n\n", admin, reason);
  184.                 ShowPlayerDialog(playerid, DIALOG_BANINFO, DIALOG_STYLE_MSGBOX, ""RED"You are banned!", str1, "BUSTED!", "GET_REKT");
  185.                 SetTimerEx("KickPlayer", 100, false, "i", playerid);
  186.             }
  187.             if(time_left > 0)
  188.             {
  189.                 if(gettime() > time_left)
  190.                 {
  191.                     SendClientMessage(playerid, -1, ""RED"bBans{FFFFFF}: Your ban has expired. You are now unbanned from the server.");
  192.                     SendClientMessage(playerid, -1, ""RED"bBans{FFFFFF}: Please relog to proceed to the login screen.");
  193.                     mysql_format(MySQL, gQuery, 128, "DELETE FROM `"Bans_Table"` WHERE `ban_name` = '%e'", pName);
  194.                     mysql_tquery(MySQL, gQuery, "", "");
  195.                     SetTimerEx("KickPlayer", 100, false, "i", playerid);
  196.                 }
  197.                 else if(gettime() < time_left)
  198.                 {
  199.                     new str2[256];
  200.                     TimestampToDate(time_left, y, m, d, h, mi, s, 0, 0);
  201.                     format(str2, sizeof(str2), ""ORANGE"You are banned from the server!\nBan Expires: "GREY"%i/%i/%i [DD/MM/YY] | %i:%i\n"ORANGE"Admin who banned you: "GREY"%s\n"ORANGE"Reason: "GREY"%s\n\n", d, m, y, h, mi, admin, reason);
  202.                     ShowPlayerDialog(playerid, DIALOG_BANINFO, DIALOG_STYLE_MSGBOX, ""RED"You are banned!", str2, "Bye Bye!", "");
  203.                     SetTimerEx("KickPlayer", 100, false, "i", playerid);
  204.                 }
  205.             }
  206.         }
  207.     }
  208.     return 1;
  209. }
  210.  
  211. //============================================================================//
Add Comment
Please, Sign In to add comment