From cc14ed34a571692b8349b89f17d11d84bb82a7b7 Mon Sep 17 00:00:00 2001 From: Tastyfish Date: Wed, 23 Nov 2011 23:09:18 -0500 Subject: [PATCH] Merged best of tg's and bay12's paper code, and closed a possible exploit --- code/defines/global.dm | 1 + .../game/objects/items/weapons/papers_bins.dm | 201 ++++-------------- 2 files changed, 41 insertions(+), 161 deletions(-) diff --git a/code/defines/global.dm b/code/defines/global.dm index 33258062da6..2f1bccb2b2f 100644 --- a/code/defines/global.dm +++ b/code/defines/global.dm @@ -163,6 +163,7 @@ var //Don't set this very much higher then 1024 unless you like inviting people in to dos your server with message spam const/MAX_MESSAGE_LEN = 1024 + const/MAX_PAPER_MESSAGE_LEN = 3072 const/shuttle_time_in_station = 1800 // 3 minutes in the station const/shuttle_time_to_arrive = 6000 // 10 minutes to arrive diff --git a/code/game/objects/items/weapons/papers_bins.dm b/code/game/objects/items/weapons/papers_bins.dm index fe4e1d2486e..1cdca99ea36 100644 --- a/code/game/objects/items/weapons/papers_bins.dm +++ b/code/game/objects/items/weapons/papers_bins.dm @@ -14,7 +14,6 @@ CLIPBOARDS // PAPER /obj/item/weapon/paper/New() - ..() src.pixel_y = rand(-8, 8) src.pixel_x = rand(-9, 9) @@ -22,160 +21,35 @@ CLIPBOARDS src.overlays += "paper_words" return - /obj/item/weapon/paper/examine() set src in view() ..() if (!( istype(usr, /mob/living/carbon/human) || istype(usr, /mob/dead/observer) || istype(usr, /mob/living/silicon) )) - usr << browse(text("[][]", src.name, stars(src.info)), text("window=[]", src.name)) + // actually strip formatting, so stars doesn't screw up + var/t = dd_replacetext(src.info, "\n", "") + t = dd_replacetext(t, "\[b\]", "") + t = dd_replacetext(t, "\[/b\]", "") + t = dd_replacetext(t, "\[i\]", "") + t = dd_replacetext(t, "\[/i\]", "") + t = dd_replacetext(t, "\[u\]", "") + t = dd_replacetext(t, "\[/u\]", "") + usr << browse(text("[][]", src.name, stars(t)), text("window=[]", src.name)) onclose(usr, "[src.name]") else - usr << browse(text("[][]", src.name, src.info), text("window=[]", src.name)) + // if people want lazy bb-code + var/t = dd_replacetext(src.info, "\n", "
") + t = dd_replacetext(t, "\[b\]", "") + t = dd_replacetext(t, "\[/b\]", "") + t = dd_replacetext(t, "\[i\]", "") + t = dd_replacetext(t, "\[/i\]", "") + t = dd_replacetext(t, "\[u\]", "") + t = dd_replacetext(t, "\[/u\]", "") + t = text("[]", t) + usr << browse(text("[][]", src.name, t), text("window=[]", src.name)) onclose(usr, "[src.name]") return -/obj/item/weapon/pen/proc/formatText(var/s) - if (text_size < 2 || text_size > 7) - text_size = 3 - if (!(text_color)) - text_color = "#000000" - - var/textToAddHeader = "" - var/textToAddFooter = "" - - if (text_color && text_size) - textToAddHeader = "" - textToAddFooter = "" - - if (text_bold == 1) - textToAddHeader = "[textToAddHeader]" - textToAddFooter = "[textToAddFooter]" - - if (text_underline == 1) - textToAddHeader = "[textToAddHeader]" - textToAddFooter = "[textToAddFooter]" - - if (text_italic == 1) - textToAddHeader = "[textToAddHeader]" - textToAddFooter = "[textToAddFooter]" - - if (text_break == 1) - textToAddFooter = "[textToAddFooter]
" - - var/r = "[textToAddHeader][s][textToAddFooter]" - return r - -/obj/item/weapon/pen/attack_self(mob/user as mob) - var/dat - - dat = text("How would you like to write?
") - - dat = text("[formatText("example")]
") - - dat += text("size:
") - dat += text("2 ") - dat += text("3 ") - dat += text("4 ") - dat += text("5 ") - dat += text("6 ") - dat += text("7

