diff options
author | ariel- <ariel-@users.noreply.github.com> | 2016-08-25 08:49:24 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-25 08:49:24 -0300 |
commit | 8a8362ef153eca50be0bcb5670e615b9685607fc (patch) | |
tree | a8f0ba68263e57ff439496796285430e396eceb7 | |
parent | 6992393b3c10b7b2d557205401b04d51bc9dc565 (diff) |
Channel Followup: avoid setting an invisible gm as Channel owner (#17597)
* Core/Chat: avoid setting an invisible gm (as in .gm visible off) as channel owner, giving it away to other players.
- This can now only happen if the channel is empty or every other member is an invisible gm, too.
Fixes #17424
* Feedback based changes
-rw-r--r-- | src/server/game/Chat/Channels/Channel.cpp | 48 | ||||
-rw-r--r-- | src/server/game/Chat/Channels/Channel.h | 7 | ||||
-rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 3 |
3 files changed, 52 insertions, 6 deletions
diff --git a/src/server/game/Chat/Channels/Channel.cpp b/src/server/game/Chat/Channels/Channel.cpp index a34f0f4d9a2..22601b711d1 100644 --- a/src/server/game/Chat/Channels/Channel.cpp +++ b/src/server/game/Chat/Channels/Channel.cpp @@ -29,6 +29,7 @@ Channel::Channel(std::string const& name, uint32 channelId, uint32 team /*= 0*/) _announceEnabled(true), _ownershipEnabled(true), _persistentChannel(false), + _isOwnerInvisible(false), _channelFlags(0), _channelId(channelId), _channelTeam(team), @@ -197,8 +198,11 @@ void Channel::JoinChannel(Player* player, std::string const& pass) SendToAll(&data); } + bool newChannel = _playersStore.empty(); + PlayerInfo& pinfo = _playersStore[guid]; pinfo.flags = MEMBER_FLAG_NONE; + pinfo.invisible = !player->isGMVisible(); WorldPacket data; MakeYouJoined(&data); @@ -213,9 +217,13 @@ void Channel::JoinChannel(Player* player, std::string const& pass) UpdateChannelUseageInDB(); // If the channel has no owner yet and ownership is allowed, set the new owner. - if (!_ownerGuid && _ownershipEnabled) + // or if the owner was a GM with .gm visible off + // don't do this if the new player is, too, an invis GM, unless the channel was empty + if (_ownershipEnabled && (newChannel || !pinfo.IsInvisible()) && (!_ownerGuid || _isOwnerInvisible)) { - SetOwner(guid, _playersStore.size() > 1); + _isOwnerInvisible = pinfo.IsInvisible(); + + SetOwner(guid, !newChannel && !_isOwnerInvisible); pinfo.SetModerator(true); } } @@ -262,13 +270,28 @@ void Channel::LeaveChannel(Player* player, bool send) // Update last_used timestamp in db UpdateChannelUseageInDB(); - // If the channel owner left and there are still players inside, pick a new owner + // If the channel owner left and there are players still inside, pick a new owner + // do not pick invisible gm owner unless there are only invisible gms in that channel (rare) if (changeowner && _ownershipEnabled && !_playersStore.empty()) { - auto itr = _playersStore.begin(); - ObjectGuid newowner = itr->first; + PlayerContainer::iterator itr; + for (itr = _playersStore.begin(); itr != _playersStore.end(); ++itr) + { + if (!itr->second.IsInvisible()) + break; + } + + if (itr == _playersStore.end()) + itr = _playersStore.begin(); + + ObjectGuid newOwner = itr->first; itr->second.SetModerator(true); - SetOwner(newowner); + + SetOwner(newOwner); + + // if the new owner is invisible gm, set flag to automatically choose a new owner + if (itr->second.IsInvisible()) + _isOwnerInvisible = true; } } } @@ -468,6 +491,19 @@ void Channel::SetMode(Player const* player, std::string const& p2n, bool mod, bo SetMute(newp->GetGUID(), set); } +void Channel::SetInvisible(Player const* player, bool on) +{ + auto itr = _playersStore.find(player->GetGUID()); + if (itr == _playersStore.end()) + return; + + itr->second.SetInvisible(on); + + // we happen to be owner too, update flag + if (_ownerGuid == player->GetGUID()) + _isOwnerInvisible = on; +} + void Channel::SetOwner(Player const* player, std::string const& newname) { ObjectGuid guid = player->GetGUID(); diff --git a/src/server/game/Chat/Channels/Channel.h b/src/server/game/Chat/Channels/Channel.h index 23f9e5ae28f..4859a984967 100644 --- a/src/server/game/Chat/Channels/Channel.h +++ b/src/server/game/Chat/Channels/Channel.h @@ -119,6 +119,10 @@ class TC_GAME_API Channel struct PlayerInfo { uint8 flags; + bool invisible; + + bool IsInvisible() const { return invisible; } + void SetInvisible(bool on) { invisible = on; } bool HasFlag(uint8 flag) const { return (flags & flag) != 0; } void SetFlag(uint8 flag) { flags |= flag; } @@ -181,6 +185,8 @@ class TC_GAME_API Channel void SetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, true); } void UnsetMute(Player const* player, std::string const& newname) { SetMode(player, newname, false, false); } + void SetInvisible(Player const* player, bool on); + void SetOwner(ObjectGuid guid, bool exclaim = true); void SetOwner(Player const* player, std::string const& name); void SendWhoOwner(ObjectGuid guid); @@ -291,6 +297,7 @@ class TC_GAME_API Channel bool _announceEnabled; //< Whether we should broadcast a packet whenever a player joins/exits the channel bool _ownershipEnabled; //< Whether the channel has to maintain an owner bool _persistentChannel; //< Whether the channel is saved to DB + bool _isOwnerInvisible; //< Whether the channel is owned by invisible GM, ownership should change to first player that joins channel uint8 _channelFlags; uint32 _channelId; diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index dce0d9b6ad7..e2f6686aae0 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -2609,6 +2609,9 @@ void Player::SetGMVisible(bool on) m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GM, GetSession()->GetSecurity()); } + + for (Channel* channel : m_channels) + channel->SetInvisible(this, !on); } bool Player::IsGroupVisibleFor(Player const* p) const |