From a16bd833f2da0ce7f7bf613f3f1131a89921ed37 Mon Sep 17 00:00:00 2001 From: Selis Date: Thu, 15 Jun 2023 21:32:13 +0200 Subject: [PATCH] Adding DB Capability for Mentors --- SQL/DBSchema.sql | 9 +++++++++ code/game/world.dm | 18 ++++++++++++++++++ code/modules/mentor/mentor.dm | 14 +++++++++++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/SQL/DBSchema.sql b/SQL/DBSchema.sql index 597873757a..8e66782b8e 100644 --- a/SQL/DBSchema.sql +++ b/SQL/DBSchema.sql @@ -289,6 +289,15 @@ CREATE TABLE IF NOT EXISTS `vr_player_hours` ( -- Data exporting was unselected. +-- CHOMPedit Start - Mentors Database Table +CREATE TABLE IF NOT EXISTS `erro_mentor` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `ckey` varchar(32) NOT NULL, + `mentor` int(16) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB AUTO_INCREMENT=35 DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT; +-- CHOMPedit End + /*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */; /*!40014 SET FOREIGN_KEY_CHECKS=IF(@OLD_FOREIGN_KEY_CHECKS IS NULL, 1, @OLD_FOREIGN_KEY_CHECKS) */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; diff --git a/code/game/world.dm b/code/game/world.dm index b204bc94fa..53a280e1d3 100644 --- a/code/game/world.dm +++ b/code/game/world.dm @@ -520,6 +520,24 @@ var/world_topic_spam_protect_time = world.timeofday var/ckey = copytext(line, 1, length(line)+1) var/datum/mentor/M = new /datum/mentor(ckey) M.associate(GLOB.directory[ckey]) + else // CHOMPedit Start - Implementing loading mentors from database + establish_db_connection() + if(!SSdbcore.IsConnected()) + error("Failed to connect to database in load_mentors().") + log_misc("Failed to connect to database in load_mentors().") + return + + var/DBQuery/query = SSdbcore.NewQuery("SELECT ckey, mentor FROM erro_mentor") //CHOMPEdit TGSQL + query.Execute() + while(query.NextRow()) + var/ckey = query.item[1] + var/mentor = query.item[2] + + if(mentor) + var/datum/mentor/M = new /datum/mentor(ckey) + M.associate(GLOB.directory[ckey]) + qdel(query) + // COMPedit End /world/proc/update_status() var/s = "" diff --git a/code/modules/mentor/mentor.dm b/code/modules/mentor/mentor.dm index 28f4225485..acbc796ac1 100644 --- a/code/modules/mentor/mentor.dm +++ b/code/modules/mentor/mentor.dm @@ -64,6 +64,13 @@ var/list/mentor_verbs_default = list( to_chat(src, "You have made [C] a mentor.") log_admin("[key_name(src)] made [key_name(C)] a mentor.") feedback_add_details("admin_verb","Make Mentor") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! + // CHOMPedit Start - Adding to DB Logic + var/result = tgui_alert(src, "Do you want to add this person into the mentor database? This will allow them to be a mentor in future rounds too.", "Add to Database", list("Yes", "No")) + if(result == "Yes") + var/DBQuery/query = SSdbcore.NewQuery("INSERT INTO erro_mentor (ckey, mentor) VALUES (:ckey, :mentor)", list("ckey" = C.ckey, "mentor" = 1)) + query.Execute() + qdel(query) + // CHOMPedit End /client/proc/unmake_mentor() set category = "Special Verbs" @@ -83,6 +90,11 @@ var/list/mentor_verbs_default = list( to_chat(src, "You have revoked [C]'s mentorship.") log_admin("[key_name(src)] revoked [key_name(C)]'s mentorship.") feedback_add_details("admin_verb","Unmake Mentor") //If you are copy-pasting this, ensure the 2nd parameter is unique to the new proc! + // CHOMPedit Start - Removing from DB Logic + var/DBQuery/query = SSdbcore.NewQuery("DELETE FROM erro_mentor WHERE ckey = :ckey", list("ckey" = C.ckey)) + query.Execute() + qdel(query) + // CHOMPedit End /client/proc/cmd_mentor_say(msg as text) set category = "Admin" @@ -260,4 +272,4 @@ var/list/mentor_verbs_default = list( to_chat(C, interaction_message) for(var/client/C in GLOB.admins) if (C != recipient && C != src) - to_chat(C, interaction_message) \ No newline at end of file + to_chat(C, interaction_message)