diff --git a/code/_helpers/client.dm b/code/_helpers/client.dm new file mode 100644 index 0000000000..08ad6b1086 --- /dev/null +++ b/code/_helpers/client.dm @@ -0,0 +1,51 @@ +/* + Helpers related to /client +*/ + + +/// Duck check to see if text looks like a ckey +/proc/valid_ckey(text) + var/static/regex/matcher = new (@"^[a-z0-9]{1,30}$") + return findtext(text, matcher) + + +/// Duck check to see if text looks like a key +/proc/valid_key(text) + var/static/regex/matcher = new (@"^[0-9A-Za-z][0-9A-Za-z_\. -]{2,29}$") + return findtext(text, matcher) + + +/// Get the client associated with ckey text if it is currently connected +/proc/ckey2client(text) + if (valid_ckey(text)) + for (var/client/C as anything in GLOB.clients) + if (C.ckey == text) + return C + + +/// Get the client associated with key text if it is currently connected +/proc/key2client(text) + if (valid_key(text)) + for (var/client/C as anything in GLOB.clients) + if (C.key == text) + return C + + +/// Null, or a client if thing is a client, a mob with a client, a connected ckey, or null +/proc/resolve_client(client/thing) + if (istype(thing)) + return thing + if (!thing) + thing = usr + if (ismob(thing)) + var/mob/M = thing + return M.client + return ckey2client(thing) + + +/// Null or a client from the list of connected clients, chosen by actor if actor is valid +/proc/select_client(client/actor, message = "Connected clients:", title = "Select Client") + actor = resolve_client(actor) + if (!actor) + return + return input(actor, message, title) as null | anything in GLOB.clients diff --git a/code/datums/browser.dm b/code/datums/browser.dm index 274d9132a6..56e09ebba4 100644 --- a/code/datums/browser.dm +++ b/code/datums/browser.dm @@ -148,12 +148,13 @@ // to pass a "close=1" parameter to the atom's Topic() proc for special handling. // Otherwise, the user mob's machine var will be reset directly. // -/proc/onclose(mob/user, windowid, var/atom/ref=null) - if(!user || !user.client) return +/proc/onclose(client/user, windowid, atom/ref) + user = resolve_client(user) + if (!user) + return var/param = "null" if(ref) param = "\ref[ref]" - winset(user, windowid, "on-close=\".windowclose [param]\"") //to_world("OnClose [user]: [windowid] : ["on-close=\".windowclose [param]\""]") diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index 57640ab07f..a927bc2ff1 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -1434,7 +1434,7 @@ var/obj/item/fax = locate(href_list["AdminFaxView"]) if (istype(fax, /obj/item/weapon/paper)) var/obj/item/weapon/paper/P = fax - P.show_content(usr,1) + P.show_content(usr, TRUE) else if (istype(fax, /obj/item/weapon/photo)) var/obj/item/weapon/photo/H = fax H.show(usr) @@ -1460,10 +1460,10 @@ if (istype(bundle.pages[page], /obj/item/weapon/paper)) var/obj/item/weapon/paper/P = bundle.pages[page] - P.show_content(src.owner, 1) + P.show_content(owner, TRUE) else if (istype(bundle.pages[page], /obj/item/weapon/photo)) var/obj/item/weapon/photo/H = bundle.pages[page] - H.show(src.owner) + H.show(owner) return else if(href_list["FaxReply"]) diff --git a/code/modules/paperwork/paper.dm b/code/modules/paperwork/paper.dm index 2c11287635..c807356452 100644 --- a/code/modules/paperwork/paper.dm +++ b/code/modules/paperwork/paper.dm @@ -156,13 +156,28 @@ else . += "You have to go closer if you want to read it." -/obj/item/weapon/paper/proc/show_content(var/mob/user, var/forceshow=0) - if(!(istype(user, /mob/living/carbon/human) || istype(user, /mob/observer/dead) || istype(user, /mob/living/silicon) || user.universal_understand) && !forceshow) - user << browse("