Got eluna running and working

This commit is contained in:
2025-11-17 15:34:19 +00:00
parent b7a34f6d70
commit 3866750d98
7 changed files with 50 additions and 4 deletions

View File

@@ -46,7 +46,7 @@ target_include_directories(lualib INTERFACE
/usr/include/luajit-2.1 /usr/include/luajit-2.1
${CMAKE_SOURCE_DIR}/dep/efsw/include) ${CMAKE_SOURCE_DIR}/dep/efsw/include)
target_link_libraries(lualib INTERFACE luajit-5.1 efsw) target_link_libraries(lualib INTERFACE luajit-5.1 efsw)
target_compile_definitions(lualib INTERFACE LUAJIT_VERSION ELUNA_TRINITY ELUNA_EXPANSION=9) target_compile_definitions(lualib INTERFACE ELUNA LUAJIT_VERSION ELUNA_TRINITY ELUNA_EXPANSION=9)
add_library(game add_library(game
${PRIVATE_SOURCES}) ${PRIVATE_SOURCES})

View File

@@ -31,25 +31,42 @@ ElunaConfig::~ElunaConfig()
void ElunaConfig::Initialize() void ElunaConfig::Initialize()
{ {
ELUNA_LOG_INFO("[Eluna]: Initializing Eluna configuration...");
// Load bools // Load bools
SetConfig(CONFIG_ELUNA_ENABLED, "Eluna.Enabled", true); SetConfig(CONFIG_ELUNA_ENABLED, "Eluna.Enabled", true);
ELUNA_LOG_DEBUG("[Eluna]: CONFIG_ELUNA_ENABLED = %s", GetConfig(CONFIG_ELUNA_ENABLED) ? "true" : "false");
SetConfig(CONFIG_ELUNA_TRACEBACK, "Eluna.TraceBack", false); SetConfig(CONFIG_ELUNA_TRACEBACK, "Eluna.TraceBack", false);
ELUNA_LOG_DEBUG("[Eluna]: CONFIG_ELUNA_TRACEBACK = %s", GetConfig(CONFIG_ELUNA_TRACEBACK) ? "true" : "false");
SetConfig(CONFIG_ELUNA_SCRIPT_RELOADER, "Eluna.ScriptReloader", false); SetConfig(CONFIG_ELUNA_SCRIPT_RELOADER, "Eluna.ScriptReloader", false);
ELUNA_LOG_DEBUG("[Eluna]: CONFIG_ELUNA_SCRIPT_RELOADER = %s", GetConfig(CONFIG_ELUNA_SCRIPT_RELOADER) ? "true" : "false");
SetConfig(CONFIG_ELUNA_ENABLE_UNSAFE, "Eluna.UseUnsafeMethods", true); SetConfig(CONFIG_ELUNA_ENABLE_UNSAFE, "Eluna.UseUnsafeMethods", true);
ELUNA_LOG_DEBUG("[Eluna]: CONFIG_ELUNA_ENABLE_UNSAFE = %s", GetConfig(CONFIG_ELUNA_ENABLE_UNSAFE) ? "true" : "false");
SetConfig(CONFIG_ELUNA_ENABLE_DEPRECATED, "Eluna.UseDeprecatedMethods", true); SetConfig(CONFIG_ELUNA_ENABLE_DEPRECATED, "Eluna.UseDeprecatedMethods", true);
ELUNA_LOG_DEBUG("[Eluna]: CONFIG_ELUNA_ENABLE_DEPRECATED = %s", GetConfig(CONFIG_ELUNA_ENABLE_DEPRECATED) ? "true" : "false");
SetConfig(CONFIG_ELUNA_ENABLE_RELOAD_COMMAND, "Eluna.ReloadCommand", true); SetConfig(CONFIG_ELUNA_ENABLE_RELOAD_COMMAND, "Eluna.ReloadCommand", true);
ELUNA_LOG_DEBUG("[Eluna]: CONFIG_ELUNA_ENABLE_RELOAD_COMMAND = %s", GetConfig(CONFIG_ELUNA_ENABLE_RELOAD_COMMAND) ? "true" : "false");
// Load strings // Load strings
SetConfig(CONFIG_ELUNA_SCRIPT_PATH, "Eluna.ScriptPath", "lua_scripts"); SetConfig(CONFIG_ELUNA_SCRIPT_PATH, "Eluna.ScriptPath", "lua_scripts");
ELUNA_LOG_DEBUG("[Eluna]: CONFIG_ELUNA_SCRIPT_PATH = %s", GetConfig(CONFIG_ELUNA_SCRIPT_PATH).c_str());
SetConfig(CONFIG_ELUNA_ONLY_ON_MAPS, "Eluna.OnlyOnMaps", ""); SetConfig(CONFIG_ELUNA_ONLY_ON_MAPS, "Eluna.OnlyOnMaps", "");
SetConfig(CONFIG_ELUNA_REQUIRE_PATH_EXTRA, "Eluna.RequirePaths", ""); SetConfig(CONFIG_ELUNA_REQUIRE_PATH_EXTRA, "Eluna.RequirePaths", "");
SetConfig(CONFIG_ELUNA_REQUIRE_CPATH_EXTRA, "Eluna.RequireCPaths", ""); SetConfig(CONFIG_ELUNA_REQUIRE_CPATH_EXTRA, "Eluna.RequireCPaths", "");
// Load ints // Load ints
SetConfig(CONFIG_ELUNA_RELOAD_SECURITY_LEVEL, "Eluna.ReloadSecurityLevel", 3); SetConfig(CONFIG_ELUNA_RELOAD_SECURITY_LEVEL, "Eluna.ReloadSecurityLevel", 3);
ELUNA_LOG_DEBUG("[Eluna]: CONFIG_ELUNA_RELOAD_SECURITY_LEVEL = %u", GetConfig(CONFIG_ELUNA_RELOAD_SECURITY_LEVEL));
// Call extra functions // Call extra functions
TokenizeAllowedMaps(); TokenizeAllowedMaps();
ELUNA_LOG_INFO("[Eluna]: Eluna configuration initialized successfully");
} }
void ElunaConfig::SetConfig(ElunaConfigBoolValues index, char const* fieldname, bool defvalue) void ElunaConfig::SetConfig(ElunaConfigBoolValues index, char const* fieldname, bool defvalue)

