mirror of
https://github.com/EQEmu/Server.git
synced 2026-09-04 14:36:37 +00:00
Updated the command systems to automatically add new commands and remove orphaned entries from the command settings tables
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ class SharedDatabase : public Database
|
||||
void LoadCharacterInspectMessage(uint32 character_id, InspectMessage_Struct* message);
|
||||
void SaveCharacterInspectMessage(uint32 character_id, const InspectMessage_Struct* message);
|
||||
bool GetCommandSettings(std::map<std::string, std::pair<uint8, std::vector<std::string>>> &command_settings);
|
||||
bool UpdateCommandSettings(const std::vector<std::pair<std::string, uint8>> &injected, const std::vector<std::string> &orphaned);
|
||||
uint32 GetTotalTimeEntitledOnAccount(uint32 AccountID);
|
||||
void SetMailKey(int CharID, int IPAddress, int MailKey);
|
||||
std::string GetMailKey(int CharID, bool key_only = false);
|
||||
|
||||
+49
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "string_util.h"
|
||||
#include <algorithm>
|
||||
#include <fmt/format.h>
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <windows.h>
|
||||
@@ -144,6 +145,53 @@ std::string implode(std::string glue, std::vector<std::string> src)
|
||||
return final_output;
|
||||
}
|
||||
|
||||
std::string implode(std::string glue, string_string encapsulation, std::vector<std::string> src)
|
||||
{
|
||||
if (src.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::ostringstream output;
|
||||
std::vector<std::string>::iterator src_iter;
|
||||
|
||||
for (src_iter = src.begin(); src_iter != src.end(); src_iter++) {
|
||||
output << encapsulation.first << *src_iter << encapsulation.second << glue;
|
||||
}
|
||||
|
||||
std::string final_output = output.str();
|
||||
final_output.resize(output.str().size() - glue.size());
|
||||
|
||||
return final_output;
|
||||
}
|
||||
|
||||
std::vector<std::string> join_pair(string_string outer_encap, std::string joiner, string_string inner_encap, std::vector<std::pair<std::string, uint8>> src)
|
||||
{
|
||||
if (src.empty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<std::string> output;
|
||||
|
||||
for (auto src_iter : src) {
|
||||
output.push_back(
|
||||
fmt::format(
|
||||
"{}{}{}{}{}{}{}{}{}",
|
||||
outer_encap.first,
|
||||
inner_encap.first,
|
||||
src_iter.first,
|
||||
inner_encap.second,
|
||||
joiner,
|
||||
inner_encap.first,
|
||||
src_iter.second,
|
||||
inner_encap.second,
|
||||
outer_encap.second
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
std::string EscapeString(const std::string &s) {
|
||||
std::string ret;
|
||||
|
||||
@@ -514,4 +562,4 @@ bool isAlphaNumeric(const char *text)
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,10 @@ std::vector<std::string> split(std::string str_to_split, char delimiter);
|
||||
const std::string StringFormat(const char* format, ...);
|
||||
const std::string vStringFormat(const char* format, va_list args);
|
||||
std::string implode(std::string glue, std::vector<std::string> src);
|
||||
typedef std::pair<std::string, std::string> string_string;
|
||||
std::string implode(std::string glue, string_string encapsulation, std::vector<std::string> src);
|
||||
// wanted to make 'join_pair' a template function..this will do for now
|
||||
std::vector<std::string> join_pair(string_string outer_encap, std::string joiner, string_string inner_encap, std::vector<std::pair<std::string, uint8>> src);
|
||||
std::vector<std::string> SplitString(const std::string &s, char delim);
|
||||
std::string EscapeString(const char *src, size_t sz);
|
||||
std::string EscapeString(const std::string &s);
|
||||
|
||||
Reference in New Issue
Block a user