Temp ban system (gamingpro)

Started by gamingpro, Jul 17, 2023, 12:42 AM

Previous topic - Next topic

gamingpro

Hey guys 8) , i maded this tempban system, i love to share all things i maded it to others, for help  :) ,
Now this is the code:



Add that line in onScriptLoad function

TempBans <- ConnectSQL("TempBans.db");
QuerySQL(TempBans, "CREATE TABLE IF NOT EXISTS TempBans(Name TEXT, UID TEXT, UID2 TEXT, IP FLOAT, Admin TEXT, Reason TEXT, Time INTEGER, NowTime INTEGER)");


Add this line in onPlayerJoin function

CheckTempBan( player );


Add this line in onPlayerCommand Function

if( cmd == "tempban" )
{
if(!text) MessagePlayer("Error - use /"+cmd+" <Player/ID> [Days:Hours:Minutes] <Reason>",player);
else {
local plr = GetPlayer(GetTok(text, " ",1));local expire = GetTok(text, " ",2);local reason = GetTok(text, " ",3 NumTok(text, " "));local ban_expire = split(expire, ":");
if(!plr) MessagePlayer("Unknow player!",player);
else if(!expire) MessagePlayer("Error - Please write expire time format DAYS:HOURS:MINUTES and should numbers!",player);
else if(NumTok(expire, ":") != 3) MessagePlayer("Error - Invalid format, The format must be DAYS:HOURS:MINUTES!",player);
else if(IsNum(ban_expire[0]) && IsNum(ban_expire[1]) && IsNum(ban_expire[2]))
{
if(!reason) reason = "None";
local calc = (time()+ban_expire[0].tointeger()*24*60*60 + ban_expire[1].tointeger()*60*60 + ban_expire[2].tointeger()*60);
QuerySQL(TempBans, "INSERT INTO TempBans(Name, UID, UID2, IP, Admin, Reason, Time, NowTime) VALUES('"+plr.Name.tolower()+"', '"+plr.UniqueID+"', '"+plr.UniqueID2+"', '"+plr.IP.tofloat()+"', '"+player.Name+"', '"+reason+"', '"+calc+"', '"+time()+"')");
Message("[#FF0000]Admin:[ "+player.Name+" ] banned:[ "+plr.Name+" ] Reason:[ "+reason+" ] Time:[ "+GetRemainingTime(calc,time())+" ]");
plr.Kick();
}
else MessagePlayer("Error - Format must be integer!",player);
}
}
else if( cmd == "untempban" )
{
if(!text) MessagePlayer("Error - Syntax; /"+cmd+" <Full-Nick>",player);
else {
local q = QuerySQL(TempBans, "SELECT * FROM TempBans WHERE Name='"+text.tolower()+"'");
if(!q) MessagePlayer("Error - "+text+" is not tempbanned!.",player);
else {
QuerySQL(TempBans, "DELETE FROM TempBans WHERE Name='"+text.tolower()+"'");
MessagePlayer("[#00FF00][SUCCESS]: [#FFFFFF]"+text+" has been untempbanned!.",player);
}
}
}



Functions

