From f0bf4efccaa59f88b56f74b4f5ee895628a4c995 Mon Sep 17 00:00:00 2001 From: Atermonera Date: Sun, 24 May 2020 14:23:14 -0700 Subject: [PATCH] Adds vchat export chatlog verb (#7214) --- code/modules/client/client procs.dm | 8 ++- code/modules/vchat/js/vchat.js | 7 +++ code/modules/vchat/vchat_client.dm | 58 ++++++++++++++++++- .../atermonera - vchat_exportlog.yml | 5 ++ 4 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 html/changelogs/atermonera - vchat_exportlog.yml diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index 1fae4dec3e..a97c449115 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -454,18 +454,20 @@ client/verb/character_setup() if(src.chatOutputLoadedAt > (world.time - 10 SECONDS)) alert(src, "You can only try to reload VChat every 10 seconds at most.") return - + + verbs -= /client/proc/vchat_export_log + //Log, disable log_debug("[key_name(src)] reloaded VChat.") winset(src, null, "outputwindow.htmloutput.is-visible=false;outputwindow.oldoutput.is-visible=false;outputwindow.chatloadlabel.is-visible=true") - + //The hard way qdel_null(src.chatOutput) chatOutput = new /datum/chatOutput(src) //veechat chatOutput.send_resources() spawn() chatOutput.start() - + //This is for getipintel.net. //You're welcome to replace this proc with your own that does your own cool stuff. diff --git a/code/modules/vchat/js/vchat.js b/code/modules/vchat/js/vchat.js index dab5cc330c..028d5b52bb 100644 --- a/code/modules/vchat/js/vchat.js +++ b/code/modules/vchat/js/vchat.js @@ -89,6 +89,7 @@ function start_vchat() { //Inform byond we're done vchat_state.ready = true; push_Topic('done_loading'); + push_Topic_showingnum(this.showingnum); //I'll do my own winsets doWinset("htmloutput", {"is-visible": true}); @@ -352,6 +353,7 @@ function start_vue() { } set_storage("showingnum",this.showingnum); + push_Topic_showingnum(this.showingnum); // Send the buffer length back to byond so we have it in case of reconnect this.attempt_archive(); }, current_categories: function(newSetting, oldSetting) { @@ -799,6 +801,11 @@ function push_Topic(topic_uri) { window.location = '?_src_=chat&proc=' + topic_uri; //Yes that's really how it works. } +// Send the showingnum back to byond +function push_Topic_showingnum(topic_num) { + window.location = '?_src_=chat&showingnum=' + topic_num; +} + //Tells byond client to focus the main map window. function focusMapWindow() { window.location = 'byond://winset?mapwindow.map.focus=true'; diff --git a/code/modules/vchat/vchat_client.dm b/code/modules/vchat/vchat_client.dm index 8456c5225f..881d3619c6 100644 --- a/code/modules/vchat/vchat_client.dm +++ b/code/modules/vchat/vchat_client.dm @@ -15,11 +15,15 @@ GLOBAL_LIST_INIT(vchatFiles, list( // First do logging in database if(isclient(target)) var/client/C = target - vchat_add_message(C.ckey,message) + vchat_add_message(C.ckey, message) else if(ismob(target)) var/mob/M = target if(M.ckey) - vchat_add_message(M.ckey,message) + vchat_add_message(M.ckey, message) + else if(target == world) + for(var/client/C in GLOB.clients) + if(!QDESTROYING(C)) // Might be necessary? + vchat_add_message(C.ckey, message) // Now lets either queue it for sending, or send it right now if(Master.current_runlevel == RUNLEVEL_INIT || !SSchat?.subsystem_initialized) @@ -37,6 +41,7 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic var/list/message_queue = list() var/broken = FALSE var/resources_sent = FALSE + var/message_buffer = 200 // Number of messages being actively shown to the user, used to play back that many messages on reconnect var/last_topic_time = 0 var/too_many_topics = 0 @@ -128,11 +133,14 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic send_playerinfo() load_database() + owner.verbs += /client/proc/vchat_export_log + //Perform DB shenanigans /datum/chatOutput/proc/load_database() set waitfor = FALSE var/list/results = vchat_get_messages(owner.ckey) //If there's bad performance on reconnects, look no further - for(var/list/message in results) + for(var/i in max(1, results.len - message_buffer)) // Only send them the number of buffered messages, instead of the ENTIRE log + var/list/message = results[i] var/count = 10 to_chat_immediate(owner, message["time"], message["message"]) count++ @@ -233,6 +241,9 @@ GLOBAL_DATUM_INIT(iconCache, /savefile, new("data/iconCache.sav")) //Cache of ic if("debug") data = debugmsg(arglist(params)) + if(href_list["showingnum"]) + message_buffer = CLAMP(text2num(href_list["showingnum"]), 50, 2000) + if(data) send_event(event = data) @@ -368,3 +379,44 @@ var/to_chat_src var/list/tojson = list("time" = time, "message" = message); target << output(jsEncode(tojson), "htmloutput:putmessage") + +/client/proc/vchat_export_log() + set name = "Export chatlog" + set category = "OOC" + + if(chatOutput.broken) + to_chat(src, "Error: VChat isn't processing your messages!") + return + + var/list/results = vchat_get_messages(ckey) + if(!LAZYLEN(results)) + to_chat(src, "Error: No messages found! Please inform a dev if you do have messages!") + return + + var/o_file = "data/chatlog_tmp/[ckey]_chat_log" + if(fexists(o_file) && !fdel(o_file)) + to_chat(src, "Error: Your chat log is already being prepared. Please wait until it's been downloaded before trying to export it again.") + return + + o_file = file(o_file) + + // Write the CSS file to the log + o_file << "" + + // Write the messages to the log + for(var/list/result in results) + o_file << "[result["message"]]
" + + o_file << "" + + // Send the log to the client + src << ftp(o_file, "log_[time2text(world.timeofday, "YYYY_MM_DD_(hh_mm)")].html") + + // clean up the file on our end + spawn(10 SECONDS) + if(!fdel(o_file)) + spawn(1 MINUTE) + if(!fdel(o_file)) + log_debug("Warning: [ckey]'s chatlog could not be deleted one minute after file transfer was initiated. It is located at 'data/chatlog_tmp/[ckey]_chat_log' and will need to be manually removed.") \ No newline at end of file diff --git a/html/changelogs/atermonera - vchat_exportlog.yml b/html/changelogs/atermonera - vchat_exportlog.yml new file mode 100644 index 0000000000..a2915951a2 --- /dev/null +++ b/html/changelogs/atermonera - vchat_exportlog.yml @@ -0,0 +1,5 @@ +author: Atermonera +delete-after: True +changes: + - rscadd: "Added verb to export vchat logs, found in OOC tab when vchat has successfully loaded." + - tweak: "Vchat only sends you enough messages to fill your buffer on reconnect, instead of all of them."