News:
BannedIPs <- []; //Banned IPs will be stored hereBannedNicks <- []; //Banned Nicks will be stored here //Load up ban data into array.function onScriptLoad( ){ LoadModule("sq_lite"); database <- ConnectSQL("Banlist.db"); LoadBansInMemory(); //Load ban files into array. print( "Banlist loaded!" );}//Disconnect database.function onScriptUnload( ){ DisconnectSQL( database );}
function LoadBansInMemory(){ local query = QuerySQL(database, "CREATE TABLE IF NOT EXISTS Banlist ( Nick TEXT, Reason TEXT, Date TEXT, IP TEXT)" ); FreeSQLQuery( query ); //Store data into array. local q = QuerySQL( database, "SELECT Nick, Reason, Date, IP FROM Banlist" ); while ( GetSQLColumnData ( q, 0 ) ) { BannedIPs.push( GetSQLColumnData( q, 3 ).tostring() ); BannedNicks.push( GetSQLColumnData( q, 0 ).tostring() ); GetSQLNextRow( q ); } FreeSQLQuery( q );}
//Function to ban a player.function BanPlayer( admin, player, reason ){ if( BannedIPs.find( player.IP.tostring() ) == null ) { BannedIPs.push( player.IP.tostring() ); BannedNicks.push( player.Name.tolower() ); local q = QuerySQL( database,"INSERT INTO Banlist ( Nick, Reason, Date, IP) VALUES ( '"+player.Name+"', '"+reason+"', '"+GetFullTime()+"', '"+player.IP+"')" ); FreeSQLQuery( q ); Message( "[BAN] Banned: " + player + " by: " + admin + " for: " + reason); KickPlayer( player ); }}
//Function to unban a player using IP.function UnbanFromIP( ip ){ if( BannedIPs.find( ip.tostring() ) != null ) { local query = QuerySQL( database, "SELECT Nick FROM Banlist WHERE IP='" + ip + "' COLLATE NOCASE" ); local nickname = GetSQLColumnData( query, 0 ); FreeSQLQuery( query ); query = QuerySQL( database,"DELETE FROM Banlist WHERE Nick='" +nickname+ "' COLLATE NOCASE" ); FreeSQLQuery( query ); BannedNicks.remove( BannedNicks.find( nickname.tostring() ) ); BannedIPs.remove( BannedIPs.find( ip.tostring() ) ); }}//Function to unban a player from their nickname.function UnbanFromNick( nickname ){ if( BannedNicks.find( nickname.tostring() ) != null ) { local query = QuerySQL( database, "SELECT IP FROM Banlist WHERE Nick='" + nickname + "' COLLATE NOCASE" ); local ip = GetSQLColumnData( query, 0 ); FreeSQLQuery( query ); query = QuerySQL( database,"DELETE FROM Banlist WHERE Nick='" +nickname+ "' COLLATE NOCASE" ); FreeSQLQuery( query ); BannedNicks.remove( BannedNicks.find( nickname ) ); BannedIPs.remove( BannedIPs.find( ip.tostring() ) ); }}
function onPlayerJoin( player ){ // Check if the name is banned if( ( BannedNicks.find( player.Name.tolower() ) != null ) || ( BannedIPs.find( player.IP.tostring() ) != null ) ) { Message("[BAN] Auto-Kicking: " + player.Name + " for Ban Evading."); KickPlayer( player ); return; }}
function IsStringIP( string ){ local Format = split(string, "."); if( Format != 4 ) return false; return true;}
gj