function CheckTempBan(plr)
{
local q = QuerySQL(TempBans, "SELECT * FROM TempBans WHERE Name='"+plr.Name.tolower()+"'");
if(q){
local admin = GetSQLColumnData(q,4), reason = GetSQLColumnData(q,5),t = GetSQLColumnData(q,6);
if(time() >= t){
QuerySQL(TempBans, "DELETE FROM TempBans WHERE Name='"+plr.Name.tolower()+"'");
}
else {
Message("[#FF0000]"+plr.Name+" Banned from the server Reason:[ "+reason+" ] Admin:[ "+admin+" ], Time Left:[ "+GetRemainingTime(t.tointeger(),time().tointeger())+" ]");
plr.Kick();
FreeSQLQuery(q);
}
}
else {
local uid = QuerySQL(TempBans, "SELECT * FROM TempBans WHERE UID='"+plr.UniqueID+"'");
if(uid){
local admin = GetSQLColumnData(uid,4), reason = GetSQLColumnData(uid,5),t = GetSQLColumnData(uid,6);
if(time() >= t){
QuerySQL(TempBans, "DELETE FROM TempBans WHERE Name='"+plr.Name.tolower()+"'");
}
else {
Message("[#FF0000]"+plr.Name+" Banned from the server Reason:[ "+reason+" ] Admin:[ "+admin+" ], Time Left:[ "+GetRemainingTime(t.tointeger(),time().tointeger())+" ]");
plr.Kick();
FreeSQLQuery(uid);
}
}
else {
local uid2 = QuerySQL(TempBans, "SELECT * FROM TempBans WHERE UID2='"+plr.UniqueID2+"'");
if(uid2){
local admin = GetSQLColumnData(uid2,4), reason = GetSQLColumnData(uid2,5),t = GetSQLColumnData(uid2,6);
if(time() >= t){
QuerySQL(TempBans, "DELETE FROM TempBans WHERE Name='"+plr.Name.tolower()+"'");
}
else {
Message("[#FF0000]"+plr.Name+" Banned from the server Reason:[ "+reason+" ] Admin:[ "+admin+" ], Time Left:[ "+GetRemainingTime(t.tointeger(),time().tointeger())+" ]");
plr.Kick();
FreeSQLQuery(uid2);
}
}
else {
local ip = QuerySQL(TempBans, "SELECT * FROM TempBans WHERE IP='"+plr.IP.tofloat()+"'");
if(ip){
local admin = GetSQLColumnData(ip,4), reason = GetSQLColumnData(ip,5),t = GetSQLColumnData(ip,6);
if(time() >= t){
QuerySQL(TempBans, "DELETE FROM TempBans WHERE Name='"+plr.Name.tolower()+"'");
}
else {
Message("[#FF0000]"+plr.Name+" Banned from the server Reason:[ "+reason+" ] Admin:[ "+admin+" ], Time Left:[ "+GetRemainingTime(t.tointeger(),time().tointeger())+" ]");
plr.Kick();
FreeSQLQuery(ip);
}
}
}
}
}
}
function GetRemainingTime(basict, oldt)
{
    local time = basict-oldt, min = ( time / 60 ).tointeger();
    local year = 0, month = 0, week = 0, day = 0, hour = 0;
    local total_time = "";
    while(min >= 60){hour++;min-=60;}
    while(hour >= 24){day++;hour-=24;}
    while(day >= 7){week++;day-=7;}
    while(week >= 5){month++;week-=5;}
    while(month >= 12){year++;month-=12;}
    if(year > 0){if(total_time != "")total_time += year+" year(s), ";else total_time = year+" year(s) ";}
    if(month > 0){if(total_time != "") total_time += month+" month(s), ";else total_time = month+" month(s) ";}
    if(week > 0){if(total_time != "")total_time += week+" week(s), ";else total_time = week+" week(s) ";}
    if(day > 0){if(total_time != "")total_time += day+" day(s), ";else total_time = day+" day(s) ";}
    if(hour > 0){if(total_time != "")total_time += hour+" hour(s), ";else total_time = hour+" hour(s) ";}
    if(min > 0){if(total_time != "")total_time += min+" minute(s)"; else total_time = min+" minute(s) ";}
    if(year == 0 && month == 0 && week == 0 && day == 0 && hour == 0 && min == 0) total_time = "Some seconds and will unban";
    return total_time;
}
function GetTok( string, separator, n, ... )
{
 local m = ( vargv.len() > 0 ) ? vargv[ 0 ] : n, tokenized = split( string, separator ), text = "";

 if ( ( n > tokenized.len() ) || ( n < 1 ) ) return null;

 for ( ; n <= m; n++ )
 {
  text += text == "" ? tokenized[ n - 1 ] : separator + tokenized[ n - 1 ];
 }

 return text;
}
function NumTok(string, separator)
{
    local tokenized = split(string, separator);
    return tokenized.len();
}
function GetPlayer( target )
{
 local target1 = target.tostring();

 if ( IsNum( target ) )
 {
  target = target.tointeger();

  if ( FindPlayer( target) ) return FindPlayer( target );
  else return null;
 }
 else if ( FindPlayer( target ) ) return FindPlayer( target );
 else return null;
}

habi

You forgot to write syntax:
1. /tempban <Player/ID> [Days:Hours:Minutes] <Reason>
2. /untempban

