| using System; | 
| using System.Collections; | 
| using System.Collections.Generic; | 
| using System.Text.RegularExpressions; | 
|   | 
| using UnityEngine; | 
| using UnityEngine.UI; | 
| using Cysharp.Threading.Tasks; | 
|   | 
|     public class ChatSendComponent : MonoBehaviour | 
|     { | 
|         [SerializeField] Button m_SendBtn; | 
|         [SerializeField] InputField m_ChatInput; | 
|         [SerializeField] Button m_ExtentBtn; | 
|         // [SerializeField] VoiceRecorder m_VoiceRecorder; | 
|         [SerializeField] RichText m_ChatValueDisplay; | 
|         [SerializeField] Text m_Placeholder; | 
|         [SerializeField, Header("上移高度")] float m_UpHeight = 300.0f; | 
|   | 
|         public Text placeholder { get { return m_Placeholder; } } | 
|         public Button sendBtn { get { return m_SendBtn; } } | 
|   | 
|         // PhantasmPavilionModel phantasmPavilionModel { get { return ModelCenter.Instance.GetModel<PhantasmPavilionModel>(); } } | 
|         // VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } } | 
|         // [NonSerialized] public UIBase parent; | 
|   | 
|         private bool m_OnChating = false; | 
|   | 
|         private void Awake() | 
|         { | 
|             m_SendBtn.onClick.AddListener(OnChatSend); | 
|             m_ExtentBtn.onClick.AddListener(OnExtent); | 
|             m_ChatInput.onValueChanged.AddListener(OnChatValueChange); | 
|         } | 
|   | 
|         private void OnEnable() | 
|         { | 
|             // m_VoiceRecorder.voiceRecordSuccessEvent += OnVoiceRecordSuccessEvent; | 
|             FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent; | 
|             ChatCenter.Instance.UpdateChatValueEvent += UpdateChatValueEvent; | 
|             ChatCenter.Instance.UpdateChatType += UpdateChatType; | 
|             m_ChatInput.characterLimit = ChatCenter.Instance.chatCharacterLimit; | 
|             // WindowCenter.Instance.windowAfterCloseEvent += WindowAfterCloseEvent; | 
|             // phantasmPavilionModel.SendChatAction += OnSendChatAction; | 
|             m_OnChating = false; | 
|         } | 
|   | 
|         private void OnDisable() | 
|         { | 
|             // m_VoiceRecorder.voiceRecordSuccessEvent -= OnVoiceRecordSuccessEvent; | 
|             FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent; | 
|             ChatCenter.Instance.UpdateChatValueEvent -= UpdateChatValueEvent; | 
|             ChatCenter.Instance.UpdateChatType -= UpdateChatType; | 
|             // WindowCenter.Instance.windowAfterCloseEvent -= WindowAfterCloseEvent; | 
|             // phantasmPavilionModel.SendChatAction -= OnSendChatAction; | 
|         } | 
|   | 
|         // private void WindowAfterCloseEvent(Window _window) | 
|         // { | 
|         //     if (_window is ChatExtentWin) | 
|         //     { | 
|         //         if (parent != null) | 
|         //         { | 
|         //             parent.transform.localPosition = parent.transform.localPosition.SetY(0); | 
|         //         } | 
|         //     } | 
|         // } | 
|   | 
|         private void LateUpdate() | 
|         { | 
|         } | 
|   | 
|         private void UpdateChatType() | 
|         { | 
|             m_Placeholder.text = ChatManager.Instance.presentChatType == ChatInfoType.Trumpet ? Language.Get("L1012") : Language.Get("L1111"); | 
|         } | 
|   | 
|         bool ChangeBranch() | 
|         { | 
|             if (m_ChatInput.text.StartsWith("#@#BrancH")) | 
|             { | 
|                 if (m_ChatInput.text.Split(' ')[1] == "c") | 
|                 { | 
|                     //删除记录 | 
|                     LocalSave.DeleteKey("#@#BrancH"); | 
|                     ScrollTip.ShowTip("清理分支设置"); | 
|                 } | 
|                 else | 
|                 { | 
|                     //切换分支 | 
|                     LocalSave.SetString("#@#BrancH", m_ChatInput.text.Split(' ')[1]); | 
|                     ScrollTip.ShowTip("分支设置完毕"); | 
|                 } | 
|                 return true; | 
|             } | 
|             return false; | 
|         } | 
|   | 
|         private void OnChatSend() | 
|         { | 
|             if (ChangeBranch()) return; | 
|   | 
|             if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Chat)) | 
|             { | 
|                 FuncOpen.Instance.ProcessorFuncErrorTip((int)FuncOpenEnum.Chat); | 
|                 return; | 
|             } | 
|   | 
|             // TODO YYL | 
|             // if (vipModel.realRecharge < ChatCenter.Instance.talkRechargeLimmit ||  | 
|             //     PlayerDatas.Instance.baseData.LV < ChatCenter.Instance.talkLevelLimmit) | 
|             // { | 
|             //     SysNotifyMgr.Instance.ShowTip("mdtqInfo1", ChatCenter.Instance.talkRechargeLimmit, ChatCenter.Instance.talkLevelLimmit); | 
|             //     return; | 
|             // } | 
|   | 
|             if (ChatManager.Instance.presentChatType == ChatInfoType.CrossServer) | 
|             { | 
|                 if (!FuncOpen.Instance.IsFuncOpen(162)) | 
|                 { | 
|                     SysNotifyMgr.Instance.ShowTip("CrossServerHint"); | 
|                     return; | 
|                 } | 
|             } | 
|             ChatExtraData? info = null; | 
|             SinglePack singlePack = PackManager.Instance.GetSinglePack(PackType.Item); | 
|             if (ChatManager.Instance.presentChatType == ChatInfoType.Trumpet) | 
|             { | 
|                 if (ChatCenter.Instance.IsChatBanned || ChatCenter.Instance.clientBanned) | 
|                 { | 
|                     return; | 
|                 } | 
|   | 
|                 var count = singlePack.GetCountById(ChatCenter.Instance.bugleItem); | 
|                 if (count < 1) | 
|                 { | 
|                     ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("NoTrumpet"), () => | 
|                     { | 
|                         // TODO YYL | 
|                         // WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.StoreFunc2); | 
|                     }); | 
|                     return; | 
|                 } | 
|   | 
|                 var items = singlePack.GetItemsById(ChatCenter.Instance.bugleItem); | 
|                 info = new ChatExtraData() { infoint1 = items[0].gridIndex }; | 
|             } | 
|             if (m_ChatInput.text.Length < 1) | 
|             { | 
|                 return; | 
|             } | 
|             if (m_OnChating) | 
|             { | 
|                 return; | 
|             } | 
|             if (CheckChatCD()) | 
|             { | 
|                 SysNotifyMgr.Instance.ShowTip("OnChatCD"); | 
|                 return; | 
|             } | 
|             if (!ChatCenter.Instance.clientBanned) | 
|             { | 
|                 CheckRepeatContent(m_ChatInput.text); | 
|                 CheckMaliceChat(m_ChatInput.text); | 
|             } | 
|             m_OnChating = true; | 
|             string msg = m_ChatInput.text; | 
|   | 
|             string tmpMsg = ImgAnalysis.ReplaceFace(msg, out int faceCount); | 
|   | 
|             if (DirtyWordConfig.IsDirtWord(tmpMsg)) | 
|             { | 
|                 tmpMsg = DirtyWordConfig.IsDirtWord(tmpMsg, '*'); | 
|                 tmpMsg = tmpMsg.Replace("*", ""); | 
|                 m_ChatInput.text = tmpMsg; | 
|                 SysNotifyMgr.Instance.ShowTip("DirtyWordWarn"); | 
|                 m_OnChating = false; | 
|                 return; | 
|             } | 
|   | 
|             ChatManager.Instance.SendChatInfo(ChatManager.Instance.presentChatType, msg, info, false); | 
|             StartCoroutine(Co_CoolDowmChat()); | 
|   | 
|             // TODO YYL | 
|             // ModelCenter.Instance.GetModel<FirstTimeRechargeModel>().AskFirstRechargeMore(msg); | 
|         } | 
|   | 
|         private void OnChatSend(string msg) | 
|         { | 
|             if (ChangeBranch()) return; | 
|   | 
|             if (!FuncOpen.Instance.IsFuncOpen((int)FuncOpenEnum.Chat)) | 
|             { | 
|                 FuncOpen.Instance.ProcessorFuncErrorTip((int)FuncOpenEnum.Chat); | 
|                 return; | 
|             } | 
|             if (ChatManager.Instance.presentChatType == ChatInfoType.CrossServer) | 
|             { | 
|                 if (!FuncOpen.Instance.IsFuncOpen(162)) | 
|                 { | 
|                     SysNotifyMgr.Instance.ShowTip("CrossServerHint"); | 
|                     return; | 
|                 } | 
|             } | 
|             ChatExtraData? info = null; | 
|             SinglePack singlePack = PackManager.Instance.GetSinglePack(PackType.Item); | 
|             if (ChatManager.Instance.presentChatType == ChatInfoType.Trumpet) | 
|             { | 
|                 if (ChatCenter.Instance.IsChatBanned || ChatCenter.Instance.clientBanned) | 
|                 { | 
|                     return; | 
|                 } | 
|   | 
|                 var count = singlePack.GetCountById(ChatCenter.Instance.bugleItem); | 
|                 if (count < 1) | 
|                 { | 
|                     ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("NoTrumpet"), () => | 
|                     { | 
|                         // TODO YYL | 
|                         // WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.StoreFunc2); | 
|                     }); | 
|                     return; | 
|                 } | 
|   | 
|                 var items = singlePack.GetItemsById(ChatCenter.Instance.bugleItem); | 
|                 info = new ChatExtraData() { infoint1 = items[0].gridIndex }; | 
|             } | 
|             if (msg.Length < 1) | 
|             { | 
|                 return; | 
|             } | 
|             if (m_OnChating) | 
|             { | 
|                 return; | 
|             } | 
|             if (CheckChatCD()) | 
|             { | 
|                 SysNotifyMgr.Instance.ShowTip("OnChatCD"); | 
|                 return; | 
|             } | 
|             if (!ChatCenter.Instance.clientBanned) | 
|             { | 
|                 CheckRepeatContent(msg); | 
|                 CheckMaliceChat(msg); | 
|             } | 
|             m_OnChating = true; | 
|             ChatManager.Instance.SendChatInfo(ChatManager.Instance.presentChatType, msg, info, false); | 
|             StartCoroutine(Co_CoolDowmChat()); | 
|         } | 
|   | 
|         IEnumerator Co_CoolDowmChat() | 
|         { | 
|             yield return new WaitForSeconds(1.5f); | 
|             // yield return WaitingForSecondConst.WaitMS1500; | 
|             m_OnChating = false; | 
|         } | 
|   | 
|         private void OnChatValueChange(string _msg) | 
|         { | 
|             string _chat = Regex.Replace(_msg, @"\p{Cs}|&", ""); | 
|             if (!_chat.Equals(_msg)) | 
|             { | 
|                 m_ChatInput.text = _chat; | 
|                 ChatCenter.Instance.chatInputLength = m_ChatInput.text.Length; | 
|             } | 
|             if (_msg.Equals(string.Empty)) | 
|             { | 
|                 ChatCenter.Instance.recentlyChat = null; | 
|             } | 
|             m_ChatValueDisplay.text = _chat; | 
|             MatchCollection matchArray = HrefAnalysis.EquipRegex.Matches(_chat); | 
|             if (matchArray.Count == 0) | 
|             { | 
|                 ChatManager.Instance.itemPlaceList.Clear(); | 
|                 ChatCenter.Instance.recentlyChat = null; | 
|                 return; | 
|             } | 
|             if (ChatCenter.Instance.recentlyChat == null) | 
|             { | 
|                 if (ChatManager.Instance.itemPlaceList.Count == matchArray.Count) | 
|                 { | 
|                     return; | 
|                 } | 
|             } | 
|             if (ChatCenter.Instance.recentlyChat != null) | 
|             { | 
|                 var _recentlyChat = ChatCenter.Instance.recentlyChat; | 
|                 for (int i = 0, m = 0; i < _recentlyChat.itemIndexs.Count; i++) | 
|                 { | 
|                     if (m < matchArray.Count) | 
|                     { | 
|                         Match match = matchArray[m]; | 
|                         if (_recentlyChat.itemNames[_recentlyChat.itemIndexs[i]] != match.Groups[1].Value) | 
|                         { | 
|                             _recentlyChat.itemIndexs.RemoveAt(i); | 
|                             i--; | 
|                         } | 
|                         else | 
|                         { | 
|                             m++; | 
|                         } | 
|                     } | 
|                 } | 
|                 return; | 
|             } | 
|             for (int i = 0, m = 0; i < ChatManager.Instance.itemPlaceList.Count; i++) | 
|             { | 
|                 if (m < matchArray.Count) | 
|                 { | 
|                     Match match = matchArray[m]; | 
|                     ItemModel itemModel = ChatManager.Instance.itemPlaceList[i]; | 
|                     ItemConfig cfg = ItemConfig.Get((int)itemModel.itemId); | 
|                     if (cfg.ItemName != match.Groups[1].Value) | 
|                     { | 
|                         ChatManager.Instance.itemPlaceList.RemoveAt(i); | 
|                         i--; | 
|                     } | 
|                     else | 
|                     { | 
|                         m++; | 
|                     } | 
|                 } | 
|             } | 
|         } | 
|   | 
|         private void UpdateChatValueEvent(string _msg, bool _add, bool _force) | 
|         { | 
|             if (_add) | 
|             { | 
|                 m_ChatInput.text += _msg; | 
|                 ChatCenter.Instance.chatInputLength = m_ChatInput.text.Length; | 
|             } | 
|             else | 
|             { | 
|                 m_ChatInput.text = _msg; | 
|                 ChatCenter.Instance.chatInputLength = m_ChatInput.text.Length; | 
|             } | 
|         } | 
|   | 
|         private void OnExtent() | 
|         { | 
|             // if (!WindowCenter.Instance.IsOpen<ChatExtentWin>()) | 
|             // { | 
|             //     WindowCenter.Instance.Open<ChatExtentWin>(true); | 
|             //     if (parent != null) | 
|             //     { | 
|             //         parent.transform.localPosition = parent.transform.localPosition.SetY(m_UpHeight); | 
|             //     } | 
|             // } | 
|             // else | 
|             // { | 
|             //     WindowCenter.Instance.Close<ChatExtentWin>(); | 
|             //     if (parent != null) | 
|             //     { | 
|             //         parent.transform.localPosition = parent.transform.localPosition.SetY(0); | 
|             //     } | 
|             // } | 
|         } | 
|   | 
|         // private void OnVoiceRecordSuccessEvent(int _instance, float _length) | 
|         // { | 
|         //     var _type = ChatManager.Instance.presentChatType; | 
|         //     ChatCenter.Instance.SetVoice(_instance, _type, _length, _type == ChatInfoType.Friend ? ChatManager.Instance.PteChatID : 0); | 
|         // } | 
|   | 
|         private void OnFuncStateChangeEvent(int _id) | 
|         { | 
|             if (_id == (int)FuncOpenEnum.Chat) | 
|             { | 
|             } | 
|         } | 
|   | 
|         #region 恶意发言 | 
|         static string repeatChatContent = string.Empty; | 
|         static int repeatChatCount = 0; | 
|         static DateTime repeatTime = DateTime.Now; | 
|         private void CheckRepeatContent(string _content) | 
|         { | 
|             if (ChatManager.Instance.IsAssitChat(_content, true) == 0 && repeatChatContent.Equals(_content) | 
|                 && (TimeUtility.ServerNow - repeatTime).TotalSeconds < ChatCenter.Instance.banCheckSecond) | 
|             { | 
|                 repeatChatCount++; | 
|                 if (repeatChatCount >= ChatCenter.Instance.repeatCountLimit) | 
|                 { | 
|                     Co_ClientBan().Forget(); | 
|                 } | 
|             } | 
|             else | 
|             { | 
|                 repeatChatContent = _content; | 
|                 repeatChatCount = 1; | 
|                 repeatTime = TimeUtility.ServerNow; | 
|             } | 
|         } | 
|   | 
|         static int maliceChatCount = 0; | 
|         static int maliceRecordCount = 0; | 
|         static DateTime maliceChatTime = DateTime.Now; | 
|         private void CheckMaliceChat(string _content) | 
|         { | 
|             if ((TimeUtility.ServerNow - maliceChatTime).TotalSeconds < ChatCenter.Instance.banCheckSecond | 
|                 && maliceChatCount > 0 && maliceRecordCount < ChatCenter.Instance.maliceCheckCount) | 
|             { | 
|                 maliceRecordCount++; | 
|                 if (ChatManager.GetUTF8InfoLen(_content) == 1) | 
|                 { | 
|                     maliceChatCount++; | 
|                 } | 
|                 if (maliceChatCount >= ChatCenter.Instance.maliceLimitCount) | 
|                 { | 
|                     Co_ClientBan().Forget(); | 
|                 } | 
|             } | 
|             else | 
|             { | 
|                 if (ChatManager.GetUTF8InfoLen(_content) == 1) | 
|                 { | 
|                     maliceChatCount = 1; | 
|                     maliceRecordCount = 1; | 
|                     maliceChatTime = TimeUtility.ServerNow; | 
|                 } | 
|                 else | 
|                 { | 
|                     maliceChatCount = 0; | 
|                     maliceRecordCount = 0; | 
|                 } | 
|             } | 
|         } | 
|   | 
|         async UniTask Co_ClientBan() | 
|         { | 
|             await UniTask.Yield(); | 
|             ChatCenter.Instance.ChatClientBan(); | 
|         } | 
|         #endregion | 
|   | 
|         #region 聊天CD | 
|         private DateTime chatCdTime = DateTime.Now; | 
|         private int chatCdCount = 0; | 
|         private bool chatBusy = false; | 
|         public bool CheckChatCD() | 
|         { | 
|             if (chatBusy && (DateTime.Now - chatCdTime).TotalSeconds < 10) | 
|             { | 
|                 return true; | 
|             } | 
|             else if (chatBusy) | 
|             { | 
|                 chatBusy = false; | 
|                 chatCdCount = 0; | 
|             } | 
|             if ((DateTime.Now - chatCdTime).TotalSeconds < 2) | 
|             { | 
|                 chatCdCount++; | 
|             } | 
|             else | 
|             { | 
|                 chatCdCount = 1; | 
|             } | 
|             if (chatCdCount > 5) | 
|             { | 
|                 chatBusy = true; | 
|                 return true; | 
|             } | 
|             chatCdTime = DateTime.Now; | 
|             return false; | 
|         } | 
|         #endregion | 
|   | 
|         private void OnSendChatAction(string msg) | 
|         { | 
|             OnChatSend(msg); | 
|             // WindowCenter.Instance.Close<ChatExtentWin>(); | 
|             // if (parent != null) | 
|             // { | 
|             //     parent.transform.localPosition = parent.transform.localPosition.SetY(0); | 
|             // } | 
|         } | 
|     } |