Skip to content

Commit 93501b2

Browse files
siliconsZandario
andauthored
refactors whitelist to toml config (#7182)
Co-authored-by: Zandario <zandarioh@gmail.com>
1 parent 7e8cd3f commit 93501b2

File tree

22 files changed

+172
-172
lines changed

22 files changed

+172
-172
lines changed

citadel.dme

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,6 @@
543543
#include "code\controllers\verbs.dm"
544544
#include "code\controllers\configuration\config_entry.dm"
545545
#include "code\controllers\configuration\configuration.dm"
546-
#include "code\controllers\configuration\whitelists.dm"
547546
#include "code\controllers\configuration\entries\admin.dm"
548547
#include "code\controllers\configuration\entries\chat_bridge.dm"
549548
#include "code\controllers\configuration\entries\cross_server.dm"

code/__DEFINES/controllers/_repository.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ GLOBAL_REAL(RS##what, /datum/controller/repository/##what); \
3131
RS##what.Initialize(); \
3232
} \
3333
/datum/controller/subsystem/repository/__get_all_repositories() { \
34-
. = ..(); \
34+
. = ..() || list(); \
3535
. += RS##what; \
3636
} \
3737
/datum/controller/repository/##what

code/__DEFINES/species/species.dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#define SPECIES_ID_SCORI "scori"
4141
#define SPECIES_ID_SERGLING "sergling"
4242
#define SPECIES_ID_SHADEKIN "shadekin"
43-
#define SPECIES_ID_SHADEKIN_BLACK "blackeyedshadekin"
43+
#define SPECIES_ID_SHADEKIN_BLACK "shadekin_blackeyed"
4444
#define SPECIES_ID_SHADOW "shadow"
4545
#define SPECIES_ID_SKELETON "skeleton"
4646
#define SPECIES_ID_SKRELL "skrell"

code/__DEFINES/species/species_flags.dm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ DEFINE_BITFIELD(species_fluff_flags, list(
7575
/// Species is selectable and visible in chargen. This must be on a species to be roundstart/latejoin.
7676
#define SPECIES_SPAWN_CHARACTER (1<<1)
7777
/// Must be whitelisted to play roundstart/latejoin.
78+
/// TODO: get rid of this, rework whitelist system to config
7879
#define SPECIES_SPAWN_WHITELISTED (1<<2)
7980
/// Must be whitelisted to see this species at all.
8081
#define SPECIES_SPAWN_SECRET (1<<3)
8182
/// Cannot normally spawn; something must pass in PREFS_COPY_TO_NO_CHECK_SPECIES to spawn checks to use!
8283
#define SPECIES_SPAWN_RESTRICTED (1<<4)
8384
/// if set, check species.id in WL, otherwise use uid
85+
/// TODO: get rid of this, rework whitelist system to config
8486
#define SPECIES_SPAWN_WHITELIST_FLEXIBLE (1<<5)
8587
//? FLAGS ABOVE ARE RELEVANT TO UI.
8688
//? If you change them, change necessary TGUI too.

code/__HELPERS/lists/merge.dm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* if a key isn't a list, it'll be turned into a list when two keys exist
1313
*
1414
* originally made for dynamic tool functions
15+
*
16+
* TODO: better name
1517
*/
1618
/proc/merge_double_lazy_assoc_list(list/A, list/B)
1719
. = A.Copy()
@@ -25,3 +27,23 @@
2527
.[key] = list(.[key], B[key])
2628
else
2729
.[key] = B[key]
30+
31+
/**
32+
* merges two 2-deep lists, ergo list(key = list(values))
33+
* dedupes values
34+
*
35+
* ## Input
36+
*
37+
* list("A" = list("a", "b", "c"))
38+
* list("A" = list("d"))
39+
*
40+
* ## Output
41+
*
42+
* list("A" = list("a", "b", "c", "d"))
43+
*/
44+
/proc/merge_2_nested_list(list/A, list/B)
45+
. = list()
46+
for(var/k1 in A)
47+
.[k1] = A[k1].Copy()
48+
for(var/k2 in B)
49+
.[k2] += B[k2]

code/controllers/configuration/configuration.dm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
for(var/J in legacy_configs)
4040
LoadEntries(J)
4141
break
42-
// loadmaplist(CONFIG_MAPS_FILE)
43-
LoadWhitelists()
4442
LoadMOTD()
4543

4644
loaded = TRUE

code/controllers/configuration/whitelists.dm

Lines changed: 0 additions & 97 deletions
This file was deleted.

code/controllers/toml_config/toml_configuration.dm

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,23 @@
55
GLOBAL_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

code/game/world.dm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ GLOBAL_LIST(topic_status_cache)
121121
#ifdef UNIT_TESTS
122122
HandleTestRun()
123123
#endif
124-
125124
if(config_legacy.ToRban)
126125
addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(ToRban_autoupdate)), 5 MINUTES)
127126

code/modules/jobs/job.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
*/
116116
/datum/role/job/proc/check_client_availability(client/C, check_char, latejoin)
117117
. = NONE
118-
if(whitelist_only && !config.check_job_whitelist(ckey(title), C.ckey))
118+
if(whitelist_only && !Configuration.check_role_whitelist(id, C.ckey))
119119
. |= ROLE_UNAVAILABLE_WHITELIST
120120
if(!slots_remaining())
121121
. |= ROLE_UNAVAILABLE_SLOTS_FULL
@@ -146,7 +146,7 @@
146146
*/
147147
/datum/role/job/proc/check_client_availability_one(client/C, check_char, latejoin)
148148
. = NONE
149-
if(whitelist_only && !config.check_job_whitelist(ckey(title), C.ckey))
149+
if(whitelist_only && !Configuration.check_role_whitelist(id, C.ckey))
150150
return ROLE_UNAVAILABLE_WHITELIST
151151
else if(latejoin && !slots_remaining(TRUE))
152152
return ROLE_UNAVAILABLE_SLOTS_FULL

0 commit comments

Comments
 (0)