Skip to content

Commit

Permalink
[MIRROR] Moves as many db related date/time operations to the db side…
Browse files Browse the repository at this point in the history
… to avoid byond bugs with dates and times. (#2460) (#3298)

* Moves as many db related date/time operations to the db side to avoid byond bugs with dates and times.

* text2num moment for ipintel (#83032)

* Update blackbox.dm

* SQLtime->ISOtime

---------

Co-authored-by: NovaBot <[email protected]>
Co-authored-by: Kyle Spier-Swenson <[email protected]>
Co-authored-by: Zephyr <[email protected]>
Co-authored-by: Mal <[email protected]>
Co-authored-by: Iajret <[email protected]>
  • Loading branch information
6 people authored May 15, 2024
1 parent bfe01ad commit a380ff9
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 34 deletions.
2 changes: 1 addition & 1 deletion code/__HELPERS/logging/_logging.dm
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ GLOBAL_LIST_INIT(testing_global_profiler, list("_PROFILE_NAME" = "Global"))
SSdbcore.add_log_to_mass_insert_queue(
format_table_name("game_log"),
list(
"datetime" = SQLtime(),
"datetime" = ISOtime(),
"round_id" = "[GLOB.round_id]",
"ckey" = key_name(src),
"loc" = loc_name(src),
Expand Down
2 changes: 1 addition & 1 deletion code/__HELPERS/time.dm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
SSticker.gametime_offset = CEILING(SSticker.gametime_offset, 3600)

//returns timestamp in a sql and a not-quite-compliant ISO 8601 friendly format
/proc/SQLtime(timevar)
/proc/ISOtime(timevar)
return time2text(timevar || world.timeofday, "YYYY-MM-DD hh:mm:ss")


Expand Down
26 changes: 16 additions & 10 deletions code/controllers/subsystem/blackbox.dm
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,17 @@ SUBSYSTEM_DEF(blackbox)
return
var/playercount = LAZYLEN(GLOB.player_list)
var/admincount = GLOB.admins.len
var/datum/db_query/query_record_playercount = SSdbcore.NewQuery(/* NOVA EDIT CHANGE - MULTISERVER */{"
/* // NOVA EDIT CHANGE - MULTISERVER - ORIGINAL:
var/datum/db_query/query_record_playercount = SSdbcore.NewQuery({"
INSERT INTO [format_table_name("legacy_population")] (playercount, admincount, time, server_ip, server_port, round_id)
VALUES (:playercount, :admincount, NOW(), INET_ATON(:server_ip), :server_port, :round_id)
*/
var/datum/db_query/query_record_playercount = SSdbcore.NewQuery({"
INSERT INTO [format_table_name("legacy_population")] (playercount, admincount, time, server_name, server_ip, server_port, round_id)
VALUES (:playercount, :admincount, :time, :server_name, INET_ATON(:server_ip), :server_port, :round_id)
VALUES (:playercount, :admincount, NOW(), :server_name, INET_ATON(:server_ip), :server_port, :round_id)
"}, list(
"playercount" = playercount,
"admincount" = admincount,
"time" = SQLtime(),
"server_name" = CONFIG_GET(string/serversqlname), // NOVA EDIT ADDITION - MULTISERVER
"server_ip" = world.internet_address || "0",
"server_port" = "[world.port]",
Expand Down Expand Up @@ -299,7 +303,7 @@ Versioning

var/datum/db_query/query_log_ahelp = SSdbcore.NewQuery({"
INSERT INTO [format_table_name("ticket")] (ticket, action, message, recipient, sender, server_ip, server_port, round_id, timestamp, urgent)
VALUES (:ticket, :action, :message, :recipient, :sender, INET_ATON(:server_ip), :server_port, :round_id, :time, :urgent)
VALUES (:ticket, :action, :message, :recipient, :sender, INET_ATON(:server_ip), :server_port, :round_id, NOW(), :urgent)
"}, list(
"ticket" = ticket,
"action" = action,
Expand All @@ -309,7 +313,6 @@ Versioning
"server_ip" = world.internet_address || "0",
"server_port" = world.port,
"round_id" = GLOB.round_id,
"time" = SQLtime(),
"urgent" = urgent,
))
query_log_ahelp.Execute()
Expand All @@ -336,9 +339,14 @@ Versioning
if(!SSdbcore.Connect())
return

var/datum/db_query/query_report_death = SSdbcore.NewQuery(/* NOVA EDIT CHANGE - MULTISERVER */{"
/* NOVA EDIT CHANGE - MULTISERVER - ORIGINAL:
var/datum/db_query/query_report_death = SSdbcore.NewQuery({"
INSERT INTO [format_table_name("death")] (pod, x_coord, y_coord, z_coord, mapname, server_ip, server_port, round_id, tod, job, special, name, byondkey, laname, lakey, bruteloss, fireloss, brainloss, oxyloss, toxloss, staminaloss, last_words, suicide)
VALUES (:pod, :x_coord, :y_coord, :z_coord, :map, INET_ATON(:internet_address), :port, :round_id, NOW(), :job, :special, :name, :key, :laname, :lakey, :brute, :fire, :brain, :oxy, :tox, :stamina, :last_words, :suicide)
*/
var/datum/db_query/query_report_death = SSdbcore.NewQuery({"
INSERT INTO [format_table_name("death")] (pod, x_coord, y_coord, z_coord, mapname, server_name, server_ip, server_port, round_id, tod, job, special, name, byondkey, laname, lakey, bruteloss, fireloss, brainloss, oxyloss, toxloss, staminaloss, last_words, suicide)
VALUES (:pod, :x_coord, :y_coord, :z_coord, :map, :server_name, INET_ATON(:internet_address), :port, :round_id, :time, :job, :special, :name, :key, :laname, :lakey, :brute, :fire, :brain, :oxy, :tox, :clone, :stamina, :last_words, :suicide)
VALUES (:pod, :x_coord, :y_coord, :z_coord, :map, :server_name, INET_ATON(:internet_address), :port, :round_id, NOW(), :job, :special, :name, :key, :laname, :lakey, :brute, :fire, :brain, :oxy, :tox, :clone, :stamina, :last_words, :suicide)
"}, list(
"name" = L.real_name,
"key" = L.ckey,
Expand All @@ -363,7 +371,6 @@ Versioning
"internet_address" = world.internet_address || "0",
"port" = "[world.port]",
"round_id" = GLOB.round_id,
"time" = SQLtime(),
))
if(query_report_death)
query_report_death.Execute(async = TRUE)
Expand Down Expand Up @@ -394,7 +401,7 @@ Versioning
:message,
:fine,
:paid,
:timestamp
NOW()
) ON DUPLICATE KEY UPDATE
paid = paid + VALUES(paid)"}, list(
"server_ip" = world.internet_address || "0",
Expand All @@ -408,7 +415,6 @@ Versioning
"message" = message,
"fine" = fine,
"paid" = paid,
"timestamp" = SQLtime()
))
if(query_report_citation)
query_report_citation.Execute(async = TRUE)
Expand Down
6 changes: 5 additions & 1 deletion code/controllers/subsystem/ipintel.dm
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ SUBSYSTEM_DEF(ipintel)
if(intel.query_status != "success")
return intel
intel.result = data["result"]
intel.date = SQLtime()
if(istext(intel.result))
intel.result = text2num(intel.result)
intel.date = ISOtime()
intel.address = address
cached_queries[address] = intel
add_intel_to_database(intel)
Expand Down Expand Up @@ -158,6 +160,8 @@ SUBSYSTEM_DEF(ipintel)
var/datum/ip_intel/intel = new
intel.query_status = "cached"
intel.result = data["intel"]
if(istext(intel.result))
intel.result = text2num(intel.result)
intel.date = data["date"]
intel.address = address
return TRUE
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystem/time_track.dm
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ SUBSYSTEM_DEF(time_track)
send_maps_values += packet["value"]
send_maps_values += packet["calls"]

SSblackbox.record_feedback("associative", "time_dilation_current", 1, list("[SQLtime()]" = list("current" = "[time_dilation_current]", "avg_fast" = "[time_dilation_avg_fast]", "avg" = "[time_dilation_avg]", "avg_slow" = "[time_dilation_avg_slow]")))
SSblackbox.record_feedback("associative", "time_dilation_current", 1, list("[ISOtime()]" = list("current" = "[time_dilation_current]", "avg_fast" = "[time_dilation_avg_fast]", "avg" = "[time_dilation_avg]", "avg_slow" = "[time_dilation_avg_slow]")))
log_perf(
list(
world.time,
Expand Down
20 changes: 10 additions & 10 deletions code/modules/admin/permissionedit.dm
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ ADMIN_VERB(edit_admin_permissions, R_PERMISSIONS, "Permissions Panel", "Edit adm
qdel(query_add_admin)
var/datum/db_query/query_add_admin_log = SSdbcore.NewQuery({"
INSERT INTO [format_table_name("admin_log")] (datetime, round_id, adminckey, adminip, operation, target, log)
VALUES (:time, :round_id, :adminckey, INET_ATON(:adminip), 'add admin', :target, CONCAT('New admin added: ', :target))
"}, list("time" = SQLtime(), "round_id" = "[GLOB.round_id]", "adminckey" = usr.ckey, "adminip" = usr.client.address, "target" = .))
VALUES (NOW(), :round_id, :adminckey, INET_ATON(:adminip), 'add admin', :target, CONCAT('New admin added: ', :target))
"}, list("round_id" = "[GLOB.round_id]", "adminckey" = usr.ckey, "adminip" = usr.client.address, "target" = .))
if(!query_add_admin_log.warn_execute())
qdel(query_add_admin_log)
return FALSE
Expand All @@ -275,8 +275,8 @@ ADMIN_VERB(edit_admin_permissions, R_PERMISSIONS, "Permissions Panel", "Edit adm
qdel(query_add_rank)
var/datum/db_query/query_add_rank_log = SSdbcore.NewQuery({"
INSERT INTO [format_table_name("admin_log")] (datetime, round_id, adminckey, adminip, operation, target, log)
VALUES (:time, :round_id, :adminckey, INET_ATON(:adminip), 'remove admin', :admin_ckey, CONCAT('Admin removed: ', :admin_ckey))
"}, list("time" = SQLtime(), "round_id" = "[GLOB.round_id]", "adminckey" = usr.ckey, "adminip" = usr.client.address, "admin_ckey" = admin_ckey))
VALUES (NOW(), :round_id, :adminckey, INET_ATON(:adminip), 'remove admin', :admin_ckey, CONCAT('Admin removed: ', :admin_ckey))
"}, list("round_id" = "[GLOB.round_id]", "adminckey" = usr.ckey, "adminip" = usr.client.address, "admin_ckey" = admin_ckey))
if(!query_add_rank_log.warn_execute())
qdel(query_add_rank_log)
return
Expand Down Expand Up @@ -423,8 +423,8 @@ ADMIN_VERB(edit_admin_permissions, R_PERMISSIONS, "Permissions Panel", "Edit adm
qdel(query_add_rank)
var/datum/db_query/query_add_rank_log = SSdbcore.NewQuery({"
INSERT INTO [format_table_name("admin_log")] (datetime, round_id, adminckey, adminip, operation, target, log)
VALUES (:time, :round_id, :adminckey, INET_ATON(:adminip), 'add rank', :new_rank, CONCAT('New rank added: ', :new_rank))
"}, list("time" = SQLtime(), "round_id" = "[GLOB.round_id]", "adminckey" = usr.ckey, "adminip" = usr.client.address, "new_rank" = custom_rank.name))
VALUES (NOW(), :round_id, :adminckey, INET_ATON(:adminip), 'add rank', :new_rank, CONCAT('New rank added: ', :new_rank))
"}, list("round_id" = "[GLOB.round_id]", "adminckey" = usr.ckey, "adminip" = usr.client.address, "new_rank" = custom_rank.name))
if(!query_add_rank_log.warn_execute())
qdel(query_add_rank_log)
return
Expand All @@ -440,8 +440,8 @@ ADMIN_VERB(edit_admin_permissions, R_PERMISSIONS, "Permissions Panel", "Edit adm
qdel(query_change_rank)
var/datum/db_query/query_change_rank_log = SSdbcore.NewQuery({"
INSERT INTO [format_table_name("admin_log")] (datetime, round_id, adminckey, adminip, operation, target, log)
VALUES (:time, :round_id, :adminckey, INET_ATON(:adminip), 'change admin rank', :target, CONCAT('Rank of ', :target, ' changed from ', :old_rank, ' to ', :new_rank))
"}, list("time" = SQLtime(), "round_id" = "[GLOB.round_id]", "adminckey" = usr.ckey, "adminip" = usr.client.address, "target" = admin_ckey, "old_rank" = old_rank, "new_rank" = joined_rank))
VALUES (NOW(), :round_id, :adminckey, INET_ATON(:adminip), 'change admin rank', :target, CONCAT('Rank of ', :target, ' changed from ', :old_rank, ' to ', :new_rank))
"}, list("round_id" = "[GLOB.round_id]", "adminckey" = usr.ckey, "adminip" = usr.client.address, "target" = admin_ckey, "old_rank" = old_rank, "new_rank" = joined_rank))
if(!query_change_rank_log.warn_execute())
qdel(query_change_rank_log)
return
Expand Down Expand Up @@ -539,8 +539,8 @@ ADMIN_VERB(edit_admin_permissions, R_PERMISSIONS, "Permissions Panel", "Edit adm
qdel(query_add_rank)
var/datum/db_query/query_add_rank_log = SSdbcore.NewQuery({"
INSERT INTO [format_table_name("admin_log")] (datetime, round_id, adminckey, adminip, operation, target, log)
VALUES (:time, :round_id, :adminckey, INET_ATON(:adminip), 'remove rank', :admin_rank, CONCAT('Rank removed: ', :admin_rank))
"}, list("time" = SQLtime(), "round_id" = "[GLOB.round_id]", "adminckey" = usr.ckey, "adminip" = usr.client.address, "admin_rank" = admin_rank))
VALUES (NOW(), :round_id, :adminckey, INET_ATON(:adminip), 'remove rank', :admin_rank, CONCAT('Rank removed: ', :admin_rank))
"}, list("round_id" = "[GLOB.round_id]", "adminckey" = usr.ckey, "adminip" = usr.client.address, "admin_rank" = admin_rank))
if(!query_add_rank_log.warn_execute())
qdel(query_add_rank_log)
return
Expand Down
4 changes: 2 additions & 2 deletions code/modules/admin/sql_ban_system.dm
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@
return
var/kn = key_name(usr)
var/kna = key_name_admin(usr)
var/change_message = "[usr.client.key] unbanned [target] from [role] on [SQLtime()] during round #[GLOB.round_id]<hr>"
var/change_message = "[usr.client.key] unbanned [target] from [role] on [ISOtime()] during round #[GLOB.round_id]<hr>"
var/datum/db_query/query_unban = SSdbcore.NewQuery({"
UPDATE [format_table_name("ban")] SET
unbanned_datetime = NOW(),
Expand Down Expand Up @@ -914,7 +914,7 @@

var/kn = key_name(usr)
var/kna = key_name_admin(usr)
var/change_message = "[usr.client.key] re-activated ban of [target] from [role] on [SQLtime()] during round #[GLOB.round_id]<hr>"
var/change_message = "[usr.client.key] re-activated ban of [target] from [role] on [ISOtime()] during round #[GLOB.round_id]<hr>"
var/datum/db_query/query_reban = SSdbcore.NewQuery({"
UPDATE [format_table_name("ban")] SET
unbanned_datetime = NULL,
Expand Down
10 changes: 5 additions & 5 deletions code/modules/admin/sql_message_system.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
return
if(isnull(expiry))
if(tgui_alert(usr, "Set an expiry time? Expired messages are hidden like deleted ones.", "Expiry time?", list("Yes", "No", "Cancel")) == "Yes")
var/expire_time = input("Set expiry time for [type] as format YYYY-MM-DD HH:MM:SS. All times in server time. HH:MM:SS is optional and 24-hour. Must be later than current time for obvious reasons.", "Set expiry time", SQLtime()) as null|text
var/expire_time = input("Set expiry time for [type] as format YYYY-MM-DD HH:MM:SS. All times in server time. HH:MM:SS is optional and 24-hour. Must be later than current time for obvious reasons.", "Set expiry time", ISOtime()) as null|text
if(!expire_time)
return
var/datum/db_query/query_validate_expire_time = SSdbcore.NewQuery(
Expand Down Expand Up @@ -184,7 +184,7 @@
if(!new_text)
qdel(query_find_edit_message)
return
var/edit_text = "Edited by [editor_key] on [SQLtime()] from<br>[old_text]<br>to<br>[new_text]<hr>"
var/edit_text = "Edited by [editor_key] on [ISOtime()] from<br>[old_text]<br>to<br>[new_text]<hr>"
var/datum/db_query/query_edit_message = SSdbcore.NewQuery({"
UPDATE [format_table_name("messages")]
SET text = :text, lasteditor = :lasteditor, edits = CONCAT(IFNULL(edits,''),:edit_text)
Expand Down Expand Up @@ -254,7 +254,7 @@
return
new_expiry = query_validate_expire_time_edit.item[1]
qdel(query_validate_expire_time_edit)
var/edit_text = "Expiration time edited by [editor_key] on [SQLtime()] from [(old_expiry ? old_expiry : "no expiration date")] to [new_expiry]<hr>"
var/edit_text = "Expiration time edited by [editor_key] on [ISOtime()] from [(old_expiry ? old_expiry : "no expiration date")] to [new_expiry]<hr>"
var/datum/db_query/query_edit_message_expiry = SSdbcore.NewQuery({"
UPDATE [format_table_name("messages")]
SET expire_timestamp = :expire_time, lasteditor = :lasteditor, edits = CONCAT(IFNULL(edits,''),:edit_text)
Expand Down Expand Up @@ -308,7 +308,7 @@
qdel(query_find_edit_note_severity)
return
new_severity = new_severity
var/edit_text = "Note severity edited by [editor_key] on [SQLtime()] from [old_severity] to [new_severity]<hr>"
var/edit_text = "Note severity edited by [editor_key] on [ISOtime()] from [old_severity] to [new_severity]<hr>"
var/datum/db_query/query_edit_note_severity = SSdbcore.NewQuery({"
UPDATE [format_table_name("messages")]
SET severity = :severity, lasteditor = :lasteditor, edits = CONCAT(IFNULL(edits,''),:edit_text)
Expand Down Expand Up @@ -352,7 +352,7 @@
var/target_key = query_find_message_secret.item[2]
var/admin_key = query_find_message_secret.item[3]
var/secret = text2num(query_find_message_secret.item[4])
var/edit_text = "Made [secret ? "not secret" : "secret"] by [editor_key] on [SQLtime()]<hr>"
var/edit_text = "Made [secret ? "not secret" : "secret"] by [editor_key] on [ISOtime()]<hr>"
var/datum/db_query/query_message_secret = SSdbcore.NewQuery({"
UPDATE [format_table_name("messages")]
SET secret = NOT secret, lasteditor = :lasteditor, edits = CONCAT(IFNULL(edits,''),:edit_text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@
if(stored_research.can_afford(price))
user.investigate_log("researched [id]([json_encode(price)]) on techweb id [stored_research.id] via [computer].", INVESTIGATE_RESEARCH)
if(istype(stored_research, /datum/techweb/science))
SSblackbox.record_feedback("associative", "science_techweb_unlock", 1, list("id" = "[id]", "name" = tech_node.display_name, "price" = "[json_encode(price)]", "time" = SQLtime()))
SSblackbox.record_feedback("associative", "science_techweb_unlock", 1, list("id" = "[id]", "name" = tech_node.display_name, "price" = "[json_encode(price)]", "time" = ISOtime()))
if(stored_research.research_node_id(id))
computer.say("Successfully researched [tech_node.display_name].")
var/logname = "Unknown"
Expand Down
2 changes: 1 addition & 1 deletion code/modules/research/rdconsole.dm
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Nothing else in the console has ID requirements.
if(stored_research.can_afford(price))
user.investigate_log("researched [id]([json_encode(price)]) on techweb id [stored_research.id].", INVESTIGATE_RESEARCH)
if(istype(stored_research, /datum/techweb/science))
SSblackbox.record_feedback("associative", "science_techweb_unlock", 1, list("id" = "[id]", "name" = TN.display_name, "price" = "[json_encode(price)]", "time" = SQLtime()))
SSblackbox.record_feedback("associative", "science_techweb_unlock", 1, list("id" = "[id]", "name" = TN.display_name, "price" = "[json_encode(price)]", "time" = ISOtime()))
if(stored_research.research_node_id(id))
say("Successfully researched [TN.display_name].")
var/logname = "Unknown"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* * log_entry - Associative list representing all of the information that needs to be logged.
* Default format is as follows, for the `game_log` table (even if this could be used for another table):
* list(
* "datetime" = SQLtime(),
* "datetime" = ISOtime(),
* "round_id" = "[GLOB.round_id]",
* "ckey" = key_name(src),
* "loc" = loc_name(src),
Expand Down

0 comments on commit a380ff9

Please sign in to comment.