mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-27 15:17:01 +01:00
improve code for privacy policy by runtime loading (#5332)
## About The Pull Request changes privacy policy code to load at player connection, rather than store a list in memory ## Why It's Good For The Game We don't need to slow down server startup or use memory holding this data that persists between rounds, that is what SQL's best at ## Proof Of Testing <details> <summary>Screenshots/Videos</summary> </details> ## Changelog 🆑 code: privacy policy loads on connection rather than server load /🆑
This commit is contained in:
@@ -2,43 +2,30 @@ SUBSYSTEM_DEF(privacy)
|
||||
name = "Privacy Policy"
|
||||
flags = SS_NO_FIRE
|
||||
|
||||
VAR_PRIVATE/list/completed_by_ckey = list()
|
||||
|
||||
/datum/controller/subsystem/privacy/Initialize()
|
||||
if(!CONFIG_GET(flag/sql_enabled))
|
||||
return
|
||||
load_initial_acceptances()
|
||||
return SS_INIT_SUCCESS
|
||||
|
||||
/datum/controller/subsystem/privacy/proc/load_initial_acceptances()
|
||||
/datum/controller/subsystem/privacy/proc/has_accepted(ckey, policy_key)
|
||||
if(!SSdbcore.IsConnected())
|
||||
return
|
||||
|
||||
var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, policy_key FROM [format_table_name("privacy_policy_acceptances")]")
|
||||
|
||||
if(!query.Execute())
|
||||
var/datum/db_query/query = SSdbcore.NewQuery("SELECT ckey, policy_key FROM [format_table_name("privacy_policy_acceptances")] WHERE ckey = :ckey AND policy_key = :policy_key",
|
||||
list(
|
||||
"ckey" = ckey,
|
||||
"policy_key" = policy_key)
|
||||
)
|
||||
if(!query.warn_execute())
|
||||
qdel(query)
|
||||
return
|
||||
|
||||
while(query.NextRow())
|
||||
var/ckey = query.item[1]
|
||||
var/policy_key = query.item[2]
|
||||
|
||||
completed_by_ckey[ckey] ||= list()
|
||||
completed_by_ckey[ckey] += policy_key
|
||||
|
||||
return FALSE
|
||||
qdel(query)
|
||||
|
||||
/datum/controller/subsystem/privacy/proc/has_accepted(ckey, policy_key)
|
||||
return completed_by_ckey[ckey] && (policy_key in completed_by_ckey[ckey])
|
||||
return TRUE
|
||||
|
||||
/datum/controller/subsystem/privacy/proc/mark_accepted(ckey, policy_key)
|
||||
if(has_accepted(ckey, policy_key))
|
||||
. = has_accepted(ckey, policy_key)
|
||||
if(.)
|
||||
return
|
||||
|
||||
completed_by_ckey[ckey] ||= list()
|
||||
completed_by_ckey[ckey] += policy_key
|
||||
|
||||
var/datum/db_query/query = SSdbcore.NewQuery(
|
||||
"INSERT IGNORE INTO [format_table_name("privacy_policy_acceptances")] (ckey, policy_key) VALUES (:ckey, :policy_key)",
|
||||
list(
|
||||
@@ -47,5 +34,6 @@ SUBSYSTEM_DEF(privacy)
|
||||
)
|
||||
)
|
||||
|
||||
query.Execute()
|
||||
query.warn_execute()
|
||||
qdel(query)
|
||||
return .
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
return GLOB.always_state
|
||||
|
||||
/datum/privacy_policy_ui/ui_close(mob/user)
|
||||
if(!SSprivacy.has_accepted(owner.ckey, CURRENT_PRIVACY_KEY))
|
||||
if(owner)
|
||||
to_chat(owner, span_danger("You must accept the Privacy Policy to continue playing."))
|
||||
New(owner)
|
||||
// we spawned async and this has already been checked if we reached this point, we don't need further checks
|
||||
if(owner)
|
||||
to_chat(owner, span_danger("You must accept the Privacy Policy to continue playing."))
|
||||
new type(owner.mob)
|
||||
qdel(src)
|
||||
|
||||
/datum/privacy_policy_ui/ui_data(mob/user)
|
||||
|
||||
Reference in New Issue
Block a user