fix(Core/World): Crash on SendWorldText(Optional) (#19531)

* fix(Core/World): Crash on SendWorldText(Optional)

* WorldText should be sent to all sessions

* now it works
This commit is contained in:
Kitzunu
2024-07-30 22:53:11 +02:00
committed by GitHub
parent 97ee20a7aa
commit a1e9dfce41
2 changed files with 67 additions and 40 deletions
+5 -19
View File
@@ -102,16 +102,10 @@ bool ChatHandler::HasLowerSecurityAccount(WorldSession* target, uint32 target_ac
void ChatHandler::SendWorldText(std::string_view str) void ChatHandler::SendWorldText(std::string_view str)
{ {
std::vector<std::string_view> lines = Acore::Tokenize(str, '\n', true); std::vector<std::string_view> lines = Acore::Tokenize(str, '\n', true);
for (SessionMap::const_iterator itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
{
WorldSession* session = itr->second;
if (!session)
continue;
// Player should be in world Player* player = m_session->GetPlayer();
Player* player = session->GetPlayer();
if (!player || !player->IsInWorld()) if (!player || !player->IsInWorld())
continue; return;
for (std::string_view line : lines) for (std::string_view line : lines)
{ {
@@ -119,26 +113,19 @@ void ChatHandler::SendWorldText(std::string_view str)
ChatHandler::BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line); ChatHandler::BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line);
player->SendDirectMessage(&data); player->SendDirectMessage(&data);
} }
}
} }
void ChatHandler::SendWorldTextOptional(std::string_view str, uint32 flag) void ChatHandler::SendWorldTextOptional(std::string_view str, uint32 flag)
{ {
std::vector<std::string_view> lines = Acore::Tokenize(str, '\n', true); std::vector<std::string_view> lines = Acore::Tokenize(str, '\n', true);
for (SessionMap::const_iterator itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
{
WorldSession* session = itr->second;
if (!session)
continue;
// Player should be in world Player* player = m_session->GetPlayer();
Player* player = session->GetPlayer();
if (!player || !player->IsInWorld()) if (!player || !player->IsInWorld())
continue; return;
if (sWorld->getBoolConfig(CONFIG_PLAYER_SETTINGS_ENABLED)) if (sWorld->getBoolConfig(CONFIG_PLAYER_SETTINGS_ENABLED))
if (player->GetPlayerSetting(AzerothcorePSSource, SETTING_ANNOUNCER_FLAGS).HasFlag(flag)) if (player->GetPlayerSetting(AzerothcorePSSource, SETTING_ANNOUNCER_FLAGS).HasFlag(flag))
continue; return;
for (std::string_view line : lines) for (std::string_view line : lines)
{ {
@@ -146,7 +133,6 @@ void ChatHandler::SendWorldTextOptional(std::string_view str, uint32 flag)
ChatHandler::BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line); ChatHandler::BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line);
player->SendDirectMessage(&data); player->SendDirectMessage(&data);
} }
}
} }
void ChatHandler::SendSysMessage(std::string_view str, bool escapeCharacters) void ChatHandler::SendSysMessage(std::string_view str, bool escapeCharacters)
+41
View File
@@ -20,6 +20,7 @@
#include "ChatCommand.h" #include "ChatCommand.h"
#include "Errors.h" #include "Errors.h"
#include "Player.h"
#include "SharedDefines.h" #include "SharedDefines.h"
#include "WorldSession.h" #include "WorldSession.h"
#include <vector> #include <vector>
@@ -54,25 +55,65 @@ public:
template<typename... Args> template<typename... Args>
void SendWorldText(uint32 strId, Args&&... args) void SendWorldText(uint32 strId, Args&&... args)
{ {
// WorldText should be sent to all sessions
SessionMap::const_iterator itr;
for (itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
{
Player* player = itr->second->GetPlayer();
if (player && player->IsInWorld())
{
m_session = player->GetSession();
SendWorldText(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...)); SendWorldText(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
} }
}
}
template<typename... Args> template<typename... Args>
void SendWorldText(char const* fmt, Args&&... args) void SendWorldText(char const* fmt, Args&&... args)
{ {
// WorldTextOptional should be sent to all sessions
SessionMap::const_iterator itr;
for (itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
{
Player* player = itr->second->GetPlayer();
if (player && player->IsInWorld())
{
m_session = player->GetSession();
SendWorldText(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...)); SendWorldText(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
} }
}
}
void SendWorldTextOptional(std::string_view str, uint32 flag); void SendWorldTextOptional(std::string_view str, uint32 flag);
template<typename... Args> template<typename... Args>
void SendWorldTextOptional(uint32 strId, uint32 flag, Args&&... args) void SendWorldTextOptional(uint32 strId, uint32 flag, Args&&... args)
{ {
// WorldTextOptional should be sent to all sessions
SessionMap::const_iterator itr;
for (itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
{
Player* player = itr->second->GetPlayer();
if (player && player->IsInWorld())
{
m_session = player->GetSession();
SendWorldTextOptional(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...), flag); SendWorldTextOptional(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...), flag);
} }
}
}
template<typename... Args> template<typename... Args>
void SendWorldTextOptional(char const* fmt, uint32 flag, Args&&... args) void SendWorldTextOptional(char const* fmt, uint32 flag, Args&&... args)
{ {
// WorldTextOptional should be sent to all sessions
SessionMap::const_iterator itr;
for (itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
{
Player* player = itr->second->GetPlayer();
if (player && player->IsInWorld())
{
m_session = player->GetSession();
SendWorldTextOptional(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...), flag); SendWorldTextOptional(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...), flag);
} }
}
}
// function with different implementation for chat/console // function with different implementation for chat/console
virtual char const* GetAcoreString(uint32 entry) const; virtual char const* GetAcoreString(uint32 entry) const;