From 6c281dfdd06307e0d8e03bf373c971265b266176 Mon Sep 17 00:00:00 2001 From: Volodymir Ohorodnytskyi <102746941+Legendaxe@users.noreply.github.com> Date: Wed, 6 Dec 2023 17:58:30 +0200 Subject: [PATCH] added: species whitelist (#822) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Что этот PR делает Добавляем ксеномодерацию по приказу генерала Гавса. ## Почему это хорошо для игры ## Изображения изменений ## Тестирование ## Changelog :cl: add: Добавлена возможность включить на сервере ксеномодерацию. (Пока что ксеномодерация отключена) /:cl: --- SQL/paradise_schema.sql | 1 + SQL/updates220/53.220.5-53.220.6.sql | 4 +++ code/__DEFINES/misc_defines.dm | 2 +- code/game/jobs/whitelist.dm | 15 ++++++++-- config/example/config.toml | 8 ++++- modular_ss220/modular_ss220.dme | 1 + .../species_whitelist/_species_whitelist.dm | 4 +++ .../species_whitelist/_species_whitelist.dme | 4 +++ .../code/species_whitelist_configuration.dm | 14 +++++++++ .../code/species_whitelist_preferences.dm | 30 +++++++++++++++++++ 10 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 SQL/updates220/53.220.5-53.220.6.sql create mode 100644 modular_ss220/species_whitelist/_species_whitelist.dm create mode 100644 modular_ss220/species_whitelist/_species_whitelist.dme create mode 100644 modular_ss220/species_whitelist/code/species_whitelist_configuration.dm create mode 100644 modular_ss220/species_whitelist/code/species_whitelist_preferences.dm diff --git a/SQL/paradise_schema.sql b/SQL/paradise_schema.sql index d00d5e14da36..6855c02dabe0 100644 --- a/SQL/paradise_schema.sql +++ b/SQL/paradise_schema.sql @@ -297,6 +297,7 @@ CREATE TABLE `player` ( `server_region` VARCHAR(32) NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci', `muted_adminsounds_ckeys` MEDIUMTEXT NULL DEFAULT NULL COLLATE 'utf8mb4_general_ci', `viewrange` VARCHAR(5) NOT NULL DEFAULT '19x15' COLLATE 'utf8mb4_general_ci', + `species_whitelist` LONGTEXT COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `ckey` (`ckey`), KEY `lastseen` (`lastseen`), diff --git a/SQL/updates220/53.220.5-53.220.6.sql b/SQL/updates220/53.220.5-53.220.6.sql new file mode 100644 index 000000000000..d39755af7e84 --- /dev/null +++ b/SQL/updates220/53.220.5-53.220.6.sql @@ -0,0 +1,4 @@ +# Updating DB from 53.220.5 to 53.220.6 +# Adds species whitelist ~legendaxe + +ALTER TABLE `player` ADD `species_whitelist` LONGTEXT COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '["human"]'; diff --git a/code/__DEFINES/misc_defines.dm b/code/__DEFINES/misc_defines.dm index 3641f687896e..1247d77e0047 100644 --- a/code/__DEFINES/misc_defines.dm +++ b/code/__DEFINES/misc_defines.dm @@ -375,7 +375,7 @@ #define INVESTIGATE_BOMB "bombs" // The SQL version required by this version of the code -#define SQL_VERSION 532205 // SS220 EDIT +#define SQL_VERSION 532206 // SS220 EDIT // Vending machine stuff #define CAT_NORMAL 1 diff --git a/code/game/jobs/whitelist.dm b/code/game/jobs/whitelist.dm index 23b2d842bc75..45c9d0d556c7 100644 --- a/code/game/jobs/whitelist.dm +++ b/code/game/jobs/whitelist.dm @@ -14,9 +14,20 @@ if(NOT_SELECTABLE in S.species_traits) return FALSE + // SS220 EDIT START + // Yes if admin - if(check_rights(R_ADMIN, FALSE)) - return TRUE + //if(check_rights(R_ADMIN, FALSE)) + // return TRUE + + if(GLOB.configuration.species_whitelist.species_whitelist_enabled) + if(!M.client?.prefs?.species_whitelist) + return FALSE + + if(!(species in M.client.prefs.species_whitelist)) + return FALSE + + // SS220 EDIT END // No if species is blacklisted if(S.blacklisted) diff --git a/config/example/config.toml b/config/example/config.toml index a5e6a38d0039..806902f22aee 100644 --- a/config/example/config.toml +++ b/config/example/config.toml @@ -147,7 +147,7 @@ ipc_screens = [ # Enable/disable the database on a whole sql_enabled = false # SQL version. If this is a mismatch, round start will be delayed -sql_version = 532205 +sql_version = 532206 # SQL server address. Can be an IP or DNS name sql_address = "127.0.0.1" # SQL server port @@ -895,3 +895,9 @@ ffmpeg_cpuaffinity = "" force_discord_verification = false ################################################################ + +[species_whitelist_configuration] + +species_whitelist_enabled = false + +################################################################ diff --git a/modular_ss220/modular_ss220.dme b/modular_ss220/modular_ss220.dme index ef38cf6c50ab..9596927f48f8 100644 --- a/modular_ss220/modular_ss220.dme +++ b/modular_ss220/modular_ss220.dme @@ -75,6 +75,7 @@ #include "mecha_skins/mecha_skins.dme" #include "queue/_queue.dme" #include "phrases/_phrases.dme" +#include "species_whitelist/_species_whitelist.dme" // --- PRIME --- // // #define MODPACK_MAIN_ONLY diff --git a/modular_ss220/species_whitelist/_species_whitelist.dm b/modular_ss220/species_whitelist/_species_whitelist.dm new file mode 100644 index 000000000000..308df37ef295 --- /dev/null +++ b/modular_ss220/species_whitelist/_species_whitelist.dm @@ -0,0 +1,4 @@ +/datum/modpack/discord_link + name = "Вайтлист на расы" + desc = "Добавление вайтлиста на расы" + author = "legendaxe" diff --git a/modular_ss220/species_whitelist/_species_whitelist.dme b/modular_ss220/species_whitelist/_species_whitelist.dme new file mode 100644 index 000000000000..4d322dfee0df --- /dev/null +++ b/modular_ss220/species_whitelist/_species_whitelist.dme @@ -0,0 +1,4 @@ +#include "_species_whitelist.dm" + +#include "code/species_whitelist_configuration.dm" +#include "code/species_whitelist_preferences.dm" diff --git a/modular_ss220/species_whitelist/code/species_whitelist_configuration.dm b/modular_ss220/species_whitelist/code/species_whitelist_configuration.dm new file mode 100644 index 000000000000..50bcfb171b4b --- /dev/null +++ b/modular_ss220/species_whitelist/code/species_whitelist_configuration.dm @@ -0,0 +1,14 @@ +/datum/server_configuration + /// Holder for the gateway configuration datum + var/datum/configuration_section/species_whitelist_configuration/species_whitelist + +/datum/server_configuration/load_all_sections() + . = ..() + species_whitelist = new() + safe_load(species_whitelist, "species_whitelist_configuration") + +/datum/configuration_section/species_whitelist_configuration + var/species_whitelist_enabled = FALSE + +/datum/configuration_section/species_whitelist_configuration/load_data(list/data) + CONFIG_LOAD_BOOL(species_whitelist_enabled, data["species_whitelist_enabled"]) diff --git a/modular_ss220/species_whitelist/code/species_whitelist_preferences.dm b/modular_ss220/species_whitelist/code/species_whitelist_preferences.dm new file mode 100644 index 000000000000..62a7ea75c89e --- /dev/null +++ b/modular_ss220/species_whitelist/code/species_whitelist_preferences.dm @@ -0,0 +1,30 @@ +/datum/preferences + var/species_whitelist + +/datum/preferences/proc/get_species_whitelist() + . = TRUE + + if(species_whitelist) + return + + var/datum/db_query/preferences_query = SSdbcore.NewQuery("SELECT species_whitelist FROM player WHERE ckey=:ckey", list( + "ckey" = parent.ckey + )) + + if(!preferences_query.warn_execute()) + qdel(preferences_query) + return FALSE + + while(preferences_query.NextRow()) + var/species_whitelist_json = preferences_query.item[1] + if(species_whitelist_json) + species_whitelist = json_decode(preferences_query.item[1]) + + qdel(preferences_query) + +/datum/preferences/load_preferences(datum/db_query/query) + . = ..() + if(!.) + return + + return get_species_whitelist()