From 27fefb1e960cb7f6a769618f716bc80141944d61 Mon Sep 17 00:00:00 2001 From: stfx Date: Sat, 11 Aug 2012 14:34:37 +0200 Subject: [PATCH] [0062] Send SMSG_DEFENSE_MESSAGE, SMSG_ZONE_UNDER_ATTACK only to players outside of instances Also remove team argument from SendDefenseMessage as all texts are sent to all teams, use seperate function to send zone attack message, cleanup some send message functions and remove deprecated send text functions --- src/game/Creature.cpp | 8 +-- src/game/World.cpp | 104 ++++++++++++++------------------------- src/game/World.h | 8 ++- src/shared/revision_nr.h | 2 +- 4 files changed, 44 insertions(+), 78 deletions(-) diff --git a/src/game/Creature.cpp b/src/game/Creature.cpp index 0b4f2adfc..ada63891f 100644 --- a/src/game/Creature.cpp +++ b/src/game/Creature.cpp @@ -1994,14 +1994,10 @@ bool Creature::LoadCreatureAddon(bool reload) return true; } -/// Send a message to LocalDefense channel for players opposition team in the zone +/// Sends a message to LocalDefense and WorldDefense channels for players of the other team void Creature::SendZoneUnderAttackMessage(Player* attacker) { - Team enemy_team = attacker->GetTeam(); - - WorldPacket data(SMSG_ZONE_UNDER_ATTACK, 4); - data << uint32(GetZoneId()); - sWorld.SendGlobalMessage(&data, NULL, (enemy_team == ALLIANCE ? HORDE : ALLIANCE)); + sWorld.SendZoneUnderAttackMessage(GetZoneId(), attacker->GetTeam() == ALLIANCE ? HORDE : ALLIANCE); } void Creature::SetInCombatWithZone() diff --git a/src/game/World.cpp b/src/game/World.cpp index b371326cf..30f4ff6cf 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -1596,23 +1596,6 @@ void World::Update(uint32 diff) sTerrainMgr.Update(diff); } -/// Send a packet to all players (except self if mentioned) -void World::SendGlobalMessage(WorldPacket* packet, WorldSession* self /*= NULL*/, Team team /*= TEAM_NONE*/) -{ - SessionMap::const_iterator itr; - for (itr = m_sessions.begin(); itr != m_sessions.end(); ++itr) - { - if (itr->second && - itr->second->GetPlayer() && - itr->second->GetPlayer()->IsInWorld() && - itr->second != self && - (team == TEAM_NONE || itr->second->GetPlayer()->GetTeam() == team)) - { - itr->second->SendPacket(packet); - } - } -} - namespace MaNGOS { class WorldWorldTextBuilder @@ -1670,7 +1653,7 @@ namespace MaNGOS }; } // namespace MaNGOS -/// Send a System Message to all players (except self if mentioned) +/// Sends a system message to all players void World::SendWorldText(int32 string_id, ...) { va_list ap; @@ -1689,59 +1672,61 @@ void World::SendWorldText(int32 string_id, ...) va_end(ap); } -/// DEPRICATED, only for debug purpose. Send a System Message to all players (except self if mentioned) -void World::SendGlobalText(const char* text, WorldSession* self) +/// Sends a packet to all players with optional team and instance restrictions +void World::SendGlobalMessage(WorldPacket* packet) { - WorldPacket data; - - // need copy to prevent corruption by strtok call in LineFromMessage original string - char* buf = mangos_strdup(text); - char* pos = buf; - - while (char* line = ChatHandler::LineFromMessage(pos)) - { - ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, line); - SendGlobalMessage(&data, self); - } - - delete[] buf; -} - -/// Send a packet to all players (or players selected team) in the zone (except self if mentioned) -void World::SendZoneMessage(uint32 zone, WorldPacket* packet, WorldSession* self /*= NULL*/, Team team /*= TEAM_NONE*/) -{ - SessionMap::const_iterator itr; - for (itr = m_sessions.begin(); itr != m_sessions.end(); ++itr) + for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr) { if (itr->second && itr->second->GetPlayer() && - itr->second->GetPlayer()->IsInWorld() && - itr->second->GetPlayer()->GetZoneId() == zone && - itr->second != self && - (team == TEAM_NONE || itr->second->GetPlayer()->GetTeam() == team)) + itr->second->GetPlayer()->IsInWorld()) { itr->second->SendPacket(packet); } } } -/// Send a System Message to all players in the zone (except self if mentioned) -void World::SendZoneText(uint32 zone, const char* text, WorldSession* self /*= NULL*/, Team team /*= TEAM_NONE*/) +/// Sends a server message to the specified or all players +void World::SendServerMessage(ServerMessageType type, const char* text /*=""*/, Player* player /*= NULL*/) { - WorldPacket data; - ChatHandler::FillMessageData(&data, NULL, CHAT_MSG_SYSTEM, LANG_UNIVERSAL, text); - SendZoneMessage(zone, &data, self, team); + WorldPacket data(SMSG_SERVER_MESSAGE, 50); // guess size + data << uint32(type); + data << text; + + if (player) + player->GetSession()->SendPacket(&data); + else + SendGlobalMessage(&data); } -/// Sends a server wide defense message to all players (or players of the specified team) -void World::SendDefenseMessage(uint32 zoneId, int32 textId, Team team /*= TEAM_NONE*/) +/// Sends a zone under attack message to all players not in an instance +void World::SendZoneUnderAttackMessage(uint32 zoneId, Team team) +{ + WorldPacket data(SMSG_ZONE_UNDER_ATTACK, 4); + data << uint32(zoneId); + + for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr) + { + if (itr->second && + itr->second->GetPlayer() && + itr->second->GetPlayer()->IsInWorld() && + itr->second->GetPlayer()->GetTeam() == team && + !itr->second->GetPlayer()->GetMap()->Instanceable()) + { + itr->second->SendPacket(&data); + } + } +} + +/// Sends a world defense message to all players not in an instance +void World::SendDefenseMessage(uint32 zoneId, int32 textId) { for (SessionMap::const_iterator itr = m_sessions.begin(); itr != m_sessions.end(); ++itr) { if (itr->second && itr->second->GetPlayer() && itr->second->GetPlayer()->IsInWorld() && - (team == TEAM_NONE || itr->second->GetPlayer()->GetTeam() == team)) + !itr->second->GetPlayer()->GetMap()->Instanceable()) { char const* message = itr->second->GetMangosString(textId); uint32 messageLength = strlen(message) + 1; @@ -1916,7 +1901,7 @@ void World::ShutdownServ(uint32 time, uint32 options, uint8 exitcode) } /// Display a shutdown message to the user(s) -void World::ShutdownMsg(bool show, Player* player) +void World::ShutdownMsg(bool show /*= false*/, Player* player /*= NULL*/) { // not show messages for idle shutdown mode if (m_ShutdownMask & SHUTDOWN_MASK_IDLE) @@ -1956,19 +1941,6 @@ void World::ShutdownCancel() DEBUG_LOG("Server %s cancelled.", (m_ShutdownMask & SHUTDOWN_MASK_RESTART ? "restart" : "shutdown")); } -/// Send a server message to the user(s) -void World::SendServerMessage(ServerMessageType type, const char* text /*=""*/, Player* player /*= NULL*/) -{ - WorldPacket data(SMSG_SERVER_MESSAGE, 50); // guess size - data << uint32(type); - data << text; - - if (player) - player->GetSession()->SendPacket(&data); - else - SendGlobalMessage(&data); -} - void World::UpdateSessions(uint32 diff) { ///- Add new sessions diff --git a/src/game/World.h b/src/game/World.h index 8060fe05e..34f0dc83a 100644 --- a/src/game/World.h +++ b/src/game/World.h @@ -507,12 +507,10 @@ class World void LoadConfigSettings(bool reload = false); void SendWorldText(int32 string_id, ...); - void SendGlobalText(const char* text, WorldSession* self); - void SendGlobalMessage(WorldPacket* packet, WorldSession* self = NULL, Team team = TEAM_NONE); - void SendZoneMessage(uint32 zone, WorldPacket* packet, WorldSession* self = NULL, Team team = TEAM_NONE); - void SendZoneText(uint32 zone, const char* text, WorldSession* self = NULL, Team team = TEAM_NONE); - void SendDefenseMessage(uint32 zoneId, int32 textId, Team team = TEAM_NONE); + void SendGlobalMessage(WorldPacket* packet); void SendServerMessage(ServerMessageType type, const char* text = "", Player* player = NULL); + void SendZoneUnderAttackMessage(uint32 zoneId, Team team); + void SendDefenseMessage(uint32 zoneId, int32 textId); /// Are we in the middle of a shutdown? bool IsShutdowning() const { return m_ShutdownTimer > 0; } diff --git a/src/shared/revision_nr.h b/src/shared/revision_nr.h index 6644b38a5..8bf9ce41c 100644 --- a/src/shared/revision_nr.h +++ b/src/shared/revision_nr.h @@ -1,4 +1,4 @@ #ifndef __REVISION_NR_H__ #define __REVISION_NR_H__ - #define REVISION_NR "0061" + #define REVISION_NR "0062" #endif // __REVISION_NR_H__