mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-18 11:25:42 +00:00
refactor(Core/World): Move SendGMText to ChatHandler and allow fmt (#19490)
* refactor(Core/World): Move SendGMText to WorldSession and allow `fmt` - Move SendGMText from World to WorldSession - Make SendGMText use fmt - Make SendGMText parse acore_string entries * Update cs_message.cpp * tokenize the string only once * Move to chathandler * Update WorldSession.cpp * make sure we have a session
This commit is contained in:
@@ -99,6 +99,26 @@ bool ChatHandler::HasLowerSecurityAccount(WorldSession* target, uint32 target_ac
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// Player should be in world
|
||||
Player* player = m_session->GetPlayer();
|
||||
if (!player || !player->IsInWorld())
|
||||
return;
|
||||
|
||||
for (std::string_view line : lines)
|
||||
{
|
||||
WorldPacket data;
|
||||
ChatHandler::BuildChatPacket(data, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, nullptr, nullptr, line);
|
||||
player->SendDirectMessage(&data);
|
||||
}
|
||||
}
|
||||
|
||||
void ChatHandler::SendWorldText(std::string_view str)
|
||||
{
|
||||
std::vector<std::string_view> lines = Acore::Tokenize(str, '\n', true);
|
||||
|
||||
@@ -51,6 +51,28 @@ public:
|
||||
|
||||
static char* LineFromMessage(char*& pos) { char* start = strtok(pos, "\n"); pos = nullptr; return start; }
|
||||
|
||||
void SendGMText(std::string_view str);
|
||||
template<typename... Args>
|
||||
void SendGMText(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();
|
||||
SendGMText(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
|
||||
}
|
||||
}
|
||||
}
|
||||
template<typename... Args>
|
||||
void SendGMText(char const* fmt, Args&&... args)
|
||||
{
|
||||
SendGMText(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
void SendWorldText(std::string_view str);
|
||||
template<typename... Args>
|
||||
void SendWorldText(uint32 strId, Args&&... args)
|
||||
|
||||
@@ -118,7 +118,7 @@ void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData)
|
||||
sTicketMgr->AddTicket(ticket);
|
||||
sTicketMgr->UpdateLastChange();
|
||||
|
||||
sWorld->SendGMText(LANG_COMMAND_TICKETNEW, GetPlayer()->GetName().c_str(), ticket->GetId());
|
||||
ChatHandler(nullptr).SendGMText(LANG_COMMAND_TICKETNEW, GetPlayer()->GetName(), ticket->GetId());
|
||||
|
||||
response = GMTICKET_RESPONSE_CREATE_SUCCESS;
|
||||
}
|
||||
@@ -145,7 +145,7 @@ void WorldSession::HandleGMTicketUpdateOpcode(WorldPacket& recv_data)
|
||||
ticket->SetMessage(message);
|
||||
ticket->SaveToDB(trans);
|
||||
|
||||
sWorld->SendGMText(LANG_COMMAND_TICKETUPDATED, GetPlayer()->GetName().c_str(), ticket->GetId());
|
||||
ChatHandler(nullptr).SendGMText(LANG_COMMAND_TICKETUPDATED, GetPlayer()->GetName(), ticket->GetId());
|
||||
|
||||
response = GMTICKET_RESPONSE_UPDATE_SUCCESS;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ void WorldSession::HandleGMTicketDeleteOpcode(WorldPacket& /*recv_data*/)
|
||||
data << uint32(GMTICKET_RESPONSE_TICKET_DELETED);
|
||||
SendPacket(&data);
|
||||
|
||||
sWorld->SendGMText(LANG_COMMAND_TICKETPLAYERABANDON, GetPlayer()->GetName().c_str(), ticket->GetId());
|
||||
ChatHandler(nullptr).SendGMText(LANG_COMMAND_TICKETPLAYERABANDON, GetPlayer()->GetName(), ticket->GetId());
|
||||
|
||||
sTicketMgr->CloseTicket(ticket->GetId(), GetPlayer()->GetGUID());
|
||||
sTicketMgr->SendTicket(this, nullptr);
|
||||
|
||||
@@ -566,7 +566,6 @@ public:
|
||||
[[nodiscard]] virtual uint16 GetConfigMaxSkillValue() const = 0;
|
||||
virtual void SetInitialWorldSettings() = 0;
|
||||
virtual void LoadConfigSettings(bool reload = false) = 0;
|
||||
virtual void SendGMText(uint32 string_id, ...) = 0;
|
||||
virtual void SendGlobalMessage(WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
|
||||
virtual void SendGlobalGMMessage(WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
|
||||
virtual bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
|
||||
|
||||
@@ -2578,32 +2578,6 @@ namespace Acore
|
||||
};
|
||||
} // namespace Acore
|
||||
|
||||
/// Send a System Message to all GMs (except self if mentioned)
|
||||
void World::SendGMText(uint32 string_id, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, string_id);
|
||||
|
||||
Acore::WorldWorldTextBuilder wt_builder(string_id, &ap);
|
||||
Acore::LocalizedPacketListDo<Acore::WorldWorldTextBuilder> wt_do(wt_builder);
|
||||
for (SessionMap::iterator itr = _sessions.begin(); itr != _sessions.end(); ++itr)
|
||||
{
|
||||
// Session should have permissions to receive global gm messages
|
||||
WorldSession* session = itr->second;
|
||||
if (!session || AccountMgr::IsPlayerAccount(session->GetSecurity()))
|
||||
continue;
|
||||
|
||||
// Player should be in world
|
||||
Player* player = session->GetPlayer();
|
||||
if (!player || !player->IsInWorld())
|
||||
continue;
|
||||
|
||||
wt_do(session->GetPlayer());
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
/// Send a packet to all players (or players selected team) in the zone (except self if mentioned)
|
||||
bool World::SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self, TeamId teamId)
|
||||
{
|
||||
|
||||
@@ -238,7 +238,6 @@ public:
|
||||
void SetInitialWorldSettings() override;
|
||||
void LoadConfigSettings(bool reload = false) override;
|
||||
|
||||
void SendGMText(uint32 string_id, ...) override;
|
||||
void SendGlobalMessage(WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) override;
|
||||
void SendGlobalGMMessage(WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) override;
|
||||
bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) override;
|
||||
|
||||
@@ -77,7 +77,7 @@ public:
|
||||
if (WorldSession* session = handler->GetSession())
|
||||
name = session->GetPlayer()->GetName();
|
||||
|
||||
sWorld->SendGMText(LANG_GM_ANNOUNCE_COLOR, name.c_str(), message.data());
|
||||
handler->SendGMText(LANG_GM_ANNOUNCE_COLOR, name, message.data());
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -92,12 +92,12 @@ public:
|
||||
}
|
||||
|
||||
// announce to logged in GMs
|
||||
static bool HandleGMAnnounceCommand(ChatHandler* /*handler*/, Tail message)
|
||||
static bool HandleGMAnnounceCommand(ChatHandler* handler, Tail message)
|
||||
{
|
||||
if (message.empty())
|
||||
return false;
|
||||
|
||||
sWorld->SendGMText(LANG_GM_BROADCAST, message.data());
|
||||
handler->SendGMText(LANG_GM_BROADCAST, message.data());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user