diff --git a/src/server/game/Chat/Channels/Channel.cpp b/src/server/game/Chat/Channels/Channel.cpp index 337fdb305..70c07494b 100644 --- a/src/server/game/Chat/Channels/Channel.cpp +++ b/src/server/game/Chat/Channels/Channel.cpp @@ -17,6 +17,7 @@ Channel::Channel(std::string const& name, uint32 channelId, uint32 channelDBId, _announce(announce), _ownership(ownership), _IsSaved(false), + _isOwnerGM(false), _flags(0), _channelId(channelId), _channelDBId(channelDBId), @@ -212,6 +213,8 @@ void Channel::JoinChannel(Player* player, std::string const& pass) JoinNotify(player); + playersStore[guid].SetOwnerGM(AccountMgr::IsGMAccount(player->GetSession()->GetSecurity())); + // Custom channel handling if (!IsConstant()) { @@ -226,8 +229,12 @@ void Channel::JoinChannel(Player* player, std::string const& pass) } // If the channel has no owner yet and ownership is allowed, set the new owner. - if (!_ownerGUID && _ownership) + // If the channel owner is a GM and the config SilentGMJoinChannel is enabled, set the new owner + if ((!_ownerGUID || (_isOwnerGM && sWorld->getBoolConfig(CONFIG_SILENTLY_GM_JOIN_TO_CHANNEL))) && _ownership) + { + _isOwnerGM = playersStore[guid].IsOwnerGM(); SetOwner(guid, false); + } if (_channelRights.flags & CHANNEL_RIGHT_CANT_SPEAK) playersStore[guid].SetMuted(true); @@ -285,10 +292,15 @@ void Channel::LeaveChannel(Player* player, bool send) for (Channel::PlayerContainer::const_iterator itr = playersStore.begin(); itr != playersStore.end(); ++itr) { newowner = itr->second.player; + if (AccountMgr::IsGMAccount(itr->second.plrPtr->GetSession()->GetSecurity())) + _isOwnerGM = true; + else + _isOwnerGM = false; if (!itr->second.plrPtr->GetSession()->GetSecurity()) break; } SetOwner(newowner); + // if the new owner is invisible gm, set flag to automatically choose a new owner } else SetOwner(0); @@ -911,13 +923,26 @@ void Channel::SetOwner(uint64 guid, bool exclaim) uint8 oldFlag = pinfo.flags; pinfo.SetOwner(true); + bool notify = true; + Player* player = ObjectAccessor::FindPlayer(_ownerGUID); + + if (player) + { + uint32 sec = player->GetSession()->GetSecurity(); + notify = !(AccountMgr::IsGMAccount(sec) && sWorld->getBoolConfig(CONFIG_SILENTLY_GM_JOIN_TO_CHANNEL)); + } + WorldPacket data; - MakeModeChange(&data, _ownerGUID, oldFlag); - SendToAll(&data); + + if (notify) + { + MakeModeChange(&data, _ownerGUID, oldFlag); + SendToAll(&data); + } FlagsNotify(pinfo.plrPtr); - if (exclaim) + if (exclaim && notify) { MakeOwnerChanged(&data, _ownerGUID); SendToAll(&data); diff --git a/src/server/game/Chat/Channels/Channel.h b/src/server/game/Chat/Channels/Channel.h index 5b6bbacc4..f25997c7c 100644 --- a/src/server/game/Chat/Channels/Channel.h +++ b/src/server/game/Chat/Channels/Channel.h @@ -150,6 +150,8 @@ class Channel if (state) flags |= MEMBER_FLAG_OWNER; else flags &= ~MEMBER_FLAG_OWNER; } + bool IsOwnerGM() const { return _gmStatus; } + void SetOwnerGM(bool on) { _gmStatus = on; } bool IsModerator() const { return flags & MEMBER_FLAG_MODERATOR; } void SetModerator(bool state) { @@ -172,6 +174,8 @@ class Channel else return false; } + private: + bool _gmStatus = false; }; public: @@ -315,6 +319,7 @@ class Channel bool _announce; bool _ownership; bool _IsSaved; + bool _isOwnerGM; uint8 _flags; uint32 _channelId; uint32 _channelDBId;