offline tempban

Started by Nihongo^, Jun 26, 2023, 04:02 PM

Previous topic - Next topic

Nihongo^

Hi, I am trying to make an offline temp ban with some of my stupid ideas in this method, I want IP and UID from the accounts or Aliases copied and pasted into the temp ban colume. Can anybody please help me with the offline ban system for discord ?

else if(cmd == "tempban")
{
if ( GetLevel( player ) < 3 )
{
ErrorMessage("[Server] - [#FFFFFF]You don't have access to use this Command.", player );
return;
}
if(text)
{
local plr = (GetTok(text, " ", 1)), expire = GetTok(text, " ", 2), reason = GetTok( text, " ", 3, NumTok( text, " " ) );
local q = QuerySQL(db, "SELECT * FROM TempBans WHERE Name='"+plr+"'");
if(!q)
{
if(plr)
{
if(expire)
{
if(reason)
{
local ban_expire = split(expire, ":");
if(NumTok(expire, ":") == 3)
{
if(IsNum(ban_expire[0]) && IsNum(ban_expire[1]) && IsNum(ban_expire[2]))
{
local calc = ((ban_expire[ 0 ].tointeger()*24*60*60) + (ban_expire[ 1 ].tointeger()*60*60) + (ban_expire[ 2 ].tointeger()*60));
local ip = QuerySQL(db, "SELECT IP FROM Accounts WHERE Name='" + plr + "'" );
local uid = QuerySQL(db, "SELECT UID FROM Accounts WHERE Name='" + plr + "'" );
local uid2 = QuerySQL(db, "SELECT UID2 FROM Accounts WHERE Name='" + plr + "'" );

QuerySQL( db, "INSERT INTO TempBans( Name, UID, UID2, IP, Time, ExpireTime, TimeExpireRatio, Admin, Reason ) VALUES ('"+plr+"', '"+uid +"', '"+uid+"', '"+ip+"', '"+time()+"', '"+calc+"', '"+expire+"', '"+player.Name+"', '"+reason+"')");

ServerMessage("[#FF0000][PRIOR BAN]: [#FFFFFF]"+plr+" is banned for Reason: "+reason+", TimeLeft: " + GetBanRemainingTime(time().tointeger(), expire.tostring())+", Admin: "+player.Name+"");
}
else ErrorMessage("[#FF0000][ERROR]: You've entered wrong values in the time, make sure you have entered numbers only!",player);
}
else ErrorMessage("[#FF0000][ERROR]: Time Format must be DAYS:HOURS:MINUTES!",player);
}
else ErrorMessage("[#FF0000][ERROR]: You must specify a reason to ban requested player!",player);
}
else ErrorMessage("[#FF0000][ERROR]: Please type the duration of the ban for the requested player!",player);
}
else ErrorMessage("[#FF0000][ERROR]: Unknown player!",player);
}
else ErrorMessage("[#FFFF00]Syntax; /tempban <player/ID> <Days:Hours:Minutes> <Reason>",player);
}
else ErrorMessage("[#FFFF00]Syntax; /tempban <player/ID> <Days:Hours:Minutes> <Reason>",player);
}



Xmair

You generally don't want to query 3 times if you are querying from the same table. What could you do instead is select multiple columns in a single query. It is also good practice to escape any input you take from the user to prevent SQL injection.

The main problem you are facing right now is that you are not retrieving the column data for the query. QuerySQL doesn't return just the result but an object which contains information about the query. Ideally, something like this would be a half-decent approach:

local accDetails = QuerySQL(db, format("SELECT IP, UID, UID2 FROM Accounts WHERE Name = '%s', escapeSQLString(plr)));
if (accDetails == null) // handle invalid nickname
else {
    QuerySQL(db, format("INSERT INTO TempBans (Name, UID, UID2, IP, Time, ExpireTime, TimeExpireRatio, Admin, Reason) VALUES ('%s', '%s', '%s', '%s', %i, %i, %s, %s, %s)", escapeSQLString(plr), GetSQLColumnData(accDetails, 1), GetSQLColumnData(accDetails, 2), GetSQLColumnData(accDetails, 0), time(), calc, expire, player.Name, escapeSQLString(reason)));
}

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

Nihongo^

#2
Thank you so much xmair for giving me such an amazing idea

just one more thing, how do now i select different columns in a different table of the same person?

Like picking IP from Accounts and picking UID from Alias table

Thank you

Xmair

Quote from: Nihongo^ on Jun 27, 2023, 08:30 AMThank you so much xmair for giving me such an amazing idea

just one more thing, how do now i select different columns in a different table of the same person?

Like picking IP from Accounts and picking UID from Alias table

Thank you
Look into JOIN queries

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD