eqemu-server/world/cli/bots_disable.cpp
Chris Miles cf49b2fe49
[CLI] Add bots:enable and bots:disable commands (#3415)
* [CLI] Add `bots:enable` and `bots:disable` commands

* Add input warning
2023-06-17 18:48:47 -05:00

37 lines
936 B
C++

#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");
}