2b2ttianxiu

Quote from: gamingpro on Jul 17, 2023, 12:42 AMHey guys 8) , i maded this tempban system, i love to share all things i maded it to others, for help  :) ,
Now this is the code:



Add that line in onScriptLoad function

TempBans <- ConnectSQL("TempBans.db");
QuerySQL(TempBans, "CREATE TABLE IF NOT EXISTS TempBans(Name TEXT, UID TEXT, UID2 TEXT, IP FLOAT, Admin TEXT, Reason TEXT, Time INTEGER, NowTime INTEGER)");


Add this line in onPlayerJoin function

CheckTempBan( player );


Add this line in onPlayerCommand Function

if( cmd == "tempban" )
{
if(!text) MessagePlayer("Error - use /"+cmd+" <Player/ID> [Days:Hours:Minutes] <Reason>",player);
else {
local plr = GetPlayer(GetTok(text, " ",1));local expire = GetTok(text, " ",2);local reason = GetTok(text, " ",3 NumTok(text, " "));local ban_expire = split(expire, ":");
if(!plr) MessagePlayer("Unknow player!",player);
else if(!expire) MessagePlayer("Error - Please write expire time format DAYS:HOURS:MINUTES and should numbers!",player);
else if(NumTok(expire, ":") != 3) MessagePlayer("Error - Invalid format, The format must be DAYS:HOURS:MINUTES!",player);
else if(IsNum(ban_expire[0]) && IsNum(ban_expire[1]) && IsNum(ban_expire[2]))
{
if(!reason) reason = "None";
local calc = (time()+ban_expire[0].tointeger()*24*60*60 + ban_expire[1].tointeger()*60*60 + ban_expire[2].tointeger()*60);
QuerySQL(TempBans, "INSERT INTO TempBans(Name, UID, UID2, IP, Admin, Reason, Time, NowTime) VALUES('"+plr.Name.tolower()+"', '"+plr.UniqueID+"', '"+plr.UniqueID2+"', '"+plr.IP.tofloat()+"', '"+player.Name+"', '"+reason+"', '"+calc+"', '"+time()+"')");
Message("[#FF0000]Admin:[ "+player.Name+" ] banned:[ "+plr.Name+" ] Reason:[ "+reason+" ] Time:[ "+GetRemainingTime(calc,time())+" ]");
plr.Kick();
}
else MessagePlayer("Error - Format must be integer!",player);
}
}
else if( cmd == "untempban" )
{
if(!text) MessagePlayer("Error - Syntax; /"+cmd+" <Full-Nick>",player);
else {
local q = QuerySQL(TempBans, "SELECT * FROM TempBans WHERE Name='"+text.tolower()+"'");
if(!q) MessagePlayer("Error - "+text+" is not tempbanned!.",player);
else {
QuerySQL(TempBans, "DELETE FROM TempBans WHERE Name='"+text.tolower()+"'");
MessagePlayer("[#00FF00][SUCCESS]: [#FFFFFF]"+text+" has been untempbanned!.",player);
}
}
}



Functions

