diff --git a/code/__DEFINES/client.dm b/code/__DEFINES/client.dm index 0914bc025ad..17571b5270b 100644 --- a/code/__DEFINES/client.dm +++ b/code/__DEFINES/client.dm @@ -1,11 +1,6 @@ /// Checks if the given target is either a client or a mock client #define IS_CLIENT_OR_MOCK(target) (istype(target, /client) || istype(target, /datum/client_interface)) -/// Ensures that the client has been fully initialized via New(), and can't somehow execute actions before that. Security measure. -/// WILL RETURN OUT OF THE ENTIRE PROC COMPLETELY IF THE CLIENT IS NOT FULLY INITIALIZED. BE WARNED IF YOU WANT RETURN VALUES. -#define VALIDATE_CLIENT(target)\ - if (!target.fully_created) {\ - to_chat(target, span_warning("You are not fully initialized yet! Please wait a moment."));\ - log_access("Client [key_name(target)] attempted to execute a verb before being fully initialized.");\ - return\ - } +/// Checks to see if a /client has fully gone through New() as a safeguard against certain operations. +/// Should return the boolean value of the fully_created var, which should be TRUE if New() has finished running. FALSE otherwise. +#define VALIDATE_CLIENT_INITIALIZATION(target) (target.fully_created) diff --git a/code/__HELPERS/clients.dm b/code/__HELPERS/clients.dm index 3b61cf1e1c4..156f9e2b5dc 100644 --- a/code/__HELPERS/clients.dm +++ b/code/__HELPERS/clients.dm @@ -10,3 +10,9 @@ if (ch < 48 || ch > 57) //0-9 return FALSE return TRUE + +/// Proc that just logs whenever an uninitialized client tries to do something before they have fully gone through New(). +/// Intended to be used in conjunction with the `VALIDATE_CLIENT_INITIALIZATION()` macro, but can be dropped anywhere when we look at the `fully_created` var on /client. +/proc/unvalidated_client_error(client/target) + to_chat(target, span_warning("You are not fully initialized yet! Please wait a moment.")) + log_access("Client [key_name(target)] attempted to execute a verb before being fully initialized.") diff --git a/code/modules/client/verbs/ooc.dm b/code/modules/client/verbs/ooc.dm index 5df802b9f60..dc55b72b09d 100644 --- a/code/modules/client/verbs/ooc.dm +++ b/code/modules/client/verbs/ooc.dm @@ -10,12 +10,15 @@ GLOBAL_VAR_INIT(normal_ooc_colour, "#002eb8") to_chat(usr, span_danger("Speech is currently admin-disabled.")) return - if(!mob) + var/client_initalized = VALIDATE_CLIENT_INITIALIZATION(src) + if(isnull(mob) || !client_initalized) + if(!client_initalized) + unvalidated_client_error() // we only want to throw this warning message when it's directly related to client failure. + + to_chat(usr, span_warning("Failed to send your OOC message. You attempted to send the following message:\n[span_big(msg)]")) return - VALIDATE_CLIENT(src) - - if(!holder) + if(isnull(holder)) if(!GLOB.ooc_allowed) to_chat(src, span_danger("OOC is globally muted.")) return