From 2d45fcf318f413034061994c9b0a7e62f1159e26 Mon Sep 17 00:00:00 2001 From: Mikhail Dzianishchyts Date: Thu, 15 Aug 2024 01:11:08 +0300 Subject: [PATCH 1/9] Make credits toggleable --- SQL/paradise_schema.sql | 4 ++++ SQL/updates220/59.220.6-59.220.7.sql | 4 ++++ code/__DEFINES/_ss220.dm | 9 +++++++++ code/__DEFINES/misc_defines.dm | 2 +- .../login_processing/10-load_preferences.dm | 3 ++- code/modules/client/preference/preferences.dm | 5 +++++ .../client/preference/preferences_mysql.dm | 8 ++++++-- .../client/preference/preferences_toggles.dm | 5 +++++ config/example/config.toml | 2 +- modular_ss220/cinematics/code/_cinematics.dm | 4 ++++ modular_ss220/credits/_credits.dm | 10 ++++++++++ modular_ss220/credits/_credits.dme | 2 ++ modular_ss220/credits/code/admin_procs.dm | 20 +++++++++++++++++++ modular_ss220/credits/code/preferences.dm | 9 +++++++++ 14 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 SQL/updates220/59.220.6-59.220.7.sql create mode 100644 modular_ss220/credits/code/admin_procs.dm create mode 100644 modular_ss220/credits/code/preferences.dm diff --git a/SQL/paradise_schema.sql b/SQL/paradise_schema.sql index 8b7a491b0ee5..7f4446a0fa0b 100644 --- a/SQL/paradise_schema.sql +++ b/SQL/paradise_schema.sql @@ -681,3 +681,7 @@ CREATE TABLE `admin_wl` ( KEY `ckey` (`ckey`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +# Updating DB from 59.220.6 to 59.220.7 +# Adds SS220 toggle prefs ~Maxiemar + +ALTER TABLE `player` ADD `toggles_220` int(11) DEFAULT NULL; diff --git a/SQL/updates220/59.220.6-59.220.7.sql b/SQL/updates220/59.220.6-59.220.7.sql new file mode 100644 index 000000000000..de52c4bedd65 --- /dev/null +++ b/SQL/updates220/59.220.6-59.220.7.sql @@ -0,0 +1,4 @@ +# Updating DB from 59.220.6 to 59.220.7 +# Adds SS220 toggle prefs ~Maxiemar + +ALTER TABLE `player` ADD `toggles_220` int(11) DEFAULT NULL; diff --git a/code/__DEFINES/_ss220.dm b/code/__DEFINES/_ss220.dm index 203e016a313f..7d65cad44f6a 100644 --- a/code/__DEFINES/_ss220.dm +++ b/code/__DEFINES/_ss220.dm @@ -1 +1,10 @@ #define MODPACK_CHAT_BADGES + +/// Interacts with the toggles220 bitflag +#define PREFTOGGLE_TOGGLE220 220 + +#define PREFTOGGLE_220_WATCH_CREDITS (1<<0) // 1 + +#define TOGGLES_220_TOTAL 1 // If you add or remove a preference toggle above, make sure you update this define with the total value of the toggles combined. + +#define TOGGLES_220_DEFAULT (PREFTOGGLE_220_WATCH_CREDITS) diff --git a/code/__DEFINES/misc_defines.dm b/code/__DEFINES/misc_defines.dm index 5cc0465f2b69..ea064768fc20 100644 --- a/code/__DEFINES/misc_defines.dm +++ b/code/__DEFINES/misc_defines.dm @@ -420,7 +420,7 @@ #define INVESTIGATE_HOTMIC "hotmic" // The SQL version required by this version of the code -#define SQL_VERSION 592206 +#define SQL_VERSION 592207 // Vending machine stuff #define CAT_NORMAL (1<<0) diff --git a/code/modules/client/login_processing/10-load_preferences.dm b/code/modules/client/login_processing/10-load_preferences.dm index 0ef03d03c4c2..7ac1c195e972 100644 --- a/code/modules/client/login_processing/10-load_preferences.dm +++ b/code/modules/client/login_processing/10-load_preferences.dm @@ -31,7 +31,8 @@ keybindings, server_region, muted_adminsounds_ckeys, - viewrange + viewrange, + toggles_220 FROM player WHERE ckey=:ckey"}, list( "ckey" = C.ckey diff --git a/code/modules/client/preference/preferences.dm b/code/modules/client/preference/preferences.dm index dfc1daf5746f..fb1a2a240488 100644 --- a/code/modules/client/preference/preferences.dm +++ b/code/modules/client/preference/preferences.dm @@ -62,6 +62,7 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts var/UI_style = "Midnight" var/toggles = TOGGLES_DEFAULT var/toggles2 = TOGGLES_2_DEFAULT // Created because 1 column has a bitflag limit of 24 (BYOND limitation not MySQL) + var/toggles220 = TOGGLES_220_DEFAULT // SS220 ADDITION var/sound = SOUND_DEFAULT var/light = LIGHT_DEFAULT /// Glow level for the lighting. Takes values from GLOW_HIGH to GLOW_DISABLE. @@ -658,6 +659,10 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts dat += "[(toggles & toggle.preftoggle_bitflag) ? "Enabled" : "Disabled"]" if(PREFTOGGLE_TOGGLE2) dat += "[(toggles2 & toggle.preftoggle_bitflag) ? "Enabled" : "Disabled"]" + // SS220 ADDITION - START + if(PREFTOGGLE_TOGGLE220) + dat += "[(toggles220 & toggle.preftoggle_bitflag) ? "Enabled" : "Disabled"]" + // SS220 ADDITION - END if(PREFTOGGLE_SOUND) dat += "[(sound & toggle.preftoggle_bitflag) ? "Enabled" : "Disabled"]" if(PREFTOGGLE_LIGHT) diff --git a/code/modules/client/preference/preferences_mysql.dm b/code/modules/client/preference/preferences_mysql.dm index 084bba3926f7..8ac3da1a28a9 100644 --- a/code/modules/client/preference/preferences_mysql.dm +++ b/code/modules/client/preference/preferences_mysql.dm @@ -32,6 +32,7 @@ server_region = query.item[25] raw_muted_admins = query.item[26] viewrange = query.item[27] + toggles220 = text2num(query.item[28]) // SS220 ADDITTION lastchangelog_2 = lastchangelog // Clone please @@ -41,6 +42,7 @@ default_slot = sanitize_integer(default_slot, 1, max_save_slots, initial(default_slot)) toggles = sanitize_integer(toggles, 0, TOGGLES_TOTAL, initial(toggles)) toggles2 = sanitize_integer(toggles2, 0, TOGGLES_2_TOTAL, initial(toggles2)) + toggles220 = sanitize_integer(toggles220, 0, TOGGLES_220_TOTAL, initial(toggles220)) sound = sanitize_integer(sound, 0, 65535, initial(sound)) UI_style_color = sanitize_hexcolor(UI_style_color, initial(UI_style_color)) UI_style_alpha = sanitize_integer(UI_style_alpha, 0, 255, initial(UI_style_alpha)) @@ -104,7 +106,8 @@ keybindings=:keybindings, server_region=:server_region, muted_adminsounds_ckeys=:muted_adminsounds_ckeys, - viewrange=:viewrange + viewrange=:viewrange, + toggles_220=:toggles220 WHERE ckey=:ckey"}, list( // OH GOD THE PARAMETERS "ooccolour" = ooccolor, @@ -133,7 +136,8 @@ "ckey" = C.ckey, "server_region" = server_region, "muted_adminsounds_ckeys" = json_encode(admin_sound_ckey_ignore), - "viewrange" = viewrange + "viewrange" = viewrange, + "toggles220" = num2text(toggles220, CEILING(log(10, (TOGGLES_220_TOTAL)), 1)) // SS220 ADDITION )) if(!query.warn_execute()) diff --git a/code/modules/client/preference/preferences_toggles.dm b/code/modules/client/preference/preferences_toggles.dm index 5ffbc2f7cb08..9b5b68ed62bb 100644 --- a/code/modules/client/preference/preferences_toggles.dm +++ b/code/modules/client/preference/preferences_toggles.dm @@ -36,6 +36,11 @@ if(PREFTOGGLE_TOGGLE2) our_prefs.toggles2 ^= preftoggle_bitflag to_chat(user, "[(our_prefs.toggles2 & preftoggle_bitflag) ? enable_message : disable_message]") + // SS220 ADDITION - START + if(PREFTOGGLE_TOGGLE220) + our_prefs.toggles220 ^= preftoggle_bitflag + to_chat(user, "[(our_prefs.toggles220 & preftoggle_bitflag) ? enable_message : disable_message]") + // SS220 ADDITION - END if(PREFTOGGLE_SOUND) our_prefs.sound ^= preftoggle_bitflag to_chat(user, "[(our_prefs.sound & preftoggle_bitflag) ? enable_message : disable_message]") diff --git a/config/example/config.toml b/config/example/config.toml index 7956ba0c4353..51de589eaafd 100644 --- a/config/example/config.toml +++ b/config/example/config.toml @@ -180,7 +180,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 = 592206 +sql_version = 592207 # SQL server address. Can be an IP or DNS name sql_address = "127.0.0.1" # SQL server port diff --git a/modular_ss220/cinematics/code/_cinematics.dm b/modular_ss220/cinematics/code/_cinematics.dm index 1a1e11ad558b..c2c3fc4f74dc 100644 --- a/modular_ss220/cinematics/code/_cinematics.dm +++ b/modular_ss220/cinematics/code/_cinematics.dm @@ -121,6 +121,10 @@ if(!watching_client || (watching_client in watching)) return + // Do not show credits if it's disabled for the client and not forced. + if(istype(src, /datum/cinematic/credits) && !GLOB.credits_forced && !(watching_client.prefs.toggles220 & PREFTOGGLE_220_WATCH_CREDITS)) + return + watching += watching_client watching_mob.overlay_fullscreen("cinematic", backdrop_type) watching_client.screen += screen diff --git a/modular_ss220/credits/_credits.dm b/modular_ss220/credits/_credits.dm index 429b361afbf2..c3e4899bc4ac 100644 --- a/modular_ss220/credits/_credits.dm +++ b/modular_ss220/credits/_credits.dm @@ -2,3 +2,13 @@ name = "Credits" desc = "Добавление титров в конце раунда, основа кода была взята из данного репозитория https://github.com/Baystation12/Baystation12" author = "Legendaxe" + +/datum/modpack/credits/initialize() + GLOB.admin_verbs_admin += list( + /client/proc/toggle_credits + ) + // Update verbs for admins who connected before subsystem initialization. + for(var/client/player in GLOB.clients) + if(!player.holder) + continue + player.add_admin_verbs() \ No newline at end of file diff --git a/modular_ss220/credits/_credits.dme b/modular_ss220/credits/_credits.dme index 4a58d90cf3c9..0a02dfaf2f28 100644 --- a/modular_ss220/credits/_credits.dme +++ b/modular_ss220/credits/_credits.dme @@ -1,5 +1,7 @@ #include "code\SScredits.dm" #include "code\credits.dm" +#include "code\admin_procs.dm" +#include "code\preferences.dm" #include "code\halloween_credits.dm" #include "code\new_year_credits.dm" #include "code\aprils_fool_credits.dm" diff --git a/modular_ss220/credits/code/admin_procs.dm b/modular_ss220/credits/code/admin_procs.dm new file mode 100644 index 000000000000..ffa31a5a0f5a --- /dev/null +++ b/modular_ss220/credits/code/admin_procs.dm @@ -0,0 +1,20 @@ +// Force everyone to watch credits? +GLOBAL_VAR_INIT(credits_forced, FALSE) + +/client/proc/toggle_credits() + set category = "Server" + set desc = "Просмотр титров по окончании раунда" + set name = "Toggle Credits" + + if(!check_rights(R_ADMIN)) + return + + GLOB.credits_forced = !GLOB.credits_forced + if(GLOB.credits_forced) + to_chat(world, "Все будут смотреть титры по окончании раунда.") + message_admins("[key_name_admin(usr)] устанавливает принудительные титры.", 1) + else + to_chat(world, "Игроки будут смотреть титры в зависимости от своих настроек.") + message_admins("[key_name_admin(usr)] устанавливает титры по умолчанию.", 1) + log_admin("[key_name(usr)] toggled credits.") + SSblackbox.record_feedback("tally", "admin_verb", 1, "Toggle Credits") \ No newline at end of file diff --git a/modular_ss220/credits/code/preferences.dm b/modular_ss220/credits/code/preferences.dm new file mode 100644 index 000000000000..712e902fdfd1 --- /dev/null +++ b/modular_ss220/credits/code/preferences.dm @@ -0,0 +1,9 @@ +/datum/preference_toggle/toggle_credits + name = "Показывать титры" + description = "Показывать титры по окончании раунда" + preftoggle_bitflag = PREFTOGGLE_220_WATCH_CREDITS + preftoggle_toggle = PREFTOGGLE_TOGGLE220 + preftoggle_category = PREFTOGGLE_CATEGORY_LIVING + enable_message = "Вы будете видеть титры в конце раундов." + disable_message = "Вы не будете видеть титры в конце раундов." + blackbox_message = "Toggle Credits" \ No newline at end of file From ec3acefe00984bb19285a8844a30ff87db885a3a Mon Sep 17 00:00:00 2001 From: Mikhail Dzianishchyts Date: Thu, 15 Aug 2024 01:34:21 +0300 Subject: [PATCH 2/9] Add missing line breaks --- modular_ss220/credits/_credits.dm | 2 +- modular_ss220/credits/code/admin_procs.dm | 2 +- modular_ss220/credits/code/preferences.dm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modular_ss220/credits/_credits.dm b/modular_ss220/credits/_credits.dm index c3e4899bc4ac..7104b4180fda 100644 --- a/modular_ss220/credits/_credits.dm +++ b/modular_ss220/credits/_credits.dm @@ -11,4 +11,4 @@ for(var/client/player in GLOB.clients) if(!player.holder) continue - player.add_admin_verbs() \ No newline at end of file + player.add_admin_verbs() diff --git a/modular_ss220/credits/code/admin_procs.dm b/modular_ss220/credits/code/admin_procs.dm index ffa31a5a0f5a..42c90fdc8f9e 100644 --- a/modular_ss220/credits/code/admin_procs.dm +++ b/modular_ss220/credits/code/admin_procs.dm @@ -17,4 +17,4 @@ GLOBAL_VAR_INIT(credits_forced, FALSE) to_chat(world, "Игроки будут смотреть титры в зависимости от своих настроек.") message_admins("[key_name_admin(usr)] устанавливает титры по умолчанию.", 1) log_admin("[key_name(usr)] toggled credits.") - SSblackbox.record_feedback("tally", "admin_verb", 1, "Toggle Credits") \ No newline at end of file + SSblackbox.record_feedback("tally", "admin_verb", 1, "Toggle Credits") diff --git a/modular_ss220/credits/code/preferences.dm b/modular_ss220/credits/code/preferences.dm index 712e902fdfd1..473738f2bdc0 100644 --- a/modular_ss220/credits/code/preferences.dm +++ b/modular_ss220/credits/code/preferences.dm @@ -6,4 +6,4 @@ preftoggle_category = PREFTOGGLE_CATEGORY_LIVING enable_message = "Вы будете видеть титры в конце раундов." disable_message = "Вы не будете видеть титры в конце раундов." - blackbox_message = "Toggle Credits" \ No newline at end of file + blackbox_message = "Toggle Credits" From 054e8e4d9ddaf48281cf551f673e346ec74f9336 Mon Sep 17 00:00:00 2001 From: Mikhail Dzianishchyts Date: Tue, 20 Aug 2024 12:50:38 +0300 Subject: [PATCH 3/9] Move prefs to a separate module --- SQL/paradise_schema.sql | 7 ++- SQL/updates220/59.220.6-59.220.7.sql | 7 ++- code/__DEFINES/_ss220.dm | 7 +-- .../login_processing/10-load_preferences.dm | 3 +- code/modules/client/preference/preferences.dm | 1 - .../client/preference/preferences_mysql.dm | 8 +-- .../client/preference/preferences_toggles.dm | 5 -- modular_ss220/_defines220/_defines220.dme | 1 + .../_defines220/code/preferences_defines.dm | 5 ++ modular_ss220/credits/_credits.dme | 1 - modular_ss220/modular_ss220.dme | 1 + modular_ss220/preferences/_preferences.dm | 4 ++ modular_ss220/preferences/_preferences.dme | 4 ++ modular_ss220/preferences/code/preferences.dm | 58 +++++++++++++++++++ .../code/preferences_toggles.dm} | 0 15 files changed, 89 insertions(+), 23 deletions(-) create mode 100644 modular_ss220/_defines220/code/preferences_defines.dm create mode 100644 modular_ss220/preferences/_preferences.dm create mode 100644 modular_ss220/preferences/_preferences.dme create mode 100644 modular_ss220/preferences/code/preferences.dm rename modular_ss220/{credits/code/preferences.dm => preferences/code/preferences_toggles.dm} (100%) diff --git a/SQL/paradise_schema.sql b/SQL/paradise_schema.sql index 049b990fcc00..3269fe1f17e2 100644 --- a/SQL/paradise_schema.sql +++ b/SQL/paradise_schema.sql @@ -715,4 +715,9 @@ ALTER TABLE `player` ADD `species_whitelist` LONGTEXT COLLATE utf8mb4_unicode_ci # Updating DB from 59.220.6 to 59.220.7 # Adds SS220 toggle prefs ~Maxiemar -ALTER TABLE `player` ADD `toggles_220` int(11) DEFAULT NULL; +DROP TABLE IF EXISTS `player_220`; +CREATE TABLE `player_220` ( + `ckey` VARCHAR(64) NOT NULL COLLATE 'utf8mb4_general_ci', + `toggles_220` int(11) DEFAULT NULL + PRIMARY KEY (`ckey`) USING BTREE, +) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB; diff --git a/SQL/updates220/59.220.6-59.220.7.sql b/SQL/updates220/59.220.6-59.220.7.sql index de52c4bedd65..bc82815db3f4 100644 --- a/SQL/updates220/59.220.6-59.220.7.sql +++ b/SQL/updates220/59.220.6-59.220.7.sql @@ -1,4 +1,9 @@ # Updating DB from 59.220.6 to 59.220.7 # Adds SS220 toggle prefs ~Maxiemar -ALTER TABLE `player` ADD `toggles_220` int(11) DEFAULT NULL; +DROP TABLE IF EXISTS `player_220`; +CREATE TABLE `player_220` ( + `ckey` VARCHAR(64) NOT NULL COLLATE 'utf8mb4_general_ci', + `toggles_220` int(11) DEFAULT NULL + PRIMARY KEY (`ckey`) USING BTREE, +) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB; \ No newline at end of file diff --git a/code/__DEFINES/_ss220.dm b/code/__DEFINES/_ss220.dm index 7d65cad44f6a..0cf3257d7da9 100644 --- a/code/__DEFINES/_ss220.dm +++ b/code/__DEFINES/_ss220.dm @@ -1,10 +1,5 @@ #define MODPACK_CHAT_BADGES +// TODO: someday preferences will use TGUI and you will probably be able to move it to modular_ss220\_defines220\code\preferences_defines.dm /// Interacts with the toggles220 bitflag #define PREFTOGGLE_TOGGLE220 220 - -#define PREFTOGGLE_220_WATCH_CREDITS (1<<0) // 1 - -#define TOGGLES_220_TOTAL 1 // If you add or remove a preference toggle above, make sure you update this define with the total value of the toggles combined. - -#define TOGGLES_220_DEFAULT (PREFTOGGLE_220_WATCH_CREDITS) diff --git a/code/modules/client/login_processing/10-load_preferences.dm b/code/modules/client/login_processing/10-load_preferences.dm index 7ac1c195e972..0ef03d03c4c2 100644 --- a/code/modules/client/login_processing/10-load_preferences.dm +++ b/code/modules/client/login_processing/10-load_preferences.dm @@ -31,8 +31,7 @@ keybindings, server_region, muted_adminsounds_ckeys, - viewrange, - toggles_220 + viewrange FROM player WHERE ckey=:ckey"}, list( "ckey" = C.ckey diff --git a/code/modules/client/preference/preferences.dm b/code/modules/client/preference/preferences.dm index fb1a2a240488..44b17907e2a5 100644 --- a/code/modules/client/preference/preferences.dm +++ b/code/modules/client/preference/preferences.dm @@ -62,7 +62,6 @@ GLOBAL_LIST_INIT(special_role_times, list( //minimum age (in days) for accounts var/UI_style = "Midnight" var/toggles = TOGGLES_DEFAULT var/toggles2 = TOGGLES_2_DEFAULT // Created because 1 column has a bitflag limit of 24 (BYOND limitation not MySQL) - var/toggles220 = TOGGLES_220_DEFAULT // SS220 ADDITION var/sound = SOUND_DEFAULT var/light = LIGHT_DEFAULT /// Glow level for the lighting. Takes values from GLOW_HIGH to GLOW_DISABLE. diff --git a/code/modules/client/preference/preferences_mysql.dm b/code/modules/client/preference/preferences_mysql.dm index 8ac3da1a28a9..084bba3926f7 100644 --- a/code/modules/client/preference/preferences_mysql.dm +++ b/code/modules/client/preference/preferences_mysql.dm @@ -32,7 +32,6 @@ server_region = query.item[25] raw_muted_admins = query.item[26] viewrange = query.item[27] - toggles220 = text2num(query.item[28]) // SS220 ADDITTION lastchangelog_2 = lastchangelog // Clone please @@ -42,7 +41,6 @@ default_slot = sanitize_integer(default_slot, 1, max_save_slots, initial(default_slot)) toggles = sanitize_integer(toggles, 0, TOGGLES_TOTAL, initial(toggles)) toggles2 = sanitize_integer(toggles2, 0, TOGGLES_2_TOTAL, initial(toggles2)) - toggles220 = sanitize_integer(toggles220, 0, TOGGLES_220_TOTAL, initial(toggles220)) sound = sanitize_integer(sound, 0, 65535, initial(sound)) UI_style_color = sanitize_hexcolor(UI_style_color, initial(UI_style_color)) UI_style_alpha = sanitize_integer(UI_style_alpha, 0, 255, initial(UI_style_alpha)) @@ -106,8 +104,7 @@ keybindings=:keybindings, server_region=:server_region, muted_adminsounds_ckeys=:muted_adminsounds_ckeys, - viewrange=:viewrange, - toggles_220=:toggles220 + viewrange=:viewrange WHERE ckey=:ckey"}, list( // OH GOD THE PARAMETERS "ooccolour" = ooccolor, @@ -136,8 +133,7 @@ "ckey" = C.ckey, "server_region" = server_region, "muted_adminsounds_ckeys" = json_encode(admin_sound_ckey_ignore), - "viewrange" = viewrange, - "toggles220" = num2text(toggles220, CEILING(log(10, (TOGGLES_220_TOTAL)), 1)) // SS220 ADDITION + "viewrange" = viewrange )) if(!query.warn_execute()) diff --git a/code/modules/client/preference/preferences_toggles.dm b/code/modules/client/preference/preferences_toggles.dm index 9b5b68ed62bb..5ffbc2f7cb08 100644 --- a/code/modules/client/preference/preferences_toggles.dm +++ b/code/modules/client/preference/preferences_toggles.dm @@ -36,11 +36,6 @@ if(PREFTOGGLE_TOGGLE2) our_prefs.toggles2 ^= preftoggle_bitflag to_chat(user, "[(our_prefs.toggles2 & preftoggle_bitflag) ? enable_message : disable_message]") - // SS220 ADDITION - START - if(PREFTOGGLE_TOGGLE220) - our_prefs.toggles220 ^= preftoggle_bitflag - to_chat(user, "[(our_prefs.toggles220 & preftoggle_bitflag) ? enable_message : disable_message]") - // SS220 ADDITION - END if(PREFTOGGLE_SOUND) our_prefs.sound ^= preftoggle_bitflag to_chat(user, "[(our_prefs.sound & preftoggle_bitflag) ? enable_message : disable_message]") diff --git a/modular_ss220/_defines220/_defines220.dme b/modular_ss220/_defines220/_defines220.dme index 3c297f31f9fb..777827a0cb81 100644 --- a/modular_ss220/_defines220/_defines220.dme +++ b/modular_ss220/_defines220/_defines220.dme @@ -19,3 +19,4 @@ #include "code/emote.dm" #include "code/lists_TG.dm" #include "code/species.dm" +#include "code/preferences_defines.dm" diff --git a/modular_ss220/_defines220/code/preferences_defines.dm b/modular_ss220/_defines220/code/preferences_defines.dm new file mode 100644 index 000000000000..c31d30bd55db --- /dev/null +++ b/modular_ss220/_defines220/code/preferences_defines.dm @@ -0,0 +1,5 @@ +#define PREFTOGGLE_220_WATCH_CREDITS (1<<0) // 1 + +#define TOGGLES_220_TOTAL 1 // If you add or remove a preference toggle above, make sure you update this define with the total value of the toggles combined. + +#define TOGGLES_220_DEFAULT (PREFTOGGLE_220_WATCH_CREDITS) \ No newline at end of file diff --git a/modular_ss220/credits/_credits.dme b/modular_ss220/credits/_credits.dme index 0a02dfaf2f28..7d1b97946084 100644 --- a/modular_ss220/credits/_credits.dme +++ b/modular_ss220/credits/_credits.dme @@ -1,7 +1,6 @@ #include "code\SScredits.dm" #include "code\credits.dm" #include "code\admin_procs.dm" -#include "code\preferences.dm" #include "code\halloween_credits.dm" #include "code\new_year_credits.dm" #include "code\aprils_fool_credits.dm" diff --git a/modular_ss220/modular_ss220.dme b/modular_ss220/modular_ss220.dme index 53c82fc422f6..3a61d9ef6079 100644 --- a/modular_ss220/modular_ss220.dme +++ b/modular_ss220/modular_ss220.dme @@ -39,6 +39,7 @@ // --- MISC --- // #include "administration/_administration.dme" +#include "preferences/_preferences.dme" #include "aesthetics_sounds/_aesthetics_sounds.dme" #include "agent_id_tgui/_agent_id_tgui.dme" #include "balance/_balance.dme" diff --git a/modular_ss220/preferences/_preferences.dm b/modular_ss220/preferences/_preferences.dm new file mode 100644 index 000000000000..13404d8e8a5a --- /dev/null +++ b/modular_ss220/preferences/_preferences.dm @@ -0,0 +1,4 @@ +/datum/modpack/preferences + name = "Кастомные настройки" + desc = "Игровые настройки, разработанные для проекта" + author = "Maxiemar" diff --git a/modular_ss220/preferences/_preferences.dme b/modular_ss220/preferences/_preferences.dme new file mode 100644 index 000000000000..4a65419c8dd1 --- /dev/null +++ b/modular_ss220/preferences/_preferences.dme @@ -0,0 +1,4 @@ +#include "_preferences.dm" + +#include "code/preferences.dm" +#include "code/preferences_toggles.dm" diff --git a/modular_ss220/preferences/code/preferences.dm b/modular_ss220/preferences/code/preferences.dm new file mode 100644 index 000000000000..20e28ad4ca95 --- /dev/null +++ b/modular_ss220/preferences/code/preferences.dm @@ -0,0 +1,58 @@ +/datum/preferences + var/toggles220 = TOGGLES_220_DEFAULT + +/datum/preferences/load_preferences(datum/db_query/query) + . = ..() + if(!.) + return + + return load_custom_preferences() + +/datum/preferences/save_preferences(client/C) + . = ..() + if(!.) + return + + return save_custom_preferences() + +/datum/preference_toggle/set_toggles(client/user) + var/datum/preferences/our_prefs = user.prefs + switch(preftoggle_toggle) + if(PREFTOGGLE_TOGGLE220) + our_prefs.toggles220 ^= preftoggle_bitflag + to_chat(user, "[(our_prefs.toggles220 & preftoggle_bitflag) ? enable_message : disable_message]") + . = ..() + +/datum/preferences/proc/load_custom_preferences() + var/datum/db_query/preferences_query = SSdbcore.NewQuery({"SELECT + toggles + FROM player_220 + WHERE ckey=:ckey"}, list( + "ckey" = parent.ckey + )) + + if(!preferences_query.warn_execute()) + qdel(preferences_query) + return FALSE + + while(preferences_query.NextRow()) + toggles220 = preferences_query.item[1] + + toggles220 = sanitize_integer(toggles220, 0, TOGGLES_220_TOTAL, initial(toggles220)) + + qdel(preferences_query) + return TRUE + +/datum/preferences/proc/save_custom_preferences() + var/datum/db_query/query = SSdbcore.NewQuery({"UPDATE player_220 SET + toggles=:toggles + WHERE ckey=:ckey"}, list( + "toggles" = num2text(toggles220, CEILING(log(10, (TOGGLES_220_TOTAL)), 1)), + )) + + if(!query.warn_execute()) + qdel(query) + return FALSE + + qdel(query) + return TRUE diff --git a/modular_ss220/credits/code/preferences.dm b/modular_ss220/preferences/code/preferences_toggles.dm similarity index 100% rename from modular_ss220/credits/code/preferences.dm rename to modular_ss220/preferences/code/preferences_toggles.dm From de0029683c17f5d2d97b8cd56d41eb887d185e4a Mon Sep 17 00:00:00 2001 From: Mikhail Dzianishchyts Date: Tue, 20 Aug 2024 12:52:47 +0300 Subject: [PATCH 4/9] Fix invalid sql --- SQL/paradise_schema.sql | 4 ++-- SQL/updates220/59.220.6-59.220.7.sql | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SQL/paradise_schema.sql b/SQL/paradise_schema.sql index 3269fe1f17e2..28077b485b4d 100644 --- a/SQL/paradise_schema.sql +++ b/SQL/paradise_schema.sql @@ -718,6 +718,6 @@ ALTER TABLE `player` ADD `species_whitelist` LONGTEXT COLLATE utf8mb4_unicode_ci DROP TABLE IF EXISTS `player_220`; CREATE TABLE `player_220` ( `ckey` VARCHAR(64) NOT NULL COLLATE 'utf8mb4_general_ci', - `toggles_220` int(11) DEFAULT NULL - PRIMARY KEY (`ckey`) USING BTREE, + `toggles_220` int(11) DEFAULT NULL, + PRIMARY KEY (`ckey`) USING BTREE ) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB; diff --git a/SQL/updates220/59.220.6-59.220.7.sql b/SQL/updates220/59.220.6-59.220.7.sql index bc82815db3f4..b185fe153530 100644 --- a/SQL/updates220/59.220.6-59.220.7.sql +++ b/SQL/updates220/59.220.6-59.220.7.sql @@ -4,6 +4,6 @@ DROP TABLE IF EXISTS `player_220`; CREATE TABLE `player_220` ( `ckey` VARCHAR(64) NOT NULL COLLATE 'utf8mb4_general_ci', - `toggles_220` int(11) DEFAULT NULL - PRIMARY KEY (`ckey`) USING BTREE, + `toggles_220` int(11) DEFAULT NULL, + PRIMARY KEY (`ckey`) USING BTREE ) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB; \ No newline at end of file From 5c6d441fdc0291c0acbc796f27ab98c62c1ee2e5 Mon Sep 17 00:00:00 2001 From: Mikhail Dzianishchyts Date: Tue, 20 Aug 2024 12:55:01 +0300 Subject: [PATCH 5/9] Add missing line breaks --- SQL/updates220/59.220.6-59.220.7.sql | 2 +- modular_ss220/_defines220/code/preferences_defines.dm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SQL/updates220/59.220.6-59.220.7.sql b/SQL/updates220/59.220.6-59.220.7.sql index b185fe153530..6d44f5976dc4 100644 --- a/SQL/updates220/59.220.6-59.220.7.sql +++ b/SQL/updates220/59.220.6-59.220.7.sql @@ -6,4 +6,4 @@ CREATE TABLE `player_220` ( `ckey` VARCHAR(64) NOT NULL COLLATE 'utf8mb4_general_ci', `toggles_220` int(11) DEFAULT NULL, PRIMARY KEY (`ckey`) USING BTREE -) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB; \ No newline at end of file +) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB; diff --git a/modular_ss220/_defines220/code/preferences_defines.dm b/modular_ss220/_defines220/code/preferences_defines.dm index c31d30bd55db..fef827769a2b 100644 --- a/modular_ss220/_defines220/code/preferences_defines.dm +++ b/modular_ss220/_defines220/code/preferences_defines.dm @@ -2,4 +2,4 @@ #define TOGGLES_220_TOTAL 1 // If you add or remove a preference toggle above, make sure you update this define with the total value of the toggles combined. -#define TOGGLES_220_DEFAULT (PREFTOGGLE_220_WATCH_CREDITS) \ No newline at end of file +#define TOGGLES_220_DEFAULT (PREFTOGGLE_220_WATCH_CREDITS) From 5046551716ed35e820e36f265be8278addd5c78c Mon Sep 17 00:00:00 2001 From: Mikhail Dzianishchyts Date: Tue, 20 Aug 2024 14:28:04 +0300 Subject: [PATCH 6/9] Add missing parameter mapping --- modular_ss220/preferences/code/preferences.dm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modular_ss220/preferences/code/preferences.dm b/modular_ss220/preferences/code/preferences.dm index 20e28ad4ca95..cc4df2865aa0 100644 --- a/modular_ss220/preferences/code/preferences.dm +++ b/modular_ss220/preferences/code/preferences.dm @@ -13,7 +13,7 @@ if(!.) return - return save_custom_preferences() + return save_custom_preferences(C) /datum/preference_toggle/set_toggles(client/user) var/datum/preferences/our_prefs = user.prefs @@ -43,11 +43,12 @@ qdel(preferences_query) return TRUE -/datum/preferences/proc/save_custom_preferences() +/datum/preferences/proc/save_custom_preferences(client/C) var/datum/db_query/query = SSdbcore.NewQuery({"UPDATE player_220 SET toggles=:toggles WHERE ckey=:ckey"}, list( "toggles" = num2text(toggles220, CEILING(log(10, (TOGGLES_220_TOTAL)), 1)), + "ckey" = C.ckey, )) if(!query.warn_execute()) From e44b171df0989eae9f033445ccb66cc485ef7274 Mon Sep 17 00:00:00 2001 From: Mikhail Dzianishchyts Date: Tue, 20 Aug 2024 14:29:16 +0300 Subject: [PATCH 7/9] Add cascade operations and insert trigger --- SQL/paradise_schema.sql | 23 ++++++++++++++++++++--- SQL/updates220/59.220.6-59.220.7.sql | 23 ++++++++++++++++++++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/SQL/paradise_schema.sql b/SQL/paradise_schema.sql index 28077b485b4d..c45890847ceb 100644 --- a/SQL/paradise_schema.sql +++ b/SQL/paradise_schema.sql @@ -717,7 +717,24 @@ ALTER TABLE `player` ADD `species_whitelist` LONGTEXT COLLATE utf8mb4_unicode_ci DROP TABLE IF EXISTS `player_220`; CREATE TABLE `player_220` ( - `ckey` VARCHAR(64) NOT NULL COLLATE 'utf8mb4_general_ci', - `toggles_220` int(11) DEFAULT NULL, + `ckey` VARCHAR(32) NOT NULL COLLATE utf8mb4_unicode_ci, + `toggles` int(11) DEFAULT NULL, PRIMARY KEY (`ckey`) USING BTREE -) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB; +) COLLATE = utf8mb4_unicode_ci ENGINE = InnoDB; + +ALTER TABLE `player_220` +ADD CONSTRAINT `fk_player_220_ckey` +FOREIGN KEY (`ckey`) REFERENCES `player`(`ckey`) +ON DELETE CASCADE +ON UPDATE CASCADE; + +DELIMITER // +CREATE TRIGGER `player_insert` +AFTER INSERT ON `player` +FOR EACH ROW +BEGIN + INSERT INTO `player_220` (`ckey`) + VALUES (NEW.ckey); +END; +// +DELIMITER ; diff --git a/SQL/updates220/59.220.6-59.220.7.sql b/SQL/updates220/59.220.6-59.220.7.sql index 6d44f5976dc4..38547f9d6606 100644 --- a/SQL/updates220/59.220.6-59.220.7.sql +++ b/SQL/updates220/59.220.6-59.220.7.sql @@ -3,7 +3,24 @@ DROP TABLE IF EXISTS `player_220`; CREATE TABLE `player_220` ( - `ckey` VARCHAR(64) NOT NULL COLLATE 'utf8mb4_general_ci', - `toggles_220` int(11) DEFAULT NULL, + `ckey` VARCHAR(32) NOT NULL COLLATE utf8mb4_unicode_ci, + `toggles` int(11) DEFAULT NULL, PRIMARY KEY (`ckey`) USING BTREE -) COLLATE = 'utf8mb4_general_ci' ENGINE = InnoDB; +) COLLATE = utf8mb4_unicode_ci ENGINE = InnoDB; + +ALTER TABLE `player_220` +ADD CONSTRAINT `fk_player_220_ckey` +FOREIGN KEY (`ckey`) REFERENCES `player`(`ckey`) +ON DELETE CASCADE +ON UPDATE CASCADE; + +DELIMITER // +CREATE TRIGGER `player_insert` +AFTER INSERT ON `player` +FOR EACH ROW +BEGIN + INSERT INTO `player_220` (`ckey`) + VALUES (NEW.ckey); +END; +// +DELIMITER ; From 2d15de43841675b1f1e67baed57a5f8cd8dba190 Mon Sep 17 00:00:00 2001 From: Mikhail Dzianishchyts Date: Tue, 20 Aug 2024 14:45:59 +0300 Subject: [PATCH 8/9] Add migration insert query --- SQL/paradise_schema.sql | 1 + SQL/updates220/59.220.6-59.220.7.sql | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/SQL/paradise_schema.sql b/SQL/paradise_schema.sql index c45890847ceb..ed435e3be7f6 100644 --- a/SQL/paradise_schema.sql +++ b/SQL/paradise_schema.sql @@ -728,6 +728,7 @@ FOREIGN KEY (`ckey`) REFERENCES `player`(`ckey`) ON DELETE CASCADE ON UPDATE CASCADE; +DROP TRIGGER IF EXISTS `player_insert`; DELIMITER // CREATE TRIGGER `player_insert` AFTER INSERT ON `player` diff --git a/SQL/updates220/59.220.6-59.220.7.sql b/SQL/updates220/59.220.6-59.220.7.sql index 38547f9d6606..12a4f9a529ec 100644 --- a/SQL/updates220/59.220.6-59.220.7.sql +++ b/SQL/updates220/59.220.6-59.220.7.sql @@ -14,6 +14,7 @@ FOREIGN KEY (`ckey`) REFERENCES `player`(`ckey`) ON DELETE CASCADE ON UPDATE CASCADE; +DROP TRIGGER IF EXISTS `player_insert`; DELIMITER // CREATE TRIGGER `player_insert` AFTER INSERT ON `player` @@ -24,3 +25,7 @@ BEGIN END; // DELIMITER ; + +INSERT INTO `player_220` (`ckey`) +SELECT `ckey` +FROM `player`; From 73d015ee25a2e667fc2d69fd15b308056cc82eb8 Mon Sep 17 00:00:00 2001 From: Mikhail Dzianishchyts Date: Tue, 20 Aug 2024 17:16:33 +0300 Subject: [PATCH 9/9] Remove updating of admin verbs --- modular_ss220/credits/_credits.dm | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modular_ss220/credits/_credits.dm b/modular_ss220/credits/_credits.dm index 7104b4180fda..ddace1d105dc 100644 --- a/modular_ss220/credits/_credits.dm +++ b/modular_ss220/credits/_credits.dm @@ -7,8 +7,3 @@ GLOB.admin_verbs_admin += list( /client/proc/toggle_credits ) - // Update verbs for admins who connected before subsystem initialization. - for(var/client/player in GLOB.clients) - if(!player.holder) - continue - player.add_admin_verbs()