Skip to content

Commit

Permalink
Merge pull request NebulaSS13#4491 from MistakeNot4892/tweak/serverwh…
Browse files Browse the repository at this point in the history
…itelist

Expanding the existing whitelist config to support several levels of severity.
  • Loading branch information
out-of-phaze authored Sep 28, 2024
2 parents ac96636 + 61dff94 commit 28a56f7
Show file tree
Hide file tree
Showing 16 changed files with 174 additions and 84 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 config 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
)
49 changes: 30 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,34 @@
#define WHITELISTFILE "data/whitelist.txt"
var/global/list/server_whitelist

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)

/proc/save_server_whitelist()
// Ensure we have the server whitelist loaded regardless of config or prior call.
if(!global.server_whitelist)
global.server_whitelist = file2list(CONFIG_SERVER_WHITELIST_FILE) || list()

// Clear blank rows.
while(null in global.server_whitelist)
global.server_whitelist -= null
while("" in global.server_whitelist)
global.server_whitelist -= ""

// Remove old list rather than append.
if(fexists(CONFIG_SERVER_WHITELIST_FILE))
fdel(CONFIG_SERVER_WHITELIST_FILE)
// Write our list out.
var/write_file = file(CONFIG_SERVER_WHITELIST_FILE)
to_file(write_file, jointext(global.server_whitelist, "\n"))

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

#undef WHITELISTFILE
8 changes: 7 additions & 1 deletion code/modules/admin/IsBanned.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//Blocks an attempt to connect before even creating our client datum thing.
/world/IsBanned(key, address, computer_id, type)

var/static/key_cache = list()
if(type == "world")
return ..()
Expand All @@ -10,6 +11,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 +25,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
31 changes: 31 additions & 0 deletions code/modules/admin/admin.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1497,3 +1497,34 @@ var/global/BSACooldown = 0

LAZYADD(global.adminfaxes, P)
faxreply = null

/datum/admins/proc/addserverwhitelist(ckey as text)
set category = "Admin"
set name = "Add Ckey To Server Whitelist"
set desc = "Permanently adds the specified ckey to the server whitelist."

ckey = ckey(ckey)

if(!ckey)
to_chat(usr, SPAN_WARNING("Please specify a ckey to insert."))
else if(check_server_whitelist(ckey)) // This will also preload the server whitelist.
to_chat(usr, SPAN_WARNING("That ckey is already server whitelisted."))
else
global.server_whitelist |= ckey
save_server_whitelist()
log_and_message_admins("has added [ckey] to the server whitelist.", usr)

/datum/admins/proc/removeserverwhitelist(ckey as text)
set category = "Admin"
set name = "Remove Ckey From Server Whitelist"
set desc = "Permanently removes the specified ckey from the server whitelist."

