From 81acd797b4df988717b95f2e0c4e8727c94bcd13 Mon Sep 17 00:00:00 2001 From: Akkadius Date: Mon, 23 Dec 2019 00:38:50 -0600 Subject: [PATCH] Add initial world server CLI handler interface --- world/CMakeLists.txt | 2 + world/world_server_command_handler.cpp | 105 +++++++++++++++++++++++++ world/world_server_command_handler.h | 34 ++++++++ 3 files changed, 141 insertions(+) create mode 100644 world/world_server_command_handler.cpp create mode 100644 world/world_server_command_handler.h diff --git a/world/CMakeLists.txt b/world/CMakeLists.txt index c042a7364..e60b3d666 100644 --- a/world/CMakeLists.txt +++ b/world/CMakeLists.txt @@ -22,6 +22,7 @@ SET(world_sources wguild_mgr.cpp world_config.cpp world_console_connection.cpp + world_server_command_handler.cpp worlddb.cpp zonelist.cpp zoneserver.cpp @@ -51,6 +52,7 @@ SET(world_headers world_config.h world_console_connection.h world_tcp_connection.h + world_server_command_handler.h worlddb.h zonelist.h zoneserver.h diff --git a/world/world_server_command_handler.cpp b/world/world_server_command_handler.cpp new file mode 100644 index 000000000..ed6a3e844 --- /dev/null +++ b/world/world_server_command_handler.cpp @@ -0,0 +1,105 @@ +/** + * EQEmulator: Everquest Server Emulator + * Copyright (C) 2001-2019 EQEmulator Development Team (https://github.com/EQEmu/Server) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY except by those people which sell it, which + * are required to give you total support for your newly bought product; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "world_server_command_handler.h" +#include "../common/eqemu_logsys.h" +#include "../common/json/json.h" +#include "../common/version.h" + +namespace WorldserverCommandHandler { + + /** + * @param argc + * @param argv + */ + void CommandHandler(int argc, char **argv) + { + if (argc == 1) { return; } + + argh::parser cmd; + cmd.parse(argc, argv, argh::parser::PREFER_PARAM_FOR_UNREG_OPTION); + EQEmuCommand::DisplayDebug(cmd); + + /** + * Declare command mapping + */ + auto function_map = EQEmuCommand::function_map; + + /** + * Register commands + */ + function_map["test:hello-world"] = &WorldserverCommandHandler::HelloWorld; + function_map["database:version"] = &WorldserverCommandHandler::DatabaseVersion; + + EQEmuCommand::HandleMenu(function_map, cmd, argc, argv); + } + + /** + * @param argc + * @param argv + * @param cmd + * @param description + */ + void HelloWorld(int argc, char **argv, argh::parser &cmd, std::string &description) + { + description = "Test command"; + + if (cmd[{"-h", "--help"}]) { + return; + } + + std::vector arguments = {}; + std::vector options = { + "--hello", + "--write" + }; + + EQEmuCommand::ValidateCmdInput(arguments, options, cmd, argc, argv); + + LogInfo("hello world!"); + + } + + /** + * @param argc + * @param argv + * @param cmd + * @param description + */ + void 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; + } + +} \ No newline at end of file diff --git a/world/world_server_command_handler.h b/world/world_server_command_handler.h new file mode 100644 index 000000000..a9b14cc58 --- /dev/null +++ b/world/world_server_command_handler.h @@ -0,0 +1,34 @@ +/** + * EQEmulator: Everquest Server Emulator + * Copyright (C) 2001-2019 EQEmulator Development Team (https://github.com/EQEmu/Server) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY except by those people which sell it, which + * are required to give you total support for your newly bought product; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "iostream" +#include "../common/cli/eqemu_command_handler.h" + +#ifndef EQEMU_WORLD_SERVER_COMMAND_HANDLER_H +#define EQEMU_WORLD_SERVER_COMMAND_HANDLER_H + +namespace WorldserverCommandHandler { + void CommandHandler(int argc, char **argv); + void HelloWorld(int argc, char **argv, argh::parser &cmd, std::string &description); + void DatabaseVersion(int argc, char **argv, argh::parser &cmd, std::string &description); +}; + + +#endif //EQEMU_WORLD_SERVER_COMMAND_HANDLER_H