55GLOBAL_REAL (Configuration, / datum / controller/ toml_configuration)
66
77// todo: /datum/controller/configuration
8+ // todo: needs stronger vv guarding; it still exposes list refs.
89/ datum / controller/ toml_configuration
910 // / Entries by type.
1011 VAR_PRIVATE / list / datum / toml_config_entry/ typed_entries
1112 // / Entries as same structure as the underlying toml/json
1213 VAR_PRIVATE / list / datum / toml_config_entry/ keyed_entries
1314
15+ // / TODO: database whitelist when this is stupid
16+ // / species id = list(ckeys)
17+ VAR_PRIVATE / list / species_whitelist
18+ // / TODO: database whitelist when this is stupid
19+ // / language id = list(ckeys)
20+ VAR_PRIVATE / list / language_whitelist
21+ // / TODO: database whitelist when this is stupid
22+ // / role id = list(ckeys)
23+ VAR_PRIVATE / list / role_whitelist
24+
1425/ datum / controller/ toml_configuration/ CanProcCall(procname)
1526 switch (procname)
1627 if (NAMEOF_PROC (src , New), NAMEOF_PROC (src , Destroy), NAMEOF_PROC (src , Initialize))
@@ -19,7 +30,11 @@ GLOBAL_REAL(Configuration, /datum/controller/toml_configuration)
1930 return FALSE
2031 if (NAMEOF_PROC (src , get_sensitive_entry), NAMEOF_PROC (src , set_sensitive_entry))
2132 return FALSE
22- if (NAMEOF_PROC (src , reload), NAMEOF_PROC (src , reset), NAMEOF_PROC (src , load), NAMEOF_PROC (src , recursively_load_from_list))
33+ if (NAMEOF_PROC (src , reload))
34+ return FALSE
35+ if (NAMEOF_PROC (src , reset), NAMEOF_PROC (src , load), NAMEOF_PROC (src , load_impl))
36+ return FALSE
37+ if (NAMEOF_PROC (src , reset_whitelist), NAMEOF_PROC (src , load_whitelist), NAMEOF_PROC (src , load_whitelist_impl))
2338 return FALSE
2439 return .. ()
2540
@@ -120,6 +135,10 @@ GLOBAL_REAL(Configuration, /datum/controller/toml_configuration)
120135 load (" config.default/config.toml" )
121136 load (" config/config.toml" )
122137
138+ reset_whitelist ()
139+ load_whitelist (" config.default/whitelist.toml" )
140+ load_whitelist (" config/whitelist.toml" )
141+
123142/* *
124143 * Resets the configuration.
125144 */
@@ -150,9 +169,9 @@ GLOBAL_REAL(Configuration, /datum/controller/toml_configuration)
150169 if (! decoded)
151170 CRASH (" failed to decode config [ filelike] !" )
152171
153- recursively_load_from_list (decoded, keyed_entries)
172+ load_impl (decoded, keyed_entries)
154173
155- / datum / controller/ toml_configuration/ proc / recursively_load_from_list ( list / decoded_list, list / entry_list)
174+ / datum / controller/ toml_configuration/ proc / load_impl ( list / decoded_list, list / entry_list)
156175 if (! decoded_list || ! entry_list)
157176 return
158177 for (var /key in decoded_list)
@@ -162,10 +181,83 @@ GLOBAL_REAL(Configuration, /datum/controller/toml_configuration)
162181 if (! islist(next_entry_list))
163182 // todo: warn
164183 else
165- recursively_load_from_list (value, next_entry_list[key])
184+ load_impl (value, next_entry_list[key])
166185 else
167186 var /datum /toml_config_entry/entry = entry_list[key]
168187 if (! istype(entry))
169188 // todo: warn
170189 else
171190 entry. apply(value)
191+
192+ / datum / controller/ toml_configuration/ proc / reset_whitelist()
193+ role_whitelist = list ()
194+ species_whitelist = list ()
195+ language_whitelist = list ()
196+
197+ / datum / controller/ toml_configuration/ proc / load_whitelist(filelike)
198+ var /list /decoded
199+ if (istext(filelike))
200+ if (! fexists(filelike))
201+ CRASH (" failed to load [ filelike] : does not exist" )
202+ decoded = rustg_read_toml_file(filelike)
203+ else if (isfile(filelike))
204+ // noa path, it might be rsc cache; rust_g can't read that directly.
205+ fdel (" tmp/config/loading.toml" )
206+ fcopy (filelike, " tmp/config/loading.toml" )
207+ decoded = rustg_read_toml_file(" tmp/config/loading.toml" )
208+ fdel (" tmp/config/loading.toml" )
209+ if (! decoded)
210+ CRASH (" failed to decode config [ filelike] !" )
211+
212+ load_whitelist_impl (decoded)
213+
214+ / datum / controller/ toml_configuration/ proc / load_whitelist_impl( list / decoded_list)
215+ if (! decoded_list)
216+ return
217+
218+ var /list /role_whitelist = sanitize_islist(deep_copy_list(decoded_list[" whitelist" ]? [" role" ]))
219+ var /list /language_whitelist = sanitize_islist(deep_copy_list(decoded_list[" whitelist" ]? [" language" ]))
220+ var /list /species_whitelist = sanitize_islist(deep_copy_list(decoded_list[" whitelist" ]? [" species" ]))
221+
222+ // fixup: make everything ckeys
223+ for (var /list /root_list as anything in list (
224+ role_whitelist,
225+ language_whitelist,
226+ species_whitelist,
227+ ))
228+ for (var /i in 1 to length (root_list))
229+ var /id = root_list[i]
230+ var /list /ckey_list = root_list[id]
231+ for (var /j in 1 to length (ckey_list))
232+ ckey_list[j] = ckey(ckey_list[j])
233+
234+ src . role_whitelist = merge_2_nested_list(src . role_whitelist, role_whitelist)
235+ src . language_whitelist = merge_2_nested_list(src . language_whitelist, language_whitelist)
236+ src . species_whitelist = merge_2_nested_list(src . species_whitelist, species_whitelist)
237+
238+ / datum / controller/ toml_configuration/ proc / check_species_whitelist(id, ckey)
239+ return ckey(ckey) in species_whitelist[id]
240+
241+ / datum / controller/ toml_configuration/ proc / check_role_whitelist(id, ckey)
242+ return ckey(ckey) in role_whitelist[id]
243+
244+ / datum / controller/ toml_configuration/ proc / check_language_whitelist(id, ckey)
245+ return ckey(ckey) in language_whitelist[id]
246+
247+ / datum / controller/ toml_configuration/ proc / get_all_species_whitelists_for_ckey(ckey)
248+ . = list ()
249+ for (var /id in species_whitelist)
250+ if (ckey in species_whitelist[id])
251+ . += id
252+
253+ / datum / controller/ toml_configuration/ proc / get_all_role_whitelists_for_ckey(ckey)
254+ . = list ()
255+ for (var /id in role_whitelist)
256+ if (ckey in role_whitelist[id])
257+ . += id
258+
259+ / datum / controller/ toml_configuration/ proc / get_all_language_whitelists_for_ckey(ckey)
260+ . = list ()
261+ for (var /id in language_whitelist)
262+ if (ckey in language_whitelist[id])
263+ . += id
0 commit comments