Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- _ ______
- | | | ___ \
- ___| |__ | |_/ / __ _ _ __
- / __| '_ \| ___ \/ _` | '_ \
- \__ \ |_) | |_/ / (_| | | | |
- |___/_.__/\____/ \__,_|_| |_|
- Version 1.0 - SecretBoss - sbBan
- MySQL Ban System - Easy-Mysql.inc
- Special thanks to ThePhenix for easy-mysql include
- Also to Gammix for GAdmin (examples)
- • Features
- With sbBan system you can prevent hackers rulebreaker
- from joining your server, you can give them temp bans,
- account bans and ip bans, when you ban a player his IP
- will also get banned and when he joins it will appear
- like he is banned, you don't need to import tables
- Just edit configuration to your own and recompile the
- script
- • About
- I made that system for sbAdmin but sbAdmin will may late
- to be released so I decided to release it alone (Ban System)
- When I will update something on sbAdmin's ban system I will
- also update it here so you can use it on your own
- • Bugs
- I tested this system on sbAdmin local server and it worked
- if you find any bugs please report them and I will fix them
- as soon as possible thanks...
- */
- //================================================
- #include <a_samp> // SAMP Team
- #include <easy-mysql> // ThePhenix
- #include <izcmd> // Yashas and Zeex
- #include <sscanf2> // Emmet_
- #include <timestamptodate>
- //================================================
- // Configuration
- #define BANS_TABLE "bans" // Table where all Bans will be saved
- #define MYSQL_HOST "localhost" // Your MySQL's Host
- #define MYSQL_USER "root" // Your MySQL's Username
- #define MYSQL_DATABASE "sbBan" // Your MySQL's Database
- #define MYSQL_PASSWORD "" // Your MySQL's Password
- //================================================
- #define COLOR_RED 0xFF0000FF // Color to be used on messages
- #define DIALOG_SBBAN 1024 // Random Number
- //================================================
- public OnFilterScriptInit()
- {
- print("\n\n_________________________________________________________________");
- print(" sbBan \n");
- print("[sbBan]: Attempting to load sbBan system ");
- SQL::Connect(MYSQL_HOST, MYSQL_USER, MYSQL_DATABASE, MYSQL_PASSWORD);
- if(!SQL::ExistsTable(""BANS_TABLE""))
- {
- new handle = SQL::Open(SQL::CREATE, ""BANS_TABLE"");
- SQL::AddTableEntry(handle, "ban_id", SQL_TYPE_INT, 11, true);
- SQL::AddTableEntry(handle, "ban_username", SQL_TYPE_VCHAR, 24);
- SQL::AddTableEntry(handle, "ban_ip", SQL_TYPE_VCHAR, 24);
- SQL::AddTableEntry(handle, "ban_by", SQL_TYPE_VCHAR, 24);
- SQL::AddTableEntry(handle, "ban_on", SQL_TYPE_VCHAR, 24);
- SQL::AddTableEntry(handle, "ban_reason", SQL_TYPE_VCHAR, 24);
- SQL::AddTableEntry(handle, "ban_expire", SQL_TYPE_INT);
- SQL::Close(handle);
- print("[sbBan]: '"BANS_TABLE"' table created successfully!");
- }
- else if(SQL::ExistsTable(""BANS_TABLE""))
- {
- printf("[sbBan]: Total %d bans loaded from '"BANS_TABLE"'", SQL::CountRows(""BANS_TABLE""));
- }
- print("[sbBan]: sbBan Ban system loaded successfully ");
- print("[sbBan]: Version: 1.0 | Author: SecretBoss ");
- print("\n sbBan ");
- print("_________________________________________________________________\n\n");
- return 1;
- }
- //================================================
- public OnPlayerConnect(playerid)
- {
- new
- string[6][24],
- string2[156],
- expire,
- DIALOG[676]
- ;
- if(SQL::RowExistsEx(""BANS_TABLE"", "ban_username", GetName(playerid)))
- {
- new handle = SQL::OpenEx(SQL::READ, ""BANS_TABLE"", "ban_username", GetName(playerid));
- SQL::ReadString(handle, "ban_username", string[1], 24);
- SQL::ReadString(handle, "ban_ip", string[2], 24);
- SQL::ReadString(handle, "ban_by", string[3], 24);
- SQL::ReadString(handle, "ban_on", string[4], 24);
- SQL::ReadString(handle, "ban_reason", string[5], 24);
- SQL::ReadInt(handle, "ban_expire", expire);
- SQL::Close(handle);
- if(expire > gettime() || expire == 0)
- {
- strcat(DIALOG, "{FFFFFF}Your account is banned from this server,\n\n");
- format(string2, sizeof(string2), "{FFFFFF}Username: {FF0000}%s\n", string[1]);
- strcat(DIALOG, string2);
- format(string2, sizeof(string2), "{FFFFFF}IP: {FF0000}%s\n", string[2]);
- strcat(DIALOG, string2);
- format(string2, sizeof(string2), "{FFFFFF}Banned by: {FF0000}%s\n", string[3]);
- strcat(DIALOG, string2);
- format(string2, sizeof(string2), "{FFFFFF}Reason: {FF0000}%s\n", string[5]);
- strcat(DIALOG, string2);
- format(string2, sizeof(string2), "{FFFFFF}Ban date: {FF0000}%s\n", string[4]);
- strcat(DIALOG, string2);
- new expire2[68];
- if(expire == 0) expire2 = "PERMANENT";
- else expire2 = ConvertTime(expire);
- format(string2, sizeof(string2), "{FFFFFF}Timeleft: {FF0000}%s\n\n", expire2);
- strcat(DIALOG, string2);
- strcat(DIALOG, "{FFFFFF}If you think that you got banned wrongfully, please make an appeal on our forums.\n");
- strcat(DIALOG, "Make sure you saved this box by pressing F8.");
- ShowPlayerDialog(playerid, DIALOG_SBBAN, DIALOG_STYLE_MSGBOX, "Notice", DIALOG, "Close", "");
- DelayKick(playerid);
- return true;
- }
- else
- {
- SQL::DeleteRowEx(""BANS_TABLE"", "ban_username", GetName(playerid));
- SendClientMessage(playerid, COLOR_RED, "[SERVER] Your accounts's ban has expired.");
- }
- }
- else if(SQL::RowExistsEx(""BANS_TABLE"", "ban_ip", GetIP(playerid)))
- {
- new handle = SQL::OpenEx(SQL::READ, ""BANS_TABLE"", "ban_ip", GetIP(playerid));
- SQL::ReadString(handle, "ban_username", string[1], 24);
- SQL::ReadString(handle, "ban_ip", string[2], 24);
- SQL::ReadString(handle, "ban_by", string[3], 24);
- SQL::ReadString(handle, "ban_on", string[4], 24);
- SQL::ReadString(handle, "ban_reason", string[5], 24);
- SQL::ReadInt(handle, "ban_expire", expire);
- SQL::Close(handle);
- if(expire > gettime() || expire == 0)
- {
- strcat(DIALOG, "{FFFFFF}Your IP is banned from this server,\n\n");
- format(string2, sizeof(string2), "{FFFFFF}Username: {FF0000}%s\n", string[1]);
- strcat(DIALOG, string2);
- format(string2, sizeof(string2), "{FFFFFF}IP: {FF0000}%s\n", string[2]);
- strcat(DIALOG, string2);
- format(string2, sizeof(string2), "{FFFFFF}Banned by: {FF0000}%s\n", string[3]);
- strcat(DIALOG, string2);
- format(string2, sizeof(string2), "{FFFFFF}Reason: {FF0000}%s\n", string[5]);
- strcat(DIALOG, string2);
- format(string2, sizeof(string2), "{FFFFFF}Ban date: {FF0000}%s\n", string[4]);
- strcat(DIALOG, string2);
- new expire2[68];
- if(expire == 0) expire2 = "PERMANENT";
- else expire2 = ConvertTime(expire);
- format(string2, sizeof(string2), "{FFFFFF}Timeleft: {FF0000}%s\n\n", expire2);
- strcat(DIALOG, string2);
- strcat(DIALOG, "{FFFFFF}If you think that you got banned wrongfully, please make an appeal on our forums.\n");
- strcat(DIALOG, "Make sure you saved this box by pressing F8.");
- ShowPlayerDialog(playerid, DIALOG_SBBAN, DIALOG_STYLE_MSGBOX, "Notice", DIALOG, "Close", "");
- DelayKick(playerid);
- return true;
- }
- else
- {
- SQL::DeleteRowEx(""BANS_TABLE"", "ban_username", GetName(playerid));
- SendClientMessage(playerid, COLOR_RED, "[SERVER] Your IP's ban has expired.");
- }
- }
- return 1;
- }
- //================================================
- CMD:ban(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not Administrator.");
- new target, reason[35], days;
- if(sscanf(params, "is[35]I(0)", target, reason, days)) return SendClientMessage(playerid, COLOR_RED, "Usage: /ban [playerid] [reason] [days(0 for permanent ban)]");
- if(!IsPlayerConnected(target)) return SendClientMessage(playerid, COLOR_RED, "The specified player is not conected, use /oban instead.");
- if(target == playerid) return SendClientMessage(playerid, COLOR_RED, "You can't ban yourself.");
- if(IsPlayerAdmin(target)) return SendClientMessage(playerid, COLOR_RED, "You cannot use this command on higher level admin.");
- if(days < 0) return SendClientMessage(playerid, COLOR_RED, "Invalid days, must be greater than 0 for temp ban, or 0 for permanent ban.");
- if(strlen(reason) < 3 || strlen(reason) > 35) return SendClientMessage(playerid, COLOR_RED, "Invalid reason length, must be b/w 0-35 characters.");
- new bandate[18], date[3], time;
- getdate(date[0], date[1], date[2]);
- format(bandate, sizeof(bandate), "%02i/%02i/%i", date[2], date[1], date[0]);
- if(days == 0) time = 0;
- else time = ((days * 24 * 60 * 60) + gettime());
- new handle = SQL::Open(SQL::INSERT, ""BANS_TABLE"");
- SQL::ToggleAutoIncrement(handle, true);
- SQL::WriteString(handle, "ban_username", GetName(target));
- SQL::WriteString(handle, "ban_ip", GetIP(target));
- SQL::WriteString(handle, "ban_by", GetName(playerid));
- SQL::WriteString(handle, "ban_on", bandate);
- SQL::WriteString(handle, "ban_reason", reason);
- SQL::WriteInt(handle, "ban_expire", time);
- SQL::Close(handle);
- if(days == 0)
- {
- new string[144];
- format(string, sizeof(string), "* %s(%i) has been banned by Admin %s(%d) [Reason: %s]", GetName(target), target, GetName(playerid), playerid, reason);
- SendClientMessage(target, COLOR_RED, string);
- }
- else
- {
- new string[258];
- format(string, sizeof(string), "* %s(%i) has been temp banned by Admin %s(%d) [Reason: %s] [Days: %i]", GetName(target), target, GetName(playerid), playerid, reason, days);
- SendClientMessage(target, COLOR_RED, string);
- format(string, sizeof(string), "* Temp banned for %i days [Unban on %s]", days, ConvertTime(time));
- SendClientMessage(target, COLOR_RED, string);
- }
- DelayKick(target);
- return 1;
- }
- //================================================
- COMMAND:unban(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_RED, "You are not Administrator.");
- new name[24];
- if(sscanf(params,"s[24]", name)) return SendClientMessage(playerid, COLOR_RED, "Usage: /unban [username]");
- if(SQL::RowExistsEx(""BANS_TABLE"", "ban_username", name))
- {
- SQL::DeleteRowEx(""BANS_TABLE"", "ban_username", name);
- }
- else return SendClientMessage(playerid, COLOR_RED, "The specified username is not banned.");
- new string[144];
- format(string, sizeof(string), "* You have unbanned user %s successfully.", name);
- SendClientMessage(playerid, COLOR_RED, string);
- return 1;
- }
- //================================================
- GetName(playerid)
- {
- new name[24];
- GetPlayerName(playerid, name, sizeof(name));
- return name;
- }
- //================================================
- GetIP(playerid)
- {
- new p_ip[18];
- GetPlayerIp(playerid, p_ip, sizeof(p_ip));
- return p_ip;
- }
- //================================================
- ConvertTime(time)
- {
- new string[68];
- new values[6];
- TimestampToDate(time, values[0], values[1], values[2], values[3], values[4], values[5], 0, 0);
- format(string, sizeof(string), "%i.%i.%i (%i hours %i mins %i secs)", values[0], values[1], values[2], values[3], values[4], values[5]);
- return string;
- }
- //================================================
- DelayKick(playerid)
- {
- SetTimerEx("OnPlayerKicked", 2000, false, "i", playerid);
- return 1;
- }
- forward OnPlayerKicked(playerid);
- public OnPlayerKicked(playerid)
- {
- Kick(playerid);
- return 1;
- }
- //================================================
Advertisement
Add Comment
Please, Sign In to add comment