Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Muted <- array( GetMaxPlayers(), null );
- Punishment <- {
- function LoadSystem()
- {
- Punishment.CreateTable();
- print("===========================================");
- print(" ");
- print(" Punishment System by (ARG)Maximiliano");
- print(" ");
- Punishment.CountBans();
- print(" ");
- print("===========================================");
- DecreaseBanTime <- _Timer.Create(this, Punishment.DecreaseBanTime, 1000, 0);
- }
- function CreateTable()
- {
- QuerySQL( db, "CREATE TABLE IF NOT EXISTS Bans ( Name TEXT, Admin TEXT, Reason TEXT, Date TEXT, Type NUMERIC, UID VARCHAR(255), UID2 VARCHAR(255), IP VARCHAR(32) )" );
- //Types of Bans: Type 0 = Permanent - Type 1 = Temporary - Type 2 = Nick
- QuerySQL( db, "CREATE TABLE IF NOT EXISTS TempBans ( Name TEXT, Time NUMERIC )" ); // This db is where you will store the time, which will decrease every second (It can be modified to minutes or hours)
- QuerySQL( db, "CREATE TABLE IF NOT EXISTS BanIPs ( IP TEXT, Admin TEXT )" );
- QuerySQL( db, "CREATE TABLE IF NOT EXISTS Mute ( Name TEXT, Time NUMERIC )" );
- QuerySQL( db, "CREATE TABLE IF NOT EXISTS UsersDatas ( Name TEXT, UID VARCHAR(255), UID2 VARCHAR(255), IP VARCHAR(32) )" );
- }
- //------------------------------------------------- Bans functions --------------------------------------------------//
- function AddBan(player, Admin, Reason, BanType)
- {
- QuerySQL( db, "INSERT INTO Bans ( Name, Admin, Reason, Date, Type, UID, UID2, IP ) VALUES ( '" + player.Name + "', '" + Admin + "', '" + Reason + "', '" +Punishment.GetDate()+ "', '" + BanType + "', '" + e(player.UniqueID) + "', '" + e(player.UniqueID2) + "', '" + player.IP + "' )" );
- Message("[#FF4500][ADMIN][#EEDD82] " + player.Name +" was banned by " + Admin + ". Reason: " + Reason + "." );
- }
- function AddBanIP(IP, Admin)
- {
- //It will store the ips and the admin that banned them as log
- QuerySQL( db, "INSERT INTO BanIPs VALUES ( '" + IP + "', '" + Admin + "' )" );
- Message("[#FF4500][ADMIN][#EEDD82] " + IP +" banned by " + Admin );
- BanIP(IP);
- }
- function AddTempBan(player, Admin, Reason, Time)
- {
- Punishment.AddBan(player, Admin, Reason, 1);
- QuerySQL( db, "INSERT INTO TempBans ( Name, Time) VALUES ( '" + player.Name + "', '" + Time + "' )" );
- }
- function Unban(player, Admin)
- {
- QuerySQL( db, "DELETE FROM TempBans WHERE Name='" + player + "'" );
- QuerySQL( db, "DELETE FROM Bans WHERE Name='" + player + "'" );
- Message( "[#FF4500][ADMIN][#EEDD82] "+ player +" was unbanned by "+Admin+"." );
- }
- function UnbanIP(IP, Admin)
- {
- QuerySQL( db, "DELETE FROM BanIPs WHERE IP='" + IP + "'" );
- Message( "[#FF4500][ADMIN][#EEDD82] "+ IP +" unbanned by "+Admin+"." );
- UnbanIP(IP);
- }
- function CheckBan(player)
- {
- local q = QuerySQL( db, "SELECT Name,Type FROM Bans WHERE UID='" + e(player.UniqueID) + "' " );
- if ( q )
- {
- if ( GetSQLColumnData( q , 1) == 2)
- {
- if (GetSQLColumnData( q , 0).tolower() == player.Name.tolower())
- {
- Message( format("[#EAEAEA][[#F0FFF0]BAN[#EAEAEA]][#EEDD82] %s was kicked. Reason: Nick banned.", player.Name) );
- player.Kick();
- }
- }
- else
- {
- Message( format("[#EAEAEA][[#F0FFF0]BAN[#EAEAEA]][#EEDD82] %s was kicked. Reason: Banned with the account: %s", player.Name, GetSQLColumnData( q , 0)) );
- player.Kick();
- }
- }
- //This will save data that will be useful when giving offline users ban
- local q = QuerySQL( db, "SELECT * FROM UsersDatas WHERE Name='"+ player.Name +"'" )
- if( !q ) QuerySQL( db, "INSERT INTO UsersDatas ( Name, UID, UID2, IP ) VALUES ( '" + player + "', '" + player.UniqueID + "', '" + player.UniqueID2 + "', '" + player.IP + "' )" );
- }
- function DecreaseBanTime()
- {
- QuerySQL( db, "UPDATE Tempbans SET Time= (Time - 1) WHERE Time > 0" );
- local q = QuerySQL( db, "SELECT Name FROM TempBans WHERE Time='0'" );
- local name = GetSQLColumnData( q , 0);
- if( name )
- {
- Message( format("[#EAEAEA][[#F0FFF0]BAN[#EAEAEA]][#EEDD82] %s's ban time is over", name));
- Punishment.Unban(name, "SERVER");
- }
- }
- //------------------- Mute functions --------------------//
- function AddMute(player, admin, reason, Time)
- {
- QuerySQL( db, "INSERT INTO Mute ( Name, Time) VALUES ( '" + player.Name + "', '" + Time + "' )" );
- Message( "[#EAEAEA][[#F0FFF0]MUTE[#EAEAEA]][#EEDD82] "+ player.Name +"'s was muted by "+ admin +". Reason: "+ reason);
- Punishment.CheckMute(player, 1);
- }
- function UnMute(player, admin)
- {
- QuerySQL( db, "DELETE FROM Mute WHERE Name='" + player + "'" );
- _Timer.Destroy(Muted[ player.ID ].Timer);
- Muted[ player.ID ] = null;
- Message( format("[#EAEAEA][[#F0FFF0]MUTE[#EAEAEA]][#EEDD82] %s's was unmuted by %s.", player.Name, admin));
- }
- function CheckMute(player, type)
- {
- switch (type)
- {
- //Type 1: When a user join in the server or is silenced.
- //Type 2: When a user leaves the server
- case 1:
- local q = QuerySQL( db, "SELECT Time FROM Mute WHERE Name='" + player + "'" );
- if ( GetSQLColumnData( q , 0) )
- {
- try{
- Muted[ player.ID ] =
- {
- Time = GetSQLColumnData( q , 0).tointeger(),
- Timer = _Timer.Create(this, Punishment.DecreaseMuteTime, 1000, 0, player)
- };
- } catch (e)
- {
- print(e);
- }
- }
- break;
- case 2:
- QuerySQL( db, format("UPDATE Mute SET Time='"+ Muted[ player.ID ].Time +"' WHERE Name='"+ player.Name +"'" ) );
- _Timer.Destroy(Muted[ player.ID ].Timer);
- Muted[ player.ID ] = null;
- break;
- }
- }
- function DecreaseMuteTime(player)
- {
- if (Muted[ player.ID ].Time == 0)
- {
- UnMute(player, "SERVER");
- }
- else
- {
- Muted[ player.ID ].Time--;;
- }
- }
- //------------------- Other functions --------------------//
- function GetDate()
- {
- return format("%.2d/%.2d/%.2d - %.2d hour/s, %.2d minute/s, %.2d second/s", date().day, (date().month +1), date().year, date().hour, date().min, date().sec);
- }
- function CountBans()
- {
- local TempBans = QuerySQL( db, "SELECT count(*) from TempBans" ), Bans = QuerySQL( db, "SELECT count(*) from Bans WHERE Type='0'" ), BanNicks = QuerySQL( db, "SELECT count(*) from Bans WHERE Type='2'" ), IPBans = QuerySQL( db, "SELECT count(*) from BanIPs" );
- print(" "+ GetSQLColumnData( TempBans , 0) + " Accounts with temporary ban.");
- print(" "+ GetSQLColumnData( Bans , 0) + " Accounts with permanent ban.");
- print(" "+ GetSQLColumnData( BanNicks , 0) + " Nicks banneds.");
- print(" "+ GetSQLColumnData( IPBans , 0) + " IPs with ban.");
- }
- function Command(cmd, text, player)
- {
- switch ( cmd.tolower() )
- {
- case "ban":
- if (!text) MessagePlayer("Sintax: /ban <nick> <reason>", player)
- else
- {
- local plr = GetTok(text, " ", 1), reason = "Not specified.";
- local q = QuerySQL( db, "SELECT * FROM UsersDatas WHERE Name='"+ plr +"'");
- if (!q) MessagePlayer("User not found, verify that the name is complete and check upper and lower case.", player);
- else
- {
- plr = {
- Name = GetSQLColumnData( q, 0 ),
- UniqueID = GetSQLColumnData( q, 1 ),
- UniqueID2 = GetSQLColumnData( q, 2 ),
- IP = GetSQLColumnData( q, 3 )
- };
- if (GetTok(text, " ", 2)) reason = GetTok(text, " ", 2);
- Punishment.AddBan(plr, player.Name, reason, 0);
- }
- }
- break;
- case "banick":
- case "bannick":
- if (!text) MessagePlayer("Sintax: /ban <nick> <reason>", player)
- else
- {
- local plr = GetTok(text, " ", 1), reason = "Not specified.", q = QuerySQL( db, "SELECT * FROM UsersDatas WHERE Name='"+ plr +"'");
- if (!q) MessagePlayer("User not found, verify that the name is complete and check upper and lower case.", player);
- else
- {
- plr = {
- Name = GetSQLColumnData( q, 0 ),
- UniqueID = GetSQLColumnData( q, 1 ),
- UniqueID2 = GetSQLColumnData( q, 2 ),
- IP = GetSQLColumnData( q, 3 )
- }
- if (GetTok(text, " ", 2)) reason = GetTok(text, " ", 2);
- Punishment.AddBan(plr, player.Name, reason, 2);
- }
- }
- break;
- case "tempban":
- if(!text) MessagePlayer("Sintax: /banick <nick> <days:hours:minutes> <reason>", player);
- else
- {
- local plr = GetTok(text, " ", 1),
- time = GetTok(text, " ", 2),
- reason = GetTok(text, " ", 3),
- q = QuerySQL( db, "SELECT * FROM UsersDatas WHERE Name='"+ plr +"'"),
- q1 = QuerySQL( db, "SELECT * FROM TempBans WHERE Name='"+ plr +"'");
- if (!time) MessagePlayer("Sintax: /tempban <nick> <days:hours:minutes> <reason>", player);
- else if (!q) MessagePlayer("User not found, verify that the name is complete and check upper and lower case.", player);
- else if (q1) MessagePlayer("Already banned.", player);
- else
- {
- local days = (GetTok(time, ":", 1).tointeger() * 86400); //Days to seg
- local hours = (GetTok(time, ":", 2).tointeger() * 3600); //Hours to seg
- local mins = (GetTok(time, ":", 3).tointeger() * 60); //Minutes to seg
- local total = (days + hours + mins);
- plr = {
- Name = GetSQLColumnData( q, 0 ),
- UniqueID = GetSQLColumnData( q, 1 ),
- UniqueID2 = GetSQLColumnData( q, 2 ),
- IP = GetSQLColumnData( q, 3 )
- }
- if (!reason) reason = "Not specified.";
- Punishment.AddTempBan(plr, player.Name, reason, total);
- }
- }
- break;
- case "banip":
- if (!text) MessagePlayer("/banip IP", player);
- else
- {
- local ip = GetTok(text, " ", 1);
- Punishment.AddBanIP(ip, player.Name);
- }
- break;
- case "mute":
- if (!text) MessagePlayer("/mute <nick> <minutes> <reason>", player);
- else
- {
- local plr = GetPlayer(GetTok(text, " ", 1)), minutes = GetTok(text, " ", 2), reason = GetTok(text, " ", 3);
- if (!minutes || !reason) MessagePlayer("/mute <nick> <minutes> <reason>",player);
- else if ( Muted[ plr.ID ] ) MessagePlayer("Player already silenced", player);
- else Punishment.AddMute(plr, player.Name, reason, (minutes.tointeger() * 60) );
- }
- break;
- case "unbanip":
- if (!text) MessagePlayer("/unbanip IP", player);
- else
- {
- Punishment.UnBanIP(ip, player.Name);
- }
- break;
- case "unban":
- if (!text) MessagePlayer("/unban nick", player);
- else
- {
- local plr = GetTok(text, " ", 1);
- local q = QuerySQL( db, "SELECT * FROM Bans WHERE Name='"+plr+"'");
- if (!q) MessagePlayer("Player isn't banned", player);
- else Punishment.Unban(plr, player.Name);
- }
- break;
- case "unmute":
- if (!text) MessagePlayer("/unmute nick", player);
- else
- {
- local plr = GetPlayer(GetTok(text, " ", 1));
- if ( !plr ) MessagePlayer("Player not found", player);
- else if ( !Muted[ plr.ID ] ) MessagePlayer("Player isn't muted", player);
- else Punishment.UnMute(plr, player.Name);
- }
- break;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement