Merge pull request #11847 from headswe/whitelist_fix

Alien Whitelist SQL version
This commit is contained in:
PsiOmegaDelta
2015-12-31 22:56:14 +01:00
3 changed files with 45 additions and 9 deletions
+4 -1
View File
@@ -90,6 +90,7 @@ var/list/gamemode_cache = list()
var/uneducated_mice = 0 //Set to 1 to prevent newly-spawned mice from understanding human speech
var/usealienwhitelist = 0
var/usealienwhitelistSQL = 0;
var/limitalienplayers = 0
var/alien_to_human_ratio = 0.5
var/allow_extra_antags = 0
@@ -154,6 +155,7 @@ var/list/gamemode_cache = list()
var/slime_delay = 0
var/animal_delay = 0
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
@@ -573,7 +575,8 @@ var/list/gamemode_cache = list()
if("usealienwhitelist")
usealienwhitelist = 1
if("usealienwhitelist_sql") // above need to be enabled as well
usealienwhitelistSQL = 1;
if("alien_player_ratio")
limitalienplayers = 1
alien_to_human_ratio = text2num(value)
+39 -8
View File
@@ -20,32 +20,63 @@ var/list/whitelist = list()
/hook/startup/proc/loadAlienWhitelist()
if(config.usealienwhitelist)
load_alienwhitelist()
if(config.usealienwhitelistSQL)
if(!load_alienwhitelistSQL())
world.log << "Could not load alienwhitelist via SQL"
else
load_alienwhitelist()
return 1
/proc/load_alienwhitelist()
var/text = file2text("config/alienwhitelist.txt")
if (!text)
log_misc("Failed to load config/alienwhitelist.txt")
return 0
else
alien_whitelist = text2list(text, "\n")
return 1
/proc/load_alienwhitelistSQL()
var/DBQuery/query = dbcon_old.NewQuery("SELECT * FROM whitelist")
if(!query.Execute())
world.log << dbcon_old.ErrorMsg()
return 0
else
while(query.NextRow())
var/list/row = query.GetRowData()
if(alien_whitelist[row["ckey"]])
var/list/A = alien_whitelist[row["ckey"]]
A.Add(row["race"])
else
alien_whitelist[row["ckey"]] = list(row["race"])
return 1
//todo: admin aliens
/proc/is_alien_whitelisted(mob/M, var/species)
if(!config.usealienwhitelist)
return 1
if(istype(species,/datum/species) || istype(species,/datum/language))
species = "[species]";
if(species == "human" || species == "Human")
return 1
if(check_rights(R_ADMIN, 0))
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.usealienwhitelistSQL)
var race = lowertext(species)
if(!(M.ckey in alien_whitelist))
return 0;
var/list/whitelisted = alien_whitelist[M.ckey]
if(race in whitelisted)
return 1
return 0
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
+2
View File
@@ -253,6 +253,8 @@ GATEWAY_DELAY 18000
## Uncomment to restrict non-admins from using humanoid alien races
USEALIENWHITELIST
## Uncomment to use the alien whitelist system with SQL instead. (requires the above uncommented aswell)
#USEALIENWHITELIST_SQL
## Comment this to unrestrict the number of alien players allowed in the round. The number represents the number of alien players for every human player.
#ALIEN_PLAYER_RATIO 0.2