using Snxxz.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Security.Cryptography;
|
using System.Text;
|
using System.Text.RegularExpressions;
|
using UnityEngine;
|
|
[XLua.LuaCallCSharp]
|
public class LanguageVerify : Singleton<LanguageVerify>
|
|
{
|
const string Sercret = "c345a165b566d1c421afd8a748373d7f";
|
bool requireVerify
|
{
|
get
|
{
|
return VersionUtility.Instance.IsMaoErGame();
|
}
|
}
|
|
static StringBuilder sb = new StringBuilder();
|
|
const string VerifyPlayerNameUrl = "https://api.maoergame.com/game/role/response";
|
/// <summary>
|
/// 校验玩家名
|
/// </summary>
|
/// <param name="verifyName">需要检验的名字</param>
|
/// <param name="playerId">玩家id</param>
|
/// <param name="playerName">原来的角色名,创角传空</param>
|
/// <param name="level">玩家等级</param>
|
/// <param name="vipLv">玩家VIP等级</param>
|
/// <param name="callback"></param>
|
public void VerifyPlayerName(string verifyName, int playerId, string playerName, int level, int vipLv, Action<bool, string> callback)
|
{
|
if (!requireVerify)
|
{
|
if (callback != null)
|
{
|
callback(true, verifyName);
|
callback = null;
|
}
|
return;
|
}
|
NetLinkWin.Show();
|
var tables = new Dictionary<string, string>();
|
tables["game_code"] = "snxxz";
|
tables["server_id"] = ServerListCenter.Instance.currentServer.region_flag.ToString();
|
tables["server_name"] = StringUtility.Contact("s", ServerListCenter.Instance.currentServer.region_flag);
|
tables["role_name"] = verifyName;
|
tables["sender_uid"] = ModelCenter.Instance.GetModel<LoginModel>().sdkLoginResult.account;
|
tables["sender_rid"] = playerId.ToString();
|
tables["sender_name"] = playerName;
|
tables["sender_level"] = level.ToString();
|
tables["sender_vip_level"] = vipLv.ToString();
|
var ts = System.DateTime.UtcNow - new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
|
tables["timestamp"] = ((long)System.Convert.ToInt64(ts.TotalSeconds)).ToString();
|
tables["key"] = FileExtersion.GetStringMD5Hash(StringUtility.Contact(Sercret, tables["timestamp"]));
|
HttpRequest.Instance.RequestHttpPost(VerifyPlayerNameUrl, tables, HttpRequest.defaultHttpContentType, 3,
|
(bool ok, string result) =>
|
{
|
DebugEx.Log(result);
|
if (ok)
|
{
|
var response = LitJson.JsonMapper.ToObject<VerifyResponse>(result);
|
if (response != null)
|
{
|
if (response.result.Equals("success"))
|
{
|
if (callback != null)
|
{
|
callback(true, verifyName);
|
callback = null;
|
return;
|
}
|
}
|
}
|
}
|
NetLinkWin.Hide();
|
});
|
}
|
|
const string VerifyFairyUrl = "https://api.maoergame.com/game/sociaty/response";
|
public void VerifyFairy(string verifyContent, int op_type, string fairyName, int title, Action<bool, string> callback)
|
{
|
if (!requireVerify)
|
{
|
if (callback != null)
|
{
|
callback(true, verifyContent);
|
callback = null;
|
}
|
return;
|
}
|
|
var account = ModelCenter.Instance.GetModel<LoginModel>().sdkLoginResult.account;
|
var playerId = PlayerDatas.Instance.baseData.PlayerID;
|
var playerName = UIHelper.ServerStringTrim(PlayerDatas.Instance.baseData.PlayerName);
|
|
var tables = new Dictionary<string, string>();
|
tables["game_code"] = "snxxz";
|
tables["server_id"] = ServerListCenter.Instance.currentServer.region_flag.ToString();
|
tables["server_name"] = StringUtility.Contact("s", ServerListCenter.Instance.currentServer.region_flag);
|
tables["op_type"] = op_type.ToString();
|
tables["name"] = op_type == 1 ? fairyName : verifyContent;
|
|
tables["leader_uid"] = title == 3 ? account : string.Empty;
|
tables["leader_rid"] = title == 3 ? playerId.ToString() : string.Empty;
|
tables["leader_name"] = title == 3 ? playerName : string.Empty;
|
|
tables["vice_leader_uid"] = title == 2 ? account : string.Empty;
|
tables["vice_leader_rid"] = title == 2 ? playerId.ToString() : string.Empty;
|
tables["vice_leader_name"] = title == 2 ? playerName : string.Empty;
|
|
tables["edit_uid"] = account;
|
tables["edit_rid"] = playerId.ToString();
|
tables["edit_name"] = playerName;
|
|
tables["notice"] = op_type == 2 ? string.Empty : verifyContent;
|
var ts = System.DateTime.UtcNow - new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
|
tables["timestamp"] = ((long)System.Convert.ToInt64(ts.TotalSeconds)).ToString();
|
tables["key"] = FileExtersion.GetStringMD5Hash(StringUtility.Contact(Sercret, tables["timestamp"]));
|
|
HttpRequest.Instance.RequestHttpPost(VerifyFairyUrl, tables, HttpRequest.defaultHttpContentType, 3,
|
(bool ok, string result) =>
|
{
|
DebugEx.Log(result);
|
if (ok)
|
{
|
var response = LitJson.JsonMapper.ToObject<VerifyResponse>(result);
|
if (response != null)
|
{
|
if (response.result.Equals("success"))
|
{
|
if (callback != null)
|
{
|
callback(true, response.content);
|
callback = null;
|
return;
|
}
|
}
|
}
|
}
|
});
|
}
|
|
public static uint toPlayer = 0;
|
public static string toPlayerName = string.Empty;
|
public static int toPlayerLevel = 0;
|
const string VerifyChatUrl = "https://api.maoergame.com/game/chat/response";
|
public void VerifyChat(string content, ChatInfoType channelType, Action<bool, string> callback)
|
{
|
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)
|
|| chatCenter.IsClientBan(channelType))
|
{
|
if (callback != null)
|
{
|
callback(true, content);
|
callback = null;
|
}
|
return;
|
}
|
|
var sdkLoginResult = ModelCenter.Instance.GetModel<LoginModel>().sdkLoginResult;
|
var account = sdkLoginResult == null ? string.Empty : sdkLoginResult.account;
|
var playerId = PlayerDatas.Instance.baseData.PlayerID;
|
var playerName = PlayerDatas.Instance.baseData.PlayerName;
|
var ts = System.DateTime.UtcNow - new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
|
|
var tables = new Dictionary<string, string>();
|
tables["game_code"] = "snxxz";
|
tables["server_id"] = ServerListCenter.Instance.currentServer.region_flag.ToString();
|
tables["server_name"] = StringUtility.Contact("s", ServerListCenter.Instance.currentServer.region_flag);
|
tables["chat_type"] = 1.ToString();
|
tables["chat_channel"] = channel.ToString();
|
tables["chat_content"] = TransferContent(ts.Ticks, content);
|
tables["sender_uid"] = account;
|
tables["sender_rid"] = playerId.ToString();
|
tables["sender_name"] = UIHelper.ServerStringTrim(playerName);
|
tables["sender_level"] = PlayerDatas.Instance.baseData.PlayerID.ToString();
|
tables["sender_vip_level"] = PlayerDatas.Instance.baseData.VIPLv.ToString();
|
|
tables["receiver_uid"] = string.Empty;
|
tables["receiver_rid"] = channel == 3 ? toPlayer.ToString() : string.Empty;
|
tables["receiver_name"] = channel == 3 ? UIHelper.ServerStringTrim(toPlayerName) : string.Empty;
|
tables["receiver_level"] = channel == 3 ? (toPlayerLevel == 0 ? string.Empty : toPlayerLevel.ToString()) : string.Empty;
|
tables["receiver_vip_level"] = string.Empty;
|
|
tables["timestamp"] = ((long)System.Convert.ToInt64(ts.TotalSeconds)).ToString();
|
tables["key"] = FileExtersion.GetStringMD5Hash(StringUtility.Contact(Sercret, tables["timestamp"]));
|
|
HttpRequest.Instance.RequestHttpPost(VerifyChatUrl, tables, HttpRequest.defaultHttpContentType, 3,
|
(bool ok, string result) =>
|
{
|
DebugEx.Log(result);
|
if (ok)
|
{
|
var response = LitJson.JsonMapper.ToObject<VerifyResponse>(result);
|
if (response != null)
|
{
|
if (response.result.Equals("success"))
|
{
|
if (callback != null)
|
{
|
callback(true, DisTransfer(ts.Ticks, response.content));
|
callback = null;
|
return;
|
}
|
}
|
else if (response.result.Equals("verify_fail"))
|
{
|
switch (response.code)
|
{
|
case -1:
|
ServerTipDetails.DisplayNormalTip(Language.Get("L1007"));
|
break;
|
case -2:
|
SysNotifyMgr.Instance.ShowTip("VerifyErrorCode2");
|
break;
|
case -3:
|
break;
|
}
|
}
|
}
|
}
|
});
|
}
|
|
Dictionary<long, List<string>> transferContents = new Dictionary<long, List<string>>();
|
Dictionary<long, List<int>> splitContents = new Dictionary<long, List<int>>();
|
|
List<MatchString> matchs = new List<MatchString>();
|
|
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<string> list;
|
List<int> splits;
|
if (!transferContents.TryGetValue(tick, out list))
|
{
|
list = new List<string>();
|
transferContents.Add(tick, list);
|
}
|
if (!splitContents.TryGetValue(tick, out splits))
|
{
|
splits = new List<int>();
|
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<string> list;
|
if (!transferContents.TryGetValue(tick, out list))
|
{
|
return content;
|
}
|
List<int> 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:
|
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<DailyQuestModel>();
|
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;
|
}
|
}
|