Skip to content

Commit

Permalink
Key instead of ckey for user facing logs and ui (tgstation#39009)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Jordie0608 authored Aug 10, 2018
1 parent a5df026 commit 0d7ef3e
Show file tree
Hide file tree
Showing 32 changed files with 412 additions and 269 deletions.
2 changes: 1 addition & 1 deletion SQL/admin_import_2018-02-03.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def parse_text_flags(text, previous):
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.")
14 changes: 11 additions & 3 deletions SQL/database_changelog.txt
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
92 changes: 92 additions & 0 deletions SQL/populate_key_2018-07-09.py
Original file line number Diff line number Diff line change
@@ -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()
1 change: 1 addition & 0 deletions SQL/tgstation_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions SQL/tgstation_schema_prefixed.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion code/__DEFINES/subsystems.dm
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 4 additions & 4 deletions code/__HELPERS/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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]"

Expand Down
28 changes: 14 additions & 14 deletions code/controllers/subsystem/medals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<span class='greenannounce'><B>Achievement unlocked: [medal]!</B></span>")

Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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")

Expand All @@ -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]!")
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]!")
2 changes: 1 addition & 1 deletion code/datums/brain_damage/split_personality.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<span class='userdanger'>You feel your control being taken away... your other personality is in charge now!</span>")
to_chat(current_backseat, "<span class='userdanger'>You manage to take control of your body!</span>")

Expand Down
4 changes: 2 additions & 2 deletions code/datums/wires/airlock.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions code/game/gamemodes/game_mode.dm
Original file line number Diff line number Diff line change
Expand Up @@ -435,23 +435,23 @@
continue // never had a client

if(L.ckey && !GLOB.directory[L.ckey])
msg += "<b>[L.name]</b> ([L.ckey]), the [L.job] (<font color='#ffcc00'><b>Disconnected</b></font>)\n"
msg += "<b>[L.name]</b> ([L.key]), the [L.job] (<font color='#ffcc00'><b>Disconnected</b></font>)\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 += "<b>[L.name]</b> ([L.ckey]), the [L.job] (<font color='#ffcc00'><b>Connected, Inactive</b></font>)\n"
msg += "<b>[L.name]</b> ([L.key]), the [L.job] (<font color='#ffcc00'><b>Connected, Inactive</b></font>)\n"
failed = TRUE //AFK client
if(!failed && L.stat)
if(L.suiciding) //Suicider
msg += "<b>[L.name]</b> ([L.ckey]), the [L.job] (<span class='boldannounce'>Suicide</span>)\n"
msg += "<b>[L.name]</b> ([L.key]), the [L.job] (<span class='boldannounce'>Suicide</span>)\n"
failed = TRUE //Disconnected client
if(!failed && L.stat == UNCONSCIOUS)
msg += "<b>[L.name]</b> ([L.ckey]), the [L.job] (Dying)\n"
msg += "<b>[L.name]</b> ([L.key]), the [L.job] (Dying)\n"
failed = TRUE //Unconscious
if(!failed && L.stat == DEAD)
msg += "<b>[L.name]</b> ([L.ckey]), the [L.job] (Dead)\n"
msg += "<b>[L.name]</b> ([L.key]), the [L.job] (Dead)\n"
failed = TRUE //Dead

var/p_ckey = L.client.ckey
Expand Down
2 changes: 1 addition & 1 deletion code/game/machinery/computer/prisoner.dm
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
if(I && istype(I) && I.imp_in)
var/mob/living/R = I.imp_in
to_chat(R, "<span class='italics'>You hear a voice in your head saying: '[warning]'</span>")
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()
Expand Down
6 changes: 3 additions & 3 deletions code/game/machinery/doors/airlock.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions code/game/objects/structures/morgue.dm
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ GLOBAL_LIST_EMPTY(crematoriums)
if (M.stat != DEAD)
M.emote("scream")
if(user)
user.log_message("Cremated <b>[M]/[M.ckey]</b>", INDIVIDUAL_ATTACK_LOG)
log_attack("[user]/[user.ckey] cremated [M]/[M.ckey]")
user.log_message("Cremated <b>[key_name(M)]</b>", 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()
Expand Down
Loading

0 comments on commit 0d7ef3e

Please sign in to comment.