View File

@@ -106,12 +106,18 @@ void ElunaLoader::ReloadScriptCache()
void ElunaLoader::LoadScripts() void ElunaLoader::LoadScripts()
{ {
ELUNA_LOG_INFO("[Eluna]: LoadScripts() called, current cache state: %u", uint32(m_cacheState));
// only reload the cache if it is either in a reinit state or not loaded at all // only reload the cache if it is either in a reinit state or not loaded at all
if (m_cacheState != SCRIPT_CACHE_REINIT && m_cacheState != SCRIPT_CACHE_NONE) if (m_cacheState != SCRIPT_CACHE_REINIT && m_cacheState != SCRIPT_CACHE_NONE)
{
ELUNA_LOG_DEBUG("[Eluna]: Script cache is in state %u, skipping load", uint32(m_cacheState));
return; return;
}
// set the cache state to loading // set the cache state to loading
m_cacheState = SCRIPT_CACHE_LOADING; m_cacheState = SCRIPT_CACHE_LOADING;
ELUNA_LOG_DEBUG("[Eluna]: Script cache state set to LOADING");
uint32 oldMSTime = ElunaUtil::GetCurrTime(); uint32 oldMSTime = ElunaUtil::GetCurrTime();
@@ -162,6 +168,7 @@ void ElunaLoader::LoadScripts()
// set the cache state to ready // set the cache state to ready
m_cacheState = SCRIPT_CACHE_READY; m_cacheState = SCRIPT_CACHE_READY;
ELUNA_LOG_INFO("[Eluna]: Script cache state set to READY");
} }
int ElunaLoader::LoadBytecodeChunk(lua_State* /*L*/, uint8* bytes, size_t len, BytecodeBuffer* buffer) int ElunaLoader::LoadBytecodeChunk(lua_State* /*L*/, uint8* bytes, size_t len, BytecodeBuffer* buffer)

