Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bandastation db #94

Merged
merged 5 commits into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions SQL/bandastation/bandastation_update.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--
-- Table structure for table `schema_revision_220`
--
DROP TABLE IF EXISTS `schema_revision_220`;
CREATE TABLE `schema_revision_220` (
`major` TINYINT(3) unsigned NOT NULL,
`minor` TINYINT(3) unsigned NOT NULL,
`date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`major`, `minor`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

--
-- Table structure for table `ckey_whitelist`
--
DROP TABLE IF EXISTS `ckey_whitelist`;
CREATE TABLE `ckey_whitelist` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`date` DATETIME DEFAULT now() NOT NULL,
`ckey` VARCHAR(32) NOT NULL,
`adminwho` VARCHAR(32) NOT NULL,
`port` INT(5) UNSIGNED NOT NULL,
`date_start` DATETIME DEFAULT now() NOT NULL,
`date_end` DATETIME NULL,
`is_valid` BOOLEAN DEFAULT true NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Table structure for table `admin_wl`
--
DROP TABLE IF EXISTS `admin_wl`;
CREATE TABLE `admin_wl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ckey` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`admin_rank` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Administrator',
`level` int(2) NOT NULL DEFAULT '0',
`flags` int(16) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `ckey` (`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
54 changes: 54 additions & 0 deletions SQL/bandastation/database_changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Any time you make a change to the schema files, remember to increment the database schema version. Generally increment the minor number, major should be reserved for significant changes to the schema. Both values go up to 255.

Make sure to also update `DB_MAJOR_VERSION_220` and `DB_MINOR_VERSION_220`, which can be found in `code/modular_bandastation/_defines220/code/defines/subsystems.dm`.

The latest database version is 1.1; The query to update the schema revision table is:

```sql
INSERT INTO `schema_revision_220` (`major`, `minor`) VALUES (1, 1);
```
or

```sql
INSERT INTO `SS13_schema_revision_220` (`major`, `minor`) VALUES (1, 1);
```

-----------------------------------------------------
Version 1.1, 17 April 2024, by larentoun
Created the tables: schema_revision220, ckey_whitelist, admin_wl

```sql
CREATE TABLE `schema_revision220` (
`major` TINYINT(3) unsigned NOT NULL,
`minor` TINYINT(3) unsigned NOT NULL,
`date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`major`, `minor`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
```

```sql
CREATE TABLE `ckey_whitelist` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`date` DATETIME DEFAULT now() NOT NULL,
`ckey` VARCHAR(32) NOT NULL,
`adminwho` VARCHAR(32) NOT NULL,
`port` INT(5) UNSIGNED NOT NULL,
`date_start` DATETIME DEFAULT now() NOT NULL,
`date_end` DATETIME NULL,
`is_valid` BOOLEAN DEFAULT true NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```

```sql
CREATE TABLE `admin_wl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ckey` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL,
`admin_rank` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'Administrator',
`level` int(2) NOT NULL DEFAULT '0',
`flags` int(16) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
KEY `ckey` (`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```
-----------------------------------------------------
2 changes: 2 additions & 0 deletions config/bandastation/bandastation_config.txt
Original file line number Diff line number Diff line change
@@ -3,3 +3,5 @@
#TTS_ENABLED
#TTS_CACHE_ENABLED
#TTS_API_URL_SILERO

#WHITELIST220
1 change: 1 addition & 0 deletions modular_bandastation/_defines220/_defines220.dme
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
#include "code/defines/keybindings.dm"
#include "code/defines/misc.dm"
#include "code/defines/spans.dm"
#include "code/defines/subsystems.dm"
#include "code/defines/text_to_speech.dm"
#include "code/signals_mob/signals_mob_ai.dm"
#include "code/signals_mob/signals_mob_carbon.dm"
18 changes: 18 additions & 0 deletions modular_bandastation/_defines220/code/defines/subsystems.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! ## DB defines
/**
* DB major schema version for BANDASTATION
*
* Update this whenever the db schema changes
*
* make sure you add an update to the schema_version stable in the db changelog
*/
#define DB_MAJOR_VERSION_220 1

/**
* DB minor schema version for BANDASTATION
*
* Update this whenever the db schema changes
*
* make sure you add an update to the schema_version stable in the db changelog
*/
#define DB_MINOR_VERSION_220 1
4 changes: 4 additions & 0 deletions modular_bandastation/database220/_database220.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/datum/modpack/database220
name = "Database220"
desc = "Поддержка дополнительных таблиц для базы данных"
author = "larentoun, furior"
3 changes: 3 additions & 0 deletions modular_bandastation/database220/_database220.dme
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "_database220.dm"

#include "code/database220.dm"
28 changes: 28 additions & 0 deletions modular_bandastation/database220/code/database220.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/datum/controller/subsystem/dbcore
var/db_major_220 = 0
var/db_minor_220 = 0
var/schema_mismatch_220 = 0

/datum/controller/subsystem/dbcore/Initialize()
. = ..()
switch(schema_mismatch_220)
if(1)
message_admins("Database schema for BANDASTATION ([db_major_220].[db_minor_220]) doesn't match the latest schema version ([DB_MAJOR_VERSION_220].[DB_MINOR_VERSION_220]), this may lead to undefined behaviour or errors")
if(2)
message_admins("Could not get schema version for BANDASTATION from database")

/datum/controller/subsystem/dbcore/CheckSchemaVersion()
. = ..()
if(CONFIG_GET(flag/sql_enabled) && IsConnected())
var/datum/db_query/query_db_version = NewQuery("SELECT major, minor FROM [format_table_name("schema_revision_220")] ORDER BY date DESC LIMIT 1")
query_db_version.Execute()
if(query_db_version.NextRow())
db_major_220 = text2num(query_db_version.item[1])
db_minor_220 = text2num(query_db_version.item[2])
if(db_major_220 != DB_MAJOR_VERSION_220 || db_minor_220 != DB_MINOR_VERSION_220)
schema_mismatch_220 = 1 // flag admin message about mismatch
log_sql("Database schema for BANDASTATION ([db_major_220].[db_minor_220]) doesn't match the latest schema version ([DB_MAJOR_VERSION_220].[DB_MINOR_VERSION_220]), this may lead to undefined behaviour or errors")
else
schema_mismatch_220 = 2 //flag admin message about no schema version
log_sql("Could not get schema version for BANDASTATION from database")
qdel(query_db_version)
2 changes: 2 additions & 0 deletions modular_bandastation/modular_bandastation.dme
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@
#include "communication/_communication.dme"
//#include "crawl_speed/_crawl_speed.dme" // Fixing floored melee brawl, or first steps to remove RP speed
#include "cyrillic_fixes/_cyrillic_fixes.dme"
#include "database220/_database220.dme"
#include "discord/_discord.dme"
//#include "emote_panel/_emote_panel.dme" // Waiting for upstream merge
//#include "events/_events.dme" // Going for pure TG right now...
@@ -20,4 +21,5 @@
#include "pixel_shift/_pixel_shift.dme"
#include "translations/_translations.dme"
#include "tts/_tts.dme"
#include "whitelist220/_whitelist220.dme"
#include "world_topics/_world_topics.dme"
7 changes: 7 additions & 0 deletions modular_bandastation/whitelist220/_whitelist220.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/datum/modpack/whitelist220
name = "Whitelist220"
desc = "Использование вайтлиста через БД"
author = "larentoun"

/datum/modpack/whitelist220/pre_initialize()
GLOB.admin_verbs_server |= /client/proc/update_whitelist
3 changes: 3 additions & 0 deletions modular_bandastation/whitelist220/_whitelist220.dme
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "_whitelist220.dm"

#include "code/whitelist220.dm"
75 changes: 75 additions & 0 deletions modular_bandastation/whitelist220/code/whitelist220.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/datum/config_entry/flag/whitelist220
default = FALSE
protection = CONFIG_ENTRY_LOCKED

/datum/controller/configuration/Load(_directory)
. = ..()
if(CONFIG_GET(flag/whitelist220))
load_whitelist220()

/world/IsBanned(key, address, computer_id, type, real_bans_only)
. = ..()
if(.)
return .
if(!CONFIG_GET(flag/whitelist220))
return null
var/ckey = ckey(key)
if(ckey && !(ckey in GLOB.whitelist))
return list("reason"="whitelist", "desc"="\nПричина: Вас ([key]) нет в вайтлисте этого сервера. Приобрести доступ возможно у одного из стримеров Банды за баллы канала или записаться самостоятельно с помощью команды в дискорде, доступной сабам бусти, начиная со второго тира.")

/client/proc/update_whitelist()
set name = "Update whitelist"
set category = "Server"

if(!check_rights(R_SERVER))
return

load_whitelist220()

/proc/load_whitelist220()
if(IsAdminAdvancedProcCall())
to_chat(usr, span_boldannounce("Whitelist reload blocked: Advanced ProcCall detected"))
return

if(!SSdbcore.IsConnected())
return

GLOB.whitelist = list()

var/datum/db_query/whitelist_query = SSdbcore.NewQuery({"
SELECT ckey FROM ckey_whitelist WHERE
is_valid=1 AND port=:port AND date_start<=NOW() AND
(NOW()<date_end OR date_end IS NULL)
"}, list("port" = "[world.port]"))
if(!whitelist_query.warn_execute())
qdel(whitelist_query)
return

while(whitelist_query.NextRow())
var/ckey = whitelist_query.item[1]
GLOB.whitelist |= ckey

qdel(whitelist_query)

/mob/new_player/Login()
if(CONFIG_GET(flag/whitelist220) && !(ckey in GLOB.whitelist))
check_whitelist220()
. = ..()

/mob/new_player/proc/check_whitelist220()
if(!SSdbcore.IsConnected())
return
var/datum/db_query/whitelist_query = SSdbcore.NewQuery({"
SELECT ckey FROM ckey_whitelist WHERE ckey=:ckey AND
is_valid=1 AND port=:port AND date_start<=NOW() AND
(NOW()<date_end OR date_end IS NULL)
"}, list("ckey" = ckey, "port" = "[world.port]"))
if(!whitelist_query.warn_execute())
qdel(whitelist_query)
return

while(whitelist_query.NextRow())
var/ckey = whitelist_query.item[1]
GLOB.whitelist |= ckey

qdel(whitelist_query)

Unchanged files with check annotations Beta

#pragma SoftReservedKeyword error
#pragma DuplicateVariable error
#pragma DuplicateProcDefinition error
#pragma TooManyArguments error

Check warning on line 15 in tools/ci/od_lints.dm

GitHub Actions / Run Linters

tools/ci/od_lints.dm#L15

OD1002: Warning 'TooManyArguments' does not exist
#pragma PointlessParentCall error
#pragma PointlessBuiltinCall error
#pragma SuspiciousMatrixCall error
continue
message_strings += "This subsystem is marked as SS_OK_TO_FAIL_INIT. This is still a bug, but it is non-blocking."
TEST_NOTICE(src, jointext(message_strings, "\n"))

Check notice on line 22 in code/modules/unit_tests/subsystem_init.dm

GitHub Actions / Integration Tests (birdshot) / run_integration_tests

Birdshot Station: /datum/unit_test/subsystem_init

Lua Scripting (/datum/controller/subsystem/lua) is a subsystem meant to initialize but could not get initialized. The subsystem reported the following: Error initializing SSlua: FAILED (Couldn't find call_proc_by_id) This subsystem is marked as SS_OK_TO_FAIL_INIT. This is still a bug, but it is non-blocking.

Check notice on line 22 in code/modules/unit_tests/subsystem_init.dm

GitHub Actions / Integration Tests (gateway_test) / run_integration_tests

Gateway Test: /datum/unit_test/subsystem_init

Lua Scripting (/datum/controller/subsystem/lua) is a subsystem meant to initialize but could not get initialized. The subsystem reported the following: Error initializing SSlua: FAILED (Couldn't find call_proc_by_id) This subsystem is marked as SS_OK_TO_FAIL_INIT. This is still a bug, but it is non-blocking.

Check notice on line 22 in code/modules/unit_tests/subsystem_init.dm

GitHub Actions / Integration Tests (icebox) / run_integration_tests

Ice Box Station: /datum/unit_test/subsystem_init

Lua Scripting (/datum/controller/subsystem/lua) is a subsystem meant to initialize but could not get initialized. The subsystem reported the following: Error initializing SSlua: FAILED (Couldn't find call_proc_by_id) This subsystem is marked as SS_OK_TO_FAIL_INIT. This is still a bug, but it is non-blocking.

Check notice on line 22 in code/modules/unit_tests/subsystem_init.dm

GitHub Actions / Integration Tests (deltastation) / run_integration_tests

Delta Station: /datum/unit_test/subsystem_init

Lua Scripting (/datum/controller/subsystem/lua) is a subsystem meant to initialize but could not get initialized. The subsystem reported the following: Error initializing SSlua: FAILED (Couldn't find call_proc_by_id) This subsystem is marked as SS_OK_TO_FAIL_INIT. This is still a bug, but it is non-blocking.

Check notice on line 22 in code/modules/unit_tests/subsystem_init.dm

GitHub Actions / Integration Tests (metastation) / run_integration_tests

MetaStation: /datum/unit_test/subsystem_init

Lua Scripting (/datum/controller/subsystem/lua) is a subsystem meant to initialize but could not get initialized. The subsystem reported the following: Error initializing SSlua: FAILED (Couldn't find call_proc_by_id) This subsystem is marked as SS_OK_TO_FAIL_INIT. This is still a bug, but it is non-blocking.

Check notice on line 22 in code/modules/unit_tests/subsystem_init.dm

GitHub Actions / Integration Tests (multiz_debug) / run_integration_tests

MultiZ Debug: /datum/unit_test/subsystem_init

Lua Scripting (/datum/controller/subsystem/lua) is a subsystem meant to initialize but could not get initialized. The subsystem reported the following: Error initializing SSlua: FAILED (Couldn't find call_proc_by_id) This subsystem is marked as SS_OK_TO_FAIL_INIT. This is still a bug, but it is non-blocking.

Check notice on line 22 in code/modules/unit_tests/subsystem_init.dm

GitHub Actions / Integration Tests (northstar) / run_integration_tests

NorthStar: /datum/unit_test/subsystem_init

Lua Scripting (/datum/controller/subsystem/lua) is a subsystem meant to initialize but could not get initialized. The subsystem reported the following: Error initializing SSlua: FAILED (Couldn't find call_proc_by_id) This subsystem is marked as SS_OK_TO_FAIL_INIT. This is still a bug, but it is non-blocking.

Check notice on line 22 in code/modules/unit_tests/subsystem_init.dm

GitHub Actions / Integration Tests (runtimestation) / run_integration_tests

Runtime Station: /datum/unit_test/subsystem_init

Lua Scripting (/datum/controller/subsystem/lua) is a subsystem meant to initialize but could not get initialized. The subsystem reported the following: Error initializing SSlua: FAILED (Couldn't find call_proc_by_id) This subsystem is marked as SS_OK_TO_FAIL_INIT. This is still a bug, but it is non-blocking.

Check notice on line 22 in code/modules/unit_tests/subsystem_init.dm

GitHub Actions / Integration Tests (tramstation) / run_integration_tests

Tramstation: /datum/unit_test/subsystem_init

Lua Scripting (/datum/controller/subsystem/lua) is a subsystem meant to initialize but could not get initialized. The subsystem reported the following: Error initializing SSlua: FAILED (Couldn't find call_proc_by_id) This subsystem is marked as SS_OK_TO_FAIL_INIT. This is still a bug, but it is non-blocking.

Check notice on line 22 in code/modules/unit_tests/subsystem_init.dm

GitHub Actions / Alternate Tests (515, 1627, runtimestation) / run_integration_tests

Runtime Station: /datum/unit_test/subsystem_init

Lua Scripting (/datum/controller/subsystem/lua) is a subsystem meant to initialize but could not get initialized. The subsystem reported the following: Error initializing SSlua: FAILED (Couldn't find call_proc_by_id) This subsystem is marked as SS_OK_TO_FAIL_INIT. This is still a bug, but it is non-blocking.