From e6469878ced7608e72880218be0f7b3faa0a85c8 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 21 Oct 2024 21:48:43 -0700 Subject: [PATCH] [Loginserver] Automatifc Opcode File Creation (#4521) * Loginserver will auto create the opcodes file if it doesn't exist on load. * Use path manager in login opcodes. --------- Co-authored-by: KimLS --- common/eqemu_config.cpp | 1 + common/eqemu_config.h | 1 + common/path_manager.cpp | 11 ++++ common/path_manager.h | 2 + loginserver/client_manager.cpp | 103 +++++++++++++++++++++++++++------ 5 files changed, 100 insertions(+), 18 deletions(-) diff --git a/common/eqemu_config.cpp b/common/eqemu_config.cpp index 56b8ff989..85db27492 100644 --- a/common/eqemu_config.cpp +++ b/common/eqemu_config.cpp @@ -171,6 +171,7 @@ void EQEmuConfig::parse_config() PluginDir = _root["server"]["directories"].get("plugins", "plugins/").asString(); LuaModuleDir = _root["server"]["directories"].get("lua_modules", "lua_modules/").asString(); PatchDir = _root["server"]["directories"].get("patches", "./").asString(); + OpcodeDir = _root["server"]["directories"].get("opcodes", "./").asString(); SharedMemDir = _root["server"]["directories"].get("shared_memory", "shared/").asString(); LogDir = _root["server"]["directories"].get("logs", "logs/").asString(); diff --git a/common/eqemu_config.h b/common/eqemu_config.h index 6aad3d41c..7e9e3b341 100644 --- a/common/eqemu_config.h +++ b/common/eqemu_config.h @@ -95,6 +95,7 @@ class EQEmuConfig std::string PluginDir; std::string LuaModuleDir; std::string PatchDir; + std::string OpcodeDir; std::string SharedMemDir; std::string LogDir; diff --git a/common/path_manager.cpp b/common/path_manager.cpp index fba5f777a..452722c84 100644 --- a/common/path_manager.cpp +++ b/common/path_manager.cpp @@ -74,6 +74,11 @@ void PathManager::LoadPaths() m_patch_path = fs::relative(fs::path{m_server_path + "/" + c->PatchDir}).string(); } + // patches + if (File::Exists(fs::path{ m_server_path + "/" + c->OpcodeDir }.string())) { + m_opcode_path = fs::relative(fs::path{ m_server_path + "/" + c->OpcodeDir }).string(); + } + // shared_memory_path if (File::Exists(fs::path{m_server_path + "/" + c->SharedMemDir}.string())) { m_shared_memory_path = fs::relative(fs::path{ m_server_path + "/" + c->SharedMemDir }).string(); @@ -89,6 +94,7 @@ void PathManager::LoadPaths() LogInfo("lua_modules path [{}]", m_lua_modules_path); LogInfo("maps path [{}]", m_maps_path); LogInfo("patches path [{}]", m_patch_path); + LogInfo("opcode path [{}]", m_opcode_path); LogInfo("plugins path [{}]", m_plugins_path); LogInfo("quests path [{}]", m_quests_path); LogInfo("shared_memory path [{}]", m_shared_memory_path); @@ -129,6 +135,11 @@ const std::string &PathManager::GetPatchPath() const return m_patch_path; } +const std::string &PathManager::GetOpcodePath() const +{ + return m_opcode_path; +} + const std::string &PathManager::GetLuaModulesPath() const { return m_lua_modules_path; diff --git a/common/path_manager.h b/common/path_manager.h index 4283dbf64..3ef55d0a7 100644 --- a/common/path_manager.h +++ b/common/path_manager.h @@ -13,6 +13,7 @@ public: [[nodiscard]] const std::string &GetLuaModulesPath() const; [[nodiscard]] const std::string &GetMapsPath() const; [[nodiscard]] const std::string &GetPatchPath() const; + [[nodiscard]] const std::string &GetOpcodePath() const; [[nodiscard]] const std::string &GetPluginsPath() const; [[nodiscard]] const std::string &GetQuestsPath() const; [[nodiscard]] const std::string &GetServerPath() const; @@ -24,6 +25,7 @@ private: std::string m_lua_modules_path; std::string m_maps_path; std::string m_patch_path; + std::string m_opcode_path; std::string m_plugins_path; std::string m_quests_path; std::string m_server_path; diff --git a/loginserver/client_manager.cpp b/loginserver/client_manager.cpp index 8567c35b4..c82eb0de8 100644 --- a/loginserver/client_manager.cpp +++ b/loginserver/client_manager.cpp @@ -7,6 +7,79 @@ extern bool run_server; #include "../common/eqemu_logsys.h" #include "../common/misc.h" #include "../common/path_manager.h" +#include "../common/file.h" + +void CheckTitaniumOpcodeFile(const std::string &path) { + if (File::Exists(path)) { + return; + } + + auto f = fopen(path.c_str(), "w"); + if (f) { + fprintf(f, "#EQEmu Public Login Server OPCodes\n"); + fprintf(f, "OP_SessionReady=0x0001\n"); + fprintf(f, "OP_Login=0x0002\n"); + fprintf(f, "OP_ServerListRequest=0x0004\n"); + fprintf(f, "OP_PlayEverquestRequest=0x000d\n"); + fprintf(f, "OP_PlayEverquestResponse=0x0021\n"); + fprintf(f, "OP_ChatMessage=0x0016\n"); + fprintf(f, "OP_LoginAccepted=0x0017\n"); + fprintf(f, "OP_ServerListResponse=0x0018\n"); + fprintf(f, "OP_Poll=0x0029\n"); + fprintf(f, "OP_EnterChat=0x000f\n"); + fprintf(f, "OP_PollResponse=0x0011\n"); + fclose(f); + } +} + +void CheckSoDOpcodeFile(const std::string& path) { + if (File::Exists(path)) { + return; + } + + auto f = fopen(path.c_str(), "w"); + if (f) { + fprintf(f, "#EQEmu Public Login Server OPCodes\n"); + fprintf(f, "OP_SessionReady=0x0001\n"); + fprintf(f, "OP_Login=0x0002\n"); + fprintf(f, "OP_ServerListRequest=0x0004\n"); + fprintf(f, "OP_PlayEverquestRequest=0x000d\n"); + fprintf(f, "OP_PlayEverquestResponse=0x0022\n"); + fprintf(f, "OP_ChatMessage=0x0017\n"); + fprintf(f, "OP_LoginAccepted=0x0018\n"); + fprintf(f, "OP_ServerListResponse=0x0019\n"); + fprintf(f, "OP_Poll=0x0029\n"); + fprintf(f, "OP_LoginExpansionPacketData=0x0031\n"); + fprintf(f, "OP_EnterChat=0x000f\n"); + fprintf(f, "OP_PollResponse=0x0011\n"); + fclose(f); + } +} + +void CheckLarionOpcodeFile(const std::string& path) { + if (File::Exists(path)) { + return; + } + + auto f = fopen(path.c_str(), "w"); + if (f) { + fprintf(f, "#EQEmu Public Login Server OPCodes\n"); + fprintf(f, "OP_SessionReady=0x0001\n"); + fprintf(f, "OP_Login=0x0002\n"); + fprintf(f, "OP_ServerListRequest=0x0004\n"); + fprintf(f, "OP_PlayEverquestRequest=0x000d\n"); + fprintf(f, "OP_PlayEverquestResponse=0x0022\n"); + fprintf(f, "OP_ChatMessage=0x0017\n"); + fprintf(f, "OP_LoginAccepted=0x0018\n"); + fprintf(f, "OP_ServerListResponse=0x0019\n"); + fprintf(f, "OP_Poll=0x0029\n"); + fprintf(f, "OP_EnterChat=0x000f\n"); + fprintf(f, "OP_PollResponse=0x0011\n"); + fprintf(f, "OP_SystemFingerprint=0x0016\n"); + fprintf(f, "OP_ExpansionList=0x0030\n"); + fclose(f); + } +} ClientManager::ClientManager() { @@ -19,14 +92,12 @@ ClientManager::ClientManager() std::string opcodes_path = fmt::format( "{}/{}", - path.GetServerPath(), - server.config.GetVariableString( - "client_configuration", - "titanium_opcodes", - "login_opcodes.conf" - ) + path.GetOpcodePath(), + "login_opcodes.conf" ); + CheckTitaniumOpcodeFile(opcodes_path); + if (!titanium_ops->LoadOpcodes(opcodes_path.c_str())) { LogError( "ClientManager fatal error: couldn't load opcodes for Titanium file [{0}]", @@ -58,14 +129,12 @@ ClientManager::ClientManager() opcodes_path = fmt::format( "{}/{}", - path.GetServerPath(), - server.config.GetVariableString( - "client_configuration", - "sod_opcodes", - "login_opcodes.conf" - ) + path.GetOpcodePath(), + "login_opcodes_sod.conf" ); + CheckSoDOpcodeFile(opcodes_path); + if (!sod_ops->LoadOpcodes(opcodes_path.c_str())) { LogError( "ClientManager fatal error: couldn't load opcodes for SoD file {0}", @@ -98,14 +167,12 @@ ClientManager::ClientManager() opcodes_path = fmt::format( "{}/{}", - path.GetServerPath(), - server.config.GetVariableString( - "client_configuration", - "larion_opcodes", - "login_opcodes.conf" - ) + path.GetOpcodePath(), + "login_opcodes_larion.conf" ); + CheckLarionOpcodeFile(opcodes_path); + if (!larion_ops->LoadOpcodes(opcodes_path.c_str())) { LogError( "ClientManager fatal error: couldn't load opcodes for Larion file [{0}]",