refactor(Core/Chat): Move SendNotification to ChatHander (#19491)

* refactor(Core/Chat): Move SendNotification to ChatHander

* Update Battleground.cpp

* fix build

* Update src/server/game/Chat/Chat.h
This commit is contained in:
Kitzunu
2024-08-10 16:39:46 +02:00
committed by GitHub
parent ebc6218275
commit e4df159f5c
21 changed files with 96 additions and 75 deletions
@@ -1306,7 +1306,7 @@ void Battleground::ReadyMarkerClicked(Player* p)
readyMarkerClickedSet.insert(p->GetGUID()); readyMarkerClickedSet.insert(p->GetGUID());
uint32 count = readyMarkerClickedSet.size(); uint32 count = readyMarkerClickedSet.size();
uint32 req = ArenaTeam::GetReqPlayersForType(GetArenaType()); uint32 req = ArenaTeam::GetReqPlayersForType(GetArenaType());
p->GetSession()->SendNotification("You are marked as ready %u/%u", count, req); ChatHandler(p->GetSession()).SendNotification("You are marked as ready {}/{}", count, req);
if (count == req) if (count == req)
{ {
m_Events |= BG_STARTING_EVENT_2; m_Events |= BG_STARTING_EVENT_2;
+23
View File
@@ -99,6 +99,23 @@ bool ChatHandler::HasLowerSecurityAccount(WorldSession* target, uint32 target_ac
return false; return false;
} }
void ChatHandler::SendNotification(std::string_view str)
{
if (!m_session)
{
LOG_ERROR("chat.chat", "ChatHandler::SendNotification sent without a session. Skipped.");
return;
}
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);
}
}
void ChatHandler::SendGMText(std::string_view str) void ChatHandler::SendGMText(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);
@@ -157,6 +174,12 @@ void ChatHandler::SendWorldTextOptional(std::string_view str, uint32 flag)
void ChatHandler::SendSysMessage(std::string_view str, bool escapeCharacters) void ChatHandler::SendSysMessage(std::string_view str, bool escapeCharacters)
{ {
if (!m_session)
{
LOG_ERROR("chat.chat", "ChatHandler::SendSysMessage sent without a session. Skipped.");
return;
}
std::string msg{ str }; std::string msg{ str };
// Replace every "|" with "||" in msg // Replace every "|" with "||" in msg
+13 -1
View File
@@ -51,11 +51,23 @@ 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 SendNotification(std::string_view str);
template<typename... Args>
void SendNotification(uint32 strId, Args&&... args)
{
SendNotification(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
}
template<typename... Args>
void SendNotification(char const* fmt, Args&&... args)
{
SendNotification(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
}
void SendGMText(std::string_view str); void SendGMText(std::string_view str);
template<typename... Args> template<typename... Args>
void SendGMText(uint32 strId, Args&&... args) void SendGMText(uint32 strId, Args&&... args)
{ {
// WorldText should be sent to all sessions // GMText should be sent to all sessions
SessionMap::const_iterator itr; SessionMap::const_iterator itr;
for (itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr) for (itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr)
{ {
@@ -16,6 +16,7 @@
*/ */
#include "BattlegroundMgr.h" #include "BattlegroundMgr.h"
#include "Chat.h"
#include "GossipDef.h" #include "GossipDef.h"
#include "Language.h" #include "Language.h"
#include "ObjectMgr.h" #include "ObjectMgr.h"
@@ -262,9 +263,9 @@ void Player::OnGossipSelect(WorldObject* source, uint32 gossipListId, uint32 men
ToggleInstantFlight(); ToggleInstantFlight();
if (m_isInstantFlightOn) if (m_isInstantFlightOn)
GetSession()->SendNotification(LANG_INSTANT_FLIGHT_ON); ChatHandler(GetSession()).SendNotification(LANG_INSTANT_FLIGHT_ON);
else else
GetSession()->SendNotification(LANG_INSTANT_FLIGHT_OFF); ChatHandler(GetSession()).SendNotification(LANG_INSTANT_FLIGHT_OFF);
PlayerTalkClass->SendCloseGossip(); PlayerTalkClass->SendCloseGossip();
return; return;
@@ -55,7 +55,7 @@ void WorldSession::SendAuctionHello(ObjectGuid guid, Creature* unit)
{ {
if (GetPlayer()->GetLevel() < sWorld->getIntConfig(CONFIG_AUCTION_LEVEL_REQ)) if (GetPlayer()->GetLevel() < sWorld->getIntConfig(CONFIG_AUCTION_LEVEL_REQ))
{ {
SendNotification(LANG_AUCTION_REQ, sWorld->getIntConfig(CONFIG_AUCTION_LEVEL_REQ)); ChatHandler(this).SendNotification(LANG_AUCTION_REQ, sWorld->getIntConfig(CONFIG_AUCTION_LEVEL_REQ));
return; return;
} }
@@ -55,7 +55,7 @@ void WorldSession::HandleBattlemasterHelloOpcode(WorldPacket& recvData)
if (!_player->GetBGAccessByLevel(bgTypeId)) if (!_player->GetBGAccessByLevel(bgTypeId))
{ {
// temp, must be gossip message... // temp, must be gossip message...
SendNotification(LANG_YOUR_BG_LEVEL_REQ_ERROR); ChatHandler(this).SendNotification(LANG_YOUR_BG_LEVEL_REQ_ERROR);
return; return;
} }
@@ -414,7 +414,7 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPacket& recvData)
if (_player->GetCharmGUID() || _player->IsInCombat()) if (_player->GetCharmGUID() || _player->IsInCombat())
{ {
_player->GetSession()->SendNotification(LANG_YOU_IN_COMBAT); ChatHandler(_player->GetSession()).SendNotification(LANG_YOU_IN_COMBAT);
return; return;
} }
@@ -971,14 +971,14 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder const& holder)
if (pCurrChar->HasAtLoginFlag(AT_LOGIN_RESET_SPELLS)) if (pCurrChar->HasAtLoginFlag(AT_LOGIN_RESET_SPELLS))
{ {
pCurrChar->resetSpells(); pCurrChar->resetSpells();
SendNotification(LANG_RESET_SPELLS); ChatHandler(this).SendNotification(LANG_RESET_SPELLS);
} }
if (pCurrChar->HasAtLoginFlag(AT_LOGIN_RESET_TALENTS)) if (pCurrChar->HasAtLoginFlag(AT_LOGIN_RESET_TALENTS))
{ {
pCurrChar->resetTalents(true); pCurrChar->resetTalents(true);
pCurrChar->SendTalentsInfoData(false); // original talents send already in to SendInitialPacketsBeforeAddToMap, resend reset state pCurrChar->SendTalentsInfoData(false); // original talents send already in to SendInitialPacketsBeforeAddToMap, resend reset state
SendNotification(LANG_RESET_TALENTS); ChatHandler(this).SendNotification(LANG_RESET_TALENTS);
} }
if (pCurrChar->HasAtLoginFlag(AT_LOGIN_CHECK_ACHIEVS)) if (pCurrChar->HasAtLoginFlag(AT_LOGIN_CHECK_ACHIEVS))
@@ -1044,7 +1044,7 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder const& holder)
pCurrChar->SetTaxiCheater(true); pCurrChar->SetTaxiCheater(true);
if (pCurrChar->IsGameMaster()) if (pCurrChar->IsGameMaster())
SendNotification(LANG_GM_ON); ChatHandler(this).SendNotification(LANG_GM_ON);
std::string IP_str = GetRemoteAddress(); std::string IP_str = GetRemoteAddress();
LOG_INFO("entities.player", "Account: {} (IP: {}) Login Character:[{}] ({}) Level: {}", LOG_INFO("entities.player", "Account: {} (IP: {}) Login Character:[{}] ({}) Level: {}",
@@ -1239,7 +1239,7 @@ void WorldSession::HandlePlayerLoginToCharInWorld(Player* pCurrChar)
sWorld->ShutdownMsg(true, pCurrChar); sWorld->ShutdownMsg(true, pCurrChar);
if (pCurrChar->IsGameMaster()) if (pCurrChar->IsGameMaster())
SendNotification(LANG_GM_ON); ChatHandler(pCurrChar->GetSession()).SendNotification(LANG_GM_ON);
m_playerLoading = false; m_playerLoading = false;
} }
+11 -11
View File
@@ -74,7 +74,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
if (lang == LANG_UNIVERSAL && type != CHAT_MSG_AFK && type != CHAT_MSG_DND) if (lang == LANG_UNIVERSAL && type != CHAT_MSG_AFK && type != CHAT_MSG_DND)
{ {
LOG_ERROR("entities.player.cheat", "CMSG_MESSAGECHAT: Possible hacking-attempt: {} tried to send a message in universal language", GetPlayerInfo()); LOG_ERROR("entities.player.cheat", "CMSG_MESSAGECHAT: Possible hacking-attempt: {} tried to send a message in universal language", GetPlayerInfo());
SendNotification(LANG_UNKNOWN_LANGUAGE); ChatHandler(this).SendNotification(LANG_UNKNOWN_LANGUAGE);
recvData.rfinish(); recvData.rfinish();
return; return;
} }
@@ -85,7 +85,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
LanguageDesc const* langDesc = GetLanguageDescByID(lang); LanguageDesc const* langDesc = GetLanguageDescByID(lang);
if (!langDesc) if (!langDesc)
{ {
SendNotification(LANG_UNKNOWN_LANGUAGE); ChatHandler(this).SendNotification(LANG_UNKNOWN_LANGUAGE);
recvData.rfinish(); recvData.rfinish();
return; return;
} }
@@ -105,7 +105,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
if (!foundAura) if (!foundAura)
{ {
SendNotification(LANG_NOT_LEARNED_LANGUAGE); ChatHandler(this).SendNotification(LANG_NOT_LEARNED_LANGUAGE);
recvData.rfinish(); recvData.rfinish();
return; return;
} }
@@ -137,7 +137,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
if (sender->GetTotalPlayedTime() < minutes * MINUTE) if (sender->GetTotalPlayedTime() < minutes * MINUTE)
{ {
SendNotification(LANG_MUTED_PLAYER, minutes); ChatHandler(this).SendNotification(LANG_MUTED_PLAYER, minutes);
recvData.rfinish(); recvData.rfinish();
return; return;
} }
@@ -164,7 +164,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
if (sender->HasAura(1852) && type != CHAT_MSG_WHISPER) if (sender->HasAura(1852) && type != CHAT_MSG_WHISPER)
{ {
SendNotification(LANG_GM_SILENCE, sender->GetName()); ChatHandler(this).SendNotification(LANG_GM_SILENCE, sender->GetName());
recvData.rfinish(); recvData.rfinish();
return; return;
} }
@@ -296,7 +296,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
if (!_player->CanSpeak()) if (!_player->CanSpeak())
{ {
std::string timeStr = secsToTimeString(m_muteTime - GameTime::GetGameTime().count()); std::string timeStr = secsToTimeString(m_muteTime - GameTime::GetGameTime().count());
SendNotification(LANG_WAIT_BEFORE_SPEAKING, timeStr); ChatHandler(this).SendNotification(LANG_WAIT_BEFORE_SPEAKING, timeStr);
return; return;
} }
} }
@@ -361,7 +361,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
if (sender->GetLevel() < sWorld->getIntConfig(CONFIG_CHAT_SAY_LEVEL_REQ)) if (sender->GetLevel() < sWorld->getIntConfig(CONFIG_CHAT_SAY_LEVEL_REQ))
{ {
SendNotification(LANG_SAY_REQ, sWorld->getIntConfig(CONFIG_CHAT_SAY_LEVEL_REQ)); ChatHandler(this).SendNotification(LANG_SAY_REQ, sWorld->getIntConfig(CONFIG_CHAT_SAY_LEVEL_REQ));
return; return;
} }
@@ -387,7 +387,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
if (sender->GetLevel() < sWorld->getIntConfig(CONFIG_CHAT_WHISPER_LEVEL_REQ) && receiver != sender) if (sender->GetLevel() < sWorld->getIntConfig(CONFIG_CHAT_WHISPER_LEVEL_REQ) && receiver != sender)
{ {
SendNotification(LANG_WHISPER_REQ, sWorld->getIntConfig(CONFIG_CHAT_WHISPER_LEVEL_REQ)); ChatHandler(this).SendNotification(LANG_WHISPER_REQ, sWorld->getIntConfig(CONFIG_CHAT_WHISPER_LEVEL_REQ));
return; return;
} }
@@ -407,7 +407,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
// pussywizard: optimization // pussywizard: optimization
if (GetPlayer()->HasAura(1852) && !receiver->IsGameMaster()) if (GetPlayer()->HasAura(1852) && !receiver->IsGameMaster())
{ {
SendNotification(LANG_GM_SILENCE, GetPlayer()->GetName()); ChatHandler(this).SendNotification(LANG_GM_SILENCE, GetPlayer()->GetName());
return; return;
} }
@@ -590,7 +590,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData)
{ {
if (sender->GetLevel() < sWorld->getIntConfig(CONFIG_CHAT_CHANNEL_LEVEL_REQ)) if (sender->GetLevel() < sWorld->getIntConfig(CONFIG_CHAT_CHANNEL_LEVEL_REQ))
{ {
SendNotification(LANG_CHANNEL_REQ, sWorld->getIntConfig(CONFIG_CHAT_CHANNEL_LEVEL_REQ)); ChatHandler(this).SendNotification(LANG_CHANNEL_REQ, sWorld->getIntConfig(CONFIG_CHAT_CHANNEL_LEVEL_REQ));
return; return;
} }
} }
@@ -735,7 +735,7 @@ void WorldSession::HandleTextEmoteOpcode(WorldPacket& recvData)
if (!GetPlayer()->CanSpeak()) if (!GetPlayer()->CanSpeak())
{ {
std::string timeStr = secsToTimeString(m_muteTime - GameTime::GetGameTime().count()); std::string timeStr = secsToTimeString(m_muteTime - GameTime::GetGameTime().count());
SendNotification(LANG_WAIT_BEFORE_SPEAKING, timeStr); ChatHandler(this).SendNotification(LANG_WAIT_BEFORE_SPEAKING, timeStr);
return; return;
} }
+2 -1
View File
@@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>. * with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Chat.h"
#include "DatabaseEnv.h" #include "DatabaseEnv.h"
#include "Group.h" #include "Group.h"
#include "GroupMgr.h" #include "GroupMgr.h"
@@ -725,7 +726,7 @@ void WorldSession::HandleRaidReadyCheckOpcode(WorldPacket& recvData)
// Check if player is in BG // Check if player is in BG
if (_player->InBattleground()) if (_player->InBattleground())
{ {
_player->GetSession()->SendNotification(LANG_BG_READY_CHECK_ERROR); ChatHandler(_player->GetSession()).SendNotification(LANG_BG_READY_CHECK_ERROR);
return; return;
} }
} }
+2 -1
View File
@@ -16,6 +16,7 @@
*/ */
#include "AccountMgr.h" #include "AccountMgr.h"
#include "Chat.h"
#include "CharacterCache.h" #include "CharacterCache.h"
#include "DBCStores.h" #include "DBCStores.h"
#include "DatabaseEnv.h" #include "DatabaseEnv.h"
@@ -117,7 +118,7 @@ void WorldSession::HandleSendMail(WorldPacket& recvData)
if (player->GetLevel() < sWorld->getIntConfig(CONFIG_MAIL_LEVEL_REQ)) if (player->GetLevel() < sWorld->getIntConfig(CONFIG_MAIL_LEVEL_REQ))
{ {
SendNotification(LANG_MAIL_SENDER_REQ, sWorld->getIntConfig(CONFIG_MAIL_LEVEL_REQ)); ChatHandler(this).SendNotification(LANG_MAIL_SENDER_REQ, sWorld->getIntConfig(CONFIG_MAIL_LEVEL_REQ));
return; return;
} }
+5 -5
View File
@@ -1118,7 +1118,7 @@ void WorldSession::HandleWorldTeleportOpcode(WorldPacket& recv_data)
if (AccountMgr::IsAdminAccount(GetSecurity())) if (AccountMgr::IsAdminAccount(GetSecurity()))
GetPlayer()->TeleportTo(mapid, PositionX, PositionY, PositionZ, Orientation); GetPlayer()->TeleportTo(mapid, PositionX, PositionY, PositionZ, Orientation);
else else
SendNotification(LANG_PERMISSION_DENIED); ChatHandler(this).SendNotification(LANG_PERMISSION_DENIED);
} }
void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data) void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
@@ -1129,13 +1129,13 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
if (!AccountMgr::IsAdminAccount(GetSecurity())) if (!AccountMgr::IsAdminAccount(GetSecurity()))
{ {
SendNotification(LANG_PERMISSION_DENIED); ChatHandler(this).SendNotification(LANG_PERMISSION_DENIED);
return; return;
} }
if (charname.empty() || !normalizePlayerName (charname)) if (charname.empty() || !normalizePlayerName (charname))
{ {
SendNotification(LANG_NEED_CHARACTER_NAME); ChatHandler(this).SendNotification(LANG_NEED_CHARACTER_NAME);
return; return;
} }
@@ -1143,7 +1143,7 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
if (!player) if (!player)
{ {
SendNotification(LANG_PLAYER_NOT_EXIST_OR_OFFLINE, charname.c_str()); ChatHandler(this).SendNotification(LANG_PLAYER_NOT_EXIST_OR_OFFLINE, charname.c_str());
return; return;
} }
@@ -1157,7 +1157,7 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data)
if (!result) if (!result)
{ {
SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND, charname.c_str()); ChatHandler(this).SendNotification(LANG_ACCOUNT_FOR_PLAYER_NOT_FOUND, charname.c_str());
return; return;
} }
+2 -1
View File
@@ -17,6 +17,7 @@
#include "Battleground.h" #include "Battleground.h"
#include "BattlegroundAV.h" #include "BattlegroundAV.h"
#include "Chat.h"
#include "GameObjectAI.h" #include "GameObjectAI.h"
#include "Group.h" #include "Group.h"
#include "Language.h" #include "Language.h"
@@ -586,7 +587,7 @@ void WorldSession::HandlePushQuestToParty(WorldPacket& recvPacket)
// Check if player is in BG // Check if player is in BG
if (_player->InBattleground()) if (_player->InBattleground())
{ {
_player->GetSession()->SendNotification(LANG_BG_SHARE_QUEST_ERROR); ChatHandler(_player->GetSession()).SendNotification(LANG_BG_SHARE_QUEST_ERROR);
continue; continue;
} }
} }
+1 -1
View File
@@ -35,7 +35,7 @@ void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData)
if (GetPlayer()->GetLevel() < sWorld->getIntConfig(CONFIG_TICKET_LEVEL_REQ)) if (GetPlayer()->GetLevel() < sWorld->getIntConfig(CONFIG_TICKET_LEVEL_REQ))
{ {
SendNotification(LANG_TICKET_REQ, sWorld->getIntConfig(CONFIG_TICKET_LEVEL_REQ)); ChatHandler(this).SendNotification(LANG_TICKET_REQ, sWorld->getIntConfig(CONFIG_TICKET_LEVEL_REQ));
return; return;
} }
+9 -8
View File
@@ -15,6 +15,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>. * with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Chat.h"
#include "Item.h" #include "Item.h"
#include "Language.h" #include "Language.h"
#include "Log.h" #include "Log.h"
@@ -264,7 +265,7 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
// not accept case incorrect money amount // not accept case incorrect money amount
if (!_player->HasEnoughMoney(my_trade->GetMoney())) if (!_player->HasEnoughMoney(my_trade->GetMoney()))
{ {
SendNotification(LANG_NOT_ENOUGH_GOLD); ChatHandler(this).SendNotification(LANG_NOT_ENOUGH_GOLD);
my_trade->SetAccepted(false, true); my_trade->SetAccepted(false, true);
return; return;
} }
@@ -272,7 +273,7 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
// not accept case incorrect money amount // not accept case incorrect money amount
if (!trader->HasEnoughMoney(his_trade->GetMoney())) if (!trader->HasEnoughMoney(his_trade->GetMoney()))
{ {
trader->GetSession()->SendNotification(LANG_NOT_ENOUGH_GOLD); ChatHandler(trader->GetSession()).SendNotification(LANG_NOT_ENOUGH_GOLD);
his_trade->SetAccepted(false, true); his_trade->SetAccepted(false, true);
return; return;
} }
@@ -422,8 +423,8 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
{ {
clearAcceptTradeMode(my_trade, his_trade); clearAcceptTradeMode(my_trade, his_trade);
SendNotification(LANG_NOT_FREE_TRADE_SLOTS); ChatHandler(this).SendNotification(LANG_NOT_FREE_TRADE_SLOTS);
trader->GetSession()->SendNotification(LANG_NOT_PARTNER_FREE_TRADE_SLOTS); ChatHandler(trader->GetSession()).SendNotification(LANG_NOT_PARTNER_FREE_TRADE_SLOTS);
my_trade->SetAccepted(false); my_trade->SetAccepted(false);
his_trade->SetAccepted(false); his_trade->SetAccepted(false);
delete my_spell; delete my_spell;
@@ -434,8 +435,8 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/)
{ {
clearAcceptTradeMode(my_trade, his_trade); clearAcceptTradeMode(my_trade, his_trade);
SendNotification(LANG_NOT_PARTNER_FREE_TRADE_SLOTS); ChatHandler(this).SendNotification(LANG_NOT_PARTNER_FREE_TRADE_SLOTS);
trader->GetSession()->SendNotification(LANG_NOT_FREE_TRADE_SLOTS); ChatHandler(trader->GetSession()).SendNotification(LANG_NOT_FREE_TRADE_SLOTS);
my_trade->SetAccepted(false); my_trade->SetAccepted(false);
his_trade->SetAccepted(false); his_trade->SetAccepted(false);
delete my_spell; delete my_spell;
@@ -574,7 +575,7 @@ void WorldSession::HandleInitiateTradeOpcode(WorldPacket& recvPacket)
if (GetPlayer()->GetLevel() < sWorld->getIntConfig(CONFIG_TRADE_LEVEL_REQ)) if (GetPlayer()->GetLevel() < sWorld->getIntConfig(CONFIG_TRADE_LEVEL_REQ))
{ {
SendNotification(LANG_TRADE_REQ, sWorld->getIntConfig(CONFIG_TRADE_LEVEL_REQ)); ChatHandler(this).SendNotification(LANG_TRADE_REQ, sWorld->getIntConfig(CONFIG_TRADE_LEVEL_REQ));
return; return;
} }
@@ -639,7 +640,7 @@ void WorldSession::HandleInitiateTradeOpcode(WorldPacket& recvPacket)
if (pOther->GetLevel() < sWorld->getIntConfig(CONFIG_TRADE_LEVEL_REQ)) if (pOther->GetLevel() < sWorld->getIntConfig(CONFIG_TRADE_LEVEL_REQ))
{ {
SendNotification(LANG_TRADE_OTHER_REQ, sWorld->getIntConfig(CONFIG_TRADE_LEVEL_REQ)); ChatHandler(this).SendNotification(LANG_TRADE_OTHER_REQ, sWorld->getIntConfig(CONFIG_TRADE_LEVEL_REQ));
return; return;
} }
+2 -1
View File
@@ -16,6 +16,7 @@
*/ */
#include "InstanceScript.h" #include "InstanceScript.h"
#include "Chat.h"
#include "Creature.h" #include "Creature.h"
#include "DatabaseEnv.h" #include "DatabaseEnv.h"
#include "GameObject.h" #include "GameObject.h"
@@ -602,7 +603,7 @@ void InstanceScript::DoSendNotifyToInstance(char const* format, ...)
instance->DoForAllPlayers([&, buff](Player* player) instance->DoForAllPlayers([&, buff](Player* player)
{ {
player->GetSession()->SendNotification("%s", buff); ChatHandler(player->GetSession()).SendNotification("{}", buff);
}); });
} }
} }
-10
View File
@@ -787,16 +787,6 @@ bool WorldSession::DisallowHyperlinksAndMaybeKick(std::string_view str)
return false; return false;
} }
void WorldSession::SendNotification(std::string_view str)
{
WorldPacket data(SMSG_NOTIFICATION, str.size() + 1);
for (std::string_view line : Acore::Tokenize(str, '\n', true))
{
data << line.data();
SendPacket(&data);
}
}
char const* WorldSession::GetAcoreString(uint32 entry) const char const* WorldSession::GetAcoreString(uint32 entry) const
{ {
return sObjectMgr->GetAcoreString(entry, GetSessionDbLocaleIndex()); return sObjectMgr->GetAcoreString(entry, GetSessionDbLocaleIndex());
-12
View File
@@ -345,18 +345,6 @@ public:
void ReadMovementInfo(WorldPacket& data, MovementInfo* mi); void ReadMovementInfo(WorldPacket& data, MovementInfo* mi);
void WriteMovementInfo(WorldPacket* data, MovementInfo* mi); void WriteMovementInfo(WorldPacket* data, MovementInfo* mi);
void SendNotification(std::string_view str);
template<typename... Args>
void SendNotification(uint32 strId, Args&&... args)
{
SendNotification(Acore::StringFormatFmt(GetAcoreString(strId), std::forward<Args>(args)...));
}
template<typename... Args>
void SendNotification(char const* fmt, Args&&... args)
{
SendNotification(Acore::StringFormatFmt(fmt, std::forward<Args>(args)...));
}
void SendPacket(WorldPacket const* packet); void SendPacket(WorldPacket const* packet);
void SendPetNameInvalid(uint32 error, std::string const& name, DeclinedName* declinedName); void SendPetNameInvalid(uint32 error, std::string const& name, DeclinedName* declinedName);
void SendPartyResult(PartyOperation operation, std::string const& member, PartyResult res, uint32 val = 0); void SendPartyResult(PartyOperation operation, std::string const& member, PartyResult res, uint32 val = 0);
+2 -1
View File
@@ -22,6 +22,7 @@
#include "BattlegroundSA.h" #include "BattlegroundSA.h"
#include "BattlegroundWS.h" #include "BattlegroundWS.h"
#include "CellImpl.h" #include "CellImpl.h"
#include "Chat.h"
#include "Common.h" #include "Common.h"
#include "Creature.h" #include "Creature.h"
#include "DynamicObject.h" #include "DynamicObject.h"
@@ -6168,7 +6169,7 @@ void Spell::EffectPlaySound(SpellEffIndex effIndex)
{ {
case 58730: // Restricted Flight Area case 58730: // Restricted Flight Area
case 58600: // Restricted Flight Area case 58600: // Restricted Flight Area
player->GetSession()->SendNotification(LANG_ZONE_NOFLYZONE); ChatHandler(player->GetSession()).SendNotification(LANG_ZONE_NOFLYZONE);
break; break;
default: default:
break; break;
+8 -8
View File
@@ -68,22 +68,22 @@ public:
if (!enableArg) if (!enableArg)
{ {
if (!AccountMgr::IsPlayerAccount(session->GetSecurity()) && session->GetPlayer()->isGMChat()) if (!AccountMgr::IsPlayerAccount(session->GetSecurity()) && session->GetPlayer()->isGMChat())
session->SendNotification(LANG_GM_CHAT_ON); handler->SendNotification(LANG_GM_CHAT_ON);
else else
session->SendNotification(LANG_GM_CHAT_OFF); handler->SendNotification(LANG_GM_CHAT_OFF);
return true; return true;
} }
if (*enableArg) if (*enableArg)
{ {
session->GetPlayer()->SetGMChat(true); session->GetPlayer()->SetGMChat(true);
session->SendNotification(LANG_GM_CHAT_ON); handler->SendNotification(LANG_GM_CHAT_ON);
return true; return true;
} }
else else
{ {
session->GetPlayer()->SetGMChat(false); session->GetPlayer()->SetGMChat(false);
session->SendNotification(LANG_GM_CHAT_OFF); handler->SendNotification(LANG_GM_CHAT_OFF);
return true; return true;
} }
} }
@@ -206,14 +206,14 @@ public:
_player->SetGMVisible(true); _player->SetGMVisible(true);
_player->UpdateObjectVisibility(); _player->UpdateObjectVisibility();
handler->GetSession()->SendNotification(LANG_INVISIBLE_VISIBLE); handler->SendNotification(LANG_INVISIBLE_VISIBLE);
} }
else else
{ {
_player->AddAura(VISUAL_AURA, _player); _player->AddAura(VISUAL_AURA, _player);
_player->SetGMVisible(false); _player->SetGMVisible(false);
_player->UpdateObjectVisibility(); _player->UpdateObjectVisibility();
handler->GetSession()->SendNotification(LANG_INVISIBLE_INVISIBLE); handler->SendNotification(LANG_INVISIBLE_INVISIBLE);
} }
return true; return true;
@@ -223,7 +223,7 @@ public:
{ {
handler->GetPlayer()->SetGameMaster(true); handler->GetPlayer()->SetGameMaster(true);
handler->GetPlayer()->UpdateTriggerVisibility(); handler->GetPlayer()->UpdateTriggerVisibility();
handler->GetSession()->SendNotification(LANG_GM_ON); handler->SendNotification(LANG_GM_ON);
return true; return true;
} }
@@ -231,7 +231,7 @@ public:
{ {
handler->GetPlayer()->SetGameMaster(false); handler->GetPlayer()->SetGameMaster(false);
handler->GetPlayer()->UpdateTriggerVisibility(); handler->GetPlayer()->UpdateTriggerVisibility();
handler->GetSession()->SendNotification(LANG_GM_OFF); handler->SendNotification(LANG_GM_OFF);
return true; return true;
} }
}; };
+2 -2
View File
@@ -464,7 +464,7 @@ public:
auto SetCommentatorMod = [&](bool enable) auto SetCommentatorMod = [&](bool enable)
{ {
session->SendNotification(enable ? "Commentator mode on" : "Commentator mode off"); handler->SendNotification(enable ? "Commentator mode on" : "Commentator mode off");
session->GetPlayer()->SetCommentator(enable); session->GetPlayer()->SetCommentator(enable);
}; };
@@ -508,7 +508,7 @@ public:
auto SetDevMod = [&](bool enable) auto SetDevMod = [&](bool enable)
{ {
session->SendNotification(enable ? LANG_DEV_ON : LANG_DEV_OFF); handler->SendNotification(enable ? LANG_DEV_ON : LANG_DEV_OFF);
session->GetPlayer()->SetDeveloper(enable); session->GetPlayer()->SetDeveloper(enable);
sScriptMgr->OnHandleDevCommand(handler->GetSession()->GetPlayer(), enable); sScriptMgr->OnHandleDevCommand(handler->GetSession()->GetPlayer(), enable);
}; };
+3 -2
View File
@@ -16,6 +16,7 @@
*/ */
#include "CellImpl.h" #include "CellImpl.h"
#include "Chat.h"
#include "CreatureScript.h" #include "CreatureScript.h"
#include "GameEventMgr.h" #include "GameEventMgr.h"
#include "GameObjectAI.h" #include "GameObjectAI.h"
@@ -1081,7 +1082,7 @@ public:
if (player->GetQuestRewardStatus(QUEST_TELE_CRYSTAL_FLAG)) if (player->GetQuestRewardStatus(QUEST_TELE_CRYSTAL_FLAG))
return false; return false;
player->GetSession()->SendNotification(GO_TELE_TO_DALARAN_CRYSTAL_FAILED); ChatHandler(player->GetSession()).SendNotification(GO_TELE_TO_DALARAN_CRYSTAL_FAILED);
return true; return true;
} }
@@ -1599,7 +1600,7 @@ public:
else else
{ {
CloseGossipMenuFor(player); CloseGossipMenuFor(player);
player->GetSession()->SendNotification(GO_ANDERHOLS_SLIDER_CIDER_NOT_FOUND); ChatHandler(player->GetSession()).SendNotification(GO_ANDERHOLS_SLIDER_CIDER_NOT_FOUND);
return false; return false;
} }
} }