From 0d7ef3ed65578b16eeb4685582b44fdbe0cb5660 Mon Sep 17 00:00:00 2001
From: Jordie <4343468+Jordie0608@users.noreply.github.com>
Date: Sat, 11 Aug 2018 02:15:50 +1000
Subject: [PATCH] Key instead of ckey for user facing logs and ui (#39009)
* converts to using key instead of ckey for user facing logs and ui
* more key_name for airlock wires
* futureproofing check for if key changes
* --onlyckeymatch script argument and fail/success counter
* fix
---
SQL/admin_import_2018-02-03.py | 2 +-
SQL/database_changelog.txt | 14 +-
SQL/populate_key_2018-07-09.py | 92 ++++++++++++
SQL/tgstation_schema.sql | 1 +
SQL/tgstation_schema_prefixed.sql | 1 +
code/__DEFINES/subsystems.dm | 2 +-
code/__HELPERS/mobs.dm | 8 +-
code/controllers/subsystem/medals.dm | 28 ++--
code/datums/brain_damage/split_personality.dm | 2 +-
code/datums/wires/airlock.dm | 4 +-
code/game/gamemodes/game_mode.dm | 10 +-
code/game/machinery/computer/prisoner.dm | 2 +-
code/game/machinery/doors/airlock.dm | 6 +-
code/game/objects/structures/morgue.dm | 6 +-
code/modules/admin/DB_ban/functions.dm | 67 +++++----
code/modules/admin/IsBanned.dm | 25 ++--
code/modules/admin/NewBan.dm | 16 +-
code/modules/admin/admin.dm | 8 +-
code/modules/admin/permissionedit.dm | 104 ++++++-------
code/modules/admin/sql_message_system.dm | 140 ++++++++++--------
code/modules/admin/topic.dm | 67 +++++----
code/modules/admin/verbs/SDQL2/SDQL_2.dm | 6 +-
code/modules/admin/verbs/adminhelp.dm | 2 +-
code/modules/admin/verbs/debug.dm | 2 +-
code/modules/admin/verbs/mapping.dm | 4 +-
code/modules/assembly/doorcontrol.dm | 2 +-
code/modules/client/client_procs.dm | 34 ++++-
code/modules/client/preferences.dm | 6 +-
code/modules/library/lib_machines.dm | 3 +-
code/modules/mob/dead/new_player/poll.dm | 8 +-
.../projectiles/guns/misc/blastcannon.dm | 7 +-
.../reagents/reagent_containers/syringes.dm | 2 +-
32 files changed, 412 insertions(+), 269 deletions(-)
create mode 100644 SQL/populate_key_2018-07-09.py
diff --git a/SQL/admin_import_2018-02-03.py b/SQL/admin_import_2018-02-03.py
index 6bd8892b5e2..b9ce28cef17 100644
--- a/SQL/admin_import_2018-02-03.py
+++ b/SQL/admin_import_2018-02-03.py
@@ -93,7 +93,7 @@ with open("..\\config\\admins.txt") as admins_file:
matches = re.match("(.+)\\b\\s+=\\s+(.+)", line)
ckey = "".join((c for c in matches.group(1) if c not in ckeyformat)).lower()
rank = "".join((c for c in matches.group(2) if c not in ckeyExformat))
- cursor.execute("INSERT INTO {0} (ckey, rank) VALUES ('{1}', '{2}')".format(admin_table, ckey, rank))
+ cursor.execute("INSERT INTO {0} (ckey, rank) VALUES ('{1}', '{2}')".format(admin_table, ckey, rank))
db.commit()
cursor.close()
print("Import complete.")
diff --git a/SQL/database_changelog.txt b/SQL/database_changelog.txt
index d3339df1fb8..fc93bb8fec3 100644
--- a/SQL/database_changelog.txt
+++ b/SQL/database_changelog.txt
@@ -1,15 +1,23 @@
Any time you make a change to the schema files, remember to increment the database schema version. Generally increment the minor number, major should be reserved for significant changes to the schema. Both values go up to 255.
-The latest database version is 4.4; The query to update the schema revision table is:
+The latest database version is 4.5; The query to update the schema revision table is:
-INSERT INTO `schema_revision` (`major`, `minor`) VALUES (4, 4);
+INSERT INTO `schema_revision` (`major`, `minor`) VALUES (4, 5);
or
-INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (4, 4);
+INSERT INTO `SS13_schema_revision` (`major`, `minor`) VALUES (4, 5);
In any query remember to add a prefix to the table names if you use one.
----------------------------------------------------
+Version 4.5, 9 July 2018, by Jordie0608
+Modified table `player`, adding column `byond_key` to store a user's key along with their ckey.
+To populate this new column run the included script 'populate_key_2018-07', see the file for use instructions.
+
+ALTER TABLE `player` ADD `byond_key` VARCHAR(32) DEFAULT NULL AFTER `ckey`;
+
+----------------------------------------------------
+
Version 4.4, 9 May 2018, by Jordie0608
Modified table `round`, renaming column `start_datetime` to `initialize_datetime` and `end_datetime` to `shutdown_datetime` and adding columns to replace both under the same name in preparation for changes to TGS server initialization.
diff --git a/SQL/populate_key_2018-07-09.py b/SQL/populate_key_2018-07-09.py
new file mode 100644
index 00000000000..82e7a3f4af0
--- /dev/null
+++ b/SQL/populate_key_2018-07-09.py
@@ -0,0 +1,92 @@
+#Python 3+ Script for populating the key of all ckeys in player table made by Jordie0608
+#
+#Before starting ensure you have installed the mysqlclient package https://github.com/PyMySQL/mysqlclient-python
+#It can be downloaded from command line with pip:
+#pip install mysqlclient
+#And that you have run the most recent commands listed in database_changelog.txt
+#
+#To view the parameters for this script, execute it with the argument --help
+#All the positional arguments are required, remember to include a prefixe in your table name if you use one
+#--useckey and --onlynull are optional arguments, see --help for their function
+#An example of the command used to execute this script from powershell:
+#python populate_key_2018-07-09.py "localhost" "root" "password" "feedback" "SS13_player" --onlynull --useckey
+#
+#This script requires an internet connection to function
+#Sometimes byond.com fails to return the page for a valid ckey, this can be a temporary problem and may be resolved by rerunning the script
+#You can have the script use the existing ckey instead if the key is unable to be parsed with the --useckey optional argument
+#To make the script only iterate on rows that failed to parse a ckey and have a null byond_key column, use the --onlynull optional argument
+#To make the script only iterate on rows that have a matching ckey and byond_key column, use the --onlyckeymatch optional argument
+#The --onlynull and --onlyckeymatch arguments are mutually exclusive, the script can't be run with both of them enabled
+#
+#It's safe to run this script with your game server(s) active.
+
+import MySQLdb
+import argparse
+import re
+import sys
+from urllib.request import urlopen
+from datetime import datetime
+
+if sys.version_info[0] < 3:
+ raise Exception("Python must be at least version 3 for this script.")
+query_values = ""
+current_round = 0
+parser = argparse.ArgumentParser()
+parser.add_argument("address", help="MySQL server address (use localhost for the current computer)")
+parser.add_argument("username", help="MySQL login username")
+parser.add_argument("password", help="MySQL login password")
+parser.add_argument("database", help="Database name")
+parser.add_argument("playertable", help="Name of the player table (remember a prefix if you use one)")
+parser.add_argument("--useckey", help="Use the player's ckey for their key if unable to contact or parse their member page", action="store_true")
+group = parser.add_mutually_exclusive_group()
+group.add_argument("--onlynull", help="Only try to update rows if their byond_key column is null, mutually exclusive with --onlyckeymatch", action="store_true")
+group.add_argument("--onlyckeymatch", help="Only try to update rows that have matching ckey and byond_key columns from the --useckey argument, mutually exclusive with --onlynull", action="store_true")
+args = parser.parse_args()
+where = ""
+if args.onlynull:
+ where = " WHERE byond_key IS NULL"
+if args.onlyckeymatch:
+ where = " WHERE byond_key = ckey"
+db=MySQLdb.connect(host=args.address, user=args.username, passwd=args.password, db=args.database)
+cursor=db.cursor()
+player_table = args.playertable
+cursor.execute("SELECT ckey FROM {0}{1}".format(player_table, where))
+ckey_list = cursor.fetchall()
+failed_ckeys = []
+start_time = datetime.now()
+success = 0
+fail = 0
+print("Beginning script at {0}".format(start_time.strftime("%Y-%m-%d %H:%M:%S")))
+if not ckey_list:
+ print("Query returned no rows")
+for current_ckey in ckey_list:
+ link = urlopen("https://secure.byond.com/members/{0}/?format=text".format(current_ckey[0]))
+ data = link.read()
+ data = data.decode("ISO-8859-1")
+ match = re.search("\tkey = \"(.+)\"", data)
+ if match:
+ key = match.group(1)
+ success += 1
+ else:
+ fail += 1
+ failed_ckeys.append(current_ckey[0])
+ msg = "Failed to parse a key for {0}".format(current_ckey[0])
+ if args.useckey:
+ msg += ", using their ckey instead"
+ print(msg)
+ key = current_ckey[0]
+ else:
+ print(msg)
+ continue
+ cursor.execute("UPDATE {0} SET byond_key = \'{1}\' WHERE ckey = \'{2}\'".format(player_table, key, current_ckey[0]))
+ db.commit()
+end_time = datetime.now()
+print("Script completed at {0} with duration {1}".format(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), end_time - start_time))
+if failed_ckeys:
+ if args.useckey:
+ print("The following ckeys failed to parse a key so their ckey was used instead:")
+ else:
+ print("The following ckeys failed to parse a key and were skipped:")
+ print("\n".join(failed_ckeys))
+ print("Keys successfully parsed: {0} Keys failed parsing: {1}".format(success, fail))
+cursor.close()
diff --git a/SQL/tgstation_schema.sql b/SQL/tgstation_schema.sql
index dad9f1e766a..480ad58ff4e 100644
--- a/SQL/tgstation_schema.sql
+++ b/SQL/tgstation_schema.sql
@@ -309,6 +309,7 @@ DROP TABLE IF EXISTS `player`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `player` (
`ckey` varchar(32) NOT NULL,
+ `byond_key` varchar(32) DEFAULT NULL,
`firstseen` datetime NOT NULL,
`firstseen_round_id` int(11) unsigned NOT NULL,
`lastseen` datetime NOT NULL,
diff --git a/SQL/tgstation_schema_prefixed.sql b/SQL/tgstation_schema_prefixed.sql
index 8c9b15e8941..2842ee91224 100644
--- a/SQL/tgstation_schema_prefixed.sql
+++ b/SQL/tgstation_schema_prefixed.sql
@@ -309,6 +309,7 @@ DROP TABLE IF EXISTS `SS13_player`;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `SS13_player` (
`ckey` varchar(32) NOT NULL,
+ `byond_key` varchar(32) DEFAULT NULL,
`firstseen` datetime NOT NULL,
`firstseen_round_id` int(11) unsigned NOT NULL,
`lastseen` datetime NOT NULL,
diff --git a/code/__DEFINES/subsystems.dm b/code/__DEFINES/subsystems.dm
index c2ffd331969..0317b5ba7f1 100644
--- a/code/__DEFINES/subsystems.dm
+++ b/code/__DEFINES/subsystems.dm
@@ -1,7 +1,7 @@
//Update this whenever the db schema changes
//make sure you add an update to the schema_version stable in the db changelog
#define DB_MAJOR_VERSION 4
-#define DB_MINOR_VERSION 4
+#define DB_MINOR_VERSION 5
//Timing subsystem
//Don't run if there is an identical unique timer active
diff --git a/code/__HELPERS/mobs.dm b/code/__HELPERS/mobs.dm
index 24b6233c598..30fcf6b151e 100644
--- a/code/__HELPERS/mobs.dm
+++ b/code/__HELPERS/mobs.dm
@@ -192,15 +192,15 @@ Proc for attack log creation, because really why not
var/starget = "NON-EXISTENT SUBJECT"
if(target)
- if(is_mob_target && target.ckey)
- starget = "[target.name]([target.ckey])"
+ if(is_mob_target && target.key)
+ starget = "[target.name]([target.key])"
else
starget = "[target.name]"
var/ssource = "NON-EXISTENT USER" //How!?
if(user)
- if(is_mob_user && user.ckey)
- ssource = "[user.name]([user.ckey])"
+ if(is_mob_user && user.key)
+ ssource = "[user.name]([user.key])"
else
ssource = "[user.name]"
diff --git a/code/controllers/subsystem/medals.dm b/code/controllers/subsystem/medals.dm
index 21366978f66..6dafb2c3cb9 100644
--- a/code/controllers/subsystem/medals.dm
+++ b/code/controllers/subsystem/medals.dm
@@ -14,8 +14,8 @@ SUBSYSTEM_DEF(medals)
return
if(isnull(world.SetMedal(medal, player, CONFIG_GET(string/medal_hub_address), CONFIG_GET(string/medal_hub_password))))
hub_enabled = FALSE
- log_game("MEDAL ERROR: Could not contact hub to award medal:[medal] player:[player.ckey]")
- message_admins("Error! Failed to contact hub to award [medal] medal to [player.ckey]!")
+ log_game("MEDAL ERROR: Could not contact hub to award medal:[medal] player:[player.key]")
+ message_admins("Error! Failed to contact hub to award [medal] medal to [player.key]!")
return
to_chat(player, "Achievement unlocked: [medal]!")
@@ -38,8 +38,8 @@ SUBSYSTEM_DEF(medals)
if(isnull(world.SetScores(player.ckey, newscoreparam, CONFIG_GET(string/medal_hub_address), CONFIG_GET(string/medal_hub_password))))
hub_enabled = FALSE
- log_game("SCORE ERROR: Could not contact hub to set score. Score:[score] player:[player.ckey]")
- message_admins("Error! Failed to contact hub to set [score] score for [player.ckey]!")
+ log_game("SCORE ERROR: Could not contact hub to set score. Score:[score] player:[player.key]")
+ message_admins("Error! Failed to contact hub to set [score] score for [player.key]!")
/datum/controller/subsystem/medals/proc/GetScore(score, client/player, returnlist)
if(!score || !hub_enabled)
@@ -48,8 +48,8 @@ SUBSYSTEM_DEF(medals)
var/scoreget = world.GetScores(player.ckey, score, CONFIG_GET(string/medal_hub_address), CONFIG_GET(string/medal_hub_password))
if(isnull(scoreget))
hub_enabled = FALSE
- log_game("SCORE ERROR: Could not contact hub to get score. Score:[score] player:[player.ckey]")
- message_admins("Error! Failed to contact hub to get score: [score] for [player.ckey]!")
+ log_game("SCORE ERROR: Could not contact hub to get score. Score:[score] player:[player.key]")
+ message_admins("Error! Failed to contact hub to get score: [score] for [player.key]!")
return
. = params2list(scoreget)
if(!returnlist)
@@ -61,8 +61,8 @@ SUBSYSTEM_DEF(medals)
if(isnull(world.GetMedal(medal, player, CONFIG_GET(string/medal_hub_address), CONFIG_GET(string/medal_hub_password))))
hub_enabled = FALSE
- log_game("MEDAL ERROR: Could not contact hub to get medal:[medal] player: [player.ckey]")
- message_admins("Error! Failed to contact hub to get [medal] medal for [player.ckey]!")
+ log_game("MEDAL ERROR: Could not contact hub to get medal:[medal] player: [player.key]")
+ message_admins("Error! Failed to contact hub to get [medal] medal for [player.key]!")
return
to_chat(player, "[medal] is unlocked")
@@ -73,15 +73,15 @@ SUBSYSTEM_DEF(medals)
switch(result)
if(null)
hub_enabled = FALSE
- log_game("MEDAL ERROR: Could not contact hub to clear medal:[medal] player:[player.ckey]")
- message_admins("Error! Failed to contact hub to clear [medal] medal for [player.ckey]!")
+ log_game("MEDAL ERROR: Could not contact hub to clear medal:[medal] player:[player.key]")
+ message_admins("Error! Failed to contact hub to clear [medal] medal for [player.key]!")
if(TRUE)
- message_admins("Medal: [medal] removed for [player.ckey]")
+ message_admins("Medal: [medal] removed for [player.key]")
if(FALSE)
- message_admins("Medal: [medal] was not found for [player.ckey]. Unable to clear.")
+ message_admins("Medal: [medal] was not found for [player.key]. Unable to clear.")
/datum/controller/subsystem/medals/proc/ClearScore(client/player)
if(isnull(world.SetScores(player.ckey, "", CONFIG_GET(string/medal_hub_address), CONFIG_GET(string/medal_hub_password))))
- log_game("MEDAL ERROR: Could not contact hub to clear scores for [player.ckey]!")
- message_admins("Error! Failed to contact hub to clear scores for [player.ckey]!")
\ No newline at end of file
+ log_game("MEDAL ERROR: Could not contact hub to clear scores for [player.key]!")
+ message_admins("Error! Failed to contact hub to clear scores for [player.key]!")
diff --git a/code/datums/brain_damage/split_personality.dm b/code/datums/brain_damage/split_personality.dm
index 337926ce6b3..ba39845d61a 100644
--- a/code/datums/brain_damage/split_personality.dm
+++ b/code/datums/brain_damage/split_personality.dm
@@ -61,7 +61,7 @@
current_backseat = owner_backseat
free_backseat = stranger_backseat
- log_game("[key_name(current_backseat)] assumed control of [key_name(owner)] due to [src]. (Original owner: [current_controller == OWNER ? owner.ckey : current_backseat.ckey])")
+ log_game("[key_name(current_backseat)] assumed control of [key_name(owner)] due to [src]. (Original owner: [current_controller == OWNER ? owner.key : current_backseat.key])")
to_chat(owner, "You feel your control being taken away... your other personality is in charge now!")
to_chat(current_backseat, "You manage to take control of your body!")
diff --git a/code/datums/wires/airlock.dm b/code/datums/wires/airlock.dm
index c08239af30a..e6f79c67b0a 100644
--- a/code/datums/wires/airlock.dm
+++ b/code/datums/wires/airlock.dm
@@ -79,7 +79,7 @@
if(!A.secondsElectrified)
A.set_electrified(30)
if(usr)
- LAZYADD(A.shockedby, text("\[[time_stamp()]\][usr](ckey:[usr.ckey])"))
+ LAZYADD(A.shockedby, text("\[[time_stamp()]\] [key_name(usr)]"))
add_logs(usr, A, "electrified")
if(WIRE_SAFETY)
A.safe = !A.safe
@@ -134,7 +134,7 @@
if(A.secondsElectrified != -1)
A.set_electrified(-1)
if(usr)
- LAZYADD(A.shockedby, text("\[[time_stamp()]\][usr](ckey:[usr.ckey])"))
+ LAZYADD(A.shockedby, text("\[[time_stamp()]\] [key_name(usr)]"))
add_logs(usr, A, "electrified")
if(WIRE_SAFETY) // Cut to disable safeties, mend to re-enable.
A.safe = mend
diff --git a/code/game/gamemodes/game_mode.dm b/code/game/gamemodes/game_mode.dm
index 2a853f92881..2b610cebee5 100644
--- a/code/game/gamemodes/game_mode.dm
+++ b/code/game/gamemodes/game_mode.dm
@@ -435,23 +435,23 @@
continue // never had a client
if(L.ckey && !GLOB.directory[L.ckey])
- msg += "[L.name] ([L.ckey]), the [L.job] (Disconnected)\n"
+ msg += "[L.name] ([L.key]), the [L.job] (Disconnected)\n"
if(L.ckey && L.client)
var/failed = FALSE
if(L.client.inactivity >= (ROUNDSTART_LOGOUT_REPORT_TIME / 2)) //Connected, but inactive (alt+tabbed or something)
- msg += "[L.name] ([L.ckey]), the [L.job] (Connected, Inactive)\n"
+ msg += "[L.name] ([L.key]), the [L.job] (Connected, Inactive)\n"
failed = TRUE //AFK client
if(!failed && L.stat)
if(L.suiciding) //Suicider
- msg += "[L.name] ([L.ckey]), the [L.job] (Suicide)\n"
+ msg += "[L.name] ([L.key]), the [L.job] (Suicide)\n"
failed = TRUE //Disconnected client
if(!failed && L.stat == UNCONSCIOUS)
- msg += "[L.name] ([L.ckey]), the [L.job] (Dying)\n"
+ msg += "[L.name] ([L.key]), the [L.job] (Dying)\n"
failed = TRUE //Unconscious
if(!failed && L.stat == DEAD)
- msg += "[L.name] ([L.ckey]), the [L.job] (Dead)\n"
+ msg += "[L.name] ([L.key]), the [L.job] (Dead)\n"
failed = TRUE //Dead
var/p_ckey = L.client.ckey
diff --git a/code/game/machinery/computer/prisoner.dm b/code/game/machinery/computer/prisoner.dm
index 166da284354..1c1944e73ee 100644
--- a/code/game/machinery/computer/prisoner.dm
+++ b/code/game/machinery/computer/prisoner.dm
@@ -136,7 +136,7 @@
if(I && istype(I) && I.imp_in)
var/mob/living/R = I.imp_in
to_chat(R, "You hear a voice in your head saying: '[warning]'")
- log_talk(usr,"[key_name(usr)] sent an implant message to [R]/[R.ckey]: '[warning]'",LOGSAY)
+ log_talk(usr,"[key_name(usr)] sent an implant message to [key_name(R)]: '[warning]'",LOGSAY)
src.add_fingerprint(usr)
src.updateUsrDialog()
diff --git a/code/game/machinery/doors/airlock.dm b/code/game/machinery/doors/airlock.dm
index 03eeb76632b..5e5db86780b 100644
--- a/code/game/machinery/doors/airlock.dm
+++ b/code/game/machinery/doors/airlock.dm
@@ -1280,7 +1280,7 @@
bolt() //Bolt it!
set_electrified(ELECTRIFIED_PERMANENT) //Shock it!
if(origin)
- LAZYADD(shockedby, "\[[time_stamp()]\][origin](ckey:[origin.ckey])")
+ LAZYADD(shockedby, "\[[time_stamp()]\] [key_name(origin)]")
/obj/machinery/door/airlock/disable_lockdown()
@@ -1549,7 +1549,7 @@
if(wires.is_cut(WIRE_SHOCK))
to_chat(user, "The electrification wire has been cut")
else
- LAZYADD(shockedby, "\[[time_stamp()]\][user](ckey:[user.ckey])")
+ LAZYADD(shockedby, "\[[time_stamp()]\] [key_name(user)]")
add_logs(user, src, "electrified")
set_electrified(AI_ELECTRIFY_DOOR_TIME)
@@ -1559,7 +1559,7 @@
if(wires.is_cut(WIRE_SHOCK))
to_chat(user, "The electrification wire has been cut")
else
- LAZYADD(shockedby, text("\[[time_stamp()]\][user](ckey:[user.ckey])"))
+ LAZYADD(shockedby, text("\[[time_stamp()]\] [key_name(user)]"))
add_logs(user, src, "electrified")
set_electrified(ELECTRIFIED_PERMANENT)
diff --git a/code/game/objects/structures/morgue.dm b/code/game/objects/structures/morgue.dm
index a247f4c125c..111ce3ccca3 100644
--- a/code/game/objects/structures/morgue.dm
+++ b/code/game/objects/structures/morgue.dm
@@ -256,10 +256,10 @@ GLOBAL_LIST_EMPTY(crematoriums)
if (M.stat != DEAD)
M.emote("scream")
if(user)
- user.log_message("Cremated [M]/[M.ckey]", INDIVIDUAL_ATTACK_LOG)
- log_attack("[user]/[user.ckey] cremated [M]/[M.ckey]")
+ user.log_message("Cremated [key_name(M)]", INDIVIDUAL_ATTACK_LOG)
+ log_attack("[key_name(user)] cremated [key_name(M)]")
else
- log_attack("UNKNOWN cremated [M]/[M.ckey]")
+ log_attack("UNKNOWN cremated [key_name(M)]")
M.death(1)
if(M) //some animals get automatically deleted on death.
M.ghostize()
diff --git a/code/modules/admin/DB_ban/functions.dm b/code/modules/admin/DB_ban/functions.dm
index fd95783525e..ceabbb07342 100644
--- a/code/modules/admin/DB_ban/functions.dm
+++ b/code/modules/admin/DB_ban/functions.dm
@@ -2,7 +2,7 @@
#define MAX_ADMIN_BANS_PER_HEADMIN 3
//Either pass the mob you wish to ban in the 'banned_mob' attribute, or the banckey, banip and bancid variables. If both are passed, the mob takes priority! If a mob is not passed, banckey is the minimum that needs to be passed! banip and bancid are optional.
-/datum/admins/proc/DB_ban_record(bantype, mob/banned_mob, duration = -1, reason, job = "", banckey = null, banip = null, bancid = null)
+/datum/admins/proc/DB_ban_record(bantype, mob/banned_mob, duration = -1, reason, job = "", bankey = null, banip = null, bancid = null)
if(!check_rights(R_BAN))
return
@@ -64,23 +64,24 @@
if(ismob(banned_mob))
ckey = banned_mob.ckey
+ bankey = banned_mob.key
if(banned_mob.client)
computerid = banned_mob.client.computer_id
ip = banned_mob.client.address
else
computerid = banned_mob.computer_id
ip = banned_mob.lastKnownIP
- else if(banckey)
- ckey = ckey(banckey)
+ else if(bankey)
+ ckey = ckey(bankey)
computerid = bancid
ip = banip
-
+
var/had_banned_mob = banned_mob != null
var/client/banned_client = banned_mob?.client
var/banned_mob_guest_key = had_banned_mob && IsGuestKey(banned_mob.key)
banned_mob = null
- var/datum/DBQuery/query_add_ban_get_ckey = SSdbcore.NewQuery("SELECT ckey FROM [format_table_name("player")] WHERE ckey = '[ckey]'")
+ var/datum/DBQuery/query_add_ban_get_ckey = SSdbcore.NewQuery("SELECT 1 FROM [format_table_name("player")] WHERE ckey = '[ckey]'")
if(!query_add_ban_get_ckey.warn_execute())
qdel(query_add_ban_get_ckey)
return
@@ -88,14 +89,16 @@
qdel(query_add_ban_get_ckey)
if(!seen_before)
if(!had_banned_mob || (had_banned_mob && !banned_mob_guest_key))
- if(alert(usr, "[ckey] has not been seen before, are you sure you want to create a ban for them?", "Unknown ckey", "Yes", "No", "Cancel") != "Yes")
+ if(alert(usr, "[bankey] has not been seen before, are you sure you want to create a ban for them?", "Unknown ckey", "Yes", "No", "Cancel") != "Yes")
return
+ var/a_key
var/a_ckey
var/a_computerid
var/a_ip
if(istype(owner))
+ a_key = owner.key
a_ckey = owner.ckey
a_computerid = owner.computer_id
a_ip = owner.address
@@ -147,17 +150,17 @@
return
qdel(query_add_ban)
to_chat(usr, "Ban saved to database.")
- var/msg = "[key_name_admin(usr)] has added a [bantype_str] for [ckey] [(job)?"([job])":""] [(duration > 0)?"([duration] minutes)":""] with the reason: \"[reason]\" to the ban database."
+ var/msg = "[key_name_admin(usr)] has added a [bantype_str] for [bankey] [(job)?"([job])":""] [(duration > 0)?"([duration] minutes)":""] with the reason: \"[reason]\" to the ban database."
message_admins(msg,1)
var/datum/admin_help/AH = admin_ticket_log(ckey, msg)
if(announceinirc)
- send2irc("BAN ALERT","[a_ckey] applied a [bantype_str] on [ckey]")
+ send2irc("BAN ALERT","[a_key] applied a [bantype_str] on [bankey]")
if(kickbannedckey)
if(AH)
AH.Resolve() //with prejudice
- if(banned_client && banned_client.ckey == banckey)
+ if(banned_client && banned_client.ckey == ckey)
qdel(banned_client)
return 1
@@ -249,18 +252,18 @@
to_chat(usr, "Cancelled")
return
- var/datum/DBQuery/query_edit_ban_get_details = SSdbcore.NewQuery("SELECT ckey, duration, reason FROM [format_table_name("ban")] WHERE id = [banid]")
+ var/datum/DBQuery/query_edit_ban_get_details = SSdbcore.NewQuery("SELECT (SELECT byond_key FROM [format_table_name("player")] WHERE [format_table_name("player")].ckey = [format_table_name("ban")].ckey), duration, reason FROM [format_table_name("ban")] WHERE id = [banid]")
if(!query_edit_ban_get_details.warn_execute())
qdel(query_edit_ban_get_details)
return
- var/eckey = usr.ckey //Editing admin ckey
- var/pckey //(banned) Player ckey
+ var/e_key = usr.key //Editing admin key
+ var/p_key //(banned) Player key
var/duration //Old duration
var/reason //Old reason
if(query_edit_ban_get_details.NextRow())
- pckey = query_edit_ban_get_details.item[1]
+ p_key = query_edit_ban_get_details.item[1]
duration = query_edit_ban_get_details.item[2]
reason = query_edit_ban_get_details.item[3]
else
@@ -275,33 +278,33 @@
switch(param)
if("reason")
if(!value)
- value = input("Insert the new reason for [pckey]'s ban", "New Reason", "[reason]", null) as null|text
+ value = input("Insert the new reason for [p_key]'s ban", "New Reason", "[reason]", null) as null|text
value = sanitizeSQL(value)
if(!value)
to_chat(usr, "Cancelled")
return
- var/datum/DBQuery/query_edit_ban_reason = SSdbcore.NewQuery("UPDATE [format_table_name("ban")] SET reason = '[value]', edits = CONCAT(edits,'- [eckey] changed ban reason from \\\"[reason]\\\" to \\\"[value]\\\" ') WHERE id = [banid]")
+ var/datum/DBQuery/query_edit_ban_reason = SSdbcore.NewQuery("UPDATE [format_table_name("ban")] SET reason = '[value]', edits = CONCAT(edits,'- [e_key] changed ban reason from \\\"[reason]\\\" to \\\"[value]\\\" ') WHERE id = [banid]")
if(!query_edit_ban_reason.warn_execute())
qdel(query_edit_ban_reason)
return
qdel(query_edit_ban_reason)
- message_admins("[key_name_admin(usr)] has edited a ban for [pckey]'s reason from [reason] to [value]")
+ message_admins("[key_name_admin(usr)] has edited a ban for [p_key]'s reason from [reason] to [value]")
if("duration")
if(!value)
- value = input("Insert the new duration (in minutes) for [pckey]'s ban", "New Duration", "[duration]", null) as null|num
+ value = input("Insert the new duration (in minutes) for [p_key]'s ban", "New Duration", "[duration]", null) as null|num
if(!isnum(value) || !value)
to_chat(usr, "Cancelled")
return
- var/datum/DBQuery/query_edit_ban_duration = SSdbcore.NewQuery("UPDATE [format_table_name("ban")] SET duration = [value], edits = CONCAT(edits,'- [eckey] changed ban duration from [duration] to [value] '), expiration_time = DATE_ADD(bantime, INTERVAL [value] MINUTE) WHERE id = [banid]")
+ var/datum/DBQuery/query_edit_ban_duration = SSdbcore.NewQuery("UPDATE [format_table_name("ban")] SET duration = [value], edits = CONCAT(edits,'- [e_key] changed ban duration from [duration] to [value] '), expiration_time = DATE_ADD(bantime, INTERVAL [value] MINUTE) WHERE id = [banid]")
if(!query_edit_ban_duration.warn_execute())
qdel(query_edit_ban_duration)
return
qdel(query_edit_ban_duration)
- message_admins("[key_name_admin(usr)] has edited a ban for [pckey]'s duration from [duration] to [value]")
+ message_admins("[key_name_admin(usr)] has edited a ban for [p_key]'s duration from [duration] to [value]")
if("unban")
- if(alert("Unban [pckey]?", "Unban?", "Yes", "No") == "Yes")
+ if(alert("Unban [p_key]?", "Unban?", "Yes", "No") == "Yes")
DB_ban_unban_by_id(banid)
return
else
@@ -316,20 +319,20 @@
if(!check_rights(R_BAN))
return
- var/sql = "SELECT ckey FROM [format_table_name("ban")] WHERE id = [id]"
+ var/sql = "SELECT (SELECT byond_key FROM [format_table_name("player")] WHERE [format_table_name("player")].ckey = [format_table_name("ban")].ckey) FROM [format_table_name("ban")] WHERE id = [id]"
if(!SSdbcore.Connect())
return
var/ban_number = 0 //failsafe
- var/pckey
+ var/p_key
var/datum/DBQuery/query_unban_get_ckey = SSdbcore.NewQuery(sql)
if(!query_unban_get_ckey.warn_execute())
qdel(query_unban_get_ckey)
return
while(query_unban_get_ckey.NextRow())
- pckey = query_unban_get_ckey.item[1]
+ p_key = query_unban_get_ckey.item[1]
ban_number++;
qdel(query_unban_get_ckey)
@@ -354,7 +357,7 @@
qdel(query_unban)
return
qdel(query_unban)
- message_admins("[key_name_admin(usr)] has lifted [pckey]'s ban.")
+ message_admins("[key_name_admin(usr)] has lifted [p_key]'s ban.")
/client/proc/DB_ban_panel()
set category = "Admin"
@@ -399,7 +402,7 @@
output += ""
output += ""
output += ""
- output += "
[timestamp] | [server] | [admin_key]")
if(!linkless)
data += " \[Delete\]"
if(type == "note")
data += " [secret ? "\[Secret\]" : "\[Not secret\]"]"
if(type == "message sent")
data += " Message has been sent"
- if(editor_ckey)
+ if(editor_key)
data += "|"
else
data += " \[Edit\]"
- if(editor_ckey)
- data += " Last edit by [editor_ckey] (Click here to see edit log)"
+ if(editor_key)
+ data += " Last edit by [editor_key] (Click here to see edit log)"
data += " [text]