Vetted System conversion to SQL (#2075)

<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request

This PR will convert the vetted system to SQL. It will populate the with
entries from the old config file, and then that file can be safely
removed after it is imported. Also adds three verbs, one to force a
conversion, one to add, and one to remove a ckey from the database. The
admin who adds a user is record in the DB.

<!-- Please make sure to actually test your PRs. If you have not tested
your PR mention it. -->

## Why It's Good For The Game

<!-- Argue for the merits of your changes and how they benefit the game,
especially if they are controversial and/or far reaching. If you can't
actually explain WHY what you are doing will improve the game, then it
probably isn't good for the game in the first place. -->

## Proof Of Testing

![heidisql_086ihiIsfK](https://github.com/user-attachments/assets/b3f75490-b709-4c7f-883c-13c9c59ac9b1)

<!-- Compile and run your code locally. Make sure it works. This is the
place to show off your changes! We are not responsible for testing your
features. -->

## Changelog

<!-- If your PR modifies aspects of the game that can be concretely
observed by players or admins you should add a changelog. If your change
does NOT meet this description, remove this section. Be sure to properly
mark your PRs to prevent unnecessary GBP loss. You can read up on GBP
and its effects on PRs in the tgstation guides for contributors. Please
note that maintainers freely reserve the right to remove and add tags
should they deem it appropriate. You can attempt to finagle the system
all you want, but it's best to shoot for clear communication right off
the bat. -->

🆑
refactor: Vetted system is now using SQL and improved. 
/🆑

<!-- Both 🆑's are required for the changelog to work! You can put
your name to the right of the first 🆑 if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->

<!-- By opening a pull request. You have read and understood the
repository rules located on the main README.md on this project. -->

---------

Co-authored-by: The Sharkening <95130227+StrangeWeirdKitten@users.noreply.github.com>
This commit is contained in:
nevimer
2024-10-04 07:16:32 -04:00
committed by GitHub
parent 24fcf885e5
commit 37f2e97a3c
4 changed files with 86 additions and 18 deletions

View File

@@ -22,3 +22,14 @@ CREATE TABLE `jobexempt` (
PRIMARY KEY (`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
DROP TABLE IF EXISTS `vetted_list`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `vetted_list` (
`ckey` varchar(32) NOT NULL,
`admin_who_added` VARCHAR(32) DEFAULT NULL,
PRIMARY KEY (`ckey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

View File

@@ -2,10 +2,10 @@ Any time you make a change to the schema files, remember to increment the databa
Make sure to also update `DB_MAJOR_VERSION` and `DB_MINOR_VERSION`, which can be found in `code/__DEFINES/subsystem.dm`.
The latest database version is 5.30 (5.27 for /tg/); The query to update the schema revision table is:
The latest database version is 5.31 (for bubberstation, 5.30 for skyrat) (5.27 for /tg/); The query to update the schema revision table is:
```sql
INSERT INTO `schema_revision` (`major`, `minor`) VALUES (5, 30);
INSERT INTO `schema_revision` (`major`, `minor`) VALUES (5, 31);
```
or

View File

@@ -20,7 +20,7 @@
*
* make sure you add an update to the schema_version stable in the db changelog
*/
#define DB_MINOR_VERSION 30
#define DB_MINOR_VERSION 31 // BUBBER EDIT
//! ## Timing subsystem

View File

@@ -1,11 +1,14 @@
GLOBAL_LIST_EMPTY(vetted_list_legacy)
GLOBAL_PROTECT(vetted_list_legacy)
GLOBAL_LIST_EMPTY(vetted_list)
GLOBAL_PROTECT(vetted_list)
/datum/controller/subsystem/player_ranks
var/loaded_vetted_sql = FALSE
/datum/player_rank_controller/vetted
rank_title = "vetted user"
var/file_path_vetted
/datum/controller/subsystem/player_ranks/proc/is_vetted(client/user, admin_bypass = TRUE)
if(!istype(user))
CRASH("Invalid user type provided to is_vetted(), expected 'client' and obtained '[user ? user.type : "null"]'.")
@@ -24,12 +27,14 @@ GLOBAL_PROTECT(vetted_list)
/datum/controller/subsystem/player_ranks/proc/load_vetted_ckeys()
PROTECTED_PROC(TRUE)
if(loaded_vetted_sql)
return
if(IsAdminAdvancedProcCall())
return
vetted_controller = new
vetted_controller.file_path_vetted = "[global.config.directory]/bubbers/vetted_players.txt"
ASYNC
for(var/line in world.file2list(vetted_controller.file_path_vetted))
if(!line)
continue
@@ -37,20 +42,72 @@ GLOBAL_PROTECT(vetted_list)
if(findtextEx(line, "#", 1, 2))
continue
vetted_controller.add_player(line)
vetted_controller.add_player(line, legacy = TRUE)
world.log << "Added [line] to vetted list."
var/datum/db_query/query_load_player_rank = SSdbcore.NewQuery("SELECT * FROM vetted_list")
if(!query_load_player_rank.warn_execute())
return
while(query_load_player_rank.NextRow())
var/ckey = ckey(query_load_player_rank.item[1])
vetted_controller.add_player(ckey)
world.log << "Added [ckey] to vetted list."
loaded_vetted_sql = TRUE
return TRUE
/datum/player_rank_controller/vetted/add_player(ckey)
if(IsAdminAdvancedProcCall())
return
/datum/player_rank_controller/vetted/proc/convert_all_to_sql()
if(!SSdbcore.Connect())
return message_admins("Failed to connect to database. Unable to complete flat file to SQL conversion.")
for(var/ckey_ in GLOB.vetted_list_legacy)
add_player_to_sql(ckey_)
/datum/player_rank_controller/vetted/proc/add_player_to_sql(ckey, admin_mob)
var/ckey_admin = "Conversion Script"
var/mob/admin_who_added_client = admin_mob
if(istype(admin_who_added_client, /mob) && admin_who_added_client.client)
ckey_admin = admin_who_added_client?.client?.ckey
var/datum/db_query/query_add_player_rank = SSdbcore.NewQuery(
"INSERT INTO vetted_list (ckey, admin_who_added) VALUES(:ckey, :admin_who_added) \
ON DUPLICATE KEY UPDATE admin_who_added = :admin_who_added",
list("ckey" = ckey, "admin_who_added" = ckey_admin),
)
if(!query_add_player_rank.warn_execute())
return FALSE
/datum/player_rank_controller/vetted/add_player(ckey, legacy, admin)
ckey = ckey(ckey)
if(legacy)
GLOB.vetted_list_legacy[ckey] = TRUE
GLOB.vetted_list[ckey] = TRUE
add_player_to_sql(ckey, admin)
/datum/player_rank_controller/vetted/remove_player(ckey)
if(IsAdminAdvancedProcCall())
return
GLOB.vetted_list -= ckey
remove_player_from_sql(ckey)
/datum/player_rank_controller/vetted/proc/remove_player_from_sql(ckey)
var/datum/db_query/query_remove_player_vetted = SSdbcore.NewQuery(
"DELETE FROM vetted_list WHERE ckey = :ckey",
list("ckey" = ckey),
)
if(!query_remove_player_vetted.warn_execute())
return FALSE
ADMIN_VERB(convert_flatfile_vettedlist_to_sql, R_DEBUG, "Convert Vetted list to SQL", "Warning! Might be slow!", ADMIN_CATEGORY_DEBUG)
var/consent = tgui_input_list(usr, "Do you want to convert the vetted list to SQL?", "UH OH", list("Yes", "No"), "No")
if(consent == "Yes")
SSplayer_ranks.vetted_controller.convert_all_to_sql()
message_admins("[usr] has forcefully converted the vetted list file to SQL.")
ADMIN_VERB(add_vetted, R_ADMIN, "Add user to Vetted", "Adds a user to the vetted list", ADMIN_CATEGORY_MAIN)
var/user_adding = tgui_input_text(usr, "Whom is being added?", "Vetted List")
if(length(user_adding))
SSplayer_ranks.vetted_controller.add_player(ckey = user_adding, admin = usr)
message_admins("[usr] has added [user_adding] to the vetted database.")
ADMIN_VERB(remove_vetted, R_ADMIN, "Remove user from Vetted", "Removes a user from the vetted list", ADMIN_CATEGORY_MAIN)
var/user_del = tgui_input_text(usr, "Whom is being Removed?", "Vetted List")
if(length(user_del))
SSplayer_ranks.vetted_controller.remove_player(ckey = user_del)
message_admins("[usr] has removed [user_del] from the vetted databse.")