function CheckTempBan(plr)
{
local q = QuerySQL(TempBans, "SELECT * FROM TempBans WHERE Name='"+plr.Name.tolower()+"'");
if(q){
local admin = GetSQLColumnData(q,4), reason = GetSQLColumnData(q,5),t = GetSQLColumnData(q,6);
if(time() >= t){
QuerySQL(TempBans, "DELETE FROM TempBans WHERE Name='"+plr.Name.tolower()+"'");
}
else {
Message("[#FF0000]"+plr.Name+" Banned from the server Reason:[ "+reason+" ] Admin:[ "+admin+" ], Time Left:[ "+GetRemainingTime(t.tointeger(),time().tointeger())+" ]");
plr.Kick();
FreeSQLQuery(q);
}
}
else {
local uid = QuerySQL(TempBans, "SELECT * FROM TempBans WHERE UID='"+plr.UniqueID+"'");
if(uid){
local admin = GetSQLColumnData(uid,4), reason = GetSQLColumnData(uid,5),t = GetSQLColumnData(uid,6);
if(time() >= t){
QuerySQL(TempBans, "DELETE FROM TempBans WHERE Name='"+plr.Name.tolower()+"'");
}
else {
Message("[#FF0000]"+plr.Name+" Banned from the server Reason:[ "+reason+" ] Admin:[ "+admin+" ], Time Left:[ "+GetRemainingTime(t.tointeger(),time().tointeger())+" ]");
plr.Kick();
FreeSQLQuery(uid);
}
}
else {
local uid2 = QuerySQL(TempBans, "SELECT * FROM TempBans WHERE UID2='"+plr.UniqueID2+"'");
if(uid2){
local admin = GetSQLColumnData(uid2,4), reason = GetSQLColumnData(uid2,5),t = GetSQLColumnData(uid2,6);
if(time() >= t){
QuerySQL(TempBans, "DELETE FROM TempBans WHERE Name='"+plr.Name.tolower()+"'");
}
else {
Message("[#FF0000]"+plr.Name+" Banned from the server Reason:[ "+reason+" ] Admin:[ "+admin+" ], Time Left:[ "+GetRemainingTime(t.tointeger(),time().tointeger())+" ]");
plr.Kick();
FreeSQLQuery(uid2);
}
}
else {
local ip = QuerySQL(TempBans, "SELECT * FROM TempBans WHERE IP='"+plr.IP.tofloat()+"'");
if(ip){
local admin = GetSQLColumnData(ip,4), reason = GetSQLColumnData(ip,5),t = GetSQLColumnData(ip,6);
if(time() >= t){
QuerySQL(TempBans, "DELETE FROM TempBans WHERE Name='"+plr.Name.tolower()+"'");
}
else {
Message("[#FF0000]"+plr.Name+" Banned from the server Reason:[ "+reason+" ] Admin:[ "+admin+" ], Time Left:[ "+GetRemainingTime(t.tointeger(),time().tointeger())+" ]");
plr.Kick();
FreeSQLQuery(ip);
}
}
}
}
}
}
function GetRemainingTime(basict, oldt)
{
    local time = basict-oldt, min = ( time / 60 ).tointeger();
    local year = 0, month = 0, week = 0, day = 0, hour = 0;
    local total_time = "";
    while(min >= 60){hour++;min-=60;}
    while(hour >= 24){day++;hour-=24;}
    while(day >= 7){week++;day-=7;}
    while(week >= 5){month++;week-=5;}
    while(month >= 12){year++;month-=12;}
    if(year > 0){if(total_time != "")total_time += year+" year(s), ";else total_time = year+" year(s) ";}
    if(month > 0){if(total_time != "") total_time += month+" month(s), ";else total_time = month+" month(s) ";}
    if(week > 0){if(total_time != "")total_time += week+" week(s), ";else total_time = week+" week(s) ";}
    if(day > 0){if(total_time != "")total_time += day+" day(s), ";else total_time = day+" day(s) ";}
    if(hour > 0){if(total_time != "")total_time += hour+" hour(s), ";else total_time = hour+" hour(s) ";}
    if(min > 0){if(total_time != "")total_time += min+" minute(s)"; else total_time = min+" minute(s) ";}
    if(year == 0 && month == 0 && week == 0 && day == 0 && hour == 0 && min == 0) total_time = "Some seconds and will unban";
    return total_time;
}
function GetTok( string, separator, n, ... )
{
 local m = ( vargv.len() > 0 ) ? vargv[ 0 ] : n, tokenized = split( string, separator ), text = "";

 if ( ( n > tokenized.len() ) || ( n < 1 ) ) return null;

 for ( ; n <= m; n++ )
 {
  text += text == "" ? tokenized[ n - 1 ] : separator + tokenized[ n - 1 ];
 }

 return text;
}
function NumTok(string, separator)
{
    local tokenized = split(string, separator);
    return tokenized.len();
}
function GetPlayer( target )
{
 local target1 = target.tostring();

 if ( IsNum( target ) )
 {
  target = target.tointeger();

  if ( FindPlayer( target) ) return FindPlayer( target );
  else return null;
 }
 else if ( FindPlayer( target ) ) return FindPlayer( target );
 else return null;
}


That tempbans users' data cached in the server. if u want to update by database, u can query again