mirror of
https://github.com/EQEmu/Server.git
synced 2026-05-16 22:58:34 +00:00
[World CLI] Refactor world CLI to be easier to reason about (#2441)
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
#include "../../common/eqemu_logsys_log_aliases.h"
|
||||
#include "../worlddb.h"
|
||||
|
||||
void WorldserverCLI::CopyCharacter(int argc, char **argv, argh::parser &cmd, std::string &description)
|
||||
{
|
||||
description = "Copies a character into a destination account";
|
||||
|
||||
std::vector<std::string> arguments = {
|
||||
"source_character_name",
|
||||
"destination_character_name",
|
||||
"destination_account_name"
|
||||
};
|
||||
std::vector<std::string> options = {};
|
||||
|
||||
if (cmd[{"-h", "--help"}]) {
|
||||
return;
|
||||
}
|
||||
|
||||
EQEmuCommand::ValidateCmdInput(arguments, options, cmd, argc, argv);
|
||||
|
||||
std::string source_character_name = cmd(2).str();
|
||||
std::string destination_character_name = cmd(3).str();
|
||||
std::string destination_account_name = cmd(4).str();
|
||||
|
||||
LogInfo(
|
||||
"Attempting to copy character [{}] to [{}] via account [{}]",
|
||||
source_character_name,
|
||||
destination_character_name,
|
||||
destination_account_name
|
||||
);
|
||||
|
||||
database.CopyCharacter(
|
||||
source_character_name,
|
||||
destination_character_name,
|
||||
destination_account_name
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
#include "../../common/database/database_dump_service.h"
|
||||
|
||||
void WorldserverCLI::DatabaseDump(int argc, char **argv, argh::parser &cmd, std::string &description)
|
||||
{
|
||||
description = "Dumps server database tables";
|
||||
|
||||
std::vector<std::string> arguments = {};
|
||||
std::vector<std::string> options = {
|
||||
"--all",
|
||||
"--content-tables",
|
||||
"--login-tables",
|
||||
"--player-tables",
|
||||
"--bot-tables",
|
||||
"--state-tables",
|
||||
"--system-tables",
|
||||
"--query-serv-tables",
|
||||
"--table-structure-only",
|
||||
"--table-lock",
|
||||
"--dump-path=",
|
||||
"--dump-output-to-console",
|
||||
"--drop-table-syntax-only",
|
||||
"--compress"
|
||||
};
|
||||
|
||||
if (cmd[{"-h", "--help"}]) {
|
||||
return;
|
||||
}
|
||||
|
||||
EQEmuCommand::ValidateCmdInput(arguments, options, cmd, argc, argv);
|
||||
|
||||
auto s = new DatabaseDumpService();
|
||||
bool dump_all = cmd[{"-a", "--all"}];
|
||||
|
||||
if (!cmd("--dump-path").str().empty()) {
|
||||
s->SetDumpPath(cmd("--dump-path").str());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Option
|
||||
*/
|
||||
s->SetDumpContentTables(cmd[{"--content-tables"}] || dump_all);
|
||||
s->SetDumpLoginServerTables(cmd[{"--login-tables"}] || dump_all);
|
||||
s->SetDumpPlayerTables(cmd[{"--player-tables"}] || dump_all);
|
||||
s->SetDumpBotTables(cmd[{"--bot-tables"}] || dump_all);
|
||||
s->SetDumpStateTables(cmd[{"--state-tables"}] || dump_all);
|
||||
s->SetDumpSystemTables(cmd[{"--system-tables"}] || dump_all);
|
||||
s->SetDumpQueryServerTables(cmd[{"--query-serv-tables"}] || dump_all);
|
||||
s->SetDumpAllTables(dump_all);
|
||||
|
||||
s->SetDumpWithNoData(cmd[{"--table-structure-only"}]);
|
||||
s->SetDumpTableLock(cmd[{"--table-lock"}]);
|
||||
s->SetDumpWithCompression(cmd[{"--compress"}]);
|
||||
s->SetDumpOutputToConsole(cmd[{"--dump-output-to-console"}]);
|
||||
s->SetDumpDropTableSyntaxOnly(cmd[{"--drop-table-syntax-only"}]);
|
||||
|
||||
/**
|
||||
* Dump
|
||||
*/
|
||||
s->Dump();
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#include "../../common/database_schema.h"
|
||||
#include "../../common/json/json.h"
|
||||
|
||||
void WorldserverCLI::DatabaseGetSchema(int argc, char **argv, argh::parser &cmd, std::string &description)
|
||||
{
|
||||
description = "Displays server database schema";
|
||||
|
||||
if (cmd[{"-h", "--help"}]) {
|
||||
return;
|
||||
}
|
||||
|
||||
Json::Value player_tables_json;
|
||||
std::vector<std::string> player_tables = DatabaseSchema::GetPlayerTables();
|
||||
for (const auto &table: player_tables) {
|
||||
player_tables_json.append(table);
|
||||
}
|
||||
|
||||
Json::Value content_tables_json;
|
||||
std::vector<std::string> content_tables = DatabaseSchema::GetContentTables();
|
||||
for (const auto &table: content_tables) {
|
||||
content_tables_json.append(table);
|
||||
}
|
||||
|
||||
Json::Value server_tables_json;
|
||||
std::vector<std::string> server_tables = DatabaseSchema::GetServerTables();
|
||||
for (const auto &table: server_tables) {
|
||||
server_tables_json.append(table);
|
||||
}
|
||||
|
||||
Json::Value login_tables_json;
|
||||
std::vector<std::string> login_tables = DatabaseSchema::GetLoginTables();
|
||||
for (const auto &table: login_tables) {
|
||||
login_tables_json.append(table);
|
||||
}
|
||||
|
||||
Json::Value state_tables_json;
|
||||
std::vector<std::string> state_tables = DatabaseSchema::GetStateTables();
|
||||
for (const auto &table: state_tables) {
|
||||
state_tables_json.append(table);
|
||||
}
|
||||
|
||||
Json::Value version_tables_json;
|
||||
std::vector<std::string> version_tables = DatabaseSchema::GetVersionTables();
|
||||
for (const auto &table: version_tables) {
|
||||
version_tables_json.append(table);
|
||||
}
|
||||
|
||||
Json::Value bot_tables_json;
|
||||
std::vector<std::string> bot_tables = DatabaseSchema::GetBotTables();
|
||||
for (const auto &table: bot_tables) {
|
||||
bot_tables_json.append(table);
|
||||
}
|
||||
|
||||
Json::Value schema;
|
||||
|
||||
schema["content_tables"] = content_tables_json;
|
||||
schema["login_tables"] = login_tables_json;
|
||||
schema["player_tables"] = player_tables_json;
|
||||
schema["server_tables"] = server_tables_json;
|
||||
schema["state_tables"] = state_tables_json;
|
||||
schema["version_tables"] = version_tables_json;
|
||||
schema["bot_tables"] = bot_tables_json;
|
||||
|
||||
std::stringstream payload;
|
||||
payload << schema;
|
||||
|
||||
std::cout << payload.str() << std::endl;
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "../worlddb.h"
|
||||
|
||||
void WorldserverCLI::DatabaseSetAccountStatus(int argc, char **argv, argh::parser &cmd, std::string &description)
|
||||
{
|
||||
description = "Sets account status by account name";
|
||||
|
||||
std::vector<std::string> arguments = {
|
||||
"{name}",
|
||||
"{status}"
|
||||
};
|
||||
|
||||
std::vector<std::string> options = {};
|
||||
|
||||
if (cmd[{"-h", "--help"}]) {
|
||||
return;
|
||||
}
|
||||
|
||||
EQEmuCommand::ValidateCmdInput(arguments, options, cmd, argc, argv);
|
||||
|
||||
database.SetAccountStatus(
|
||||
cmd(2).str(),
|
||||
std::stoi(cmd(3).str())
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "../../common/version.h"
|
||||
#include "../../common/json/json.h"
|
||||
|
||||
void WorldserverCLI::DatabaseVersion(int argc, char **argv, argh::parser &cmd, std::string &description)
|
||||
{
|
||||
description = "Shows database version";
|
||||
|
||||
if (cmd[{"-h", "--help"}]) {
|
||||
return;
|
||||
}
|
||||
|
||||
Json::Value database_version;
|
||||
|
||||
database_version["database_version"] = CURRENT_BINARY_DATABASE_VERSION;
|
||||
database_version["bots_database_version"] = CURRENT_BINARY_BOTS_DATABASE_VERSION;
|
||||
|
||||
std::stringstream payload;
|
||||
payload << database_version;
|
||||
|
||||
std::cout << payload.str() << std::endl;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
void WorldserverCLI::TestCommand(int argc, char **argv, argh::parser &cmd, std::string &description)
|
||||
{
|
||||
description = "Test command";
|
||||
|
||||
if (cmd[{"-h", "--help"}]) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "../../common/rulesys.h"
|
||||
#include "../../common/repositories/content_flags_repository.h"
|
||||
#include "../../common/content/world_content_service.h"
|
||||
#include "../../common/repositories/criteria/content_filter_criteria.h"
|
||||
#include "../worlddb.h"
|
||||
|
||||
void WorldserverCLI::ExpansionTestCommand(int argc, char **argv, argh::parser &cmd, std::string &description)
|
||||
{
|
||||
description = "Expansion test command";
|
||||
|
||||
if (cmd[{"-h", "--help"}]) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!RuleManager::Instance()->LoadRules(&database, "default", false)) {
|
||||
LogInfo("No rule set configured, using default rules");
|
||||
}
|
||||
|
||||
content_service.SetCurrentExpansion(RuleI(Expansion, CurrentExpansion));
|
||||
|
||||
std::vector<ContentFlagsRepository::ContentFlags> flags = {};
|
||||
auto f = ContentFlagsRepository::NewEntity();
|
||||
f.enabled = 1;
|
||||
|
||||
std::vector<std::string> flag_names = {
|
||||
"hateplane_enabled",
|
||||
"patch_nerf_7077",
|
||||
};
|
||||
|
||||
for (auto &name: flag_names) {
|
||||
f.flag_name = name;
|
||||
flags.push_back(f);
|
||||
}
|
||||
|
||||
content_service.SetContentFlags(flags);
|
||||
|
||||
LogInfo(
|
||||
"Current expansion is [{}] ({}) is Velious Enabled [{}] Criteria [{}]",
|
||||
content_service.GetCurrentExpansion(),
|
||||
content_service.GetCurrentExpansionName(),
|
||||
content_service.IsTheScarsOfVeliousEnabled() ? "true" : "false",
|
||||
ContentFilterCriteria::apply()
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
#include "../../common/repositories/instance_list_repository.h"
|
||||
#include "../worlddb.h"
|
||||
|
||||
void WorldserverCLI::TestRepository(int argc, char **argv, argh::parser &cmd, std::string &description)
|
||||
{
|
||||
description = "Test command";
|
||||
|
||||
if (cmd[{"-h", "--help"}]) {
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert one
|
||||
*/
|
||||
auto e = InstanceListRepository::NewEntity();
|
||||
|
||||
e.zone = 999;
|
||||
e.version = 1;
|
||||
e.is_global = 1;
|
||||
e.start_time = 0;
|
||||
e.duration = 0;
|
||||
e.never_expires = 1;
|
||||
|
||||
auto inserted = InstanceListRepository::InsertOne(database, e);
|
||||
|
||||
LogInfo("Inserted ID is [{}] zone [{}]", inserted.id, inserted.zone);
|
||||
|
||||
/**
|
||||
* Find one
|
||||
*/
|
||||
auto f = InstanceListRepository::FindOne(database, inserted.id);
|
||||
|
||||
LogInfo("Found ID is [{}] zone [{}]", f.id, f.zone);
|
||||
|
||||
/**
|
||||
* Update one
|
||||
*/
|
||||
LogInfo("Updating instance id [{}] zone [{}]", f.id, f.zone);
|
||||
|
||||
int update_instance_list_count = InstanceListRepository::UpdateOne(database, f);
|
||||
|
||||
f.zone = 777;
|
||||
|
||||
LogInfo(
|
||||
"Updated instance id [{}] zone [{}] affected [{}]",
|
||||
f.id,
|
||||
f.zone,
|
||||
update_instance_list_count
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Delete one
|
||||
*/
|
||||
int deleted = InstanceListRepository::DeleteOne(database, f.id);
|
||||
|
||||
LogInfo("Deleting one instance [{}] deleted count [{}]", f.id, deleted);
|
||||
|
||||
/**
|
||||
* Insert many
|
||||
*/
|
||||
std::vector<InstanceListRepository::InstanceList> instance_lists;
|
||||
|
||||
auto b = InstanceListRepository::NewEntity();
|
||||
|
||||
b.zone = 999;
|
||||
b.version = 1;
|
||||
b.is_global = 1;
|
||||
b.start_time = 0;
|
||||
b.duration = 0;
|
||||
b.never_expires = 1;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
instance_lists.push_back(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert Many
|
||||
*/
|
||||
int inserted_count = InstanceListRepository::InsertMany(database, instance_lists);
|
||||
|
||||
LogInfo("Bulk insertion test, inserted [{}]", inserted_count);
|
||||
|
||||
for (auto &entry: InstanceListRepository::GetWhere(database, fmt::format("zone = {}", 999))) {
|
||||
LogInfo("Iterating through entry id [{}] zone [{}]", entry.id, entry.zone);
|
||||
}
|
||||
|
||||
LogInfo("[Max ID] {}", InstanceListRepository::GetMaxId(database));
|
||||
LogInfo("[Count] {}", InstanceListRepository::Count(database));
|
||||
LogInfo("[Count Where] {}", InstanceListRepository::Count(database, "zone = 999"));
|
||||
LogInfo("[Count Where] {}", InstanceListRepository::Count(database, "zone = 777"));
|
||||
|
||||
/**
|
||||
* Delete where
|
||||
*/
|
||||
int deleted_count = InstanceListRepository::DeleteWhere(database, fmt::format("zone = {}", 999));
|
||||
|
||||
LogInfo("Bulk deletion test, deleted [{}]", deleted_count);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "../../common/repositories/zone_repository.h"
|
||||
|
||||
void WorldserverCLI::TestRepository2(int argc, char **argv, argh::parser &cmd, std::string &description)
|
||||
{
|
||||
description = "Test command";
|
||||
|
||||
if (cmd[{"-h", "--help"}]) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto zones = ZoneRepository::GetWhere(content_db, "short_name = 'anguish'");
|
||||
|
||||
for (auto &zone: zones) {
|
||||
LogInfo(
|
||||
"Zone [{}] long_name [{}] id [{}]",
|
||||
zone.short_name,
|
||||
zone.long_name,
|
||||
zone.id
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#include "../../common/json/json.h"
|
||||
#include "../../common/version.h"
|
||||
|
||||
void WorldserverCLI::Version(int argc, char **argv, argh::parser &cmd, std::string &description)
|
||||
{
|
||||
description = "Shows server version";
|
||||
|
||||
if (cmd[{"-h", "--help"}]) {
|
||||
return;
|
||||
}
|
||||
|
||||
Json::Value j;
|
||||
|
||||
j["bots_database_version"] = CURRENT_BINARY_BOTS_DATABASE_VERSION;
|
||||
j["compile_date"] = COMPILE_DATE;
|
||||
j["compile_time"] = COMPILE_TIME;
|
||||
j["database_version"] = CURRENT_BINARY_DATABASE_VERSION;
|
||||
j["server_version"] = CURRENT_VERSION;
|
||||
|
||||
std::stringstream payload;
|
||||
payload << j;
|
||||
|
||||
std::cout << payload.str() << std::endl;
|
||||
}
|
||||
Reference in New Issue
Block a user