少年修仙传客户端代码仓库
client_linchunjie
2018-11-10 b885cdad2cd6442261531992eca05344eaf6f5cc
4700 【前端】【1.3】客户端自动禁言
4个文件已修改
155 ■■■■ 已修改文件
System/Chat/ChatCenter.cs 80 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/Chat/ChatCtrl.cs 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/Chat/ChatSendComponent.cs 66 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Utility/LanguageVerify.cs 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/Chat/ChatCenter.cs
@@ -26,6 +26,14 @@
            WindowCenter.Instance.windowAfterOpenEvent += WindowAfterOpenEvent;
            StageManager.Instance.onStageLoadFinish += OnStageLoadFinish;
            PlayerRealmData.OnPlayerCollectEnd += OnPlayerCollectEnd;
            var time = bandTime;
            banTimeArray[0] = time.Year;
            banTimeArray[1] = time.Month;
            banTimeArray[2] = time.Day;
            banTimeArray[3] = time.Hour;
            banTimeArray[4] = time.Minute;
            banTimeArray[5] = time.Second;
        }
        public override void UnInit()
@@ -55,6 +63,12 @@
            chatChannels.Add(ChatInfoType.Trumpet);
            chatChannels.Add(ChatInfoType.Fairy);
            chatChannels.Add(ChatInfoType.Friend);
            var config = Config.Instance.Get<FuncConfigConfig>("ClientChatBan");
            banCheckSecond = int.Parse(config.Numerical1);
            repeatCountLimit = int.Parse(config.Numerical2);
            maliceCheckCount = int.Parse(config.Numerical3);
            maliceLimitCount = int.Parse(config.Numerical4);
        }
        public event Action<string, bool, bool> UpdateChatValueEvent;
