Core/Chat: Corrected chat channel flag implementations

This commit is contained in:
Shauren
2023-10-07 18:29:53 +02:00
parent 0ce96adb7a
commit d2baaac9ec
9 changed files with 98 additions and 59 deletions

View File

@@ -18,6 +18,7 @@
#include "Channel.h"
#include "AccountMgr.h"
#include "ChannelAppenders.h"
#include "ChannelMgr.h"
#include "Chat.h"
#include "ChatPackets.h"
#include "DB2Stores.h"
@@ -25,10 +26,8 @@
#include "GameTime.h"
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "Language.h"
#include "Log.h"
#include "ObjectAccessor.h"
#include "ObjectMgr.h"
#include "Player.h"
#include "SocialMgr.h"
#include "StringConvert.h"
@@ -49,15 +48,15 @@ Channel::Channel(ObjectGuid const& guid, uint32 channelId, uint32 team /*= 0*/,
_zoneEntry(zoneEntry)
{
ChatChannelsEntry const* channelEntry = sChatChannelsStore.AssertEntry(channelId);
if (channelEntry->Flags & CHANNEL_DBC_FLAG_TRADE) // for trade channel
if (channelEntry->GetFlags().HasFlag(ChatChannelFlags::AllowItemLinks)) // for trade channel
_channelFlags |= CHANNEL_FLAG_TRADE;
if (channelEntry->Flags & CHANNEL_DBC_FLAG_CITY_ONLY2) // for city only channels
if (channelEntry->GetFlags().HasFlag(ChatChannelFlags::LinkedChannel)) // for city only channels
_channelFlags |= CHANNEL_FLAG_CITY;
if (channelEntry->Flags & CHANNEL_DBC_FLAG_LFG) // for LFG channel
if (channelEntry->GetFlags().HasFlag(ChatChannelFlags::LookingForGroup)) // for LFG channel
_channelFlags |= CHANNEL_FLAG_LFG;
else // for all other channels
else // for all other channels
_channelFlags |= CHANNEL_FLAG_NOT_LFG;
}
@@ -100,12 +99,12 @@ void Channel::GetChannelName(std::string& channelName, uint32 channelId, LocaleC
if (channelId)
{
ChatChannelsEntry const* channelEntry = sChatChannelsStore.AssertEntry(channelId);
if (!(channelEntry->Flags & CHANNEL_DBC_FLAG_GLOBAL))
if (channelEntry->GetFlags().HasFlag(ChatChannelFlags::ZoneBased))
{
if (channelEntry->Flags & CHANNEL_DBC_FLAG_CITY_ONLY)
channelName = fmt::sprintf(channelEntry->Name[locale], sObjectMgr->GetTrinityString(LANG_CHANNEL_CITY, locale));
else
channelName = fmt::sprintf(channelEntry->Name[locale], ASSERT_NOTNULL(zoneEntry)->AreaName[locale]);
if (channelEntry->GetFlags().HasFlag(ChatChannelFlags::LinkedChannel))
zoneEntry = ChannelMgr::SpecialLinkedArea;
channelName = fmt::sprintf(channelEntry->Name[locale], ASSERT_NOTNULL(zoneEntry)->AreaName[locale]);
}
else
channelName = channelEntry->Name[locale];

View File

@@ -98,22 +98,6 @@ enum ChannelFlags
// LookingForGroup 0x50 = 0x40 | 0x10
};
enum ChannelDBCFlags
{
CHANNEL_DBC_FLAG_NONE = 0x00000,
CHANNEL_DBC_FLAG_INITIAL = 0x00001, // General, Trade, LocalDefense, LFG
CHANNEL_DBC_FLAG_ZONE_DEP = 0x00002, // General, Trade, LocalDefense, GuildRecruitment
CHANNEL_DBC_FLAG_GLOBAL = 0x00004, // WorldDefense
CHANNEL_DBC_FLAG_TRADE = 0x00008, // Trade, LFG
CHANNEL_DBC_FLAG_CITY_ONLY = 0x00010, // Trade, GuildRecruitment, LFG
CHANNEL_DBC_FLAG_CITY_ONLY2 = 0x00020, // Trade, GuildRecruitment, LFG
CHANNEL_DBC_FLAG_DEFENSE = 0x10000, // LocalDefense, WorldDefense
CHANNEL_DBC_FLAG_GUILD_REQ = 0x20000, // GuildRecruitment
CHANNEL_DBC_FLAG_LFG = 0x40000, // LFG
CHANNEL_DBC_FLAG_UNK1 = 0x80000, // General
CHANNEL_DBC_FLAG_NO_CLIENT_JOIN = 0x200000
};
enum ChannelMemberFlags
{
MEMBER_FLAG_NONE = 0x00,

View File

@@ -22,9 +22,12 @@
#include "DB2Stores.h"
#include "Log.h"
#include "Player.h"
#include "Realm.h"
#include "World.h"
#include "WorldSession.h"
AreaTableEntry const* ChannelMgr::SpecialLinkedArea;
ChannelMgr::~ChannelMgr()
{
for (auto itr = _channels.begin(); itr != _channels.end(); ++itr)
@@ -36,6 +39,9 @@ ChannelMgr::~ChannelMgr()
/*static*/ void ChannelMgr::LoadFromDB()
{
SpecialLinkedArea = sAreaTableStore.AssertEntry(3459);
ASSERT(SpecialLinkedArea->GetFlags().HasFlag(AreaFlags::LinkedChatSpecialArea));
if (!sWorld->getBoolConfig(CONFIG_PRESERVE_CUSTOM_CHANNELS))
{
TC_LOG_INFO("server.loading", ">> Loaded 0 custom chat channels. Custom channel saving is disabled.");
@@ -268,9 +274,14 @@ ObjectGuid ChannelMgr::CreateCustomChannelGuid()
ObjectGuid ChannelMgr::CreateBuiltinChannelGuid(uint32 channelId, AreaTableEntry const* zoneEntry /*= nullptr*/) const
{
ChatChannelsEntry const* channelEntry = sChatChannelsStore.AssertEntry(channelId);
uint32 zoneId = zoneEntry ? zoneEntry->ID : 0;
if (channelEntry->Flags & (CHANNEL_DBC_FLAG_GLOBAL | CHANNEL_DBC_FLAG_CITY_ONLY))
zoneId = 0;
uint32 zoneId = 0;
if (zoneEntry && channelEntry->GetFlags().HasFlag(ChatChannelFlags::ZoneBased) && !channelEntry->GetFlags().HasFlag(ChatChannelFlags::LinkedChannel))
zoneId = zoneEntry->ID;
return ObjectGuid::Create<HighGuid::ChatChannel>(true, (channelEntry->Flags & CHANNEL_DBC_FLAG_CITY_ONLY2) != 0, zoneId, _team == ALLIANCE ? 3 : 5, channelId);
if (channelEntry->GetFlags().HasFlag(ChatChannelFlags::GlobalForTournament))
if (Cfg_CategoriesEntry const* category = sCfgCategoriesStore.LookupEntry(realm.Timezone))
if (category->GetFlags().HasFlag(CfgCategoriesFlags::Tournament))
zoneId = 0;
return ObjectGuid::Create<HighGuid::ChatChannel>(true, channelEntry->GetFlags().HasFlag(ChatChannelFlags::LinkedChannel), zoneId, _team == ALLIANCE ? 3 : 5, channelId);
}

View File

@@ -45,6 +45,7 @@ class TC_GAME_API ChannelMgr
static ChannelMgr* ForTeam(uint32 team);
static Channel* GetChannelForPlayerByNamePart(std::string const& namePart, Player* playerSearcher);
static Channel* GetChannelForPlayerByGuid(ObjectGuid channelGuid, Player* playerSearcher);
static AreaTableEntry const* SpecialLinkedArea;
void SaveToDB();
Channel* GetSystemChannel(uint32 channelId, AreaTableEntry const* zoneEntry = nullptr);

View File

@@ -617,6 +617,9 @@ struct ChatChannelsEntry
int32 Flags;
int8 FactionGroup;
int32 Ruleset;
EnumFlag<ChatChannelFlags> GetFlags() const { return static_cast<ChatChannelFlags>(Flags); }
ChatChannelRuleset GetRuleset() const { return static_cast<ChatChannelRuleset>(Ruleset); }
};
struct ChrClassUIDisplayEntry

View File

@@ -269,6 +269,38 @@ enum class CfgCategoriesFlags : uint8
DEFINE_ENUM_FLAG(CfgCategoriesFlags);
enum class ChatChannelFlags : int32
{
None = 0x00000000,
AutoJoin = 0x00000001,
ZoneBased = 0x00000002,
ReadOnly = 0x00000004,
AllowItemLinks = 0x00000008,
OnlyInCities = 0x00000010,
LinkedChannel = 0x00000020,
ZoneAttackAlerts = 0x00010000,
GuildRecruitment = 0x00020000,
LookingForGroup = 0x00040000,
GlobalForTournament = 0x00080000,
DisableRaidIcons = 0x00100000,
Regional = 0x00200000
};
DEFINE_ENUM_FLAG(ChatChannelFlags);
enum class ChatChannelRuleset : int32
{
None = 0,
Mentor = 1,
Disabled = 2,
ChromieTimeCataclysm = 3,
ChromieTimeBuringCrusade = 4,
ChromieTimeWrath = 5,
ChromieTimeMists = 6,
ChromieTimeWoD = 7,
ChromieTimeLegion = 8,
};
enum class ChrRacesFlag : int32
{
NPCOnly = 0x000001,

View File

@@ -4934,16 +4934,19 @@ void Player::RepopAtGraveyard()
bool Player::CanJoinConstantChannelInZone(ChatChannelsEntry const* channel, AreaTableEntry const* zone) const
{
if (channel->Flags & CHANNEL_DBC_FLAG_ZONE_DEP && zone->GetFlags().HasFlag(AreaFlags::NoChatChannels))
if (channel->GetFlags().HasFlag(ChatChannelFlags::ZoneBased) && zone->GetFlags().HasFlag(AreaFlags::NoChatChannels))
return false;
if ((channel->Flags & CHANNEL_DBC_FLAG_CITY_ONLY) && (!(zone->GetFlags().HasFlag(AreaFlags::AllowTradeChannel))))
if (channel->GetFlags().HasFlag(ChatChannelFlags::OnlyInCities) && !zone->GetFlags().HasFlag(AreaFlags::AllowTradeChannel))
return false;
if ((channel->Flags & CHANNEL_DBC_FLAG_GUILD_REQ) && GetGuildId())
if (channel->GetFlags().HasFlag(ChatChannelFlags::GuildRecruitment) && GetGuildId())
return false;
if (channel->Flags & CHANNEL_DBC_FLAG_NO_CLIENT_JOIN)
if (channel->GetRuleset() == ChatChannelRuleset::Disabled)
return false;
if (channel->GetFlags().HasFlag(ChatChannelFlags::Regional))
return false;
return true;
@@ -4988,19 +4991,15 @@ void Player::UpdateLocalChannels(uint32 newZone)
if (!cMgr)
return;
for (uint32 i = 0; i < sChatChannelsStore.GetNumRows(); ++i)
for (ChatChannelsEntry const* channelEntry : sChatChannelsStore)
{
ChatChannelsEntry const* channelEntry = sChatChannelsStore.LookupEntry(i);
if (!channelEntry)
continue;
if (!(channelEntry->Flags & CHANNEL_DBC_FLAG_INITIAL))
if (!channelEntry->GetFlags().HasFlag(ChatChannelFlags::AutoJoin))
continue;
Channel* usedChannel = nullptr;
for (Channel* channel : m_channels)
{
if (channel->GetChannelId() == i)
if (channel->GetChannelId() == channelEntry->ID)
{
usedChannel = channel;
break;
@@ -5013,9 +5012,9 @@ void Player::UpdateLocalChannels(uint32 newZone)
if (CanJoinConstantChannelInZone(channelEntry, current_zone))
{
if (!(channelEntry->Flags & CHANNEL_DBC_FLAG_GLOBAL))
if (channelEntry->GetFlags().HasFlag(ChatChannelFlags::ZoneBased))
{
if (channelEntry->Flags & CHANNEL_DBC_FLAG_CITY_ONLY && usedChannel)
if (channelEntry->GetFlags().HasFlag(ChatChannelFlags::LinkedChannel) && usedChannel)
continue; // Already on the channel, as city channel names are not changing
joinChannel = cMgr->GetSystemChannel(channelEntry->ID, current_zone);
@@ -7517,8 +7516,10 @@ void Player::UpdateArea(uint32 newArea)
{
// FFA_PVP flags are area and not zone id dependent
// so apply them accordingly
uint32 const oldArea = m_areaUpdateId;
m_areaUpdateId = newArea;
AreaTableEntry const* oldAreaEntry = sAreaTableStore.LookupEntry(oldArea);
AreaTableEntry const* area = sAreaTableStore.LookupEntry(newArea);
bool oldFFAPvPArea = pvpInfo.IsInFFAPvPArea;
pvpInfo.IsInFFAPvPArea = area && (area->GetFlags().HasFlag(AreaFlags::FreeForAllPvP));
@@ -7559,6 +7560,10 @@ void Player::UpdateArea(uint32 newArea)
UpdateCriteria(CriteriaType::EnterTopLevelArea, newArea);
UpdateMountCapability();
if ((oldAreaEntry && oldAreaEntry->GetFlags2().HasFlag(AreaFlags2::UseSubzoneForChatChannel))
|| (area && area->GetFlags2().HasFlag(AreaFlags2::UseSubzoneForChatChannel)))
UpdateLocalChannels(newArea);
}
void Player::UpdateZone(uint32 newZone, uint32 newArea)
@@ -7623,7 +7628,9 @@ void Player::UpdateZone(uint32 newZone, uint32 newArea)
AutoUnequipOffhandIfNeed();
// recent client version not send leave/join channel packets for built-in local channels
UpdateLocalChannels(newZone);
AreaTableEntry const* newAreaEntry = sAreaTableStore.LookupEntry(newArea);
if (!newAreaEntry || !newAreaEntry->GetFlags2().HasFlag(AreaFlags2::UseSubzoneForChatChannel))
UpdateLocalChannels(newZone);
UpdateZoneDependentAuras(newZone);
@@ -20973,18 +20980,18 @@ void Player::outDebugValues() const
if (!sLog->ShouldLog("entities.unit", LOG_LEVEL_DEBUG))
return;
TC_LOG_DEBUG("entities.unit", "HP is: \t\t\t{}\t\tMP is: \t\t\t{}", GetMaxHealth(), GetMaxPower(POWER_MANA));
TC_LOG_DEBUG("entities.unit", "AGILITY is: \t\t{}\t\tSTRENGTH is: \t\t{}", GetStat(STAT_AGILITY), GetStat(STAT_STRENGTH));
TC_LOG_DEBUG("entities.unit", "INTELLECT is: \t\t{}", GetStat(STAT_INTELLECT));
TC_LOG_DEBUG("entities.unit", "STAMINA is: \t\t{}", GetStat(STAT_STAMINA));
TC_LOG_DEBUG("entities.unit", "Armor is: \t\t{}\t\tBlock is: \t\t{}", GetArmor(), *m_activePlayerData->BlockPercentage);
TC_LOG_DEBUG("entities.unit", "HolyRes is: \t\t{}\t\tFireRes is: \t\t{}", GetResistance(SPELL_SCHOOL_MASK_HOLY), GetResistance(SPELL_SCHOOL_MASK_FIRE));
TC_LOG_DEBUG("entities.unit", "NatureRes is: \t\t{}\t\tFrostRes is: \t\t{}", GetResistance(SPELL_SCHOOL_MASK_NATURE), GetResistance(SPELL_SCHOOL_MASK_FROST));
TC_LOG_DEBUG("entities.unit", "ShadowRes is: \t\t{}\t\tArcaneRes is: \t\t{}", GetResistance(SPELL_SCHOOL_MASK_SHADOW), GetResistance(SPELL_SCHOOL_MASK_ARCANE));
TC_LOG_DEBUG("entities.unit", "MIN_DAMAGE is: \t\t{}\tMAX_DAMAGE is: \t\t{}", *m_unitData->MinDamage, *m_unitData->MaxDamage);
TC_LOG_DEBUG("entities.unit", "MIN_OFFHAND_DAMAGE is: \t{}\tMAX_OFFHAND_DAMAGE is: \t{}", *m_unitData->MinOffHandDamage, *m_unitData->MaxOffHandDamage);
TC_LOG_DEBUG("entities.unit", "MIN_RANGED_DAMAGE is: \t{}\tMAX_RANGED_DAMAGE is: \t{}", *m_unitData->MinRangedDamage, *m_unitData->MaxRangedDamage);
TC_LOG_DEBUG("entities.unit", "ATTACK_TIME is: \t{}\t\tRANGE_ATTACK_TIME is: \t{}", GetBaseAttackTime(BASE_ATTACK), GetBaseAttackTime(RANGED_ATTACK));
sLog->OutMessage("entities.unit", LOG_LEVEL_DEBUG, "HP is: \t\t\t{}\t\tMP is: \t\t\t{}", GetMaxHealth(), GetMaxPower(POWER_MANA));
sLog->OutMessage("entities.unit", LOG_LEVEL_DEBUG, "AGILITY is: \t\t{}\t\tSTRENGTH is: \t\t{}", GetStat(STAT_AGILITY), GetStat(STAT_STRENGTH));
sLog->OutMessage("entities.unit", LOG_LEVEL_DEBUG, "INTELLECT is: \t\t{}", GetStat(STAT_INTELLECT));
sLog->OutMessage("entities.unit", LOG_LEVEL_DEBUG, "STAMINA is: \t\t{}", GetStat(STAT_STAMINA));
sLog->OutMessage("entities.unit", LOG_LEVEL_DEBUG, "Armor is: \t\t{}\t\tBlock is: \t\t{}", GetArmor(), *m_activePlayerData->BlockPercentage);
sLog->OutMessage("entities.unit", LOG_LEVEL_DEBUG, "HolyRes is: \t\t{}\t\tFireRes is: \t\t{}", GetResistance(SPELL_SCHOOL_MASK_HOLY), GetResistance(SPELL_SCHOOL_MASK_FIRE));
sLog->OutMessage("entities.unit", LOG_LEVEL_DEBUG, "NatureRes is: \t\t{}\t\tFrostRes is: \t\t{}", GetResistance(SPELL_SCHOOL_MASK_NATURE), GetResistance(SPELL_SCHOOL_MASK_FROST));
sLog->OutMessage("entities.unit", LOG_LEVEL_DEBUG, "ShadowRes is: \t\t{}\t\tArcaneRes is: \t\t{}", GetResistance(SPELL_SCHOOL_MASK_SHADOW), GetResistance(SPELL_SCHOOL_MASK_ARCANE));
sLog->OutMessage("entities.unit", LOG_LEVEL_DEBUG, "MIN_DAMAGE is: \t\t{}\tMAX_DAMAGE is: \t\t{}", *m_unitData->MinDamage, *m_unitData->MaxDamage);
sLog->OutMessage("entities.unit", LOG_LEVEL_DEBUG, "MIN_OFFHAND_DAMAGE is: \t{}\tMAX_OFFHAND_DAMAGE is: \t{}", *m_unitData->MinOffHandDamage, *m_unitData->MaxOffHandDamage);
sLog->OutMessage("entities.unit", LOG_LEVEL_DEBUG, "MIN_RANGED_DAMAGE is: \t{}\tMAX_RANGED_DAMAGE is: \t{}", *m_unitData->MinRangedDamage, *m_unitData->MaxRangedDamage);
sLog->OutMessage("entities.unit", LOG_LEVEL_DEBUG, "ATTACK_TIME is: \t{}\t\tRANGE_ATTACK_TIME is: \t{}", GetBaseAttackTime(BASE_ATTACK), GetBaseAttackTime(RANGED_ATTACK));
}
/*********************************************************/

View File

@@ -431,6 +431,10 @@ void WorldSession::HandleChatMessage(ChatMsg type, Language lang, std::string ms
: ChannelMgr::GetChannelForPlayerByNamePart(target, sender);
if (chn)
{
if (ChatChannelsEntry const* chatChannel = sChatChannelsStore.LookupEntry(chn->GetChannelId()))
if (chatChannel->GetFlags().HasFlag(ChatChannelFlags::ReadOnly))
return;
sScriptMgr->OnPlayerChat(sender, type, lang, msg, chn);
chn->Say(sender->GetGUID(), msg, lang);
}

View File

@@ -35,13 +35,11 @@
#include "Group.h"
#include "Guild.h"
#include "GuildMgr.h"
#include "InstanceLockMgr.h"
#include "InstancePackets.h"
#include "InstanceScript.h"
#include "Language.h"
#include "Log.h"
#include "Map.h"
#include "MapManager.h"
#include "MiscPackets.h"
#include "Object.h"
#include "ObjectAccessor.h"