[SCRIPT] Simple UniqueID Ban

Started by MatheuS, Jan 04, 2015, 05:58 AM

Previous topic - Next topic

MatheuS

OnScriptLoad

QuerySQL( db, "CREATE TABLE IF NOT EXISTS Bans ( Name VARCHAR(32), UniqueID VARCHAR(25), Admin TEXT, Reason TEXT )" );
OnPlayerJoin
if ( CheckBan( player ) == 1 )
{
Message"[#FFFFFF]" + player.Name + " Banned from this server.");
player.Kick();
}

Function's

function Ban( player, admin, reason )
{
    QuerySQL( db, "INSERT INTO Bans ( Name, UniqueID, Admin, Reason ) VALUES ( '" + player.Name + "', '" + player.UniqueID + "', '" + admin.Name + "', '" + reason + "' )" );
Message( "** " + admin + " Banned " + player.Name + ", Reason: " + reason );
player.Kick();
}
function CheckBan( p )
{
   local q = QuerySQL( db, "SELECT * FROM Bans WHERE UniqueID='" + p.UniqueID + "'" );
   local uid = GetSQLColumnData( q, 1 );
   if ( uid ) return 1;
   else return 0;
}

function DelBan( admin, banned )
{
    QuerySQL( db, "DELETE FROM Bans WHERE Name='" + banned + "'" );
Message( "** " + admin + " Unban player - [ " + banned + " ]" );
}

Commands

    else if ( cmd == "ban" )
    {
if ( status[ player.ID ].Level < 2 )  // Here you should put your function to take the level of the player.
{
MessagePlayer("[#FF0000]Permission Denied.", player );
return;
}
else if ( !text ) MessagePlayer( "[#FF0000][Syntax] - /" + cmd + " <nick> <Reason>", player );
else
{
    local plr = GetPlayer( GetTok( text, " ", 1 ) );
    if ( !plr ) MessagePlayer("[#FF0000] Unknown ID/Name.", player );
    else
    {
            local reason = GetTok( text, " ", 2 NumTok( text, " " ) );
        if ( reason == null ) reason = "None";
        Ban( plr, player, reason );
    }
}
}

Sorry for my english.

Explanations:

is a very easy to do script, but I posted to help someone who does not have a notion.

I did not put the unban command for lack of time.

To unban someone simply use it.

QuerySQL( db, "DELETE FROM Bans WHERE Name='FullName'" );

is very simple, hope you enjoy!
if( !sucess ) tryAgain();
Thanks to the VCMP community. It was the happiest period of my life.

MacTavish

It would be better if we make different table for it like QuerySQL( db, "CREATE TABLE IF NOT EXISTS MBans ( Name VARCHAR(32), UniqueID VARCHAR(25), Admin TEXT, Reason TEXT )" );

MBans = Mac-Bans

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

MatheuS

Quote from: RATHORE on Jan 05, 2015, 11:27 AMIt would be better if we make different table for it like QuerySQL( db, "CREATE TABLE IF NOT EXISTS MBans ( Name VARCHAR(32), UniqueID VARCHAR(25), Admin TEXT, Reason TEXT )" );

MBans = Mac-Bans

but when it comes to ban does not refer to is ip or mac. ;D
if( !sucess ) tryAgain();
Thanks to the VCMP community. It was the happiest period of my life.

ysc3839

There is no text limit in SQLite. So you can replace VARCHAR(32) with TEXT

Sk

Quote from: ysc3839 on Jan 10, 2015, 05:26 AMThere is no text limit in SQLite. So you can replace VARCHAR(32) with TEXT
i think there is when you make a column of length something like 10 you can,t insert more then 10 characters other wise query will be success full but it will not insert/update any thing on the databse.
Source : Experience.

PsyChO_KiLLeR

ahhh when i type /ban nick and reason then it ban but when i rejoin it unbanned
reason?

Thijn

Quote from: Squirrel Master on Feb 28, 2015, 09:48 AMahhh when i type /ban nick and reason then it ban but when i rejoin it unbanned
reason?
The reason is probably your stupidity. If you're even too stupid to get this simple script working you must question yourself if you're ever going to create a successful server. Probably not.

PsyChO_KiLLeR

lol but i dont know
my database is not connected when i add  query on script load it give me error on this line of scriptload
QuerySQL( db1, "CREATE TABLE IF NOT EXISTS Bans ( Name VARCHAR(32), UniqueID VARCHAR(25), Admin TEXT, Reason TEXT )" );

MacTavish

#8
Because by default this is db not db1

And for god sake post screenshot of console error

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

DizzasTeR

Quote from: Beztone on Feb 28, 2015, 01:58 PMBecause by default this is db not db1

And for god sake post screenshot of console error

As I've mentioned before he doesn't  post since he doesn't get errors, he is just spamming and increasing forum stats.

ysc3839

A simple UID ban WITHOUT database! :D
function ReadLine(File)
{
local text = "";
local line = [];
while (!File.eos())
{
local chr = File.readn('b');
if (chr == '\n')
{
line.append(text);
text = "";
}
else
{
text += chr.tochar();
}
}
return line;
}

function LoadBanList()
{
local File = file("uid.banlist","r");
banlist <- ReadLine(File);
File.close();
}

//onPlayerJoin
foreach(uid in banlist)
{
if (player.UniqueID == uid) Kick(player);
}

Stormeus

Quote from: ysc3839 on Feb 28, 2015, 02:34 PMA simple UID ban WITHOUT database! :D
<snip>

This does work. However SQLite would actually be more performant when starting the server and adding bans.



One note I will make is that the length of the unique ID is 40 characters and not 25. I'm not sure if SQLite enforces limits on VARCHAR fields anyway.

Quote from: MatheuS on Jan 05, 2015, 12:47 PMbut when it comes to ban does not refer to is ip or mac. ;D

We have a secret formula.

Sk

Quote from: stormeus on Feb 28, 2015, 06:42 PMOne note I will make is that the length of the unique ID is 40 characters and not 25.
its 39 tried this at onPlayerJoin
local id = player.UniqueID;
print(id.len());

and you are right about varchar limit it does not matter.tried a simple test and u wr rit.

PsyChO_KiLLeR

problem solve about scriptload but my database is not connecting when i ban someone it dont show any error on console but when i rejoin its unban then i goto my database to check there is no table of Bans

ysc3839

Quote from: stormeus on Feb 28, 2015, 06:42 PM
Quote from: ysc3839 on Feb 28, 2015, 02:34 PMA simple UID ban WITHOUT database! :D
<snip>

This does work. However SQLite would actually be more performant when starting the server and adding bans.



One note I will make is that the length of the unique ID is 40 characters and not 25. I'm not sure if SQLite enforces limits on VARCHAR fields anyway.

Quote from: MatheuS on Jan 05, 2015, 12:47 PMbut when it comes to ban does not refer to is ip or mac. ;D

We have a secret formula.
In SQLite, the VARCHAR is same as TEXT. It's no length limit.