[CLI] Add mercs:enable and mercs:disable commands (#3416)

* [CLI] Add `mercs:enable` and `mercs:disable` commands

* Update descriptions
This commit is contained in:
Chris Miles 2023-06-17 19:30:36 -05:00 committed by GitHub
parent cf49b2fe49
commit a663c822e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 7136 additions and 0 deletions

View File

@ -2447,6 +2447,9 @@ void Database::SourceSqlFromUrl(std::string url)
return;
}
}
if (res->status == 404) {
LogError("Error retrieving URL [{}]", url);
}
}
else {
LogError("Error retrieving URL [{}]", url);

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
#include "../worlddb.h"
#include "../../common/database_schema.h"
void WorldserverCLI::MercsDisable(int argc, char **argv, argh::parser &cmd, std::string &description)
{
description = "Disables mercenaries";
if (cmd[{"-h", "--help"}]) {
return;
}
std::string input;
std::cout << "Warning! This will drop all merc tables, are you sure? [y/n]";
std::getline(std::cin, input);
if (Strings::ToLower(input) != "y") {
LogInfo("Aborting");
return;
}
std::string sql = "SET FOREIGN_KEY_CHECKS = 0;";
for (auto &t: DatabaseSchema::GetMercTables()) {
sql += fmt::format("DROP TABLE IF EXISTS {};", t);
LogInfo("Dropping table [{}]", t);
}
sql += "SET FOREIGN_KEY_CHECKS = 1;";
database.QueryDatabaseMulti(sql);
LogInfo("Setting rule Mercs:AllowMercs to false");
RuleManager::Instance()->SetRule("Mercs:AllowMercs", "false", &database, true, true);
LogInfo("Disabled mercs and dropped tables");
}

View File

@ -0,0 +1,27 @@
#include "../worlddb.h"
#include "../../common/database_schema.h"
void WorldserverCLI::MercsEnable(int argc, char **argv, argh::parser &cmd, std::string &description)
{
description = "Enables mercenaries";
if (cmd[{"-h", "--help"}]) {
return;
}
// bootstrap merc tables if they don't exist
if (!database.DoesTableExist("merc_types")) {
LogInfo("Bootstrapping merc tables");
database.SourceSqlFromUrl(
"https://raw.githubusercontent.com/EQEmu/Server/master/utils/sql/merc_tables_bootstrap.sql"
);
}
else {
LogInfo("Merc tables already exist, skipping bootstrap");
}
LogInfo("Enabling mercs");
LogInfo("Setting rule Mercs:AllowMercs to true");
RuleManager::Instance()->SetRule("Mercs:AllowMercs", "true", &database, true, true);
LogInfo("Mercs enabled");
}

View File

@ -22,6 +22,8 @@ void WorldserverCLI::CommandHandler(int argc, char **argv)
*/
function_map["bots:enable"] = &WorldserverCLI::BotsEnable;
function_map["bots:disable"] = &WorldserverCLI::BotsDisable;
function_map["mercs:enable"] = &WorldserverCLI::MercsEnable;
function_map["mercs:disable"] = &WorldserverCLI::MercsDisable;
function_map["world:version"] = &WorldserverCLI::Version;
function_map["character:copy-character"] = &WorldserverCLI::CopyCharacter;
function_map["database:version"] = &WorldserverCLI::DatabaseVersion;
@ -41,6 +43,8 @@ void WorldserverCLI::CommandHandler(int argc, char **argv)
#include "cli/bots_enable.cpp"
#include "cli/bots_disable.cpp"
#include "cli/mercs_enable.cpp"
#include "cli/mercs_disable.cpp"
#include "cli/database_concurrency.cpp"
#include "cli/copy_character.cpp"
#include "cli/database_dump.cpp"

View File

@ -9,6 +9,8 @@ public:
static void CommandHandler(int argc, char **argv);
static void BotsEnable(int argc, char **argv, argh::parser &cmd, std::string &description);
static void BotsDisable(int argc, char **argv, argh::parser &cmd, std::string &description);
static void MercsEnable(int argc, char **argv, argh::parser &cmd, std::string &description);
static void MercsDisable(int argc, char **argv, argh::parser &cmd, std::string &description);
static void Version(int argc, char **argv, argh::parser &cmd, std::string &description);
static void CopyCharacter(int argc, char **argv, argh::parser &cmd, std::string &description);
static void DatabaseVersion(int argc, char **argv, argh::parser &cmd, std::string &description);