diff --git a/code/modules/admin/DB ban/functions.dm b/code/modules/admin/DB ban/functions.dm index 540f05a9086..1796b2f232f 100644 --- a/code/modules/admin/DB ban/functions.dm +++ b/code/modules/admin/DB ban/functions.dm @@ -69,8 +69,125 @@ obj/admins/proc/DB_ban_record(var/bantype, var/mob/banned_mob, var/duration = -1 else adminwho += ", [C]" + reason = sql_sanitize_text(reason) + var/sql = "INSERT INTO erro_ban VALUES (null, Now(), '[serverip]', '[bantype_str]', '[reason]', '[job]', [(duration)?"[duration]":"0"], [(rounds)?"[rounds]":"0"], Now() + INTERVAL [(duration>0) ? duration : 0] MINUTE, '[ckey]', '[computerid]', '[ip]', '[a_ckey]', '[a_computerid]', '[a_ip]', '[who]', '[adminwho]', '', null, null, null, null, null)" var/DBQuery/query_insert = dbcon.NewQuery(sql) query_insert.Execute() - dbcon.Disconnect() \ No newline at end of file + dbcon.Disconnect() + + + +obj/admins/proc/DB_ban_unban(var/ckey, var/bantype, var/job = "") + var/user = sqlfdbklogin + var/pass = sqlfdbkpass + var/db = sqlfdbkdb + var/address = sqladdress + var/port = sqlport + + var/bantype_str + if(bantype) + var/bantype_pass = 0 + switch(bantype) + if(BANTYPE_PERMA) + bantype_str = "PERMABAN" + bantype_pass = 1 + if(BANTYPE_TEMP) + bantype_str = "TEMPBAN" + bantype_pass = 1 + if(BANTYPE_JOB_PERMA) + bantype_str = "JOB_PERMABAN" + bantype_pass = 1 + if(BANTYPE_JOB_TEMP) + bantype_str = "JOB_TEMPBAN" + bantype_pass = 1 + if(BANTYPE_ANY_FULLBAN) + bantype_str = "ANY" + bantype_pass = 1 + if( !bantype_pass ) return + + var/bantype_sql + if(bantype_str == "ANY") + bantype_sql = "(bantype = 'PERMABAN' OR (bantype = 'TEMPBAN' AND expiration_time > Now() ) )" + else + bantype_sql = "bantype = '[bantype_str]'" + + var/sql = "SELECT id FROM erro_ban WHERE ckey = '[ckey]' AND [bantype_sql] AND (unbanned is null OR unbanned = false)" + if(job) + sql += " AND job = '[job]'" + + var/DBConnection/dbcon = new() + + dbcon.Connect("dbi:mysql:[db]:[address]:[port]","[user]","[pass]") + if(!dbcon.IsConnected()) + return + + var/ban_id + var/ban_number = 0 //failsafe + + var/DBQuery/query = dbcon.NewQuery(sql) + query.Execute() + while(query.NextRow()) + ban_id = query.item[1] + ban_number++; + + if(ban_number == 0) + usr << "\red Database update failed due to no bans fitting the search criteria. If this is not a legacy ban you should contact the database admin." + return + + if(ban_number > 1) + usr << "\red Database update failed due to multiple bans fitting the search criteria. Note down the ckey, job and current time and contact the database admin." + return + + if(istext(ban_id)) + ban_id = text2num(ban_id) + if(!isnum(ban_id)) + usr << "\red Database update failed due to a ban ID mismatch. Contact the database admin." + return + + DB_ban_unban_by_id(ban_id) + + +obj/admins/proc/DB_ban_unban_by_id(var/id) + var/user = sqlfdbklogin + var/pass = sqlfdbkpass + var/db = sqlfdbkdb + var/address = sqladdress + var/port = sqlport + + var/sql = "SELECT id FROM erro_ban WHERE id = [id]" + + var/DBConnection/dbcon = new() + + dbcon.Connect("dbi:mysql:[db]:[address]:[port]","[user]","[pass]") + if(!dbcon.IsConnected()) + return + + var/ban_number = 0 //failsafe + + var/DBQuery/query = dbcon.NewQuery(sql) + query.Execute() + while(query.NextRow()) + ban_number++; + + if(ban_number == 0) + usr << "\red Database update failed due to a ban id not being present in the database." + return + + if(ban_number > 1) + usr << "\red Database update failed due to multiple bans having the same ID. Contact the database admin." + return + + if(!src.owner || !istype(src.owner, /client)) + return + + var/unban_ckey = src.owner:ckey + var/unban_computerid = src.owner:computer_id + var/unban_ip = src.owner:address + + var/sql_update = "UPDATE erro_ban SET unbanned = 1, unbanned_datetime = Now(), unbanned_ckey = '[unban_ckey]', unbanned_computerid = '[unban_computerid]', unbanned_ip = '[unban_ip]' WHERE id = [id]" + + + var/DBQuery/query_update = dbcon.NewQuery(sql_update) + query_update.Execute() \ No newline at end of file diff --git a/code/modules/admin/NewBan.dm b/code/modules/admin/NewBan.dm index c05b864ffc5..69252fd637b 100644 --- a/code/modules/admin/NewBan.dm +++ b/code/modules/admin/NewBan.dm @@ -137,7 +137,7 @@ var/savefile/Banlist log_admin("[key_name_admin(usr)] unbanned [key]") message_admins("[key_name_admin(usr)] unbanned: [key]") feedback_inc("ban_unban",1) - + usr.client.holder.DB_ban_unban( ckey(key), BANTYPE_ANY_FULLBAN) for (var/A in Banlist.dir) Banlist.cd = "/base/[A]" if (key == Banlist["key"] || id == Banlist["id"]) diff --git a/code/modules/admin/admin.dm b/code/modules/admin/admin.dm index f8feef77a79..46ed65fbde3 100644 --- a/code/modules/admin/admin.dm +++ b/code/modules/admin/admin.dm @@ -547,6 +547,7 @@ var/global/BSACooldown = 0 if("Yes") ban_unban_log_save("[key_name(usr)] unjobbanned [key_name(M)] from [job]") log_admin("[key_name(usr)] unbanned [key_name(M)] from [job]") + DB_ban_unban(M.ckey, BANTYPE_JOB_PERMA, job) feedback_inc("ban_job_unban",1) feedback_add_details("ban_job_unban","- [job]") jobban_unban(M, job) @@ -598,11 +599,15 @@ var/global/BSACooldown = 0 if ((src.rank in list("Game Admin", "Game Master" ))) var/t = href_list["removejobban"] if(t) - if(input(alert("Do you want to unjobban [t]?","Unjobban confirmation", "Yes", "No") == "Yes") && t) //No more misclicks! Unless you do it twice. + if((alert("Do you want to unjobban [t]?","Unjobban confirmation", "Yes", "No") == "Yes") && t) //No more misclicks! Unless you do it twice. log_admin("[key_name(usr)] removed [t]") message_admins("\blue [key_name_admin(usr)] removed [t]", 1) jobban_remove(t) href_list["ban"] = 1 // lets it fall through and refresh + var/t_split = dd_text2list(t, " - ") + var/key = t_split[1] + var/job = t_split[2] + DB_ban_unban(ckey(key), BANTYPE_JOB_PERMA, job) if (href_list["newban"]) if ((src.rank in list( "Temporary Admin", "Admin Candidate", "Trial Admin", "Badmin", "Game Admin", "Game Master" ))) diff --git a/code/setup.dm b/code/setup.dm index 7cbd32f8cfb..7b96a9a7030 100644 --- a/code/setup.dm +++ b/code/setup.dm @@ -399,6 +399,7 @@ var/list/liftable_structures = list(\ #define BANTYPE_TEMP 2 #define BANTYPE_JOB_PERMA 3 #define BANTYPE_JOB_TEMP 4 +#define BANTYPE_ANY_FULLBAN 5 //used to locate stuff to unban. //The number of deciseconds which someone needs to be inactive to be classified as AFK: #define AFK_THRESHOLD 3000 \ No newline at end of file