Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Title: bBan - Effective temporary/permanent ban system
- Author: biker122
- Description: bBan offers server owners to ban players
- temporarily (or) permanently on day basis.
- The system uses timestamps to check the ban
- expiry time. It works on MySQL which is a
- fastest way to send and recieve data.
- Credits: biker122 - Scripting
- BlueG - MySQL (R38) Plugin
- TimestampToDate - Jochemd
- Y_Less - sscanf(2)
- Zeex - zcmd
- */
- //=================================[Include(s)]===============================//
- #include <a_samp>
- #include <a_mysql>
- #include <sscanf2>
- #include <TimestampToDate>
- #include <zcmd>
- //============================[MySQL Configuration]===========================//
- #define MySQL_Host "localhost"
- #define MySQL_User "root"
- #define MySQL_Pass ""
- #define MySQL_Data "bBan"
- #define Bans_Table "Bans"
- new MySQL; // Connection Handler
- new gQuery[640];
- //===========================[Dialogs & Definitions]==========================//
- #define DIALOG_BANINFO ( 800 )
- #define DIALOG_BANCHECK ( 801 )
- //
- #define MAX_BAN_REASON ( 28 )
- // Colours
- #define GREY "{C0C4C4}"
- #define ORANGE "{F75A05}"
- #define RED "{FF0000}"
- //============================================================================//
- public OnFilterScriptInit()
- {
- MySQL = mysql_connect(MySQL_Host, MySQL_User, MySQL_Data, MySQL_Pass);
- mysql_log(LOG_ALL);
- switch(mysql_errno(MySQL))
- {
- case 0: print("bBan System: MySQL connection to "MySQL_Host" successful.");
- default: print("bBan System: MySQL connection to "MySQL_Host" failed.");
- }
- return 1;
- }
- public OnFilterScriptExit()
- {
- mysql_close(MySQL);
- print("bBan System: Ban system has been unloaded. MySQL connection has been terminated.");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- Check_Ban(playerid);
- return 1;
- }
- //================================[Command(s)]================================//
- CMD:ban(playerid, params[])
- {
- new reason[30], ban_id, ban_admin[MAX_PLAYER_NAME], ban_user[MAX_PLAYER_NAME], ban_time, str[512];
- new expiry;
- new d, m, y, h, mi, s;
- 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))");
- if(strlen(reason) > 30) return SendClientMessage(playerid, -1, ""RED"jBans{FFFFFF}: STRING ERROR! Reason must not exceed 30 characters!");
- if(!IsPlayerConnected(ban_id)) return SendClientMessage(playerid, -1, ""RED"jBans{FFFFFF}: PLAYER ERROR! Invalid player specified!");
- GetPlayerName(playerid, ban_user, sizeof ban_user), GetPlayerName(playerid, ban_admin, sizeof ban_admin);
- expiry = gettime() + (60*60*24*ban_time);
- 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);
- mysql_tquery(MySQL, gQuery, "", "");
- 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);
- SendClientMessageToAll(-1, str);
- if(ban_time == 0)
- {
- 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);
- ShowPlayerDialog(ban_id, DIALOG_BANINFO, DIALOG_STYLE_MSGBOX, ""RED"You are banned!", str, "BUSTED", "GET_REKT");
- SetTimerEx("KickPlayer", 500, false, "i", ban_id);
- }
- else if(ban_time > 0)
- {
- TimestampToDate(expiry , y , m, d, h, mi, s, 0, 0);
- 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);
- ShowPlayerDialog(ban_id, DIALOG_BANINFO, DIALOG_STYLE_MSGBOX, ""RED"You are banned!", str, "BUSTED", "GET_REKT");
- SetTimerEx("KickPlayer", 500, false, "i", ban_id);
- }
- return 1;
- }
- CMD:unban(playerid, params[])
- {
- new unban_user[MAX_PLAYER_NAME];
- if(sscanf(params, "s[24]", unban_user)) return SendClientMessage(playerid, -1, ""RED"jBans{FFFFFF}: Insufficient/Invalid parameter! (/unban (banned username)");
- mysql_format(MySQL, gQuery, 256, "SELECT * FROM `"Bans_Table"` WHERE `ban_name` = '%e' LIMIT 1", unban_user);
- mysql_tquery(MySQL, gQuery, "Safe_Unban", "is[24]", playerid, unban_user);
- return 1;
- }
- //================================[Function(s)]===============================//
- forward KickPlayer(playerid);
- public KickPlayer(playerid)
- {
- Kick(playerid);
- return 1;
- }
- forward Safe_Unban(playerid, user[]);
- public Safe_Unban(playerid, user[])
- {
- new rows, fields;
- cache_get_data(rows, fields);
- switch(rows)
- {
- case 0:
- {
- SendClientMessage(playerid, -1, ""RED"jBans{FFFFFF}: ERROR! There is no ban issued under the given username!");
- }
- case 1:
- {
- mysql_format(MySQL, gQuery, 256, "DELETE FROM `"Bans_Table"` WHERE `ban_name` = '%e'", user);
- mysql_tquery(MySQL, gQuery, "", "");
- new str[128];
- format(str, sizeof str, ""RED"jBans{FFFFFF}: Administrator has unbanned %s!", user);
- SendClientMessageToAll(-1, str);
- SendClientMessage(playerid, -1, ""RED"jBans{FFFFFF}: You've successfully unbanned the give username!");
- }
- }
- return 1;
- }
- forward Check_Ban(playerid);
- public Check_Ban(playerid)
- {
- new pName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pName, sizeof pName);
- mysql_format(MySQL, gQuery, sizeof(gQuery), "SELECT * FROM `"Bans_Table"` WHERE `ban_name` = '%e' LIMIT 1", pName);
- mysql_tquery(MySQL, gQuery, "Safe_Checkban", "i", playerid);
- return 1;
- }
- forward Safe_Checkban(playerid);
- public Safe_Checkban(playerid)
- {
- new rows, fields, pName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pName, sizeof pName);
- cache_get_data(rows, fields);
- switch(rows)
- {
- case 1:
- {
- new time_left, admin[24], reason[30], y, m, d, h, mi, s;
- cache_get_field_content(0, "ban_admin", admin, MySQL, 24);
- cache_get_field_content(0, "ban_reason", reason, MySQL, 30);
- time_left = cache_get_field_content_int(0, "ban_time", MySQL);
- if(time_left == 0)
- {
- new str1[400];
- 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);
- ShowPlayerDialog(playerid, DIALOG_BANINFO, DIALOG_STYLE_MSGBOX, ""RED"You are banned!", str1, "BUSTED!", "GET_REKT");
- SetTimerEx("KickPlayer", 100, false, "i", playerid);
- }
- if(time_left > 0)
- {
- if(gettime() > time_left)
- {
- SendClientMessage(playerid, -1, ""RED"bBans{FFFFFF}: Your ban has expired. You are now unbanned from the server.");
- SendClientMessage(playerid, -1, ""RED"bBans{FFFFFF}: Please relog to proceed to the login screen.");
- mysql_format(MySQL, gQuery, 128, "DELETE FROM `"Bans_Table"` WHERE `ban_name` = '%e'", pName);
- mysql_tquery(MySQL, gQuery, "", "");
- SetTimerEx("KickPlayer", 100, false, "i", playerid);
- }
- else if(gettime() < time_left)
- {
- new str2[256];
- TimestampToDate(time_left, y, m, d, h, mi, s, 0, 0);
- 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);
- ShowPlayerDialog(playerid, DIALOG_BANINFO, DIALOG_STYLE_MSGBOX, ""RED"You are banned!", str2, "Bye Bye!", "");
- SetTimerEx("KickPlayer", 100, false, "i", playerid);
- }
- }
- }
- }
- return 1;
- }
- //============================================================================//
Add Comment
Please, Sign In to add comment