world/Topic Refactor (#14850)

* world/Topic Refactor

* These arent needed anymore

* How could I forget this

* Biggest edit ever

* Forgot this

* Mini refactor
This commit is contained in:
AffectedArc07
2020-12-09 11:24:33 -05:00
committed by GitHub
parent c5d66be971
commit d6af52dd2b
14 changed files with 316 additions and 240 deletions
+36
View File
@@ -0,0 +1,36 @@
/datum/world_topic_handler
/// Key which invokes this topic
var/topic_key
/// Set this to TRUE if the topic handler needs an authorised comms key
var/requires_commskey = FALSE
/**
* Invokes the world/Topic handler
*
* This includes sanity checking for if the key is required, as well as other sanity checks
* DO NOT OVERRIDE
* Arguments:
* * input - The list of topic data, sent from [world/Topic]
*/
/datum/world_topic_handler/proc/invoke(list/input)
SHOULD_NOT_OVERRIDE(TRUE)
var/authorised = (config.comms_password && input["key"] == config.comms_password) // No password means no comms, not any password
if(requires_commskey && !authorised)
// Try keep all returns in JSON unless absolutely necessary (?ping for example)
return(json_encode(list("error" = "Invalid Key")))
return execute(input, authorised)
/**
* Actually executes the user's topic
*
* Override this to do your work in subtypes of this topic
*
* Arguments:
* * input - The list of topic data, sent from [world/Topic]
* * key_valid - Has the user entered the correct auth key
*/
/datum/world_topic_handler/proc/execute(list/input, key_valid = FALSE)
PRIVATE_PROC(TRUE) // Ensures no one can call this arbitrarily without checking key auth
CRASH("execute() not implemented/overridden for [type]")