using MongoDB.Driver; using System; using System.Collections.Generic; using System.IO; using System.Text; namespace ET { public static class AccountHelper { public static async ETTask GetFirbiddenIpCount(string ip) { List list = await DBComponent.Instance.QueryFilter(Builders.Filter.Eq(t => t.Ip, ip)); if (list == null || list.Count == 0) { return 0; } ForbiddenIP forbiddenIP = list[0]; return forbiddenIP.count; } public static string GetPlayerFormatName(this long id) { return $"【{UserComponent.Instance.Get(id)?.NickName}({id})】"; } } public sealed class SecurityUtil { public class SecurityData { public byte[] xorScale; } private static readonly byte[] xorScale; static SecurityUtil() { if (xorScale == null) { string path = Path.Combine(Environment.CurrentDirectory, "../Release/key"); string str = File.ReadAllText(path); SecurityData data = MongoHelper.FromJson(str); xorScale = data.xorScale; } } /// /// 对数组进行异或 /// /// /// public static byte[] Xor(byte[] buffer) { //------------------ //第3步:xor解密 //------------------ int iScaleLen = xorScale.Length; for (int i = 0; i < buffer.Length; i++) { buffer[i] = (byte)(buffer[i] ^ xorScale[i % iScaleLen]); } return buffer; } } }