Skip to content

Commit

Permalink
Expanding the existing whitelist config to support several levels of …
Browse files Browse the repository at this point in the history
…severity.
  • Loading branch information
MistakeNot4892 committed Sep 26, 2024
1 parent 8a5ff01 commit 256da1c
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 71 deletions.
13 changes: 11 additions & 2 deletions code/__defines/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,20 @@
#define PROJECTILE_CONTINUE -1 //if the projectile should continue flying after calling bullet_act()
#define PROJECTILE_FORCE_MISS -2 //if the projectile should treat the attack as a miss (suppresses attack and admin logs) - only applies to mobs.

//objectives
// Objective cofig enum values.
#define CONFIG_OBJECTIVE_NONE 2
#define CONFIG_OBJECTIVE_VERB 1
#define CONFIG_OBJECTIVE_ALL 0

// Server whitelist config enums.
#define CONFIG_SERVER_NO_WHITELIST 1
#define CONFIG_SERVER_JOBS_WHITELIST 2
#define CONFIG_SERVER_JOIN_WHITELIST 3
#define CONFIG_SERVER_CONNECT_WHITELIST 4

// Location for server whitelist file to load from.
#define CONFIG_SERVER_WHITELIST_FILE "config/server_whitelist.txt"

// How many times an AI tries to connect to APC before switching to low power mode.
#define AI_POWER_RESTORE_MAX_ATTEMPTS 3

Expand Down Expand Up @@ -365,4 +374,4 @@

#define RADIAL_LABELS_NONE 0
#define RADIAL_LABELS_OFFSET 1
#define RADIAL_LABELS_CENTERED 2
#define RADIAL_LABELS_CENTERED 2
2 changes: 2 additions & 0 deletions code/controllers/subsystems/jobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ SUBSYSTEM_DEF(jobs)
//Get the players who are ready
for(var/mob/new_player/player in global.player_list)
if(player.ready && player.mind && !player.mind.assigned_role)
if(get_config_value(/decl/config/enum/server_whitelist) == CONFIG_SERVER_JOIN_WHITELIST && !check_server_whitelist(player))
continue
unassigned_roundstart += player
if(unassigned_roundstart.len == 0) return 0
//Shuffle players and jobs
Expand Down
22 changes: 13 additions & 9 deletions code/datums/config/config_types/config_server.dm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
/decl/config/toggle/on/allow_ai,
/decl/config/toggle/on/allow_drone_spawn,
/decl/config/toggle/hub_visibility,
/decl/config/toggle/usewhitelist,
/decl/config/toggle/load_jobs_from_txt,
/decl/config/toggle/disable_player_mice,
/decl/config/toggle/uneducated_mice,
Expand All @@ -61,7 +60,8 @@
/decl/config/toggle/guests_allowed,
/decl/config/toggle/on/jobs_have_minimal_access,
/decl/config/toggle/on/admin_legacy_system,
/decl/config/toggle/on/ban_legacy_system
/decl/config/toggle/on/ban_legacy_system,
/decl/config/enum/server_whitelist
)

/decl/config/num/kick_inactive
Expand Down Expand Up @@ -293,13 +293,6 @@
. = ..()
world.update_hub_visibility()

/decl/config/toggle/usewhitelist
uid = "usewhitelist"
desc = list(
"Set to jobban everyone who's key is not listed in data/whitelist.txt from Captain, HoS, HoP, CE, RD, CMO, Warden, Security, Detective, and AI positions.",
"Uncomment to 1 to jobban, leave commented out to allow these positions for everyone (but see GUEST_JOBBAN above and regular jobbans)."
)

/decl/config/toggle/load_jobs_from_txt
uid = "load_jobs_from_txt"
desc = "Toggle for having jobs load up from the .txt"
Expand Down Expand Up @@ -369,3 +362,14 @@
/decl/config/toggle/on/jobs_have_minimal_access
uid = "jobs_have_minimal_access"
desc = "Add a # here if you wish to use the setup where jobs have more access. This is intended for servers with low populations - where there are not enough players to fill all roles, so players need to do more than just one job. Also for servers where they don't want people to hide in their own departments."

/decl/config/enum/server_whitelist
uid = "server_whitelist"
desc = "Determines how the server should handle whitelisting for ckeys. Whitelisted ckeys are found in '" + CONFIG_SERVER_WHITELIST_FILE + "'. Set to 'none' for no whitelisting, 'jobs' to whitelist sensitive jobs, 'join' to whitelist joining the round (observing and OOC are still available, or 'connect' to whitelist access to the server."
default_value = CONFIG_SERVER_NO_WHITELIST
enum_map = list(
"none" = CONFIG_SERVER_NO_WHITELIST,
"jobs" = CONFIG_SERVER_JOBS_WHITELIST,
"join" = CONFIG_SERVER_JOIN_WHITELIST,
"connect" = CONFIG_SERVER_CONNECT_WHITELIST
)
31 changes: 12 additions & 19 deletions code/game/jobs/whitelist.dm → code/game/jobs/server_whitelist.dm
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
#define WHITELISTFILE "data/whitelist.txt"
var/global/list/server_whitelist = list()

