diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index 20468af0511..7518b80050d 100644 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -42,29 +42,32 @@ static Optional> commandTableCache; std::vector const& ChatHandler::getCommandTable() { if (!commandTableCache) - { - // We need to initialize this at top since SetDataForCommandInTable - // calls getCommandTable() recursively. - commandTableCache = sScriptMgr->GetChatCommands(); - - WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_COMMANDS); - PreparedQueryResult result = WorldDatabase.Query(stmt); - if (result) - { - do - { - Field* fields = result->Fetch(); - std::string name = fields[0].GetString(); - - SetDataForCommandInTable(*commandTableCache, name.c_str(), fields[1].GetUInt16(), fields[2].GetString(), name); - } - while (result->NextRow()); - } - } + InitializeCommandTable(); return *commandTableCache; } +void ChatHandler::InitializeCommandTable() +{ + // We need to initialize this at top since SetDataForCommandInTable + // calls getCommandTable() recursively. + commandTableCache = sScriptMgr->GetChatCommands(); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_COMMANDS); + PreparedQueryResult result = WorldDatabase.Query(stmt); + if (result) + { + do + { + Field* fields = result->Fetch(); + std::string name = fields[0].GetString(); + + SetDataForCommandInTable(*commandTableCache, name.c_str(), fields[1].GetUInt16(), fields[2].GetString(), name); + } + while (result->NextRow()); + } +} + void ChatHandler::invalidateCommandTable() { commandTableCache.reset(); diff --git a/src/server/game/Chat/Chat.h b/src/server/game/Chat/Chat.h index e6c96212566..13e0c18c37a 100644 --- a/src/server/game/Chat/Chat.h +++ b/src/server/game/Chat/Chat.h @@ -83,6 +83,7 @@ class TC_GAME_API ChatHandler virtual bool ParseCommands(char const* text); static std::vector const& getCommandTable(); + static void InitializeCommandTable(); static void invalidateCommandTable(); void SendGlobalSysMessage(const char *str); diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 8badf72b7f8..06387511eba 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -2075,6 +2075,9 @@ void World::SetInitialWorldSettings() TC_LOG_INFO("server.loading", "Initialize query data..."); sObjectMgr->InitializeQueriesData(QUERY_DATA_ALL); + TC_LOG_INFO("server.loading", "Initialize commands..."); + ChatHandler::InitializeCommandTable(); + ///- Initialize game time and timers TC_LOG_INFO("server.loading", "Initialize game time and timers"); GameTime::UpdateGameTimers();