mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-13 23:01:30 +00:00
Add console helpers to EQEmu::LogSys cleanup world main
This commit is contained in:
parent
8ef6feac9f
commit
2ab0ce19a7
@ -123,10 +123,6 @@ namespace EQEmuCommand {
|
|||||||
bool ran_command = false;
|
bool ran_command = false;
|
||||||
for (auto &it: in_function_map) {
|
for (auto &it: in_function_map) {
|
||||||
if (it.first == argv[1]) {
|
if (it.first == argv[1]) {
|
||||||
std::cout << std::endl;
|
|
||||||
std::cout << "> " << termcolor::cyan << "Executing CLI Command" << termcolor::reset << std::endl;
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
(it.second)(argc, argv, cmd, description);
|
(it.second)(argc, argv, cmd, description);
|
||||||
ran_command = true;
|
ran_command = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -579,3 +579,25 @@ void EQEmuLogSys::StartFileLogs(const std::string &log_name)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Silence console logging
|
||||||
|
*/
|
||||||
|
void EQEmuLogSys::SilenceConsoleLogging()
|
||||||
|
{
|
||||||
|
for (int log_index = Logs::AA; log_index != Logs::MaxCategoryID; log_index++) {
|
||||||
|
log_settings[log_index].log_to_console = 0;
|
||||||
|
log_settings[log_index].is_category_enabled = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables console logging
|
||||||
|
*/
|
||||||
|
void EQEmuLogSys::EnableConsoleLogging()
|
||||||
|
{
|
||||||
|
for (int log_index = Logs::AA; log_index != Logs::MaxCategoryID; log_index++) {
|
||||||
|
log_settings[log_index].log_to_console = Logs::General;
|
||||||
|
log_settings[log_index].is_category_enabled = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -279,6 +279,16 @@ public:
|
|||||||
*/
|
*/
|
||||||
void SetConsoleHandler(std::function<void(uint16 debug_level, uint16 log_type, const std::string&)> f) { on_log_console_hook = f; }
|
void SetConsoleHandler(std::function<void(uint16 debug_level, uint16 log_type, const std::string&)> f) { on_log_console_hook = f; }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Silence console logging
|
||||||
|
*/
|
||||||
|
void SilenceConsoleLogging();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turn on all console logging
|
||||||
|
*/
|
||||||
|
void EnableConsoleLogging();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
212
world/net.cpp
212
world/net.cpp
@ -86,6 +86,7 @@ union semun {
|
|||||||
|
|
||||||
#include "../common/net/servertalk_server.h"
|
#include "../common/net/servertalk_server.h"
|
||||||
#include "../zone/data_bucket.h"
|
#include "../zone/data_bucket.h"
|
||||||
|
#include "world_server_command_handler.h"
|
||||||
|
|
||||||
ClientList client_list;
|
ClientList client_list;
|
||||||
GroupLFPList LFPGroupList;
|
GroupLFPList LFPGroupList;
|
||||||
@ -113,14 +114,30 @@ inline void UpdateWindowTitle(std::string new_title) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
void LoadDatabaseConnections()
|
||||||
RegisterExecutablePlatform(ExePlatformWorld);
|
{
|
||||||
LogSys.LoadLogSettingsDefaults();
|
LogInfo(
|
||||||
set_exception_handler();
|
"Connecting to MySQL [{}]@[{}]:[{}]",
|
||||||
|
Config->DatabaseUsername.c_str(),
|
||||||
|
Config->DatabaseHost.c_str(),
|
||||||
|
Config->DatabasePort
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
if (!database.Connect(
|
||||||
* Auto convert json config from xml
|
Config->DatabaseHost.c_str(),
|
||||||
*/
|
Config->DatabaseUsername.c_str(),
|
||||||
|
Config->DatabasePassword.c_str(),
|
||||||
|
Config->DatabaseDB.c_str(),
|
||||||
|
Config->DatabasePort
|
||||||
|
)) {
|
||||||
|
LogError("Cannot continue without a database connection");
|
||||||
|
|
||||||
|
std::exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CheckForXMLConfigUpgrade()
|
||||||
|
{
|
||||||
if (!std::ifstream("eqemu_config.json") && std::ifstream("eqemu_config.xml")) {
|
if (!std::ifstream("eqemu_config.json") && std::ifstream("eqemu_config.xml")) {
|
||||||
CheckForServerScript(true);
|
CheckForServerScript(true);
|
||||||
if(system("perl eqemu_server.pl convert_xml"));
|
if(system("perl eqemu_server.pl convert_xml"));
|
||||||
@ -128,50 +145,19 @@ int main(int argc, char** argv) {
|
|||||||
else {
|
else {
|
||||||
CheckForServerScript();
|
CheckForServerScript();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
void LoadServerConfig()
|
||||||
* Database version
|
{
|
||||||
*/
|
|
||||||
uint32 Database_Version = CURRENT_BINARY_DATABASE_VERSION;
|
|
||||||
uint32 Bots_Database_Version = CURRENT_BINARY_BOTS_DATABASE_VERSION;
|
|
||||||
if (argc >= 2) {
|
|
||||||
if (strcasecmp(argv[1], "db_version") == 0) {
|
|
||||||
std::cout << "Binary Database Version: " << Database_Version << " : " << Bots_Database_Version << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load server configuration
|
|
||||||
LogInfo("Loading server configuration");
|
LogInfo("Loading server configuration");
|
||||||
if (!WorldConfig::LoadConfig()) {
|
if (!WorldConfig::LoadConfig()) {
|
||||||
LogError("Loading server configuration failed");
|
LogError("Loading server configuration failed");
|
||||||
return 1;
|
std::exit(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Config = WorldConfig::get();
|
void RegisterLoginservers()
|
||||||
|
{
|
||||||
LogInfo("CURRENT_VERSION: [{}]", CURRENT_VERSION);
|
|
||||||
|
|
||||||
if (signal(SIGINT, CatchSignal) == SIG_ERR) {
|
|
||||||
LogError("Could not set signal handler");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (signal(SIGTERM, CatchSignal) == SIG_ERR) {
|
|
||||||
LogError("Could not set signal handler");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef WIN32
|
|
||||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
|
|
||||||
LogError("Could not set signal handler");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add Loginserver
|
|
||||||
*/
|
|
||||||
if (Config->LoginCount == 0) {
|
if (Config->LoginCount == 0) {
|
||||||
if (Config->LoginHost.length()) {
|
if (Config->LoginHost.length()) {
|
||||||
loginserverlist.Add(
|
loginserverlist.Add(
|
||||||
@ -201,23 +187,85 @@ int main(int argc, char** argv) {
|
|||||||
iterator.Advance();
|
iterator.Advance();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LogInfo("Connecting to MySQL [{}]@[{}]:[{}]", Config->DatabaseUsername.c_str(), Config->DatabaseHost.c_str(), Config->DatabasePort);
|
int main(int argc, char** argv) {
|
||||||
if (!database.Connect(
|
RegisterExecutablePlatform(ExePlatformWorld);
|
||||||
Config->DatabaseHost.c_str(),
|
LogSys.LoadLogSettingsDefaults();
|
||||||
Config->DatabaseUsername.c_str(),
|
set_exception_handler();
|
||||||
Config->DatabasePassword.c_str(),
|
|
||||||
Config->DatabaseDB.c_str(),
|
/**
|
||||||
Config->DatabasePort)) {
|
* Database version
|
||||||
LogError("Cannot continue without a database connection");
|
*/
|
||||||
|
uint32 database_version = CURRENT_BINARY_DATABASE_VERSION;
|
||||||
|
uint32 bots_database_version = CURRENT_BINARY_BOTS_DATABASE_VERSION;
|
||||||
|
if (argc >= 2) {
|
||||||
|
if (strcasecmp(argv[1], "db_version") == 0) {
|
||||||
|
std::cout << "Binary Database Version: " << database_version << " : " << bots_database_version << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command handler
|
||||||
|
*/
|
||||||
|
if (argc > 1) {
|
||||||
|
LogSys.SilenceConsoleLogging();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Config
|
||||||
|
*/
|
||||||
|
WorldConfig::LoadConfig();
|
||||||
|
Config = WorldConfig::get();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load database
|
||||||
|
*/
|
||||||
|
LoadDatabaseConnections();
|
||||||
|
|
||||||
|
LogSys.EnableConsoleLogging();
|
||||||
|
|
||||||
|
WorldserverCommandHandler::CommandHandler(argc, argv);
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckForXMLConfigUpgrade();
|
||||||
|
LoadServerConfig();
|
||||||
|
|
||||||
|
Config = WorldConfig::get();
|
||||||
|
|
||||||
|
LogInfo("CURRENT_VERSION: [{}]", CURRENT_VERSION);
|
||||||
|
|
||||||
|
if (signal(SIGINT, CatchSignal) == SIG_ERR) {
|
||||||
|
LogError("Could not set signal handler");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (signal(SIGTERM, CatchSignal) == SIG_ERR) {
|
||||||
|
LogError("Could not set signal handler");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
|
||||||
|
LogError("Could not set signal handler");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
RegisterLoginservers();
|
||||||
|
LoadDatabaseConnections();
|
||||||
|
|
||||||
guild_mgr.SetDatabase(&database);
|
guild_mgr.SetDatabase(&database);
|
||||||
|
|
||||||
/* Register Log System and Settings */
|
/**
|
||||||
|
* Logging
|
||||||
|
*/
|
||||||
database.LoadLogSettings(LogSys.log_settings);
|
database.LoadLogSettings(LogSys.log_settings);
|
||||||
LogSys.StartFileLogs();
|
LogSys.StartFileLogs();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse simple CLI passes
|
||||||
|
*/
|
||||||
bool ignore_db = false;
|
bool ignore_db = false;
|
||||||
if (argc >= 2) {
|
if (argc >= 2) {
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
@ -233,38 +281,6 @@ int main(int argc, char** argv) {
|
|||||||
std::cout << "Reboot Zones mode ON" << std::endl;
|
std::cout << "Reboot Zones mode ON" << std::endl;
|
||||||
holdzones = true;
|
holdzones = true;
|
||||||
}
|
}
|
||||||
else if (database.GetVariable("disablecommandline", tmp)) {
|
|
||||||
if (tmp.length() == 1) {
|
|
||||||
if (tmp[0] == '1') {
|
|
||||||
std::cerr << "Command line disabled in database... exiting" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (strcasecmp(argv[1], "adduser") == 0) {
|
|
||||||
if (argc == 5) {
|
|
||||||
if (Seperator::IsNumber(argv[4])) {
|
|
||||||
if (atoi(argv[4]) >= 0 && atoi(argv[4]) <= 255) {
|
|
||||||
std::string user;
|
|
||||||
std::string loginserver;
|
|
||||||
|
|
||||||
ParseAccountString(argv[2], user, loginserver);
|
|
||||||
|
|
||||||
if (database.CreateAccount(argv[2], argv[3], atoi(argv[4]), loginserver.c_str(), 0) == 0) {
|
|
||||||
std::cerr << "database.CreateAccount failed." << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cout << "Account created: Username='" << argv[2] << "', Password='" << argv[3] << "', status=" << argv[4] << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout << "Usage: world adduser username password flag" << std::endl;
|
|
||||||
std::cout << "flag = 0, 1 or 2" << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if (strcasecmp(argv[1], "flag") == 0) {
|
else if (strcasecmp(argv[1], "flag") == 0) {
|
||||||
if (argc == 4) {
|
if (argc == 4) {
|
||||||
if (Seperator::IsNumber(argv[3])) {
|
if (Seperator::IsNumber(argv[3])) {
|
||||||
@ -284,30 +300,6 @@ int main(int argc, char** argv) {
|
|||||||
std::cout << "flag = 0-200" << std::endl;
|
std::cout << "flag = 0-200" << std::endl;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else if (strcasecmp(argv[1], "startzone") == 0) {
|
|
||||||
if (argc == 3) {
|
|
||||||
if (strlen(argv[2]) < 3) {
|
|
||||||
std::cerr << "Error: zone name too short" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if (strlen(argv[2]) > 15) {
|
|
||||||
std::cerr << "Error: zone name too long" << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (database.SetVariable("startzone", argv[2])) {
|
|
||||||
std::cout << "Starting zone changed: '" << argv[2] << "'" << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cerr << "database.SetVariable failed." << std::endl;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
std::cout << "Usage: world startzone zoneshortname" << std::endl;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
else if (strcasecmp(argv[1], "ignore_db") == 0) {
|
else if (strcasecmp(argv[1], "ignore_db") == 0) {
|
||||||
ignore_db = true;
|
ignore_db = true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user