Basic Ban System

Started by Mahmoud Tornado, May 10, 2018, 08:13 PM

Previous topic - Next topic

Mahmoud Tornado

Hi Guys, As i will back to VC-MP again in 23/5 and i was making Ban system now.
I decide that i will share it, Enjoy!

onScriptLoad()
Bans <- ConnectSQL( "Bans.db" );
 QuerySQL( Bans, "CREATE TABLE IF NOT EXISTS Bans ( Name VARCHAR(32), IP VARCHAR(25), Admin TEXT, Reason TEXT, Time VARCHAR(255) DEFAULT CURRENT_TIMESTAMP)" );

onPlayerJoin( player )
CheckBan(player);   //Checking if the player banned or not.

Checkban Function
function CheckBan( player )
{
local q1 = QuerySQL( Bans, "SELECT * FROM Bans WHERE IP ='" +player.IP+"'") //Getting the database details
local ip = GetSQLColumnData(q1, 1) // Getting player ip
local name = GetSQLColumnData( q1, 0 ); // Getting player name
if (ip) KickPlayer(player)
else if (name) KickPlayer(player)
else if ( ip && name) KickPlayer( player)
else return 0
}

Baninfo function /which used in unban command.
function Baninfo( p )
{
   local q = QuerySQL( Bans, "SELECT * FROM Bans WHERE Name='" + p + "'" );
   local name = GetSQLColumnData( q, 0 );
   if ( name ) return 1;
   else return 0;
}

Commnads
      if ( cmd == "ban" )
      {
if( Stats[ player.ID ].Log == false ) MessagePlayer( "Inforamtion: You Need Login or Register First.", player );  // Check if the player registered and logged
else if ( Stats[ player.ID ].Level < 7 ) MessagePlayer("Inforamtion: You aren't authorized to use this command.", player ); // Check player level
else if ( !text ) MessagePlayer( "Syntax, /" + cmd + " <nick> <reason>", player ); // the syntax of the command
                else
{
local plr = GetPlayer( GetTok( text, " ", 1 ) ); //getplayer
if ( !plr ) MessagePlayer( "Information: Invalid Player Nick / ID!", player ); // if player not playing
else
{
local reason = GetTok( text, " ", 2 ); //get reason
local now = date(); // For the time date.
if ( reason == null ) reason = "None"; //if no reason return None
{
QuerySQL( Bans, "INSERT INTO Bans ( Name, IP, Admin, Reason, Time ) VALUES ( '" + plr.Name + "', '" + plr.IP + "', '" + player.Name + "', '" + reason + "', '"+ now.year +"/"+now.month+"/"+now.day+"/"+now.hour+":"+ now.min + "' )" ); //Add player to Ban List "added the time"
Message( "Administration Command: Admin " + player.Name + " Banned " + plr.Name + " for Reason: " + reason ); //Msg
KickPlayer( plr ); //kick player
}
}
}
}
else if ( cmd == "unban" )
{
if( Stats[ player.ID ].Log == false ) MessagePlayer( "Inforamtion: You Need Login or Register First.", player );  // Check if the player registered and logged
else if ( Stats[ player.ID ].Level < 7 ) MessagePlayer("Inforamtion: You aren't authorized to use this command.", player ); // Check player level
else if ( !text ) MessagePlayer( "Syntax, /" + cmd + " <Full Nick>", player ); //The Syntax of the command
else if ( Baninfo( text ) == 0 ) MessagePlayer( "Information:" + text + " is not Banned.", player ); //Check if player in banned list
else
{
  QuerySQL( Bans, "DELETE FROM Bans WHERE Name='" + text + "'" ); //Deleting player from the list
Message( "Administration Command: Admin " + player.Name + " UnBanned " +  text + "."); /msg
}
}

else if ( cmd == "baninfo" )
{
if ( !text ) MessagePlayer( "Inforamtion: /"+cmd+" <Full-Nick>", player );
else {
local q = QuerySQL( Bans, "SELECT * FROM Bans WHERE Name='" + text + "' COLLATE NOCASE" );
if ( GetSQLColumnData( q, 0 ) != text ) MessagePlayer( "Information: " + text + " is not Banned.", player );
else
{
MessagePlayer("BanInfo: Name("+GetSQLColumnData( q, 0 )+"), IP("+GetSQLColumnData( q, 1 )+"), Reason("+GetSQLColumnData( q, 3 )+"), Time("+GetSQLColumnData( q, 4 )+", BannedBy("+GetSQLColumnData( q, 2 )+").",player)
}
}
}

