mirror of
https://github.com/PolarisSS13/Polaris.git
synced 2026-08-29 16:18:35 +01:00
adds client helpers, fixes an oversight from 8451
This commit is contained in:
@@ -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
|
||||
@@ -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]\""]")
|
||||
|
||||
@@ -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"])
|
||||
|
||||
@@ -156,13 +156,28 @@
|
||||
else
|
||||
. += "<span class='notice'>You have to go closer if you want to read it.</span>"
|
||||
|
||||
/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("<HTML><HEAD><TITLE>[name]</TITLE></HEAD><BODY>[stars(info)][stamps]</BODY></HTML>", "window=[name]")
|
||||
onclose(user, "[name]")
|
||||
else
|
||||
user << browse("<HTML><HEAD><TITLE>[name]</TITLE></HEAD><BODY>[info][stamps]</BODY></HTML>", "window=[name]")
|
||||
onclose(user, "[name]")
|
||||
|
||||
/obj/item/weapon/paper/proc/show_content(mob/user, force_show)
|
||||
if (!user)
|
||||
return
|
||||
var/user_is_client = isclient(user)
|
||||
if (!user_is_client && !ismob(user))
|
||||
return
|
||||
var/understands = force_show
|
||||
if (!understands)
|
||||
if (user_is_client)
|
||||
understands = TRUE
|
||||
else if (user.universal_understand)
|
||||
understands = TRUE
|
||||
else if (isobserver(user))
|
||||
understands = TRUE
|
||||
else if (ishuman(user))
|
||||
understands = TRUE
|
||||
else if (issilicon(user))
|
||||
understands = TRUE
|
||||
user << browse("<HTML><HEAD><TITLE>[name]</TITLE></HEAD><BODY>[understands ? info : stars(info)][stamps]</BODY></HTML>", "window=[name]")
|
||||
onclose(user, "[name]")
|
||||
|
||||
|
||||
/obj/item/weapon/paper/verb/rename()
|
||||
set name = "Rename paper"
|
||||
|
||||
@@ -102,6 +102,7 @@
|
||||
#include "code\_helpers\_lists.dm"
|
||||
#include "code\_helpers\atmospherics.dm"
|
||||
#include "code\_helpers\atom_movables.dm"
|
||||
#include "code\_helpers\client.dm"
|
||||
#include "code\_helpers\events.dm"
|
||||
#include "code\_helpers\files.dm"
|
||||
#include "code\_helpers\game.dm"
|
||||
|
||||
Reference in New Issue
Block a user