mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
Eluna remove crash possibility of using ReloadEluna global function on returning hooks, restrict the use of the reload command
This commit is contained in:
@@ -421,7 +421,7 @@ namespace LuaGlobalFunctions
|
|||||||
|
|
||||||
int ReloadEluna(lua_State* L)
|
int ReloadEluna(lua_State* L)
|
||||||
{
|
{
|
||||||
Eluna::ReloadEluna();
|
Eluna::reload = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
33
HookMgr.cpp
33
HookMgr.cpp
@@ -304,6 +304,12 @@ void Eluna::OnShutdownCancel()
|
|||||||
|
|
||||||
void Eluna::OnWorldUpdate(uint32 diff)
|
void Eluna::OnWorldUpdate(uint32 diff)
|
||||||
{
|
{
|
||||||
|
if (reload)
|
||||||
|
{
|
||||||
|
ReloadEluna();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_EventMgr->Update(diff);
|
m_EventMgr->Update(diff);
|
||||||
EVENT_BEGIN(ServerEventBindings, WORLD_EVENT_ON_UPDATE, return);
|
EVENT_BEGIN(ServerEventBindings, WORLD_EVENT_ON_UPDATE, return);
|
||||||
Push(L, diff);
|
Push(L, diff);
|
||||||
@@ -458,24 +464,27 @@ bool Eluna::OnRemove(Player* pPlayer, Item* item)
|
|||||||
bool Eluna::OnCommand(Player* player, const char* text)
|
bool Eluna::OnCommand(Player* player, const char* text)
|
||||||
{
|
{
|
||||||
std::string fullcmd(text);
|
std::string fullcmd(text);
|
||||||
char* creload = strtok((char*)text, " ");
|
if (player->GetSession()->GetSecurity() >= SEC_ADMINISTRATOR)
|
||||||
char* celuna = strtok(NULL, "");
|
|
||||||
if (creload && celuna)
|
|
||||||
{
|
{
|
||||||
std::string reload(creload);
|
char* creload = strtok((char*)text, " ");
|
||||||
std::string eluna(celuna);
|
char* celuna = strtok(NULL, "");
|
||||||
std::transform(reload.begin(), reload.end(), reload.begin(), ::tolower);
|
if (creload && celuna)
|
||||||
if (reload == "reload")
|
|
||||||
{
|
{
|
||||||
std::transform(eluna.begin(), eluna.end(), eluna.begin(), ::tolower);
|
std::string reload(creload);
|
||||||
if (std::string("eluna").find(eluna) == 0)
|
std::string eluna(celuna);
|
||||||
|
std::transform(reload.begin(), reload.end(), reload.begin(), ::tolower);
|
||||||
|
if (reload == "reload")
|
||||||
{
|
{
|
||||||
eWorld->SendServerMessage(SERVER_MSG_STRING, "Reloading Eluna...");
|
std::transform(eluna.begin(), eluna.end(), eluna.begin(), ::tolower);
|
||||||
ReloadEluna();
|
if (std::string("eluna").find(eluna) == 0)
|
||||||
return false;
|
{
|
||||||
|
Eluna::reload = true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool result = true;
|
bool result = true;
|
||||||
EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_COMMAND, return result);
|
EVENT_BEGIN(PlayerEventBindings, PLAYER_EVENT_ON_COMMAND, return result);
|
||||||
Push(L, player);
|
Push(L, player);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
Eluna::ScriptPaths Eluna::scripts;
|
Eluna::ScriptPaths Eluna::scripts;
|
||||||
Eluna* Eluna::GEluna = NULL;
|
Eluna* Eluna::GEluna = NULL;
|
||||||
|
bool Eluna::reload = false;
|
||||||
|
|
||||||
extern void RegisterFunctions(lua_State* L);
|
extern void RegisterFunctions(lua_State* L);
|
||||||
|
|
||||||
@@ -45,8 +46,11 @@ void Eluna::Uninitialize()
|
|||||||
|
|
||||||
void Eluna::ReloadEluna()
|
void Eluna::ReloadEluna()
|
||||||
{
|
{
|
||||||
|
eWorld->SendServerMessage(SERVER_MSG_STRING, "Reloading Eluna...");
|
||||||
Uninitialize();
|
Uninitialize();
|
||||||
Initialize();
|
Initialize();
|
||||||
|
|
||||||
|
reload = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Eluna::Eluna():
|
Eluna::Eluna():
|
||||||
|
|||||||
@@ -353,6 +353,7 @@ public:
|
|||||||
typedef std::set<std::string> ScriptPaths;
|
typedef std::set<std::string> ScriptPaths;
|
||||||
|
|
||||||
static Eluna* GEluna;
|
static Eluna* GEluna;
|
||||||
|
static bool reload;
|
||||||
|
|
||||||
lua_State* L;
|
lua_State* L;
|
||||||
int userdata_table;
|
int userdata_table;
|
||||||
@@ -380,6 +381,8 @@ public:
|
|||||||
static ScriptPaths scripts;
|
static ScriptPaths scripts;
|
||||||
static void Initialize();
|
static void Initialize();
|
||||||
static void Uninitialize();
|
static void Uninitialize();
|
||||||
|
// Use Eluna::reload = true; instead.
|
||||||
|
// This will be called on next update
|
||||||
static void ReloadEluna();
|
static void ReloadEluna();
|
||||||
void static GetScripts(std::string path, ScriptPaths& scripts);
|
void static GetScripts(std::string path, ScriptPaths& scripts);
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ void RegisterGlobals(lua_State* L)
|
|||||||
lua_register(L, "GetMapById", &LuaGlobalFunctions::GetMapById); // GetMapById(mapId, instance) - Returns map object of id specified. UNDOCUMENTED
|
lua_register(L, "GetMapById", &LuaGlobalFunctions::GetMapById); // GetMapById(mapId, instance) - Returns map object of id specified. UNDOCUMENTED
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
lua_register(L, "ReloadEluna", &LuaGlobalFunctions::ReloadEluna); // ReloadEluna() - Reload's Eluna engine.
|
lua_register(L, "ReloadEluna", &LuaGlobalFunctions::ReloadEluna); // ReloadEluna() - Reload's Eluna engine. Warning! Reloading should be used only for testing.
|
||||||
lua_register(L, "SendWorldMessage", &LuaGlobalFunctions::SendWorldMessage); // SendWorldMessage(msg) - Sends a broadcast message to everyone
|
lua_register(L, "SendWorldMessage", &LuaGlobalFunctions::SendWorldMessage); // SendWorldMessage(msg) - Sends a broadcast message to everyone
|
||||||
lua_register(L, "WorldDBQuery", &LuaGlobalFunctions::WorldDBQuery); // WorldDBQuery(sql) - Executes given SQL query to world database instantly and returns a QueryResult object
|
lua_register(L, "WorldDBQuery", &LuaGlobalFunctions::WorldDBQuery); // WorldDBQuery(sql) - Executes given SQL query to world database instantly and returns a QueryResult object
|
||||||
lua_register(L, "WorldDBExecute", &LuaGlobalFunctions::WorldDBExecute); // WorldDBExecute(sql) - Executes given SQL query to world database (not instant)
|
lua_register(L, "WorldDBExecute", &LuaGlobalFunctions::WorldDBExecute); // WorldDBExecute(sql) - Executes given SQL query to world database (not instant)
|
||||||
|
|||||||
Reference in New Issue
Block a user