mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 01:11:29 +00:00
[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:
parent
b45e0e80b5
commit
cf49b2fe49
@ -2408,3 +2408,52 @@ uint8 Database::GetMinStatus(uint32 zone_id, uint32 instance_version)
|
||||
|
||||
return !zones.empty() ? zones[0].min_status : 0;
|
||||
}
|
||||
|
||||
void Database::SourceSqlFromUrl(std::string url)
|
||||
{
|
||||
try {
|
||||
uri request_uri(url);
|
||||
|
||||
LogHTTPDetail(
|
||||
"parsing url [{}] path [{}] host [{}] query_string [{}] protocol [{}] port [{}]",
|
||||
url,
|
||||
request_uri.get_path(),
|
||||
request_uri.get_host(),
|
||||
request_uri.get_query(),
|
||||
request_uri.get_scheme(),
|
||||
request_uri.get_port()
|
||||
);
|
||||
|
||||
LogInfo("Downloading and installing from [{}]", url);
|
||||
|
||||
// http get request
|
||||
httplib::Client cli(
|
||||
fmt::format(
|
||||
"{}://{}",
|
||||
request_uri.get_scheme(),
|
||||
request_uri.get_host()
|
||||
)
|
||||
);
|
||||
|
||||
cli.set_connection_timeout(0, 60000000); // 60 sec
|
||||
cli.set_read_timeout(60, 0); // 60 seconds
|
||||
cli.set_write_timeout(60, 0); // 60 seconds
|
||||
|
||||
if (auto res = cli.Get(request_uri.get_path())) {
|
||||
if (res->status == 200) {
|
||||
auto results = QueryDatabaseMulti(res->body);
|
||||
if (!results.ErrorMessage().empty()) {
|
||||
LogError("Error sourcing SQL [{}]", results.ErrorMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
LogError("Error retrieving URL [{}]", url);
|
||||
}
|
||||
|
||||
}
|
||||
catch (std::invalid_argument iae) {
|
||||
LogError("URI parser error [{}]", iae.what());
|
||||
}
|
||||
}
|
||||
|
||||
@ -263,7 +263,7 @@ public:
|
||||
void ClearInvSnapshots(bool from_now = false);
|
||||
|
||||
void SourceDatabaseTableFromUrl(std::string table_name, std::string url);
|
||||
|
||||
void SourceSqlFromUrl(std::string url);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
4581
utils/sql/bot_tables_bootstrap.sql
Normal file
4581
utils/sql/bot_tables_bootstrap.sql
Normal file
File diff suppressed because it is too large
Load Diff
36
world/cli/bots_disable.cpp
Normal file
36
world/cli/bots_disable.cpp
Normal 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
world/cli/bots_enable.cpp
Normal file
26
world/cli/bots_enable.cpp
Normal 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);
|
||||
}
|
||||
@ -20,6 +20,8 @@ void WorldserverCLI::CommandHandler(int argc, char **argv)
|
||||
/**
|
||||
* Register commands
|
||||
*/
|
||||
function_map["bots:enable"] = &WorldserverCLI::BotsEnable;
|
||||
function_map["bots:disable"] = &WorldserverCLI::BotsDisable;
|
||||
function_map["world:version"] = &WorldserverCLI::Version;
|
||||
function_map["character:copy-character"] = &WorldserverCLI::CopyCharacter;
|
||||
function_map["database:version"] = &WorldserverCLI::DatabaseVersion;
|
||||
@ -37,6 +39,8 @@ void WorldserverCLI::CommandHandler(int argc, char **argv)
|
||||
EQEmuCommand::HandleMenu(function_map, cmd, argc, argv);
|
||||
}
|
||||
|
||||
#include "cli/bots_enable.cpp"
|
||||
#include "cli/bots_disable.cpp"
|
||||
#include "cli/database_concurrency.cpp"
|
||||
#include "cli/copy_character.cpp"
|
||||
#include "cli/database_dump.cpp"
|
||||
|
||||
@ -7,6 +7,8 @@
|
||||
class WorldserverCLI {
|
||||
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 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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user