using vnxbqy.UI; using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Text.RegularExpressions; using UnityEngine; public class LanguageVerify : Singleton { const string Sercret = "c345a165b566d1c421afd8a748373d7f"; static StringBuilder sb = new StringBuilder(); /// /// 校验玩家名 /// /// 需要检验的名字 /// 玩家id /// 原来的角色名,创角传空 /// 玩家等级 /// 玩家VIP等级 /// public void VerifyPlayerName(string verifyName, int playerId, string playerName, int level, int vipLv, Action callback) { if (callback != null) { callback(true, verifyName); callback = null; } return; } public void VerifyFairy(string verifyContent, int op_type, string fairyName, int title, Action callback) { if (callback != null) { callback(true, verifyContent); callback = null; } return; } public static uint toPlayer = 0; public static string toPlayerName = string.Empty; public static int toPlayerLevel = 0; public void VerifyChat(string content, ChatInfoType channelType, Action callback) { int channel = 0; var chatCenter = ModelCenter.Instance.GetModel(); if (chatCenter.IsChatBanned || chatCenter.IsClientBan(channelType)) { if (!(IsFairyFeast(channelType) || IsSystemChat(content))) { return; } } if (!GetChannel(channelType, out channel)) { return; } if (callback != null) { callback(true, content); callback = null; } } Dictionary> transferContents = new Dictionary>(); Dictionary> splitContents = new Dictionary>(); List matchs = new List(); struct MatchString { public int index; public string value; } void AddMathcs(MatchCollection _matchs) { if (_matchs.Count == 0) { return; } foreach (Match match in _matchs) { matchs.Add(new MatchString() { index = match.Index, value = match.Value, }); } } string TransferContent(long tick, string content) { List list; List splits; if (!transferContents.TryGetValue(tick, out list)) { list = new List(); transferContents.Add(tick, list); } if (!splitContents.TryGetValue(tick, out splits)) { splits = new List(); splitContents.Add(tick, splits); } list.Clear(); splits.Clear(); matchs.Clear(); AddMathcs(WordAnalysis.Color_Start_Regex.Matches(content)); AddMathcs(WordAnalysis.Color_End_Regex.Matches(content)); AddMathcs(ImgAnalysis.FaceRegex.Matches(content)); AddMathcs(ChatCtrl.InviteRegex.Matches(content)); AddMathcs(WordAnalysis.Size_Start_Regex.Matches(content)); AddMathcs(WordAnalysis.Size_End_Regex.Matches(content)); AddMathcs(WordAnalysis.Space_Regex.Matches(content)); AddMathcs(ChatCtrl.KillRegex.Matches(content)); AddMathcs(ChatCenter.s_VoiceRegex.Matches(content)); matchs.Sort((x, y) => { return x.index.CompareTo(y.index); }); var index = 0; for (int i = 0; i < matchs.Count; i++) { list.Add(matchs[i].value); var length = matchs[i].index - index; splits.Add(length); index += length + matchs[i].value.Length; } content = WordAnalysis.Color_Start_Regex.Replace(content, string.Empty); content = WordAnalysis.Color_End_Regex.Replace(content, string.Empty); content = ImgAnalysis.FaceRegex.Replace(content, string.Empty); content = ChatCtrl.InviteRegex.Replace(content, string.Empty); content = WordAnalysis.Size_Start_Regex.Replace(content, string.Empty); content = WordAnalysis.Size_End_Regex.Replace(content, string.Empty); content = WordAnalysis.Space_Regex.Replace(content, string.Empty); content = ChatCtrl.KillRegex.Replace(content, string.Empty); content = ChatCenter.s_VoiceRegex.Replace(content, string.Empty); return content; } string DisTransfer(long tick, string content) { List list; if (!transferContents.TryGetValue(tick, out list)) { return content; } List splits; if (!splitContents.TryGetValue(tick, out splits)) { return content; } var index = 0; sb.Length = 0; for (int i = 0; i < splits.Count; i++) { sb.Append(content.Substring(index, splits[i])); if (i < list.Count) { sb.Append(list[i]); } index += splits[i]; } sb.Append(content.Substring(index)); transferContents.Remove(tick); splitContents.Remove(tick); return sb.ToString(); } bool IsSystemChat(string content) { if (ChatCtrl.InviteRegex.IsMatch(content) || ChatCtrl.KillRegex.IsMatch(content)) { return true; } return false; } bool GetChannel(ChatInfoType type, out int channel) { channel = 0; switch (type) { case ChatInfoType.World: case ChatInfoType.CrossServer: channel = 0; break; case ChatInfoType.Team: channel = 4; break; case ChatInfoType.Area: case ChatInfoType.Trumpet: case ChatInfoType.default1: channel = 5; break; case ChatInfoType.Fairy: channel = 2; break; case ChatInfoType.Friend: channel = 3; break; default: return false; } return true; } bool IsFairyFeast(ChatInfoType type) { var dailyQuestModel = ModelCenter.Instance.GetModel(); DailyQuestOpenTime dailyQuestOpenTime; if (dailyQuestModel.TryGetOpenTime((int)DailyQuestType.FairyFeast, out dailyQuestOpenTime)) { return type == ChatInfoType.Fairy && dailyQuestOpenTime.InOpenTime(); } return false; } public class VerifyResponse { public string result; public int code; public string content; } }