") - - dat += text("Color:
") - dat += text("black: ") - dat += text("1 ") - dat += text("2 ") - dat += text("3 ") - dat += text("4 ") - dat += text("5 ") - dat += text("6
") - - dat += text("Red: ") - dat += text("1 ") - dat += text("2 ") - dat += text("3 ") - dat += text("4 ") - dat += text("5 ") - dat += text("6
") - - dat += text("Yellow: ") - dat += text("1 ") - dat += text("2 ") - dat += text("3 ") - dat += text("4 ") - dat += text("5 ") - dat += text("6
") - - dat += text("Green: ") - dat += text("1 ") - dat += text("2 ") - dat += text("3 ") - dat += text("4 ") - dat += text("5 ") - dat += text("6
") - - dat += text("Cyan: ") - dat += text("1 ") - dat += text("2 ") - dat += text("3 ") - dat += text("4 ") - dat += text("5 ") - dat += text("6
") - - dat += text("Blue: ") - dat += text("1 ") - dat += text("2 ") - dat += text("3 ") - dat += text("4 ") - dat += text("5 ") - dat += text("6
") - - dat += text("Purple: ") - dat += text("1 ") - dat += text("2 ") - dat += text("3 ") - dat += text("4 ") - dat += text("5 ") - dat += text("6

") - - if (text_bold) - dat += text("Bold: yes / no
") - else - dat += text("Bold: yes / no
") - - if (text_italic) - dat += text("Italic: yes / no
") - else - dat += text("Italic: yes / no
") - - if (text_underline) - dat += text("Underline: yes / no
") - else - dat += text("Underline: yes / no
") - - if (text_break) - dat += text("Jump into a new line at the end? yes / no
") - else - dat += text("Jump into a new line at the end? yes / no
") - user << browse("[dat]", "window=pen") - -/obj/item/weapon/pen/Topic(href, href_list) - usr.machine = src - if(href_list["color"]) - src.text_color = "#" - src.text_color += href_list["color"] - if(href_list["size"]) - src.text_size = text2num(href_list["size"]) - if(href_list["bold"]) - src.text_bold = text2num(href_list["bold"]) - if(href_list["underline"]) - src.text_underline = text2num(href_list["underline"]) - if(href_list["italic"]) - src.text_italic = text2num(href_list["italic"]) - if(href_list["break"]) - src.text_break = text2num(href_list["break"]) - attack_self(usr) - return /obj/item/weapon/paper/verb/rename() set name = "Rename paper" @@ -217,30 +91,35 @@ CLIPBOARDS clown = 1 if (istype(P, /obj/item/weapon/pen)) - var/obj/item/weapon/pen/PEN = P + if(src.stamped != null && src.stamped.len > 0) + user << "\blue This paper has been stamped and can no longer be edited." + return + + var/t = "[src.info]" + do + t = input(user, "What text do you wish to add?", text("[]", src.name), t) as message + if ((!in_range(src, usr) && src.loc != user && !( istype(src.loc, /obj/item/weapon/clipboard) ) && src.loc.loc != user && user.equipped() != P)) + return + + if(lentext(t) >= MAX_PAPER_MESSAGE_LEN) + var/cont = input(user, "Your message is too long! Would you like to continue editing it?", "", "yes") in list("yes", "no") + if(cont == "no") + break + while(lentext(t) > MAX_PAPER_MESSAGE_LEN) - var/t = strip_html(input(user, "What text do you wish to add?", text("[]", src.name), null),8192) as message - t = text("[PEN.formatText(t)]") if ((!in_range(src, usr) && src.loc != user && !( istype(src.loc, /obj/item/weapon/clipboard) ) && src.loc.loc != user && user.equipped() != P)) return - /* - t = copytext(sanitize(t),1,MAX_MESSAGE_LEN) - t = dd_replacetext(t, "\n", "
") - t = dd_replacetext(t, "\[b\]", "") - t = dd_replacetext(t, "\[/b\]", "") - t = dd_replacetext(t, "\[i\]", "") - t = dd_replacetext(t, "\[/i\]", "") - t = dd_replacetext(t, "\[u\]", "") - t = dd_replacetext(t, "\[/u\]", "") - t = dd_replacetext(t, "\[sign\]", text("[]", user.real_name)) - */ - t = text("[]", t) + + // check for exploits + if(findtext(t, "