diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm index b4a6f53a7561a5..2e9d2ee2714366 100644 --- a/code/__HELPERS/game.dm +++ b/code/__HELPERS/game.dm @@ -586,3 +586,28 @@ continue C.energy_fail(rand(duration_min,duration_max)) + +/** + * Sends a round tip to a target. If selected_tip is null, a random tip will be sent instead (5% chance of it being silly). + * Tips that starts with the @ character won't be html encoded. That's necessary for any tip containing markup tags, + * just make sure they don't also have html characters like <, > and ' which will be garbled. + */ +/proc/send_tip_of_the_round(target, selected_tip) + var/message + if(selected_tip) + message = selected_tip + else + var/list/randomtips = world.file2list("strings/tips.txt") + var/list/memetips = world.file2list("strings/sillytips.txt") + if(randomtips.len && prob(95)) + message = pick(randomtips) + else if(memetips.len) + message = pick(memetips) + + if(!message) + return + if(message[1] != "@") + message = html_encode(message) + else + message = copytext(message, 2) + to_chat(target, span_purple("Tip of the round: [message]")) diff --git a/code/controllers/subsystem/ticker.dm b/code/controllers/subsystem/ticker.dm index 5d3d05919b30dd..1240fca786dff4 100755 --- a/code/controllers/subsystem/ticker.dm +++ b/code/controllers/subsystem/ticker.dm @@ -171,7 +171,7 @@ SUBSYSTEM_DEF(ticker) timeLeft -= wait if(timeLeft <= 300 && !tipped) - send_tip_of_the_round() + send_tip_of_the_round(world, selected_tip) tipped = TRUE if(timeLeft <= 0) @@ -461,21 +461,6 @@ SUBSYSTEM_DEF(ticker) var/mob/living/L = I L.notransform = FALSE -/datum/controller/subsystem/ticker/proc/send_tip_of_the_round() - var/m - if(selected_tip) - m = selected_tip - else - var/list/randomtips = world.file2list("strings/tips.txt") - var/list/memetips = world.file2list("strings/sillytips.txt") - if(randomtips.len && prob(95)) - m = pick(randomtips) - else if(memetips.len) - m = pick(memetips) - - if(m) - to_chat(world, span_purple("Tip of the round: [html_encode(m)]")) - /datum/controller/subsystem/ticker/proc/check_queue() if(!queued_players.len) return diff --git a/code/game/say.dm b/code/game/say.dm index 8933e7d44a138c..22504bdc7a0244 100644 --- a/code/game/say.dm +++ b/code/game/say.dm @@ -99,9 +99,9 @@ GLOBAL_LIST_INIT(freqtospan, list( var/spanned = attach_spans(input, spans) return "[say_mod(input, message_mods)], \"[spanned]\"" -/// Transforms the speech emphasis mods from [/atom/movable/proc/say_emphasis] into the appropriate HTML tags +/// Transforms the speech emphasis mods from [/atom/movable/proc/say_emphasis] into the appropriate HTML tags. Includes escaping. #define ENCODE_HTML_EMPHASIS(input, char, html, varname) \ - var/static/regex/##varname = regex("[char](.+?)[char]", "g");\ + var/static/regex/##varname = regex("(?$1") /// Scans the input sentence for speech emphasis modifiers, notably |italics|, +bold+, and _underline_ -mothblocks @@ -109,6 +109,8 @@ GLOBAL_LIST_INIT(freqtospan, list( ENCODE_HTML_EMPHASIS(input, "\\|", "i", italics) ENCODE_HTML_EMPHASIS(input, "\\+", "b", bold) ENCODE_HTML_EMPHASIS(input, "_", "u", underline) + var/static/regex/remove_escape_backlashes = regex("\\\\(_|\\+|\\|)", "g") // Removes backslashes used to escape text modification. + input = remove_escape_backlashes.Replace_char(input, "$1") return input #undef ENCODE_HTML_EMPHASIS diff --git a/code/modules/admin/verbs/admin.dm b/code/modules/admin/verbs/admin.dm index 3338559d7cbe6d..6a7d45f6f18380 100644 --- a/code/modules/admin/verbs/admin.dm +++ b/code/modules/admin/verbs/admin.dm @@ -16,11 +16,11 @@ if(!SSticker) return - SSticker.selected_tip = input - // If we've already tipped, then send it straight away. if(SSticker.tipped) - SSticker.send_tip_of_the_round() + send_tip_of_the_round(world, input) + else + SSticker.selected_tip = input message_admins("[key_name_admin(usr)] sent a tip of the round.") log_admin("[key_name(usr)] sent \"[input]\" as the Tip of the Round.") diff --git a/code/modules/reagents/chemistry/reagents/medicine_reagents.dm b/code/modules/reagents/chemistry/reagents/medicine_reagents.dm index 4dd9f14cb5517c..f5426ac4889253 100644 --- a/code/modules/reagents/chemistry/reagents/medicine_reagents.dm +++ b/code/modules/reagents/chemistry/reagents/medicine_reagents.dm @@ -890,7 +890,7 @@ . = ..() /datum/reagent/medicine/mannitol/overdose_start(mob/living/owner) - to_chat(owner, span_notice("You suddenly feel E N L I G H T E N E D!")) + to_chat(owner, span_notice("You suddenly feel E N L I G H T E N E D!")) /datum/reagent/medicine/mannitol/overdose_process(mob/living/owner, delta_time, times_fired) if(DT_PROB(65, delta_time)) @@ -903,8 +903,8 @@ else tips = world.file2list("strings/chemistrytips.txt") var/message = pick(tips) - to_chat(owner, span_purple("Tip of the round: [html_encode(message)]")) - ..() + send_tip_of_the_round(owner, message) + return ..() /datum/reagent/medicine/neurine name = "Neurine" diff --git a/strings/tips.txt b/strings/tips.txt index 557ac96e2eae28..3a4c045fdfe6e6 100644 --- a/strings/tips.txt +++ b/strings/tips.txt @@ -253,3 +253,5 @@ Standard epipens contain a potent coagulant that not only slow bloodloss, but al Anything you can light a cigarette with, you can use to cauterize a bleeding wound. Technically, that includes the supermatter. If you're bleeding, you can apply pressure to the limb by grabbing yourself while targeting the bleeding limb. This will slow you down and take up a hand, but it'll slow down how fast you lose blood. Note this won't help the bleeding clot any faster. Laying down will help slow down bloodloss. Death will halt it entirely. +♪ Hey, have you ever tried appending the % character before your messages when speaking in-game? ♫ +@You can use the |, + and _ characters to emphasize parts of what you say in-game (e.g. say"my _ass_ |is| +heavy+." will be outputted as "my ass is heavy."). You can also escape these emphasizers by appending backslashes before them (e.g. say"1\+2\+3" will come out as "1+2+3" and not "1\2\3").