From a8457b91f3f6dca0e37b7d620813e2e01a2223ce Mon Sep 17 00:00:00 2001
From: Gamer025 <33846895+Gamer025@users.noreply.github.com>
Date: Mon, 24 Apr 2023 22:47:12 +0200
Subject: [PATCH] Fixes silo logging + add log file based logging to silo
(#74806)
## About The Pull Request
Fixes deposit logs not working for the silo because they passed in the
mats argument in the wrong format.
Also adds log file based logging to the silo with a new log file:
silo.log.
This log should contain every deposit and withdraw action performed on
the silo and from which machine and location inluding material amounts.
## Why It's Good For The Game
Fixes broken ingame logs + adds better external logs for potential stat
tracking.
## Changelog
:cl: Gamer025
fix: Ingame ore silo logs should now log deposit actions correctly
config: New config for silo logs
/:cl:
---
code/__DEFINES/logging.dm | 1 +
code/game/world.dm | 6 +--
.../logging/categories/log_category_silo.dm | 2 +
code/modules/mining/machine_redemption.dm | 2 +-
code/modules/mining/machine_silo.dm | 45 ++++++++++++++-----
.../mob/living/silicon/robot/robot_model.dm | 2 +-
.../modules/research/machinery/_production.dm | 2 +-
tgstation.dme | 1 +
8 files changed, 44 insertions(+), 17 deletions(-)
create mode 100644 code/modules/logging/categories/log_category_silo.dm
diff --git a/code/__DEFINES/logging.dm b/code/__DEFINES/logging.dm
index 9e0da264669..d086fa2ae62 100644
--- a/code/__DEFINES/logging.dm
+++ b/code/__DEFINES/logging.dm
@@ -72,6 +72,7 @@
// Log categories
#define LOG_CATEGORY_NOT_FOUND "invalid_category"
#define LOG_CATEGORY_TARGET_ZONE_SWITCH "target_zone_switch"
+#define LOG_CATEGORY_SILO "silo"
//wrapper macros for easier grepping
#define DIRECT_OUTPUT(A, B) A << B
diff --git a/code/game/world.dm b/code/game/world.dm
index 9257660caaa..6105da28e82 100644
--- a/code/game/world.dm
+++ b/code/game/world.dm
@@ -298,12 +298,12 @@ GLOBAL_VAR(restart_counter)
TgsEndProcess()
log_world("World rebooted at [time_stamp()]")
-
+
shutdown_logging() // Past this point, no logging procs can be used, at risk of data loss.
auxcleanup()
-
+
TgsReboot() // TGS can decide to kill us right here, so it's important to do it last
-
+
..()
/world/proc/auxcleanup()
diff --git a/code/modules/logging/categories/log_category_silo.dm b/code/modules/logging/categories/log_category_silo.dm
new file mode 100644
index 00000000000..c3fd1faf8b8
--- /dev/null
+++ b/code/modules/logging/categories/log_category_silo.dm
@@ -0,0 +1,2 @@
+/datum/log_category/silo
+ category = LOG_CATEGORY_SILO
diff --git a/code/modules/mining/machine_redemption.dm b/code/modules/mining/machine_redemption.dm
index f37092fcfc8..a7a03a6d662 100644
--- a/code/modules/mining/machine_redemption.dm
+++ b/code/modules/mining/machine_redemption.dm
@@ -74,7 +74,7 @@
var/mats = stack_mats & mat_container.materials
var/amount = gathered_ore.amount
mat_container.insert_item(gathered_ore, ore_multiplier, breakdown_flags=BREAKDOWN_FLAGS_ORM) //insert it
- materials.silo_log(src, "smelted", amount, "someone", mats)
+ materials.silo_log(src, "smelted", amount, gathered_ore.name, mats)
qdel(gathered_ore)
SEND_SIGNAL(src, COMSIG_ORM_COLLECTED_ORE)
diff --git a/code/modules/mining/machine_silo.dm b/code/modules/mining/machine_silo.dm
index 0cca6f51865..700e798eabf 100644
--- a/code/modules/mining/machine_silo.dm
+++ b/code/modules/mining/machine_silo.dm
@@ -66,7 +66,8 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
// assumes unlimited space...
var/amount = I.amount
materials.user_insert(I, user, breakdown_flags)
- silo_log(M, "deposited", amount, "sheets", item_mats)
+ var/list/matlist = I.get_material_composition(breakdown_flags)
+ silo_log(M, "deposited", amount, I.name, matlist)
return TRUE
/obj/machinery/ore_silo/attackby(obj/item/W, mob/user, params)
@@ -173,7 +174,7 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
var/datum/component/material_container/materials = GetComponent(/datum/component/material_container)
var/count = materials.retrieve_sheets(text2num(href_list["eject_amt"]), eject_sheet, drop_location())
var/list/matlist = list()
- matlist[eject_sheet] = MINERAL_MATERIAL_AMOUNT
+ matlist[eject_sheet] = MINERAL_MATERIAL_AMOUNT * count
silo_log(src, "ejected", -count, "sheets", matlist)
return TRUE
else if(href_list["page"])
@@ -188,11 +189,20 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
I.buffer = src
return TRUE
+/**
+ * Creates a log entry for depositing/withdrawing from the silo both ingame and in text based log
+ *
+ * Arguments:
+ * - [M][/obj/machinery]: The machine performing the action.
+ * - action: Text that visually describes the action (smelted/deposited/resupplied...)
+ * - amount: The amount of sheets/objects deposited/withdrawn by this action. Positive for depositing, negative for withdrawing.
+ * - noun: Name of the object the action was performed with (sheet, units, ore...)
+ * - [mats][list]: Assoc list in format (material datum = amount of raw materials). Wants the actual amount of raw (iron, glass...) materials involved in this action. If you have 10 metal sheets each worth 2000 iron you would pass a list with the iron material datum = 20000
+ */
/obj/machinery/ore_silo/proc/silo_log(obj/machinery/M, action, amount, noun, list/mats)
if (!length(mats))
return
var/datum/ore_silo_log/entry = new(M, action, amount, noun, mats)
-
var/list/datum/ore_silo_log/logs = GLOB.silo_access_logs[REF(src)]
if(!LAZYLEN(logs))
GLOB.silo_access_logs[REF(src)] = logs = list(entry)
@@ -226,9 +236,21 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
amount = _amount
noun = _noun
materials = mats.Copy()
- for(var/each in materials)
- materials[each] *= abs(_amount)
format()
+ var/list/data = list(
+ "machine_name" = machine_name,
+ "area_name" = AREACOORD(M),
+ "action" = action,
+ "amount" = abs(amount),
+ "noun" = noun,
+ "raw_materials" = get_raw_materials(""),
+ "direction" = amount < 0 ? "withdrawn" : "deposited",
+ )
+ GLOB.logger.Log(
+ LOG_CATEGORY_SILO,
+ "[machine_name] in \[[AREACOORD(M)]\] [action] [abs(amount)]x [noun] | [get_raw_materials("")]",
+ data,
+ )
/datum/ore_silo_log/proc/merge(datum/ore_silo_log/other)
if (other == src || action != other.action || noun != other.noun)
@@ -245,13 +267,14 @@ GLOBAL_LIST_EMPTY(silo_access_logs)
/datum/ore_silo_log/proc/format()
name = "[machine_name]: [action] [amount]x [noun]"
+ formatted = "([timestamp]) [machine_name] in [area_name]
[action] [abs(amount)]x [noun]
[get_raw_materials("")]"
- var/list/msg = list("([timestamp]) [machine_name] in [area_name]
[action] [abs(amount)]x [noun]
")
- var/sep = ""
+/datum/ore_silo_log/proc/get_raw_materials(separator)
+ var/list/msg = list()
for(var/key in materials)
var/datum/material/M = key
- var/val = round(materials[key]) / MINERAL_MATERIAL_AMOUNT
- msg += sep
- sep = ", "
+ var/val = round(materials[key])
+ msg += separator
+ separator = ", "
msg += "[amount < 0 ? "-" : "+"][val] [M.name]"
- formatted = msg.Join()
+ return msg.Join()
diff --git a/code/modules/mob/living/silicon/robot/robot_model.dm b/code/modules/mob/living/silicon/robot/robot_model.dm
index 34a5cfcf5b7..758d6e0c965 100644
--- a/code/modules/mob/living/silicon/robot/robot_model.dm
+++ b/code/modules/mob/living/silicon/robot/robot_model.dm
@@ -186,7 +186,7 @@
storage_datum.energy += mat_container.use_amount_mat(to_stock, storage_datum.mat_type)
charger.balloon_alert(robot, "+ [to_stock]u [initial(storage_datum.mat_type.name)]")
- charger.materials.silo_log(charger, "resupplied", -to_stock, "units", list(storage_datum.mat_type))
+ charger.materials.silo_log(charger, "resupplied", -1, "units", list(GET_MATERIAL_REF(storage_datum.mat_type) = to_stock))
playsound(charger, 'sound/weapons/gun/general/mag_bullet_insert.ogg', 50, vary = FALSE)
return
charger.balloon_alert(robot, "restock process complete")
diff --git a/code/modules/research/machinery/_production.dm b/code/modules/research/machinery/_production.dm
index c39261512c5..d0ac21f7f91 100644
--- a/code/modules/research/machinery/_production.dm
+++ b/code/modules/research/machinery/_production.dm
@@ -349,7 +349,7 @@
var/count = mat_container.retrieve_sheets(text2num(eject_amt), eject_sheet, drop_location())
var/list/matlist = list()
- matlist[eject_sheet] = MINERAL_MATERIAL_AMOUNT
+ matlist[eject_sheet] = MINERAL_MATERIAL_AMOUNT * count
materials.silo_log(src, "ejected", -count, "sheets", matlist)
diff --git a/tgstation.dme b/tgstation.dme
index dce87ecc8e2..0300c6dc473 100644
--- a/tgstation.dme
+++ b/tgstation.dme
@@ -3705,6 +3705,7 @@
#include "code\modules\lighting\static_lighting_area.dm"
#include "code\modules\logging\log_category.dm"
#include "code\modules\logging\log_holder.dm"
+#include "code\modules\logging\categories\log_category_silo.dm"
#include "code\modules\logging\categories\log_category_target_zone_switch.dm"
#include "code\modules\mafia\_defines.dm"
#include "code\modules\mafia\controller.dm"