Ejemplo n.º 1
0
        void SetMute(ObjectGuid guid, bool set)
        {
            if (!IsOn(guid))
            {
                return;
            }

            PlayerInfo playerInfo = _playersStore.LookupByKey(guid);

            if (playerInfo.IsMuted() != set)
            {
                ChannelMemberFlags oldFlag = _playersStore[guid].GetFlags();
                playerInfo.SetMuted(set);

                ChannelNameBuilder builder = new ChannelNameBuilder(this, new ModeChangeAppend(guid, oldFlag, playerInfo.GetFlags()));
                SendToAll(builder);
            }
        }
Ejemplo n.º 2
0
        public void List(Player player)
        {
            ObjectGuid guid = player.GetGUID();

            if (!IsOn(guid))
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
                SendToOne(builder, guid);
                return;
            }

            string channelName = GetName(player.GetSession().GetSessionDbcLocale());

            Log.outDebug(LogFilter.ChatSystem, "SMSG_CHANNEL_LIST {0} Channel: {1}", player.GetSession().GetPlayerInfo(), channelName);

            ChannelListResponse list = new ChannelListResponse();

            list.Display      = true; /// always true?
            list.Channel      = channelName;
            list.ChannelFlags = GetFlags();

            uint gmLevelInWhoList = WorldConfig.GetUIntValue(WorldCfg.GmLevelInWhoList);

            foreach (var pair in _playersStore)
            {
                Player member = Global.ObjAccessor.FindConnectedPlayer(pair.Key);

                // PLAYER can't see MODERATOR, GAME MASTER, ADMINISTRATOR characters
                // MODERATOR, GAME MASTER, ADMINISTRATOR can see all
                if (member && (player.GetSession().HasPermission(RBACPermissions.WhoSeeAllSecLevels) ||
                               member.GetSession().GetSecurity() <= (AccountTypes)gmLevelInWhoList) &&
                    member.IsVisibleGloballyFor(player))
                {
                    list.Members.Add(new ChannelListResponse.ChannelPlayer(pair.Key, Global.WorldMgr.GetVirtualRealmAddress(), pair.Value.GetFlags()));
                }
            }

            player.SendPacket(list);
        }
Ejemplo n.º 3
0
        public void UnBan(Player player, string badname)
        {
            ObjectGuid good = player.GetGUID();

            if (!IsOn(good))
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
                SendToOne(builder, good);
                return;
            }

            PlayerInfo info = _playersStore.LookupByKey(good);

            if (!info.IsModerator() && !player.GetSession().HasPermission(RBACPermissions.ChangeChannelNotModerator))
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotModeratorAppend());
                SendToOne(builder, good);
                return;
            }

            Player     bad    = Global.ObjAccessor.FindPlayerByName(badname);
            ObjectGuid victim = bad ? bad.GetGUID() : ObjectGuid.Empty;

            if (victim.IsEmpty() || !IsBanned(victim))
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerNotFoundAppend(badname));
                SendToOne(builder, good);
                return;
            }

            _bannedStore.Remove(victim);

            ChannelNameBuilder builder1 = new ChannelNameBuilder(this, new PlayerUnbannedAppend(good, victim));

            SendToAll(builder1);

            UpdateChannelInDB();
        }
Ejemplo n.º 4
0
        public void SetOwner(ObjectGuid guid, bool exclaim = true)
        {
            if (!_ownerGuid.IsEmpty())
            {
                // [] will re-add player after it possible removed
                var playerInfo = _playersStore.LookupByKey(_ownerGuid);
                if (playerInfo != null)
                {
                    playerInfo.SetOwner(false);
                }
            }

            _ownerGuid = guid;
            if (!_ownerGuid.IsEmpty())
            {
                ChannelMemberFlags oldFlag = GetPlayerFlags(_ownerGuid);
                var playerInfo             = _playersStore.LookupByKey(_ownerGuid);
                if (playerInfo == null)
                {
                    return;
                }

                playerInfo.SetModerator(true);
                playerInfo.SetOwner(true);

                ChannelNameBuilder builder = new ChannelNameBuilder(this, new ModeChangeAppend(_ownerGuid, oldFlag, GetPlayerFlags(_ownerGuid)));
                SendToAll(builder);

                if (exclaim)
                {
                    ChannelNameBuilder ownerChangedBuilder = new ChannelNameBuilder(this, new OwnerChangedAppend(_ownerGuid));
                    SendToAll(ownerChangedBuilder);
                }

                UpdateChannelInDB();
            }
        }
