Updated the command systems to automatically add new commands and remove orphaned entries from the command settings tables

This commit is contained in:
Uleat
2019-08-30 06:38:48 -04:00
parent f837d423ef
commit d341a1b38f
9 changed files with 240 additions and 15 deletions
+32
View File
@@ -18,6 +18,7 @@
#include <iostream>
#include <cstring>
#include <fmt/format.h>
#if defined(_MSC_VER) && _MSC_VER >= 1800
#include <algorithm>
@@ -1469,6 +1470,37 @@ bool SharedDatabase::GetCommandSettings(std::map<std::string, std::pair<uint8, s
return true;
}
bool SharedDatabase::UpdateCommandSettings(const std::vector<std::pair<std::string, uint8>> &injected, const std::vector<std::string> &orphaned)
{
bool return_value = true;
if (injected.size()) {
std::string query = fmt::format(
"REPLACE INTO `command_settings`(`command`, `access`) VALUES {}",
implode(",", string_string("(", ")"), join_pair(string_string(), ",", string_string("'", "'"), injected))
);
if (!QueryDatabase(query).Success()) {
return_value = false;
}
}
if (orphaned.size()) {
std::string query = fmt::format(
"DELETE FROM `command_settings` WHERE `command` IN ({})",
implode(",", string_string("'", "'"), orphaned)
);
if (!QueryDatabase(query).Success()) {
return_value = false;
}
}
return return_value;
}
bool SharedDatabase::LoadSkillCaps(const std::string &prefix) {
skill_caps_mmf.reset(nullptr);