From e4df159f5c370e1a1890a6a999b33b30d72eb55e Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Sat, 10 Aug 2024 16:39:46 +0200 Subject: [PATCH] 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 --- .../game/Battlegrounds/Battleground.cpp | 2 +- src/server/game/Chat/Chat.cpp | 23 +++++++++++++++++++ src/server/game/Chat/Chat.h | 14 ++++++++++- .../game/Entities/Player/PlayerGossip.cpp | 5 ++-- .../game/Handlers/AuctionHouseHandler.cpp | 2 +- .../game/Handlers/BattleGroundHandler.cpp | 4 ++-- src/server/game/Handlers/CharacterHandler.cpp | 8 +++---- src/server/game/Handlers/ChatHandler.cpp | 22 +++++++++--------- src/server/game/Handlers/GroupHandler.cpp | 3 ++- src/server/game/Handlers/MailHandler.cpp | 3 ++- src/server/game/Handlers/MiscHandler.cpp | 10 ++++---- src/server/game/Handlers/QuestHandler.cpp | 3 ++- src/server/game/Handlers/TicketHandler.cpp | 2 +- src/server/game/Handlers/TradeHandler.cpp | 17 +++++++------- src/server/game/Instances/InstanceScript.cpp | 3 ++- src/server/game/Server/WorldSession.cpp | 10 -------- src/server/game/Server/WorldSession.h | 12 ---------- src/server/game/Spells/SpellEffects.cpp | 3 ++- src/server/scripts/Commands/cs_gm.cpp | 16 ++++++------- src/server/scripts/Commands/cs_misc.cpp | 4 ++-- src/server/scripts/World/go_scripts.cpp | 5 ++-- 21 files changed, 96 insertions(+), 75 deletions(-) diff --git a/src/server/game/Battlegrounds/Battleground.cpp b/src/server/game/Battlegrounds/Battleground.cpp index d3189c258..87a09f993 100644 --- a/src/server/game/Battlegrounds/Battleground.cpp +++ b/src/server/game/Battlegrounds/Battleground.cpp @@ -1306,7 +1306,7 @@ void Battleground::ReadyMarkerClicked(Player* p) readyMarkerClickedSet.insert(p->GetGUID()); uint32 count = readyMarkerClickedSet.size(); 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) { m_Events |= BG_STARTING_EVENT_2; diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index ec3f5c156..4e0afcde5 100644 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -99,6 +99,23 @@ bool ChatHandler::HasLowerSecurityAccount(WorldSession* target, uint32 target_ac 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 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) { std::vector 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) { + if (!m_session) + { + LOG_ERROR("chat.chat", "ChatHandler::SendSysMessage sent without a session. Skipped."); + return; + } + std::string msg{ str }; // Replace every "|" with "||" in msg diff --git a/src/server/game/Chat/Chat.h b/src/server/game/Chat/Chat.h index 20771bcac..9fb02cd43 100644 --- a/src/server/game/Chat/Chat.h +++ b/src/server/game/Chat/Chat.h @@ -51,11 +51,23 @@ public: static char* LineFromMessage(char*& pos) { char* start = strtok(pos, "\n"); pos = nullptr; return start; } + void SendNotification(std::string_view str); + template + void SendNotification(uint32 strId, Args&&... args) + { + SendNotification(Acore::StringFormatFmt(GetAcoreString(strId), std::forward(args)...)); + } + template + void SendNotification(char const* fmt, Args&&... args) + { + SendNotification(Acore::StringFormatFmt(fmt, std::forward(args)...)); + } + void SendGMText(std::string_view str); template void SendGMText(uint32 strId, Args&&... args) { - // WorldText should be sent to all sessions + // GMText should be sent to all sessions SessionMap::const_iterator itr; for (itr = sWorld->GetAllSessions().begin(); itr != sWorld->GetAllSessions().end(); ++itr) { diff --git a/src/server/game/Entities/Player/PlayerGossip.cpp b/src/server/game/Entities/Player/PlayerGossip.cpp index 953adca83..1029ae478 100644 --- a/src/server/game/Entities/Player/PlayerGossip.cpp +++ b/src/server/game/Entities/Player/PlayerGossip.cpp @@ -16,6 +16,7 @@ */ #include "BattlegroundMgr.h" +#include "Chat.h" #include "GossipDef.h" #include "Language.h" #include "ObjectMgr.h" @@ -262,9 +263,9 @@ void Player::OnGossipSelect(WorldObject* source, uint32 gossipListId, uint32 men ToggleInstantFlight(); if (m_isInstantFlightOn) - GetSession()->SendNotification(LANG_INSTANT_FLIGHT_ON); + ChatHandler(GetSession()).SendNotification(LANG_INSTANT_FLIGHT_ON); else - GetSession()->SendNotification(LANG_INSTANT_FLIGHT_OFF); + ChatHandler(GetSession()).SendNotification(LANG_INSTANT_FLIGHT_OFF); PlayerTalkClass->SendCloseGossip(); return; diff --git a/src/server/game/Handlers/AuctionHouseHandler.cpp b/src/server/game/Handlers/AuctionHouseHandler.cpp index fad0182c5..a9a43c895 100644 --- a/src/server/game/Handlers/AuctionHouseHandler.cpp +++ b/src/server/game/Handlers/AuctionHouseHandler.cpp @@ -55,7 +55,7 @@ void WorldSession::SendAuctionHello(ObjectGuid guid, Creature* unit) { 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; } diff --git a/src/server/game/Handlers/BattleGroundHandler.cpp b/src/server/game/Handlers/BattleGroundHandler.cpp index dacd0b5c7..c2a9bc4b9 100644 --- a/src/server/game/Handlers/BattleGroundHandler.cpp +++ b/src/server/game/Handlers/BattleGroundHandler.cpp @@ -55,7 +55,7 @@ void WorldSession::HandleBattlemasterHelloOpcode(WorldPacket& recvData) if (!_player->GetBGAccessByLevel(bgTypeId)) { // temp, must be gossip message... - SendNotification(LANG_YOUR_BG_LEVEL_REQ_ERROR); + ChatHandler(this).SendNotification(LANG_YOUR_BG_LEVEL_REQ_ERROR); return; } @@ -414,7 +414,7 @@ void WorldSession::HandleBattleFieldPortOpcode(WorldPacket& recvData) if (_player->GetCharmGUID() || _player->IsInCombat()) { - _player->GetSession()->SendNotification(LANG_YOU_IN_COMBAT); + ChatHandler(_player->GetSession()).SendNotification(LANG_YOU_IN_COMBAT); return; } diff --git a/src/server/game/Handlers/CharacterHandler.cpp b/src/server/game/Handlers/CharacterHandler.cpp index 6c503243c..762d39e22 100644 --- a/src/server/game/Handlers/CharacterHandler.cpp +++ b/src/server/game/Handlers/CharacterHandler.cpp @@ -971,14 +971,14 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder const& holder) if (pCurrChar->HasAtLoginFlag(AT_LOGIN_RESET_SPELLS)) { pCurrChar->resetSpells(); - SendNotification(LANG_RESET_SPELLS); + ChatHandler(this).SendNotification(LANG_RESET_SPELLS); } if (pCurrChar->HasAtLoginFlag(AT_LOGIN_RESET_TALENTS)) { pCurrChar->resetTalents(true); 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)) @@ -1044,7 +1044,7 @@ void WorldSession::HandlePlayerLoginFromDB(LoginQueryHolder const& holder) pCurrChar->SetTaxiCheater(true); if (pCurrChar->IsGameMaster()) - SendNotification(LANG_GM_ON); + ChatHandler(this).SendNotification(LANG_GM_ON); std::string IP_str = GetRemoteAddress(); LOG_INFO("entities.player", "Account: {} (IP: {}) Login Character:[{}] ({}) Level: {}", @@ -1239,7 +1239,7 @@ void WorldSession::HandlePlayerLoginToCharInWorld(Player* pCurrChar) sWorld->ShutdownMsg(true, pCurrChar); if (pCurrChar->IsGameMaster()) - SendNotification(LANG_GM_ON); + ChatHandler(pCurrChar->GetSession()).SendNotification(LANG_GM_ON); m_playerLoading = false; } diff --git a/src/server/game/Handlers/ChatHandler.cpp b/src/server/game/Handlers/ChatHandler.cpp index 1eda1e8a9..d1691c325 100644 --- a/src/server/game/Handlers/ChatHandler.cpp +++ b/src/server/game/Handlers/ChatHandler.cpp @@ -74,7 +74,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData) 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()); - SendNotification(LANG_UNKNOWN_LANGUAGE); + ChatHandler(this).SendNotification(LANG_UNKNOWN_LANGUAGE); recvData.rfinish(); return; } @@ -85,7 +85,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData) LanguageDesc const* langDesc = GetLanguageDescByID(lang); if (!langDesc) { - SendNotification(LANG_UNKNOWN_LANGUAGE); + ChatHandler(this).SendNotification(LANG_UNKNOWN_LANGUAGE); recvData.rfinish(); return; } @@ -105,7 +105,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData) if (!foundAura) { - SendNotification(LANG_NOT_LEARNED_LANGUAGE); + ChatHandler(this).SendNotification(LANG_NOT_LEARNED_LANGUAGE); recvData.rfinish(); return; } @@ -137,7 +137,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData) if (sender->GetTotalPlayedTime() < minutes * MINUTE) { - SendNotification(LANG_MUTED_PLAYER, minutes); + ChatHandler(this).SendNotification(LANG_MUTED_PLAYER, minutes); recvData.rfinish(); return; } @@ -164,7 +164,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData) if (sender->HasAura(1852) && type != CHAT_MSG_WHISPER) { - SendNotification(LANG_GM_SILENCE, sender->GetName()); + ChatHandler(this).SendNotification(LANG_GM_SILENCE, sender->GetName()); recvData.rfinish(); return; } @@ -296,7 +296,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData) if (!_player->CanSpeak()) { std::string timeStr = secsToTimeString(m_muteTime - GameTime::GetGameTime().count()); - SendNotification(LANG_WAIT_BEFORE_SPEAKING, timeStr); + ChatHandler(this).SendNotification(LANG_WAIT_BEFORE_SPEAKING, timeStr); return; } } @@ -361,7 +361,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData) 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; } @@ -387,7 +387,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData) 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; } @@ -407,7 +407,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData) // pussywizard: optimization if (GetPlayer()->HasAura(1852) && !receiver->IsGameMaster()) { - SendNotification(LANG_GM_SILENCE, GetPlayer()->GetName()); + ChatHandler(this).SendNotification(LANG_GM_SILENCE, GetPlayer()->GetName()); return; } @@ -590,7 +590,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket& recvData) { 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; } } @@ -735,7 +735,7 @@ void WorldSession::HandleTextEmoteOpcode(WorldPacket& recvData) if (!GetPlayer()->CanSpeak()) { std::string timeStr = secsToTimeString(m_muteTime - GameTime::GetGameTime().count()); - SendNotification(LANG_WAIT_BEFORE_SPEAKING, timeStr); + ChatHandler(this).SendNotification(LANG_WAIT_BEFORE_SPEAKING, timeStr); return; } diff --git a/src/server/game/Handlers/GroupHandler.cpp b/src/server/game/Handlers/GroupHandler.cpp index 8cf5dda04..96ef394c3 100644 --- a/src/server/game/Handlers/GroupHandler.cpp +++ b/src/server/game/Handlers/GroupHandler.cpp @@ -15,6 +15,7 @@ * with this program. If not, see . */ +#include "Chat.h" #include "DatabaseEnv.h" #include "Group.h" #include "GroupMgr.h" @@ -725,7 +726,7 @@ void WorldSession::HandleRaidReadyCheckOpcode(WorldPacket& recvData) // Check if player is in BG if (_player->InBattleground()) { - _player->GetSession()->SendNotification(LANG_BG_READY_CHECK_ERROR); + ChatHandler(_player->GetSession()).SendNotification(LANG_BG_READY_CHECK_ERROR); return; } } diff --git a/src/server/game/Handlers/MailHandler.cpp b/src/server/game/Handlers/MailHandler.cpp index ab9179d61..3c8482a3b 100644 --- a/src/server/game/Handlers/MailHandler.cpp +++ b/src/server/game/Handlers/MailHandler.cpp @@ -16,6 +16,7 @@ */ #include "AccountMgr.h" +#include "Chat.h" #include "CharacterCache.h" #include "DBCStores.h" #include "DatabaseEnv.h" @@ -117,7 +118,7 @@ void WorldSession::HandleSendMail(WorldPacket& recvData) 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; } diff --git a/src/server/game/Handlers/MiscHandler.cpp b/src/server/game/Handlers/MiscHandler.cpp index bbdf138b1..0f5debee7 100644 --- a/src/server/game/Handlers/MiscHandler.cpp +++ b/src/server/game/Handlers/MiscHandler.cpp @@ -1118,7 +1118,7 @@ void WorldSession::HandleWorldTeleportOpcode(WorldPacket& recv_data) if (AccountMgr::IsAdminAccount(GetSecurity())) GetPlayer()->TeleportTo(mapid, PositionX, PositionY, PositionZ, Orientation); else - SendNotification(LANG_PERMISSION_DENIED); + ChatHandler(this).SendNotification(LANG_PERMISSION_DENIED); } void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data) @@ -1129,13 +1129,13 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data) if (!AccountMgr::IsAdminAccount(GetSecurity())) { - SendNotification(LANG_PERMISSION_DENIED); + ChatHandler(this).SendNotification(LANG_PERMISSION_DENIED); return; } if (charname.empty() || !normalizePlayerName (charname)) { - SendNotification(LANG_NEED_CHARACTER_NAME); + ChatHandler(this).SendNotification(LANG_NEED_CHARACTER_NAME); return; } @@ -1143,7 +1143,7 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data) 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; } @@ -1157,7 +1157,7 @@ void WorldSession::HandleWhoisOpcode(WorldPacket& recv_data) 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; } diff --git a/src/server/game/Handlers/QuestHandler.cpp b/src/server/game/Handlers/QuestHandler.cpp index c9555f414..5d03deda1 100644 --- a/src/server/game/Handlers/QuestHandler.cpp +++ b/src/server/game/Handlers/QuestHandler.cpp @@ -17,6 +17,7 @@ #include "Battleground.h" #include "BattlegroundAV.h" +#include "Chat.h" #include "GameObjectAI.h" #include "Group.h" #include "Language.h" @@ -586,7 +587,7 @@ void WorldSession::HandlePushQuestToParty(WorldPacket& recvPacket) // Check if player is in BG if (_player->InBattleground()) { - _player->GetSession()->SendNotification(LANG_BG_SHARE_QUEST_ERROR); + ChatHandler(_player->GetSession()).SendNotification(LANG_BG_SHARE_QUEST_ERROR); continue; } } diff --git a/src/server/game/Handlers/TicketHandler.cpp b/src/server/game/Handlers/TicketHandler.cpp index 2d56b6757..6d53bf95b 100644 --- a/src/server/game/Handlers/TicketHandler.cpp +++ b/src/server/game/Handlers/TicketHandler.cpp @@ -35,7 +35,7 @@ void WorldSession::HandleGMTicketCreateOpcode(WorldPacket& recvData) 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; } diff --git a/src/server/game/Handlers/TradeHandler.cpp b/src/server/game/Handlers/TradeHandler.cpp index 55c8079ef..9d649ae85 100644 --- a/src/server/game/Handlers/TradeHandler.cpp +++ b/src/server/game/Handlers/TradeHandler.cpp @@ -15,6 +15,7 @@ * with this program. If not, see . */ +#include "Chat.h" #include "Item.h" #include "Language.h" #include "Log.h" @@ -264,7 +265,7 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/) // not accept case incorrect money amount if (!_player->HasEnoughMoney(my_trade->GetMoney())) { - SendNotification(LANG_NOT_ENOUGH_GOLD); + ChatHandler(this).SendNotification(LANG_NOT_ENOUGH_GOLD); my_trade->SetAccepted(false, true); return; } @@ -272,7 +273,7 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/) // not accept case incorrect money amount 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); return; } @@ -422,8 +423,8 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/) { clearAcceptTradeMode(my_trade, his_trade); - SendNotification(LANG_NOT_FREE_TRADE_SLOTS); - trader->GetSession()->SendNotification(LANG_NOT_PARTNER_FREE_TRADE_SLOTS); + ChatHandler(this).SendNotification(LANG_NOT_FREE_TRADE_SLOTS); + ChatHandler(trader->GetSession()).SendNotification(LANG_NOT_PARTNER_FREE_TRADE_SLOTS); my_trade->SetAccepted(false); his_trade->SetAccepted(false); delete my_spell; @@ -434,8 +435,8 @@ void WorldSession::HandleAcceptTradeOpcode(WorldPacket& /*recvPacket*/) { clearAcceptTradeMode(my_trade, his_trade); - SendNotification(LANG_NOT_PARTNER_FREE_TRADE_SLOTS); - trader->GetSession()->SendNotification(LANG_NOT_FREE_TRADE_SLOTS); + ChatHandler(this).SendNotification(LANG_NOT_PARTNER_FREE_TRADE_SLOTS); + ChatHandler(trader->GetSession()).SendNotification(LANG_NOT_FREE_TRADE_SLOTS); my_trade->SetAccepted(false); his_trade->SetAccepted(false); delete my_spell; @@ -574,7 +575,7 @@ void WorldSession::HandleInitiateTradeOpcode(WorldPacket& recvPacket) 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; } @@ -639,7 +640,7 @@ void WorldSession::HandleInitiateTradeOpcode(WorldPacket& recvPacket) 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; } diff --git a/src/server/game/Instances/InstanceScript.cpp b/src/server/game/Instances/InstanceScript.cpp index 332c1797c..0c0581192 100644 --- a/src/server/game/Instances/InstanceScript.cpp +++ b/src/server/game/Instances/InstanceScript.cpp @@ -16,6 +16,7 @@ */ #include "InstanceScript.h" +#include "Chat.h" #include "Creature.h" #include "DatabaseEnv.h" #include "GameObject.h" @@ -602,7 +603,7 @@ void InstanceScript::DoSendNotifyToInstance(char const* format, ...) instance->DoForAllPlayers([&, buff](Player* player) { - player->GetSession()->SendNotification("%s", buff); + ChatHandler(player->GetSession()).SendNotification("{}", buff); }); } } diff --git a/src/server/game/Server/WorldSession.cpp b/src/server/game/Server/WorldSession.cpp index cc3a0c911..af1e0c15b 100644 --- a/src/server/game/Server/WorldSession.cpp +++ b/src/server/game/Server/WorldSession.cpp @@ -787,16 +787,6 @@ bool WorldSession::DisallowHyperlinksAndMaybeKick(std::string_view str) 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 { return sObjectMgr->GetAcoreString(entry, GetSessionDbLocaleIndex()); diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h index 52f3e9425..777176afb 100644 --- a/src/server/game/Server/WorldSession.h +++ b/src/server/game/Server/WorldSession.h @@ -345,18 +345,6 @@ public: void ReadMovementInfo(WorldPacket& data, MovementInfo* mi); void WriteMovementInfo(WorldPacket* data, MovementInfo* mi); - void SendNotification(std::string_view str); - template - void SendNotification(uint32 strId, Args&&... args) - { - SendNotification(Acore::StringFormatFmt(GetAcoreString(strId), std::forward(args)...)); - } - template - void SendNotification(char const* fmt, Args&&... args) - { - SendNotification(Acore::StringFormatFmt(fmt, std::forward(args)...)); - } - void SendPacket(WorldPacket const* packet); void SendPetNameInvalid(uint32 error, std::string const& name, DeclinedName* declinedName); void SendPartyResult(PartyOperation operation, std::string const& member, PartyResult res, uint32 val = 0); diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index e1172ff87..90724ec7d 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -22,6 +22,7 @@ #include "BattlegroundSA.h" #include "BattlegroundWS.h" #include "CellImpl.h" +#include "Chat.h" #include "Common.h" #include "Creature.h" #include "DynamicObject.h" @@ -6168,7 +6169,7 @@ void Spell::EffectPlaySound(SpellEffIndex effIndex) { case 58730: // Restricted Flight Area case 58600: // Restricted Flight Area - player->GetSession()->SendNotification(LANG_ZONE_NOFLYZONE); + ChatHandler(player->GetSession()).SendNotification(LANG_ZONE_NOFLYZONE); break; default: break; diff --git a/src/server/scripts/Commands/cs_gm.cpp b/src/server/scripts/Commands/cs_gm.cpp index bb64f0114..fed5b9416 100644 --- a/src/server/scripts/Commands/cs_gm.cpp +++ b/src/server/scripts/Commands/cs_gm.cpp @@ -68,22 +68,22 @@ public: if (!enableArg) { if (!AccountMgr::IsPlayerAccount(session->GetSecurity()) && session->GetPlayer()->isGMChat()) - session->SendNotification(LANG_GM_CHAT_ON); + handler->SendNotification(LANG_GM_CHAT_ON); else - session->SendNotification(LANG_GM_CHAT_OFF); + handler->SendNotification(LANG_GM_CHAT_OFF); return true; } if (*enableArg) { session->GetPlayer()->SetGMChat(true); - session->SendNotification(LANG_GM_CHAT_ON); + handler->SendNotification(LANG_GM_CHAT_ON); return true; } else { session->GetPlayer()->SetGMChat(false); - session->SendNotification(LANG_GM_CHAT_OFF); + handler->SendNotification(LANG_GM_CHAT_OFF); return true; } } @@ -206,14 +206,14 @@ public: _player->SetGMVisible(true); _player->UpdateObjectVisibility(); - handler->GetSession()->SendNotification(LANG_INVISIBLE_VISIBLE); + handler->SendNotification(LANG_INVISIBLE_VISIBLE); } else { _player->AddAura(VISUAL_AURA, _player); _player->SetGMVisible(false); _player->UpdateObjectVisibility(); - handler->GetSession()->SendNotification(LANG_INVISIBLE_INVISIBLE); + handler->SendNotification(LANG_INVISIBLE_INVISIBLE); } return true; @@ -223,7 +223,7 @@ public: { handler->GetPlayer()->SetGameMaster(true); handler->GetPlayer()->UpdateTriggerVisibility(); - handler->GetSession()->SendNotification(LANG_GM_ON); + handler->SendNotification(LANG_GM_ON); return true; } @@ -231,7 +231,7 @@ public: { handler->GetPlayer()->SetGameMaster(false); handler->GetPlayer()->UpdateTriggerVisibility(); - handler->GetSession()->SendNotification(LANG_GM_OFF); + handler->SendNotification(LANG_GM_OFF); return true; } }; diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp index fe32b740c..57ac36b43 100644 --- a/src/server/scripts/Commands/cs_misc.cpp +++ b/src/server/scripts/Commands/cs_misc.cpp @@ -464,7 +464,7 @@ public: 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); }; @@ -508,7 +508,7 @@ public: 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); sScriptMgr->OnHandleDevCommand(handler->GetSession()->GetPlayer(), enable); }; diff --git a/src/server/scripts/World/go_scripts.cpp b/src/server/scripts/World/go_scripts.cpp index f87dac591..76db9de22 100644 --- a/src/server/scripts/World/go_scripts.cpp +++ b/src/server/scripts/World/go_scripts.cpp @@ -16,6 +16,7 @@ */ #include "CellImpl.h" +#include "Chat.h" #include "CreatureScript.h" #include "GameEventMgr.h" #include "GameObjectAI.h" @@ -1081,7 +1082,7 @@ public: if (player->GetQuestRewardStatus(QUEST_TELE_CRYSTAL_FLAG)) return false; - player->GetSession()->SendNotification(GO_TELE_TO_DALARAN_CRYSTAL_FAILED); + ChatHandler(player->GetSession()).SendNotification(GO_TELE_TO_DALARAN_CRYSTAL_FAILED); return true; } @@ -1599,7 +1600,7 @@ public: else { CloseGossipMenuFor(player); - player->GetSession()->SendNotification(GO_ANDERHOLS_SLIDER_CIDER_NOT_FOUND); + ChatHandler(player->GetSession()).SendNotification(GO_ANDERHOLS_SLIDER_CIDER_NOT_FOUND); return false; } }