Skip to content

Commit

Permalink
"Get Server Logs" can now jump to a specific round ID (#3501)
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy authored Sep 22, 2024
1 parent 47c6798 commit 93d40fb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 13 deletions.
47 changes: 35 additions & 12 deletions monkestation/code/__HELPERS/files.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var/regex/whitelist_regex
if(whitelist)
// try not to look at it too hard. yes i wrote this by hand.
whitelist_regex = new("(?:\[\\/\\\\\]$|(?:^|\\\\|\\/)(?:[regex_quote_list(whitelist)])\\.(?:[regex_quote_list(valid_extensions)])$)", "i")
whitelist_regex = new("(?:\[\\/\\\\\]$|(?:^|\\\\|\\/)(?:[regex_quote_list(whitelist)]|(?:profiler|sendmaps)-\[0-9\]+)\\.(?:[regex_quote_list(valid_extensions)])$)", "i")

// wow why was this ever a parameter
var/root = "data/logs/"
Expand All @@ -15,19 +15,18 @@
var/path = root

for(var/i in 1 to max_iterations)
var/list/choices
var/list/choices = flist(path)
if(whitelist_regex)
choices = list()
for(var/listed_path in flist(path))
if(whitelist_regex.Find(listed_path))
choices += listed_path
else
choices = flist(path)
for(var/listed_path in choices)
if(!whitelist_regex.Find(listed_path))
choices -= listed_path
choices = sort_list(choices)
if(path != root)
choices.Insert(1, "/")
choices = sort_list(choices)
if(allow_folder)
choices += "Download Folder"
choices.Insert(1, "Download Folder")
if(root_type == BROWSE_ROOT_ALL_LOGS && SSdbcore.IsConnected())
choices.Insert(1, "Choose Round ID")

var/choice = tgui_input_list(src, "Choose a file to access", "Download", choices)
if(!choice)
Expand All @@ -36,11 +35,35 @@
if("/")
path = root
continue
if("Choose Round ID")
var/current_round_id = text2num(GLOB.round_id)
var/target_round = tgui_input_number(
src,
message = "Choose which round ID you wish to go to",
title = "Download",
default = current_round_id,
max_value = current_round_id,
min_value = 1
)
if(!target_round)
to_chat(src, span_warning("No round ID chosen."), type = MESSAGE_TYPE_DEBUG, confidential = TRUE)
return
var/round_folder = get_log_directory_by_round_id(target_round)
if(!round_folder)
to_chat(src, span_warning("Could not find log directory for round [target_round]!"), type = MESSAGE_TYPE_DEBUG, confidential = TRUE)
return
path = "[round_folder]/"
continue
if("Download Folder")
if(!allow_folder)
return
var/list/comp_flist = flist(path)
var/confirmation = input(src, "Are you SURE you want to download all the files in this folder? (This will open [length(comp_flist)] prompt[length(comp_flist) == 1 ? "" : "s"])", "Confirmation") in list("Yes", "No")
var/confirmation = tgui_input_list(
user = src,
message = "Are you SURE you want to download all the files in this folder? (This will open [length(comp_flist)] prompt[length(comp_flist) == 1 ? "" : "s"])",
title = "Confirmation",
items = list("Yes", "No")
)
if(confirmation != "Yes")
continue
for(var/file in comp_flist)
Expand All @@ -50,7 +73,7 @@

if(copytext_char(path, -1) != "/") //didn't choose a directory, no need to iterate again
break
if(!fexists(path) || !valid_ext_regex.Find(path))
if(!rustg_file_exists(path) || !valid_ext_regex.Find(path))
to_chat(src, "<font color='red'>Error: browse_files(): File not found/Invalid file([path]).</font>")
return

Expand Down
24 changes: 23 additions & 1 deletion monkestation/code/game/world.dm
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,33 @@
if(!GLOB.round_id || !SSdbcore.IsConnected())
return
var/datum/db_query/set_log_directory = SSdbcore.NewQuery({"
UPDATE `[format_table_name("round")]`
UPDATE [format_table_name("round")]
SET
`log_directory` = :log_directory
WHERE
`id` = :round_id
"}, list("log_directory" = GLOB.log_directory, "round_id" = GLOB.round_id))
set_log_directory.Execute()
QDEL_NULL(set_log_directory)

/proc/get_log_directory_by_round_id(round_id)
if(!isnum(round_id) || round_id <= 0 || !SSdbcore.IsConnected())
return
var/datum/db_query/query_log_directory = SSdbcore.NewQuery({"
SELECT `log_directory`
FROM
[format_table_name("round")]
WHERE
`id` = :round_id
"}, list("round_id" = round_id))
if(!query_log_directory.warn_execute())
qdel(query_log_directory)
return
if(!query_log_directory.NextRow())
qdel(query_log_directory)
CRASH("Failed to get log directory for round [round_id]")
var/log_directory = query_log_directory.item[1]
QDEL_NULL(query_log_directory)
if(!rustg_file_exists(log_directory))
CRASH("Log directory '[log_directory]' for round ID [round_id] doesn't exist!")
return log_directory

0 comments on commit 93d40fb

Please sign in to comment.