private void AddChannelPassword(MODERequest cmd)
 {
     if (Password == null)
     {
         Password = cmd.Password;
     }
 }
 private void RemoveChannelPassword(MODERequest cmd)
 {
     if (Password == cmd.Password)
     {
         Password = null;
     }
 }
        /// <summary>
        /// We only care about how to set mode in this channel
        /// we do not need to care about if the user is legal
        /// because MODEHandler will check for us
        /// </summary>
        /// <param name="changer"></param>
        /// <param name="cmd"></param>
        public void SetProperties(ChatChannelUser changer, MODERequest cmd)
        {
            switch (cmd.RequestType)
            {
            case ModeRequestType.AddChannelUserLimits:
                AddChannelUserLimits(cmd);
                break;

            case ModeRequestType.RemoveChannelUserLimits:
                RemoveChannelUserLimits(cmd);
                break;

            case ModeRequestType.AddBanOnUser:
                AddBanOnUser(cmd);
                break;

            case ModeRequestType.RemoveBanOnUser:
                RemoveBanOnUser(cmd);
                break;

            case ModeRequestType.AddChannelPassword:
                AddChannelPassword(cmd);
                break;

            case ModeRequestType.RemoveChannelPassword:
                RemoveChannelPassword(cmd);
                break;

            case ModeRequestType.AddChannelOperator:
                AddChannelOperator(cmd);
                break;

            case ModeRequestType.RemoveChannelOperator:
                RemoveChannelOperator(cmd);
                break;

            case ModeRequestType.EnableUserVoicePermission:
                EnableUserVoicePermission(cmd);
                break;

            case ModeRequestType.DisableUserVoicePermission:
                DisableUserVoicePermission(cmd);
                break;

            case ModeRequestType.SetChannelModesWithUserLimit:
                AddChannelUserLimits(cmd);
                goto default;

            default:
                ChannelMode.ChangeModes(cmd);
                break;
            }
        }
        public void ChangeModes(MODERequest cmd)
        {
            switch (cmd.RequestType)
            {
            case ModeRequestType.SetChannelModes:
                SetChannelModes(cmd);
                break;

            case ModeRequestType.SetChannelModesWithUserLimit:
                SetChannelModes(cmd);
                break;
            }
        }
        private void RemoveChannelOperator(MODERequest cmd)
        {
            var result = ChannelUsers.Where(u => u.UserInfo.UserName == cmd.UserName);

            if (result.Count() != 1)
            {
                return;
            }
            ChatChannelUser user = result.First();

            if (user.IsChannelCreator)
            {
                user.SetChannelCreator(false);
            }
        }
        private void DisableUserVoicePermission(MODERequest cmd)
        {
            var result = ChannelUsers.Where(u => u.UserInfo.UserName == cmd.UserName);

            if (result.Count() != 1)
            {
                return;
            }

            ChatChannelUser user = result.First();

            if (user.IsVoiceable)
            {
                user.SetVoicePermission(false);
            }
        }
        private void RemoveBanOnUser(MODERequest cmd)
        {
            var result = BanList.Where(u => u.UserInfo.NickName == cmd.NickName);

            if (result.Count() == 1)
            {
                ChatChannelUser user = result.First();
                BanList.TryTake(out user);
                return;
            }
            if (result.Count() > 1)
            {
                LogWriter.ToLog(LogEventLevel.Error,
                                $"Multiple user with same nick name in channel {ChannelName}");
            }
        }
        private void AddBanOnUser(MODERequest cmd)
        {
            var result = ChannelUsers.Where(u => u.UserInfo.NickName == cmd.NickName);

            if (result.Count() != 1)
            {
                return;
            }
            ChatChannelUser user = result.First();

            if (BanList.Where(u => u.UserInfo.NickName == cmd.NickName).Count() == 1)
            {
                return;
            }

            BanList.Add(user);
        }
        private void AddChannelOperator(MODERequest cmd)
        {
            // check whether this user is in this channel
            var result = ChannelUsers.Where(u => u.UserInfo.UserName == cmd.UserName);

            if (result.Count() != 1)
            {
                return;
            }
            ChatChannelUser user = result.First();

            //if this user is already in operator we do not add it
            if (user.IsChannelOperator)
            {
                return;
            }
            user.SetChannelOperator(true);
        }
        private void SetChannelModes(MODERequest cmd)
        {
            List <string> flags = new List <string>();

            if (cmd.ModeFlag == null)
            {
                return;
            }
            for (int i = 0; i < cmd.ModeFlag.Length; i += 2)
            {
                flags.Add($"{cmd.ModeFlag[i]}{cmd.ModeFlag[i + 1]}");
            }

            foreach (var f in flags)
            {
                SetModeByFlag(f);
            }
        }
 private void RemoveChannelUserLimits(MODERequest cmd)
 {
     MaxNumberUser = 200;
 }
 private void AddChannelUserLimits(MODERequest cmd)
 {
     MaxNumberUser = cmd.LimitNumber;
 }
示例#13
0
 public MODEHandler(ISession session, ChatRequestBase request) : base(session, request)
 {
     _request = (MODERequest)request;
 }