mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-24 14:16:31 +00:00
Merge branch 'master' into Playerbot
This commit is contained in:
@@ -99,19 +99,41 @@ bool ChatHandler::HasLowerSecurityAccount(WorldSession* target, uint32 target_ac
|
||||
return false;
|
||||
}
|
||||
|
||||
void ChatHandler::SendWorldText(std::string_view str)
|
||||
void ChatHandler::SendNotification(std::string_view str)
|
||||
{
|
||||
std::vector<std::string_view> lines = Acore::Tokenize(str, '\n', true);
|
||||
for (std::string_view line : lines)
|
||||
{
|
||||
WorldPacket data(SMSG_NOTIFICATION, line.size() + 1);
|
||||
data << line.data();
|
||||
m_session->SendPacket(&data);
|
||||
}
|
||||
}
|
||||
|
||||
Player* player = m_session->GetPlayer();
|
||||
if (!player || !player->IsInWorld())
|
||||
void ChatHandler::SendGMText(std::string_view str)
|
||||
{
|
||||
std::vector<std::string_view> lines = Acore::Tokenize(str, '\n', true);
|
||||
// Session should have permissions to receive global gm messages
|
||||
if (AccountMgr::IsPlayerAccount(m_session->GetSecurity()))
|
||||
return;
|
||||
|
||||
for (std::string_view line : lines)
|
||||
{
|
||||
WorldPacket data;
|
||||
ChatHandler::BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line);
|
||||
player->SendDirectMessage(&data);
|
||||
m_session->SendPacket(&data);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatHandler::SendWorldText(std::string_view str)
|
||||
{
|
||||
std::vector<std::string_view> lines = Acore::Tokenize(str, '\n', true);
|
||||
|
||||
for (std::string_view line : lines)
|
||||
{
|
||||
WorldPacket data;
|
||||
ChatHandler::BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line);
|
||||
m_session->SendPacket(&data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,9 +142,6 @@ void ChatHandler::SendWorldTextOptional(std::string_view str, uint32 flag)
|
||||
std::vector<std::string_view> lines = Acore::Tokenize(str, '\n', true);
|
||||
|
||||
Player* player = m_session->GetPlayer();
|
||||
if (!player || !player->IsInWorld())
|
||||
return;
|
||||
|
||||
if (sWorld->getBoolConfig(CONFIG_PLAYER_SETTINGS_ENABLED))
|
||||
if (player->GetPlayerSetting(AzerothcorePSSource, SETTING_ANNOUNCER_FLAGS).HasFlag(flag))
|
||||
return;
|
||||
@@ -483,6 +502,23 @@ Player* ChatHandler::getSelectedPlayerOrSelf() const
|
||||
return targetPlayer;
|
||||
}
|
||||
|
||||
bool ChatHandler::HasSession() const
|
||||
{
|
||||
if (!m_session)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ChatHandler::DoForAllValidSessions(std::function<void(Player*)> exec)
|
||||
{
|
||||
SessionMap::const_iterator itr;
|
||||
for (itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
|
||||
if (Player* player = itr->second->GetPlayer())
|
||||
if (player->IsInWorld())
|
||||
exec(player);
|
||||
}
|
||||
|
||||
char* ChatHandler::extractKeyFromLink(char* text, char const* linkType, char** something1)
|
||||
{
|
||||
// skip empty
|
||||
@@ -1003,6 +1039,11 @@ int CliHandler::GetSessionDbLocaleIndex() const
|
||||
return sObjectMgr->GetDBCLocaleIndex();
|
||||
}
|
||||
|
||||
bool CliHandler::HasSession() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AddonChannelCommandHandler::ParseCommands(std::string_view str)
|
||||
{
|
||||
if (memcmp(str.data(), "AzerothCore\t", 12))
|
||||
|
||||
@@ -69,36 +69,62 @@ public:
|
||||
|
||||
static char* LineFromMessage(char*& pos) { char* start = strtok(pos, "\n"); pos = nullptr; return start; }
|
||||
|
||||
void SendNotification(std::string_view str);
|
||||
template<typename... Args>
|
||||
void SendNotification(uint32 strId, Args&&... args)
|
||||
{
|
||||
if (HasSession())
|
||||
SendNotification(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
|
||||
}
|
||||
template<typename... Args>
|
||||
void SendNotification(char const* fmt, Args&&... args)
|
||||
{
|
||||
if (HasSession())
|
||||
SendNotification(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
void SendGMText(std::string_view str);
|
||||
template<typename... Args>
|
||||
void SendGMText(uint32 strId, Args&&... args)
|
||||
{
|
||||
// GMText should be sent to all sessions
|
||||
DoForAllValidSessions([&](Player* player)
|
||||
{
|
||||
m_session = player->GetSession();
|
||||
SendGMText(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
|
||||
});
|
||||
}
|
||||
template<typename... Args>
|
||||
void SendGMText(char const* fmt, Args&&... args)
|
||||
{
|
||||
// GMText should be sent to all sessions
|
||||
DoForAllValidSessions([&](Player* player)
|
||||
{
|
||||
m_session = player->GetSession();
|
||||
SendGMText(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
|
||||
});
|
||||
}
|
||||
|
||||
void SendWorldText(std::string_view str);
|
||||
template<typename... 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())
|
||||
DoForAllValidSessions([&](Player* player)
|
||||
{
|
||||
m_session = player->GetSession();
|
||||
SendWorldText(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
template<typename... 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())
|
||||
// WorldText should be sent to all sessions
|
||||
DoForAllValidSessions([&](Player* player)
|
||||
{
|
||||
m_session = player->GetSession();
|
||||
SendWorldText(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void SendWorldTextOptional(std::string_view str, uint32 flag);
|
||||
@@ -106,31 +132,21 @@ public:
|
||||
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())
|
||||
DoForAllValidSessions([&](Player* player)
|
||||
{
|
||||
m_session = player->GetSession();
|
||||
SendWorldTextOptional(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...), flag);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
template<typename... 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())
|
||||
DoForAllValidSessions([&](Player* player)
|
||||
{
|
||||
m_session = player->GetSession();
|
||||
SendWorldTextOptional(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...), flag);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// function with different implementation for chat/console
|
||||
@@ -143,13 +159,15 @@ public:
|
||||
template<typename... Args>
|
||||
void PSendSysMessage(char const* fmt, Args&&... args)
|
||||
{
|
||||
SendSysMessage(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
|
||||
if (HasSession())
|
||||
SendSysMessage(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
void PSendSysMessage(uint32 entry, Args&&... args)
|
||||
{
|
||||
SendSysMessage(PGetParseString(entry, std::forward<Args>(args)...));
|
||||
if (HasSession())
|
||||
SendSysMessage(PGetParseString(entry, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
template<typename... Args>
|
||||
@@ -198,6 +216,12 @@ public:
|
||||
// Returns either the selected player or self if there is no selected player
|
||||
Player* getSelectedPlayerOrSelf() const;
|
||||
|
||||
// Has different implementation for console
|
||||
virtual bool HasSession() const;
|
||||
// Do whatever you want to all the players with a valid session [including GameMasters], i.e.: param exec = [&](Player* p) { p->Whatever(); }
|
||||
// A "valid" session requires player->IsInWorld() to be true
|
||||
void DoForAllValidSessions(std::function<void(Player*)> exec);
|
||||
|
||||
char* extractKeyFromLink(char* text, char const* linkType, char** something1 = nullptr);
|
||||
char* extractKeyFromLink(char* text, char const* const* linkTypes, int* found_idx, char** something1 = nullptr);
|
||||
char* extractQuotedArg(char* args);
|
||||
@@ -247,6 +271,9 @@ public:
|
||||
LocaleConstant GetSessionDbcLocale() const override;
|
||||
int GetSessionDbLocaleIndex() const override;
|
||||
|
||||
// CLI does not have a session, so we override it to always be true to output SendNotification and PSendSysMessage to console
|
||||
bool HasSession() const override;
|
||||
|
||||
private:
|
||||
void* m_callbackArg;
|
||||
Print* m_print;
|
||||
|
||||
Reference in New Issue
Block a user