ckey = ckey(ckey)
if(!ckey)
to_chat(usr, SPAN_WARNING("Please specify a ckey to remove."))
else if(!check_server_whitelist(ckey)) // This will also preload the server whitelist.
to_chat(usr, SPAN_WARNING("That ckey is not server whitelisted."))
else
global.server_whitelist -= ckey
save_server_whitelist()
log_and_message_admins("has removed [ckey] from the server whitelist.", usr)
2 changes: 2 additions & 0 deletions code/modules/admin/admin_verbs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ var/global/list/admin_verbs_server = list(
/datum/admins/proc/toggle_aliens,
/client/proc/toggle_random_events,
/client/proc/nanomapgen_DumpImage,
/datum/admins/proc/addserverwhitelist,
/datum/admins/proc/removeserverwhitelist,
/datum/admins/proc/panicbunker,
/datum/admins/proc/addbunkerbypass,
/datum/admins/proc/revokebunkerbypass
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
4 changes: 3 additions & 1 deletion code/modules/ghosttrap/trap.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// Check for bans, proper atom types, etc.
/decl/ghosttrap/proc/assess_candidate(var/mob/observer/ghost/candidate, var/mob/target, var/feedback = TRUE)
. = TRUE
if(!candidate.MayRespawn(feedback, minutes_since_death))
if(get_config_value(/decl/config/enum/server_whitelist) == CONFIG_SERVER_JOIN_WHITELIST && !check_server_whitelist(candidate))
. = FALSE
else if(!candidate.MayRespawn(feedback, minutes_since_death))
. = FALSE
else if(islist(ban_checks))
for(var/bantype in ban_checks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,24 @@
/proc/try_drone_spawn(var/mob/user, var/obj/machinery/drone_fabricator/fabricator)

if(GAME_STATE < RUNLEVEL_GAME)
to_chat(user, "<span class='danger'>The game hasn't started yet!</span>")
to_chat(user, SPAN_WARNING("The game hasn't started yet!"))
return

if(get_config_value(/decl/config/enum/server_whitelist) == CONFIG_SERVER_JOIN_WHITELIST && !check_server_whitelist(user))
to_chat(user, SPAN_WARNING("Non-whitelisted players cannot join rounds except as observers."))
return

if(!get_config_value(/decl/config/toggle/on/allow_drone_spawn))
to_chat(user, "<span class='danger'>That verb is not currently permitted.</span>")
to_chat(user, SPAN_WARNING("That verb is not currently permitted."))
return

if(jobban_isbanned(user,ASSIGNMENT_ROBOT))
to_chat(user, "<span class='danger'>You are banned from playing synthetics and cannot spawn as a drone.</span>")
to_chat(user, SPAN_WARNING("You are banned from playing synthetics and cannot spawn as a drone."))
return

if(get_config_value(/decl/config/num/use_age_restriction_for_jobs) && isnum(user.client.player_age))
if(user.client.player_age <= 3)
to_chat(user, "<span class='danger'> Your account is not old enough to play as a maintenance drone.</span>")
to_chat(user, SPAN_WARNING("Your account is not old enough to play as a maintenance drone."))
return

if(!user.MayRespawn(1, DRONE_SPAWN_DELAY))
Expand All @@ -135,7 +139,7 @@
all_fabricators[DF.fabricator_tag] = DF

if(!all_fabricators.len)
to_chat(user, "<span class='danger'>There are no available drone spawn points, sorry.</span>")
to_chat(user, SPAN_WARNING("There are no available drone spawn points, sorry."))
return

var/choice = input(user,"Which fabricator do you wish to use?") as null|anything in all_fabricators
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
20 changes: 13 additions & 7 deletions code/modules/mob/observer/ghost/ghost.dm
Original file line number Diff line number Diff line change
Expand Up @@ -372,27 +372,31 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp
if(ishuman(following))
to_chat(src, medical_scan_results(following, 1, SKILL_MAX))

else to_chat(src, "<span class='notice'>Not a scannable target.</span>")
else to_chat(src, SPAN_WARNING("\The [following] is not a scannable target."))

/mob/observer/ghost/verb/become_mouse()
set name = "Become mouse"
set category = "Ghost"

if(get_config_value(/decl/config/enum/server_whitelist) == CONFIG_SERVER_JOIN_WHITELIST && !check_server_whitelist(src))
to_chat(src, SPAN_WARNING("Non-whitelisted players cannot join rounds except as observers."))
return

if(get_config_value(/decl/config/toggle/disable_player_mice))
to_chat(src, "<span class='warning'>Spawning as a mouse is currently disabled.</span>")
to_chat(src, SPAN_WARNING("Spawning as a mouse is currently disabled."))
return

if(!MayRespawn(1, ANIMAL_SPAWN_DELAY))
return

var/turf/T = get_turf(src)
if(!T || isAdminLevel(T.z))
to_chat(src, "<span class='warning'>You may not spawn as a mouse on this Z-level.</span>")
to_chat(src, SPAN_WARNING("You may not spawn as a mouse on this Z-level."))
return

var/response = alert(src, "Are you -sure- you want to become a mouse?","Are you sure you want to squeek?","Squeek!","Nope!")
if(response != "Squeek!") return //Hit the wrong key...again.

if(response != "Squeek!")
return

//find a viable mouse candidate
var/mob/living/simple_animal/passive/mouse/host
Expand All @@ -405,14 +409,16 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp
vent_found = pick(found_vents)
host = new /mob/living/simple_animal/passive/mouse(vent_found.loc)
else
to_chat(src, "<span class='warning'>Unable to find any unwelded vents to spawn mice at.</span>")
to_chat(src, SPAN_WARNING("Unable to find any unwelded vents to spawn mice at."))

if(host)
if(get_config_value(/decl/config/toggle/uneducated_mice))
host.universal_understand = FALSE
announce_ghost_joinleave(src, 0, "They are now a mouse.")
host.ckey = src.ckey
host.status_flags |= NO_ANTAG
to_chat(host, "<span class='info'>You are now a mouse. Try to avoid interaction with players, and do not give hints away that you are more than a simple rodent.</span>")
to_chat(host, SPAN_INFO("You are now a mouse. Try to avoid interaction with players, and do not give hints away that you are more than a simple rodent."))

/mob/observer/ghost/verb/view_manfiest()
set name = "Show Crew Manifest"
set category = "Ghost"
Expand Down
Loading

0 comments on commit 28a56f7

Please sign in to comment.