Thanks, Your Friend
MahmoudTornado

 :edit:
Adding Time, Checkban with Ip "By Helathien", baninfo command.
 :edit:
Fixing some small bugs.

Kid_Buu



Saiyan Attack

warchief ban system detected ...

Mahmoud Tornado

I don't have warchief Script.

Saiyan Attack

Quote from: Mahmoud Tornado on May 10, 2018, 11:24 PMI don't have warchief Script.
hahaha stop lying then where did you copied this code and stop saying that you make this ban system ...
Quote from: Mahmoud Tornado on May 10, 2018, 08:13 PMHi Guys, As i will back to VC-MP again in 23/5 and i was making Ban system now.
I decide that i will share it, Enjoy!
Thanks, Your Friend
MahmoudTornado

Mahmoud Tornado

Quote from: Saiyan Attack on May 11, 2018, 09:36 AM
Quote from: Mahmoud Tornado on May 10, 2018, 11:24 PMI don't have warchief Script.
hahaha stop lying then where did you copied this code and stop saying that you make this ban system ...
Quote from: Mahmoud Tornado on May 10, 2018, 08:13 PMHi Guys, As i will back to VC-MP again in 23/5 and i was making Ban system now.
I decide that i will share it, Enjoy!
Thanks, Your Friend
MahmoudTornado
You don't know if I have warchief Script or not to say that I'm lying.
And if I had that script I was added my server from along time ago.
And I'm who made that system.

Mohamed Boubekri

#7
GooD Work Bro!
But when someone Type /ban, the cmd will not work because 'Stats' Didn't Exist!
First Try to Add Class, Else delete the line in /ban Like:
if( Stats[ player.ID ].Log == false ) MessagePlayer( "[#00de00]Inforamtion: [#fbf3f3]You Need Login or Register First.", player );  // Check if the player registered and loggedSome Players will not know how to deal with the system, but u try to add a definition of Class.
| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].

Mahmoud Tornado

Quote from: Mohamed on May 11, 2018, 02:27 PMGooD Work Bro!
But when someone Type /ban, the cmd will not work because 'Stats' Didn't Exist!
First Try to Add Class, Else delete the line in /ban Like:
if( Stats[ player.ID ].Log == false ) MessagePlayer( "[#00de00]Inforamtion: [#fbf3f3]You Need Login or Register First.", player );  // Check if the player registered and loggedSome Players will not know how to deal with the system, but u try to add a definition of Class
it's not a problem as the people can see it.
But anyways Thanks

=RK=MarineForce

its not show admin name exmaple banned by admin [varchar] reason hp hax

Mahmoud Tornado

Quote from: =RK=MarineForce on Jul 18, 2018, 03:59 PMits not show admin name exmaple banned by admin [varchar] reason hp hax
I don't think so, as i tested it.
if you wanna it like this " banned by admin [varchar] reason hp hax "
use this:
  Message( "[#00de00]Administration Command: [#fbf3f3]" + plr.Name + " Has Been Banned By " + player.Name + " for " + reason );


=RK=MarineForce

Thanks i can use it on diego ban ur diego same but ur best :P i will check it on diego

Mahmoud Tornado

Quote from: =RK=MarineForce on Jul 19, 2018, 12:12 PMThanks i can use it on diego ban ur diego same but ur best :P i will check it on diego
Can anyone translate this to english, please?

[KM]Helathien

#13
I haven't checked it on server, but seeing from the code I can see that the CheckBan function only checks the Name of the player, whereas when you banned the player his name and IP Both were saved.
This way player can just change his name and come. So please also add
local q1 = QuerySQL( Bans, "SELECT * FROM Bans WHERE IP ='" +player.IP+"'")
local ip = GetSQLColumnData(q1, 1)
if (ip) KickPlayer(player)
else if (name) KickPlayer(player)
else if ( ip && name) KickPlayer( player)
else return 0

I am on mobile right now, but you get the idea.
Good job BTW.
Feel free to PM me for any help.
If I am not available on the forum come to VKs Official Server I am usually there.

Tajammul

Warcheif Ban System lol !!! xD
 :o 8)