@@ -307,7 +321,7 @@
        const string downloadUrl = "http://{0}.voice.2460web.com:53001/voice/download";
        private void SendSpeech(byte[] encode, long _tick)
        {
            if (IsChatBanned)
            if (IsChatBanned || clientBanned)
            {
                SaveSpeech((int)PlayerDatas.Instance.PlayerId, _tick, encode);
                return;
@@ -873,7 +887,7 @@
        public void HandleChatBanned(ChatInfoType channel, string message, int toPlayer)
        {
            if (IsChatBanned)
            if (IsChatBanned || clientBanned)
            {
                var playerId = PlayerDatas.Instance.baseData.PlayerID;
                var playerName = UIHelper.ServerStringTrim(PlayerDatas.Instance.baseData.PlayerName);
@@ -940,6 +954,68 @@
        }
        #endregion
        #region 聊天禁言
        public bool clientBanned
        {
            get
            {
                var time = new DateTime(banTimeArray[0], banTimeArray[1], banTimeArray[2],
                    banTimeArray[3], banTimeArray[4], banTimeArray[5]);
                return TimeUtility.ServerNow < time;
            }
        }
        public int banCheckSecond = 60;
        public int repeatCountLimit = 5;
        public int maliceCheckCount = 10;
        public int maliceLimitCount = 5;
        public int banHour
        {
            get { return LocalSave.GetInt("ClientChatBanHour", 0); }
            set
            {
                LocalSave.SetInt("ClientChatBanHour", value);
            }
        }
        private int[] banTimeArray = new int[6];
        private DateTime bandTime
        {
            get
            {
                var timeArray = LocalSave.GetIntArray("ClientChatBanTime");
                if (null == timeArray)
                {
                    return TimeUtility.OriginalTime;
                }
                else
                {
                    return new DateTime(timeArray[0], timeArray[1], timeArray[2], timeArray[3], timeArray[4], timeArray[5]);
                }
            }
            set
            {
                banTimeArray[0] = value.Year;
                banTimeArray[1] = value.Month;
                banTimeArray[2] = value.Day;
                banTimeArray[3] = value.Hour;
                banTimeArray[4] = value.Minute;
                banTimeArray[5] = value.Second;
                LocalSave.SetIntArray("ClientChatBanTime", banTimeArray);
            }
        }
        public void ChatClientBan()
        {
            var time = TimeUtility.ServerNow;
            var hour = Mathf.Min(24, banHour + 1);
            banHour = hour;
            time = time.AddTicks(hour * TimeSpan.TicksPerHour);
            bandTime = time;
        }
        #endregion
    }
}
System/Chat/ChatCtrl.cs
@@ -221,8 +221,8 @@
    {
        try
        {
            if (chatCenter.IsChatBanned || IsInviteChat(content)
                || KillRegex.IsMatch(content))
            if (chatCenter.IsChatBanned || chatCenter.clientBanned ||
                IsInviteChat(content) || KillRegex.IsMatch(content))
            {
                return;
            }
@@ -299,7 +299,7 @@
                 msg = CheckHasItem(result, _recentlyChat);
                 chatCenter.recentlyChat = null;
                 if (chatCenter.IsChatBanned)
                 if (chatCenter.IsChatBanned || chatCenter.clientBanned)
                 {
                     var toPlayer = PteChatID;
                     if (info.HasValue && info.Value.infoint1 == 0)
System/Chat/ChatSendComponent.cs
@@ -84,7 +84,7 @@
            SinglePackModel singlePack = _packModel.GetSinglePackModel(PackType.rptItem);
            if (ChatCtrl.Inst.presentChatType == ChatInfoType.Trumpet)
            {
                if (chatCenter.IsChatBanned)
                if (chatCenter.IsChatBanned || chatCenter.clientBanned)
                {
                    return;
                }
@@ -104,10 +104,10 @@
            {
                return;
            }
            if (CheckRepeatContent(m_ChatInput.text))
            if (!chatCenter.clientBanned)
            {
                SysNotifyMgr.Instance.ShowTip("RepeatChat");
                return;
                CheckRepeatContent(m_ChatInput.text);
                CheckMaliceChat(m_ChatInput.text);
            }
            if (CheckChatCD())
            {
@@ -246,31 +246,67 @@
            }
        }
        #region 重复内容
        #region 恶意发言
        private string repeatChatContent = string.Empty;
        private int repeatChatCount = 0;
        private DateTime repeatTime = DateTime.Now;
        private bool CheckRepeatContent(string _content)
        private void CheckRepeatContent(string _content)
        {
            if (repeatChatContent.Equals(_content) && (DateTime.Now - repeatTime).TotalSeconds < 10)
            if (repeatChatContent.Equals(_content)
                && (TimeUtility.ServerNow - repeatTime).TotalSeconds < chatCenter.banCheckSecond)
            {
                repeatChatCount++;
                if (repeatChatCount > 3)
                if (repeatChatCount >= chatCenter.repeatCountLimit)
                {
                    return true;
                }
                else
                {
                    repeatTime = DateTime.Now;
                    SnxxzGame.Instance.StartCoroutine(Co_ClientBan());
                }
            }
            else
            {
                repeatChatContent = _content;
                repeatChatCount = 1;
                repeatTime = DateTime.Now;
                repeatTime = TimeUtility.ServerNow;
            }
            return false;
        }
        int maliceChatCount = 0;
        int maliceRecordCount = 0;
        private DateTime maliceChatTime = DateTime.Now;
        private void CheckMaliceChat(string _content)
        {
            if ((TimeUtility.ServerNow - maliceChatTime).TotalSeconds < chatCenter.banCheckSecond
                && maliceChatCount > 0 && maliceRecordCount < chatCenter.maliceCheckCount)
            {
                maliceRecordCount++;
                if (_content.Length == 1)
                {
                    maliceChatCount++;
                }
                if (maliceChatCount >= chatCenter.maliceLimitCount)
                {
                    SnxxzGame.Instance.StartCoroutine(Co_ClientBan());
                }
            }
            else
            {
                if (_content.Length == 1)
                {
                    maliceChatCount = 1;
                    maliceRecordCount = 1;
                    maliceChatTime = TimeUtility.ServerNow;
                }
                else
                {
                    maliceChatCount = 0;
                    maliceRecordCount = 0;
                }
            }
        }
        IEnumerator Co_ClientBan()
        {
            yield return null;
            chatCenter.ChatClientBan();
        }
        #endregion
Utility/LanguageVerify.cs
@@ -154,7 +154,8 @@
        int channel = 0;
        var chatCenter = ModelCenter.Instance.GetModel<ChatCenter>();
        if (!requireVerify || !GetChannel(channelType, out channel) || PlayerDatas.Instance.baseData.VIPLv >= 4
            || IsFairyFeast(channelType) || chatCenter.IsChatBanned || IsSystemChat(content))
            || IsFairyFeast(channelType) || chatCenter.IsChatBanned || IsSystemChat(content)
            || chatCenter.clientBanned)
        {
            if (callback != null)
            {