From 1feef1575e5330b263808b379557d0bcb37cd481 Mon Sep 17 00:00:00 2001 From: harryob Date: Sun, 3 Nov 2024 04:58:55 +0000 Subject: [PATCH] known alts (#7336) admins can now mark players as having "known alts", which do not flag in connection history :cl: admin: you can add "known alts" to players, now /:cl: --------- Co-authored-by: Drathek <76988376+Drulikar@users.noreply.github.com> --- code/datums/entities/player_sticky_ban.dm | 124 ++++++++++++++++++++++ code/modules/admin/admin_verbs.dm | 2 + code/modules/tgui_panel/telemetry.dm | 18 ++-- 3 files changed, 132 insertions(+), 12 deletions(-) diff --git a/code/datums/entities/player_sticky_ban.dm b/code/datums/entities/player_sticky_ban.dm index 70715d1ce2f0..bfe6342ec774 100644 --- a/code/datums/entities/player_sticky_ban.dm +++ b/code/datums/entities/player_sticky_ban.dm @@ -131,3 +131,127 @@ BSQL_PROTECT_DATUM(/datum/entity/stickyban) "ip", "linked_stickyban", ) + +/// Returns either a list containing the primary CKEYs this alt is connected to, +/// or FALSE. +/proc/get_player_is_alt(ckey) + var/list/datum/view_record/known_alt/alts = DB_VIEW(/datum/view_record/known_alt, DB_COMP("ckey", DB_EQUALS, ckey)) + if(!length(alts)) + return FALSE + + var/ckeys = list() + for(var/datum/view_record/known_alt/alt as anything in alts) + ckeys += alt.player_ckey + + return ckeys + +/client/proc/add_known_alt() + set name = "Add Known Alt" + set category = "Admin.Alt" + + var/player_ckey = ckey(tgui_input_text(src, "What is the player's primary Ckey?", "Player Ckey")) + if(!player_ckey) + return + + var/datum/entity/player/player = get_player_from_key(player_ckey) + if(!istype(player)) + return + + var/existing_alts = get_player_is_alt(player_ckey) + if(existing_alts) + var/confirm = tgui_alert(src, "Primary Ckey [player_ckey] is already an alt for [english_list(existing_alts)].", "Primary Ckey", list("Confirm", "Cancel")) + + if(confirm != "Confirm") + return + + var/whitelist_to_add = ckey(tgui_input_text(src, "What is the Ckey that should be added to known alts?", "Alt Ckey")) + if(!whitelist_to_add) + return + + var/alts_existing_primaries = get_player_is_alt(whitelist_to_add) + if(alts_existing_primaries) + if(player_ckey in alts_existing_primaries) + to_chat(src, SPAN_WARNING("The alt '[whitelist_to_add]' is already set as an alt Ckey for '[player_ckey]'.")) + return + + var/confirm = tgui_alert(src, "Alt is already an alt for [english_list(alts_existing_primaries)].", "Alt Ckey", list("Confirm", "Cancel")) + + if(confirm != "Confirm") + return + + var/datum/entity/known_alt/alt = DB_ENTITY(/datum/entity/known_alt) + alt.player_id = player.id + alt.player_ckey = player.ckey + alt.ckey = whitelist_to_add + + alt.save() + + to_chat(src, SPAN_NOTICE("[alt.ckey] added to the known alts of [player.ckey].")) + +/client/proc/remove_known_alt() + set name = "Remove Known Alt" + set category = "Admin.Alt" + + var/player_ckey = ckey(tgui_input_text(src, "What is the player's primary Ckey?", "Player Ckey")) + if(!player_ckey) + return + + var/datum/entity/player/player = get_player_from_key(player_ckey) + if(!istype(player)) + return + + var/existing_alts = get_player_is_alt(player_ckey) + if(existing_alts) + var/confirm = tgui_alert(src, "Primary Ckey [player_ckey] is already an alt for [english_list(existing_alts)].", "Primary Ckey", list("Confirm", "Cancel")) + + if(confirm != "Confirm") + return + + var/list/datum/view_record/known_alt/alts = DB_VIEW(/datum/view_record/known_alt, DB_COMP("player_id", DB_EQUALS, player.id)) + if(!length(alts)) + to_chat(src, SPAN_WARNING("User has no alts on record.")) + return + + var/options = list() + for(var/datum/view_record/known_alt/alt in alts) + options[alt.ckey] = alt.id + + var/picked = tgui_input_list(src, "Which known alt should be removed?", "Alt Removal", options) + if(!picked) + return + + var/picked_id = options[picked] + var/datum/entity/known_alt/to_delete = DB_ENTITY(/datum/entity/known_alt, picked_id) + to_delete.delete() + + to_chat(src, SPAN_NOTICE("[picked] removed from the known alts of [player.ckey].")) + +/datum/entity/known_alt + var/player_id + var/player_ckey + var/ckey + +/datum/entity_meta/known_alt + entity_type = /datum/entity/known_alt + table_name = "known_alts" + field_types = list( + "player_id" = DB_FIELDTYPE_BIGINT, + "player_ckey" = DB_FIELDTYPE_STRING_LARGE, + "ckey" = DB_FIELDTYPE_STRING_LARGE, + ) + +/datum/view_record/known_alt + var/id + var/player_id + var/player_ckey + var/ckey + +/datum/entity_view_meta/known_alt + root_record_type = /datum/entity/known_alt + destination_entity = /datum/view_record/known_alt + fields = list( + "id", + "player_id", + "player_ckey", + "ckey", + ) diff --git a/code/modules/admin/admin_verbs.dm b/code/modules/admin/admin_verbs.dm index 5f5135bd0905..9e7482714a3d 100644 --- a/code/modules/admin/admin_verbs.dm +++ b/code/modules/admin/admin_verbs.dm @@ -74,6 +74,8 @@ GLOBAL_LIST_INIT(admin_verbs_default, list( /client/proc/cmd_admin_tacmaps_panel, /client/proc/other_records, /client/proc/toggle_admin_afk_safety, + /client/proc/add_known_alt, + /client/proc/remove_known_alt, /client/proc/toogle_door_control, )) diff --git a/code/modules/tgui_panel/telemetry.dm b/code/modules/tgui_panel/telemetry.dm index bd49596aa19a..951a82736b58 100644 --- a/code/modules/tgui_panel/telemetry.dm +++ b/code/modules/tgui_panel/telemetry.dm @@ -65,16 +65,9 @@ if (!ckey) return -/* - var/list/all_known_alts = GLOB.known_alts.load_known_alts() - var/list/our_known_alts = list() - - for (var/known_alt in all_known_alts) - if (known_alt[1] == ckey) - our_known_alts += known_alt[2] - else if (known_alt[2] == ckey) - our_known_alts += known_alt[1] -*/ + var/list/known_alts = list() + for(var/datum/view_record/known_alt/alts in DB_VIEW(/datum/view_record/known_alt, DB_COMP("player_ckey", DB_EQUALS, ckey))) + known_alts += alts.ckey var/list/found @@ -98,10 +91,11 @@ "address" = row["address"], "computer_id" = row["computer_id"], )) + */ - if (row["ckey"] in our_known_alts) + if (row["ckey"] in known_alts) continue - */ + if (world.IsBanned(row["ckey"], row["address"], row["computer_id"], real_bans_only = TRUE, is_telemetry = TRUE)) found = row