mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-03-16 14:05:28 +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:
@@ -0,0 +1,5 @@
|
|||||||
|
--
|
||||||
|
DELETE FROM `acore_string` WHERE `entry` IN (6613,6615);
|
||||||
|
INSERT INTO `acore_string` (`entry`, `content_default`, `locale_koKR`, `locale_frFR`, `locale_deDE`, `locale_zhCN`, `locale_zhTW`, `locale_esES`, `locale_esMX`, `locale_ruRU`) VALUES
|
||||||
|
(6613, '|cfff00000[GM Announcement]: {}|r', NULL, NULL, '|cfff00000[GM Ankündigung von [{}]]: {}|r', '|cfff00000[管理员公告]: {}|r', NULL, NULL, NULL, NULL),
|
||||||
|
(6615, '|cffffff00[|c1f40af20GM Announce by|r |cffff0000{}|cffffff00]:|r {}|r', NULL, NULL, '|cffffff00[|c1f40af20GM Ankündigung von|r |cffff0000{}|cffffff00]:|r {}|r', '|cffffff00[|c1f40af20管理员广播|r |cffff0000{}|cffffff00]:|r {}|r', NULL, NULL, NULL, NULL);
|
||||||
@@ -99,6 +99,26 @@ bool ChatHandler::HasLowerSecurityAccount(WorldSession* target, uint32 target_ac
|
|||||||
return false;
|
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)
|
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);
|
||||||
|
|||||||
@@ -51,6 +51,28 @@ public:
|
|||||||
|
|
||||||
static char* LineFromMessage(char*& pos) { char* start = strtok(pos, "\n"); pos = nullptr; return start; }
|
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);
|
void SendWorldText(std::string_view str);
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void SendWorldText(uint32 strId, Args&&... args)
|
void SendWorldText(uint32 strId, Args&&... args)
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData)
|
|||||||
sTicketMgr->AddTicket(ticket);
|
sTicketMgr->AddTicket(ticket);
|
||||||
sTicketMgr->UpdateLastChange();
|
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;
|
response = GMTICKET_RESPONSE_CREATE_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -145,7 +145,7 @@ void WorldSession::HandleGMTicketUpdateOpcode(WorldPacket& recv_data)
|
|||||||
ticket->SetMessage(message);
|
ticket->SetMessage(message);
|
||||||
ticket->SaveToDB(trans);
|
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;
|
response = GMTICKET_RESPONSE_UPDATE_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -163,7 +163,7 @@ void WorldSession::HandleGMTicketDeleteOpcode(WorldPacket& /*recv_data*/)
|
|||||||
data << uint32(GMTICKET_RESPONSE_TICKET_DELETED);
|
data << uint32(GMTICKET_RESPONSE_TICKET_DELETED);
|
||||||
SendPacket(&data);
|
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->CloseTicket(ticket->GetId(), GetPlayer()->GetGUID());
|
||||||
sTicketMgr->SendTicket(this, nullptr);
|
sTicketMgr->SendTicket(this, nullptr);
|
||||||
|
|||||||
@@ -566,7 +566,6 @@ public:
|
|||||||
[[nodiscard]] virtual uint16 GetConfigMaxSkillValue() const = 0;
|
[[nodiscard]] virtual uint16 GetConfigMaxSkillValue() const = 0;
|
||||||
virtual void SetInitialWorldSettings() = 0;
|
virtual void SetInitialWorldSettings() = 0;
|
||||||
virtual void LoadConfigSettings(bool reload = false) = 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 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 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;
|
virtual bool SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self = nullptr, TeamId teamId = TEAM_NEUTRAL) = 0;
|
||||||
|
|||||||
@@ -2578,32 +2578,6 @@ namespace Acore
|
|||||||
};
|
};
|
||||||
} // 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)
|
/// 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)
|
bool World::SendZoneMessage(uint32 zone, WorldPacket const* packet, WorldSession* self, TeamId teamId)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -238,7 +238,6 @@ public:
|
|||||||
void SetInitialWorldSettings() override;
|
void SetInitialWorldSettings() override;
|
||||||
void LoadConfigSettings(bool reload = false) 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 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;
|
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;
|
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())
|
if (WorldSession* session = handler->GetSession())
|
||||||
name = session->GetPlayer()->GetName();
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,12 +92,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// announce to logged in GMs
|
// announce to logged in GMs
|
||||||
static bool HandleGMAnnounceCommand(ChatHandler* /*handler*/, Tail message)
|
static bool HandleGMAnnounceCommand(ChatHandler* handler, Tail message)
|
||||||
{
|
{
|
||||||
if (message.empty())
|
if (message.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
sWorld->SendGMText(LANG_GM_BROADCAST, message.data());
|
handler->SendGMText(LANG_GM_BROADCAST, message.data());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ public:
|
|||||||
MOCK_METHOD(uint16, GetConfigMaxSkillValue, (), (const));
|
MOCK_METHOD(uint16, GetConfigMaxSkillValue, (), (const));
|
||||||
MOCK_METHOD(void, SetInitialWorldSettings, ());
|
MOCK_METHOD(void, SetInitialWorldSettings, ());
|
||||||
MOCK_METHOD(void, LoadConfigSettings, (bool reload), ());
|
MOCK_METHOD(void, LoadConfigSettings, (bool reload), ());
|
||||||
void SendGMText(uint32 string_id, ...) override {}
|
|
||||||
MOCK_METHOD(void, SendGlobalMessage, (WorldPacket const* packet, WorldSession* self, TeamId teamId), ());
|
MOCK_METHOD(void, SendGlobalMessage, (WorldPacket const* packet, WorldSession* self, TeamId teamId), ());
|
||||||
MOCK_METHOD(void, SendGlobalGMMessage, (WorldPacket const* packet, WorldSession* self, TeamId teamId), ());
|
MOCK_METHOD(void, SendGlobalGMMessage, (WorldPacket const* packet, WorldSession* self, TeamId teamId), ());
|
||||||
MOCK_METHOD(bool, SendZoneMessage, (uint32 zone, WorldPacket const* packet, WorldSession* self, TeamId teamId), ());
|
MOCK_METHOD(bool, SendZoneMessage, (uint32 zone, WorldPacket const* packet, WorldSession* self, TeamId teamId), ());
|
||||||
|
|||||||
Reference in New Issue
Block a user