diff --git a/code/controllers/configuration.dm b/code/controllers/configuration.dm index 1d3970e2b98..ceb65c71ab2 100644 --- a/code/controllers/configuration.dm +++ b/code/controllers/configuration.dm @@ -153,6 +153,7 @@ var/list/gamemode_cache = list() var/admin_legacy_system = 0 //Defines whether the server uses the legacy admin system with admins.txt or the SQL system. Config option in config.txt var/ban_legacy_system = 0 //Defines whether the server uses the legacy banning system with the files in /data or the SQL system. Config option in config.txt var/use_age_restriction_for_jobs = 0 //Do jobs use account age restrictions? --requires database + var/sql_whitelists = 0 //Defined whether the server uses an SQL based whitelist system, or the legacy one with two .txts. Config option in config.txt var/simultaneous_pm_warning_timeout = 100 @@ -674,6 +675,9 @@ var/list/gamemode_cache = list() if("aggressive_changelog") config.aggressive_changelog = 1 + if("sql_whitelists") + config.sql_whitelists = 1 + else log_misc("Unknown setting in configuration: '[name]'") diff --git a/code/game/jobs/whitelist.dm b/code/game/jobs/whitelist.dm index f1dc546aeaf..ebcd4dcb3e1 100644 --- a/code/game/jobs/whitelist.dm +++ b/code/game/jobs/whitelist.dm @@ -3,49 +3,91 @@ var/list/whitelist = list() /hook/startup/proc/loadWhitelist() - if(config.usewhitelist) + if (config.usewhitelist) load_whitelist() return 1 /proc/load_whitelist() - whitelist = file2list(WHITELISTFILE) - if(!whitelist.len) whitelist = null + if (config.sql_whitelists) + establish_db_connection() + + if (!dbcon.IsConnected()) + //Continue with the old code if we have no database. + error("Database connection failed while loading whitelists. Reverting to legacy system.") + config.sql_whitelists = 0 + else + return + + whitelist = file2list(WHITELISTFILE) + if (!whitelist.len) + whitelist = null + +/proc/check_whitelist(mob/M) + if (config.sql_whitelists) + var/head_of_staff_whitelist = 1 + if (M.client && M.client.whitelist_status) + return (M.client.whitelist_status & head_of_staff_whitelist) -/proc/check_whitelist(mob/M /*, var/rank*/) - if(!whitelist) return 0 - return ("[M.ckey]" in whitelist) + else + if (!whitelist) + return 0 + return ("[M.ckey]" in whitelist) /var/list/alien_whitelist = list() /hook/startup/proc/loadAlienWhitelist() - if(config.usealienwhitelist) + if (config.usealienwhitelist) load_alienwhitelist() return 1 /proc/load_alienwhitelist() + if (config.sql_whitelists) + establish_db_connection() + + if (!dbcon.IsConnected()) + //Continue with the old code if we have no database. + error("Database connection failed while loading alien whitelists. Reverting to legacy system.") + config.sql_whitelists = 0 + else + var/DBQuery/query = dbcon.NewQuery("SELECT status_name, flag FROM ss13_whitelist_statuses") + query.Execute() + + while (query.NextRow()) + if (query.item[1] in whitelisted_species) + whitelisted_species[query.item[1]] = text2num(query.item[2]) + + return + var/text = file2text("config/alienwhitelist.txt") if (!text) log_misc("Failed to load config/alienwhitelist.txt") else alien_whitelist = text2list(text, "\n") -//todo: admin aliens /proc/is_alien_whitelisted(mob/M, var/species) - if(!config.usealienwhitelist) + if (!config.usealienwhitelist) return 1 - if(species == "human" || species == "Human") - return 1 - if(check_rights(R_ADMIN, 0)) + + if (!M || !species) + return 0 + + if (lowertext(species) == "human") return 1 + if(!alien_whitelist) return 0 - if(M && species) - for (var/s in alien_whitelist) - if(findtext(s,"[M.ckey] - [species]")) - return 1 - if(findtext(s,"[M.ckey] - All")) - return 1 + + if (config.sql_whitelists) + if (M.client && M.client.whitelist_status) + return (M.client.whitelist_status & whitelisted_species[species]) + else + if (M && species) + for (var/s in alien_whitelist) + if (findtext(s,"[M.ckey] - [species]")) + return 1 + if (findtext(s,"[M.ckey] - All")) + return 1 return 0 #undef WHITELISTFILE diff --git a/code/modules/client/client defines.dm b/code/modules/client/client defines.dm index 1155882b82e..bbb2359f13e 100644 --- a/code/modules/client/client defines.dm +++ b/code/modules/client/client defines.dm @@ -45,5 +45,6 @@ var/player_age = "Requires database" //So admins know why it isn't working - Used to determine how old the account is - in days. var/related_accounts_ip = "Requires database" //So admins know why it isn't working - Used to determine what other accounts previously logged in from this ip var/related_accounts_cid = "Requires database" //So admins know why it isn't working - Used to determine what other accounts previously logged in from this computer id + var/whitelist_status = 0 //Used to determine what whitelists the player has access to. Uses bitflag values! preload_rsc = 0 // This is 0 so we can set it to an URL once the player logs in and have them download the resources from a different server. diff --git a/code/modules/client/client procs.dm b/code/modules/client/client procs.dm index 53e41dd808b..6fe3abb30b3 100644 --- a/code/modules/client/client procs.dm +++ b/code/modules/client/client procs.dm @@ -221,13 +221,14 @@ var/sql_ckey = sql_sanitize_text(src.ckey) - var/DBQuery/query = dbcon.NewQuery("SELECT id, datediff(Now(),firstseen) as age FROM ss13_player WHERE ckey = '[sql_ckey]'") + var/DBQuery/query = dbcon.NewQuery("SELECT id, datediff(Now(),firstseen) as age, whitelist_status FROM ss13_player WHERE ckey = '[sql_ckey]'") query.Execute() var/sql_id = 0 player_age = 0 // New players won't have an entry so knowing we have a connection we set this to zero to be updated if their is a record. while(query.NextRow()) sql_id = query.item[1] player_age = text2num(query.item[2]) + whitelist_status = text2num(query.item[3]) break var/DBQuery/query_ip = dbcon.NewQuery("SELECT ckey FROM ss13_player WHERE ip = '[address]'")