Ejemplo n.º 5
0
        void KickOrBan(Player player, string badname, bool ban)
        {
            ObjectGuid good = player.GetGUID();

            if (!IsOn(good))
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotMemberAppend());
                SendToOne(builder, good);
                return;
            }

            PlayerInfo info = _playersStore.LookupByKey(good);

            if (!info.IsModerator() && !player.GetSession().HasPermission(RBACPermissions.ChangeChannelNotModerator))
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotModeratorAppend());
                SendToOne(builder, good);
                return;
            }

            Player     bad    = Global.ObjAccessor.FindPlayerByName(badname);
            ObjectGuid victim = bad ? bad.GetGUID() : ObjectGuid.Empty;

            if (victim.IsEmpty() || !IsOn(victim))
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerNotFoundAppend(badname));
                SendToOne(builder, good);
                return;
            }

            bool changeowner = _ownerGuid == victim;

            if (!player.GetSession().HasPermission(RBACPermissions.ChangeChannelNotModerator) && changeowner && good != _ownerGuid)
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new NotOwnerAppend());
                SendToOne(builder, good);
                return;
            }

            if (ban && !IsBanned(victim))
            {
                _bannedStore.Add(victim);
                UpdateChannelInDB();

                if (!player.GetSession().HasPermission(RBACPermissions.SilentlyJoinChannel))
                {
                    ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerBannedAppend(good, victim));
                    SendToAll(builder);
                }
            }
            else if (!player.GetSession().HasPermission(RBACPermissions.SilentlyJoinChannel))
            {
                ChannelNameBuilder builder = new ChannelNameBuilder(this, new PlayerKickedAppend(good, victim));
                SendToAll(builder);
            }

            _playersStore.Remove(victim);
            bad.LeftChannel(this);

            if (changeowner && _ownershipEnabled && !_playersStore.Empty())
            {
                info.SetModerator(true);
                SetOwner(good);
            }
        }
Ejemplo n.º 6
0
        public void LeaveChannel(Player player, bool send = true)
        {
            ObjectGuid guid = player.GetGUID();

            if (!IsOn(guid))
            {
                if (send)
                {
                    var builder = new ChannelNameBuilder(this, new NotMemberAppend());
                    SendToOne(builder, guid);
                }
                return;
            }

            player.LeftChannel(this);

            if (send)
            {
                /*
                 * ChannelNameBuilder<YouLeftAppend> builder = new ChannelNameBuilder(this, new YouLeftAppend());
                 * SendToOne(builder, guid);
                 */

                SendToOne(new ChannelNotifyLeftBuilder(this), guid);
            }

            PlayerInfo info        = _playersStore.LookupByKey(guid);
            bool       changeowner = info.IsOwner();

            _playersStore.Remove(guid);

            if (_announceEnabled && !player.GetSession().HasPermission(RBACPermissions.SilentlyJoinChannel))
            {
                var builder = new ChannelNameBuilder(this, new LeftAppend(guid));
                SendToAll(builder);
            }

            LeaveNotify(player);

            if (!IsConstant())
            {
                // Update last_used timestamp in db
                UpdateChannelUseageInDB();

                // If the channel owner left and there are still playersStore 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())
                {
                    ObjectGuid newowner = ObjectGuid.Empty;
                    foreach (var key in _playersStore.Keys)
                    {
                        if (!_playersStore[key].IsInvisible())
                        {
                            newowner = key;
                            break;
                        }
                    }

                    if (newowner.IsEmpty())
                    {
                        newowner = _playersStore.First().Key;
                    }

                    _playersStore[newowner].SetModerator(true);

                    SetOwner(newowner);

                    // if the new owner is invisible gm, set flag to automatically choose a new owner
                    if (_playersStore[newowner].IsInvisible())
                    {
                        _isOwnerInvisible = true;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void JoinChannel(Player player, string pass)
        {
            ObjectGuid guid = player.GetGUID();

            if (IsOn(guid))
            {
                // Do not send error message for built-in channels
                if (!IsConstant())
                {
                    var builder = new ChannelNameBuilder(this, new PlayerAlreadyMemberAppend(guid));
                    SendToOne(builder, guid);
                }
                return;
            }

            if (IsBanned(guid))
            {
                var builder = new ChannelNameBuilder(this, new BannedAppend());
                SendToOne(builder, guid);
                return;
            }

            if (!string.IsNullOrEmpty(_channelPassword) && pass != _channelPassword)
            {
                var builder = new ChannelNameBuilder(this, new WrongPasswordAppend());
                SendToOne(builder, guid);
                return;
            }

            if (HasFlag(ChannelFlags.Lfg) && WorldConfig.GetBoolValue(WorldCfg.RestrictedLfgChannel) &&
                Global.AccountMgr.IsPlayerAccount(player.GetSession().GetSecurity()) && //FIXME: Move to RBAC
                player.GetGroup())
            {
                var builder = new ChannelNameBuilder(this, new NotInLFGAppend());
                SendToOne(builder, guid);
                return;
            }

            player.JoinedChannel(this);

            if (_announceEnabled && !player.GetSession().HasPermission(RBACPermissions.SilentlyJoinChannel))
            {
                var builder = new ChannelNameBuilder(this, new JoinedAppend(guid));
                SendToAll(builder);
            }

            bool newChannel = _playersStore.Empty();

            PlayerInfo playerInfo = new PlayerInfo();

            playerInfo.SetInvisible(!player.isGMVisible());
            _playersStore[guid] = playerInfo;

            /*
             * ChannelNameBuilder<YouJoinedAppend> builder = new ChannelNameBuilder(this, new YouJoinedAppend());
             * SendToOne(builder, guid);
             */

            SendToOne(new ChannelNotifyJoinedBuilder(this), guid);

            JoinNotify(player);

            // Custom channel handling
            if (!IsConstant())
            {
                // Update last_used timestamp in db
                if (!_playersStore.Empty())
                {
                    UpdateChannelUseageInDB();
                }

                // If the channel has no owner yet and ownership is allowed, set the new owner.
                // 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 || !playerInfo.IsInvisible()) && (_ownerGuid.IsEmpty() || _isOwnerInvisible))
                {
                    _isOwnerInvisible = playerInfo.IsInvisible();

                    SetOwner(guid, !newChannel && !_isOwnerInvisible);
                    _playersStore[guid].SetModerator(true);
                }
            }
        }