[CLI] Add bots:enable and bots:disable commands (#3415)

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

* Add input warning
This commit is contained in:
Chris Miles
2023-06-17 18:48:47 -05:00
committed by GitHub
parent b45e0e80b5
commit cf49b2fe49
7 changed files with 4699 additions and 1 deletions
+36
View File
@@ -0,0 +1,36 @@
#include "../worlddb.h"
#include "../../common/database_schema.h"
void WorldserverCLI::BotsDisable(int argc, char **argv, argh::parser &cmd, std::string &description)
{
description = "Disables bots and drops tables";
if (cmd[{"-h", "--help"}]) {
return;
}
std::string input;
std::cout << "Warning! This will drop all bot tables, are you sure? [y/n]";
std::getline(std::cin, input);
if (Strings::ToLower(input) != "y") {
LogInfo("Aborting");
return;
}
// drop bot tables
std::string sql = "SET FOREIGN_KEY_CHECKS = 0;";
for (auto &t: DatabaseSchema::GetBotTables()) {
sql += fmt::format("DROP TABLE IF EXISTS {};", t);
LogInfo("Dropping table [{}]", t);
}
sql += "SET FOREIGN_KEY_CHECKS = 1;";
database.QueryDatabaseMulti(sql);
// disable bots
LogInfo("Setting rule Bots:Enabled to false");
RuleManager::Instance()->SetRule("Bots:Enabled", "false", &database, true, true);
LogInfo("Bots disabled");
}
+26
View File
@@ -0,0 +1,26 @@
#include "../worlddb.h"
#include "../../common/rulesys.h"
void WorldserverCLI::BotsEnable(int argc, char **argv, argh::parser &cmd, std::string &description)
{
description = "Bootstraps bot tables and enables bots";
if (cmd[{"-h", "--help"}]) {
return;
}
// bootstrap bot tables if they don't exist
if (!database.DoesTableExist("bot_data")) {
LogInfo("Bootstrapping bot tables");
database.SourceSqlFromUrl(
"https://raw.githubusercontent.com/EQEmu/Server/master/utils/sql/bot_tables_bootstrap.sql"
);
}
else {
LogInfo("Bot tables already exist, skipping bootstrap");
}
LogInfo("Enabling bots");
LogInfo("Setting rule Bots:Enabled to true");
RuleManager::Instance()->SetRule("Bots:Enabled", "true", &database, true, true);
}