Skip to content

Commit

Permalink
[MIRROR] add computer command logging (#2731)
Browse files Browse the repository at this point in the history
Co-authored-by: MuckerMayhem <[email protected]>
Co-authored-by: Lexanx <[email protected]>
  • Loading branch information
3 people authored Nov 24, 2024
1 parent 08c8594 commit 8b96ad9
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 2 deletions.
2 changes: 2 additions & 0 deletions baystation12.dme
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@
#include "code\datums\repositories\attack_logs.dm"
#include "code\datums\repositories\cameras.dm"
#include "code\datums\repositories\client.dm"
#include "code\datums\repositories\computer_logs.dm"
#include "code\datums\repositories\follow.dm"
#include "code\datums\repositories\images.dm"
#include "code\datums\repositories\mobs.dm"
Expand Down Expand Up @@ -1404,6 +1405,7 @@
#include "code\modules\admin\secrets\fun_secrets\power_all_smes.dm"
#include "code\modules\admin\secrets\fun_secrets\waddle.dm"
#include "code\modules\admin\secrets\investigation\attack_logs.dm"
#include "code\modules\admin\secrets\investigation\computer_logs.dm"
#include "code\modules\admin\secrets\investigation\view_persistant.dm"
#include "code\modules\admin\verbs\adminhelp.dm"
#include "code\modules\admin\verbs\adminjump.dm"
Expand Down
3 changes: 3 additions & 0 deletions code/_helpers/logging.dm
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ var/global/log_end= world.system_type == UNIX ? ascii2text(13) : ""
to_world_log("## UNIT_TEST ##: [text]")
log_debug(text)

/proc/log_computer_command(text)
if (config.log_computer_commands)
game_log("COMPUTER_COMMAND", text)

//This replaces world.log so it displays both in DD and the file
/proc/log_world(text)
Expand Down
11 changes: 9 additions & 2 deletions code/controllers/configuration.dm
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@

/// log world.log to game log
var/static/log_world_output = FALSE
//[SIERRA-ADD]

//[SIERRA-ADD]
/// log signals messages
var/static/log_signals = FALSE
//[/SIERRA-ADD]
//[/SIERRA-ADD]

/// log computer commands
var/static/log_computer_commands = FALSE

/// Allows admins with relevant permissions to have their own ooc colour
var/static/allow_admin_ooccolor = FALSE

Expand Down Expand Up @@ -550,6 +555,8 @@
log_hrefs = TRUE
if ("log_runtime")
log_runtime = TRUE
if ("log_computer_commands")
log_computer_commands = TRUE
if ("generate_asteroid")
generate_map = TRUE
if ("no_click_cooldown")
Expand Down
26 changes: 26 additions & 0 deletions code/datums/repositories/computer_logs.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var/global/repository/computer_logs/computer_log_repository = new()

/repository/computer_logs
var/list/computer_logs_

/repository/computer_logs/New()
..()
computer_logs_ = list()

/repository/computer_logs/proc/store_computer_log(mob/user, turf/location, command)
// Newest logs first
computer_logs_.Insert(1, new/datum/computer_log(user, location, command))

/datum/computer_log
var/station_time
var/datum/mob_lite/user
var/turf/location
var/command

/datum/computer_log/New(mob/user, location, command)
station_time = time_stamp()
src.user = mob_repository.get_lite_mob(user)
src.location = location
src.command = command

location = get_turf(user)
35 changes: 35 additions & 0 deletions code/modules/admin/secrets/investigation/computer_logs.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/datum/admin_secret_item/investigation/computer_logs
name = "Computer Logs"
var/list/filters_per_client

/datum/admin_secret_item/investigation/computer_logs/New()
..()
filters_per_client = list()

/datum/admin_secret_item/investigation/computer_logs/execute(mob/user)
. = ..()
if(!.)
return
var/dat = list()
dat += "<a href='?src=\ref[src]'>Refresh</a>"
dat += "<HR>"
dat += "<table border='1' style='width:100%;border-collapse:collapse;'>"
dat += "<tr><th style='text-align:left;'>Time</th><th style='text-align:left;'>User</th><th style='text-align:left;'>Command</th></tr>"

for(var/log in computer_log_repository.computer_logs_)
var/datum/computer_log/al = log

dat += "<tr><td>[al.station_time]</td>"

if(al.user)
dat += "<td>[al.user.key_name(check_if_offline = FALSE)] <a HREF='?_src_=holder;adminplayeropts=[al.user.ref]'>PP</a></td>"

dat += "<td colspan=5>[al.command]"
if(al.location)
dat += " <a style='text-align:right;' HREF='?_src_=holder;adminplayerobservecoodjump=1;X=[al.location.x];Y=[al.location.y];Z=[al.location.z]'>JMP</a>"
dat += "</td></tr>"
dat += "</table>"

var/datum/browser/popup = new(user, "computer_attack_logs", "Computer Logs", 800, 400)
popup.set_content(jointext(dat, null))
popup.open()
2 changes: 2 additions & 0 deletions code/modules/modular_computers/terminal/terminal.dm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
var/input = sanitize(href_list["input"])
history += "> [input]"
var/output = parse(input, usr)
log_computer_command("[key_name(usr)]: [input]")
computer_log_repository.store_computer_log(usr, get_turf(computer.holder), input)
if(QDELETED(src)) // Check for exit.
return TOPIC_HANDLED
history += output
Expand Down
3 changes: 3 additions & 0 deletions config/example/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ LOG_ATTACK
## log admin warning messages
##LOG_ADMINWARN ## Also duplicates a bunch of other messages.

## log computer commands
# LOG_COMPUTER_COMMANDS

## Log all timers on timer auto reset
# LOG_TIMERS_ON_BUCKET_RESET

Expand Down

0 comments on commit 8b96ad9

Please sign in to comment.