var/global/list/whitelist = list()

/hook/startup/proc/loadWhitelist()
if(get_config_value(/decl/config/toggle/usewhitelist))
load_whitelist()
return 1

/proc/load_whitelist()
whitelist = file2list(WHITELISTFILE)
if(!length(whitelist))
whitelist = null

/proc/check_whitelist(mob/M /*, var/rank*/)
if(!whitelist)
return 0
return ("[M.ckey]" in whitelist)
/proc/check_server_whitelist(ckey)
if(get_config_value(/decl/config/enum/server_whitelist) == CONFIG_SERVER_NO_WHITELIST)
return TRUE
if(ismob(ckey))
var/mob/checking = ckey
ckey = checking.ckey
if(!istext(ckey))
return FALSE
if(!global.server_whitelist)
global.server_whitelist = file2list(CONFIG_SERVER_WHITELIST_FILE) || list()
return (ckey in global.server_whitelist)

var/global/list/alien_whitelist = list()
/hook/startup/proc/loadAlienWhitelist()
Expand Down Expand Up @@ -106,5 +101,3 @@ var/global/list/alien_whitelist = list()
if(findtext(s,"[ckey] - All"))
return TRUE
return FALSE

#undef WHITELISTFILE
7 changes: 6 additions & 1 deletion code/modules/admin/IsBanned.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@

var/ckeytext = ckey(key)

if(get_config_value(/decl/config/enum/server_whitelist) == CONFIG_SERVER_CONNECT_WHITELIST && !check_server_whitelist(ckeytext))
log_access("Failed Login: [key] - Not server whitelisted")
message_admins("<span class='notice'>Failed Login: [key] - Not server whitelisted</span>")
return list("reason"="whitelist", "desc"="\nReason: This server requires players to be whitelisted to join.")

if(admin_datums[ckeytext])
key_cache[key] = 0
return ..()
Expand All @@ -19,7 +24,7 @@
log_access("Failed Login: [key] - Guests not allowed")
message_admins("<span class='notice'>Failed Login: [key] - Guests not allowed</span>")
key_cache[key] = 0
return list("reason"="guest", "desc"="\nReason: Guests not allowed. Please sign in with a byond account.")
return list("reason"="guest", "desc"="\nReason: Guests not allowed. Please sign in with a BYOND account.")

var/client/C = global.ckey_directory[ckeytext]
//If this isn't here, then topic call spam will result in all clients getting kicked with a connecting too fast error.
Expand Down
2 changes: 1 addition & 1 deletion code/modules/admin/banjob.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var/global/jobban_keylist[0] //to store the keys & ranks
if (SSjobs.guest_jobbans(rank))
if(get_config_value(/decl/config/toggle/on/guest_jobban) && IsGuestKey(M.key))
return "Guest Job-ban"
if(get_config_value(/decl/config/toggle/usewhitelist) && !check_whitelist(M))
if(get_config_value(/decl/config/enum/server_whitelist) == CONFIG_SERVER_JOBS_WHITELIST && !check_server_whitelist(M))
return "Whitelisted Job"
return ckey_is_jobbanned(M.ckey, rank)
return 0
Expand Down
8 changes: 6 additions & 2 deletions code/modules/mob/new_player/new_player.dm
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,15 @@ INITIALIZE_IMMEDIATE(/mob/new_player)
return 0

if(GAME_STATE != RUNLEVEL_GAME)
to_chat(usr, "<span class='warning'>The round is either not ready, or has already finished...</span>")
to_chat(usr, SPAN_WARNING("The round is either not ready, or has already finished."))
return 0

if(get_config_value(/decl/config/enum/server_whitelist) == CONFIG_SERVER_JOIN_WHITELIST && !check_server_whitelist(usr))
alert("Non-whitelisted players are not permitted to join rounds except as observers.")
return 0

if(!get_config_value(/decl/config/toggle/on/enter_allowed))
to_chat(usr, "<span class='notice'>There is an administrative lock on entering the game!</span>")
to_chat(usr, SPAN_WARNING("There is an administrative lock on entering the game!"))
return 0

if(!job || !job.is_available(client))
Expand Down
Loading

0 comments on commit 256da1c

Please sign in to comment.