View File

@@ -39,6 +39,8 @@
extern "C" extern "C"
{ {
#include "lua.h" #include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}; };
class AuctionHouseObject; class AuctionHouseObject;

View File

@@ -23,6 +23,7 @@
#include "LuaEngine/LuaEngine.h" #include "LuaEngine/LuaEngine.h"
#include "LuaEngine/ElunaMgr.h" #include "LuaEngine/ElunaMgr.h"
#include "LuaEngine/ElunaConfig.h" #include "LuaEngine/ElunaConfig.h"
#include "LuaEngine/ElunaLoader.h"
#include "AccountMgr.h" #include "AccountMgr.h"
#include "AchievementMgr.h" #include "AchievementMgr.h"
#include "AreaTriggerDataStore.h" #include "AreaTriggerDataStore.h"
@@ -1264,6 +1265,13 @@ bool World::SetInitialWorldSettings()
///- Initialize config settings ///- Initialize config settings
LoadConfigSettings(); LoadConfigSettings();
///- Initialize Eluna configuration and loader
TC_LOG_INFO("server.loading", "Initializing Eluna...");
sElunaConfig->Initialize();
TC_LOG_INFO("server.loading", "Loading Eluna scripts...");
sElunaLoader->LoadScripts();
TC_LOG_INFO("server.loading", "Eluna initialization complete");
///- Initialize Allowed Security Level ///- Initialize Allowed Security Level
LoadDBAllowedSecurityLevel(); LoadDBAllowedSecurityLevel();

View File

@@ -211,10 +211,14 @@ add_library(scripts STATIC
target_link_libraries(scripts target_link_libraries(scripts
PRIVATE PRIVATE
trinity-core-interface trinity-core-interface
game
lualib
PUBLIC PUBLIC
game-interface) game-interface)
target_include_directories(scripts target_include_directories(scripts
PRIVATE
/usr/include/luajit-2.1
PUBLIC PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}) ${CMAKE_CURRENT_SOURCE_DIR})

View File

@@ -31,6 +31,7 @@ EndScriptData */
#ifdef ELUNA #ifdef ELUNA
#include "LuaEngine.h" #include "LuaEngine.h"
#include "ElunaMgr.h" #include "ElunaMgr.h"
#include "ElunaConfig.h"
#endif #endif
using namespace Trinity::ChatCommands; using namespace Trinity::ChatCommands;
@@ -53,16 +54,23 @@ private:
static bool HandleLuaCommand(ChatHandler* handler, char const* args) static bool HandleLuaCommand(ChatHandler* handler, char const* args)
{ {
#ifdef ELUNA #ifdef ELUNA
// Check if Eluna is enabled at runtime
if (!sElunaConfig->IsElunaEnabled())
{
handler->SendSysMessage("Eluna is not enabled on this server.");
return false;
}
if (!*args) if (!*args)
{ {
handler->SendSysMessage("Usage: .lua <code>"); handler->SendSysMessage("Usage: .lua <code>");
return false; return false;
} }
// Get the global Eluna instance // Get the global Eluna instance directly from ElunaMgr
// Note: We don't use ElunaInfo here because its destructor would destroy the instance
ElunaInfoKey key = ElunaInfoKey::MakeGlobalKey(0); ElunaInfoKey key = ElunaInfoKey::MakeGlobalKey(0);
ElunaInfo info(key); Eluna* eluna = sElunaMgr->Get(key);
Eluna* eluna = info.GetEluna();
if (!eluna || !eluna->HasLuaState()) if (!eluna || !eluna->HasLuaState())
{ {