You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
3.4 KiB
102 lines
3.4 KiB
1 month ago
|
using System;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
using Sog;
|
||
|
|
||
|
namespace Account
|
||
|
{
|
||
|
public static class DeviceIdLimitSvc
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 是否被限制登录(同设备id相同时间内登录帐号数量限制)
|
||
|
/// </summary>
|
||
|
/// <param name="accountType"></param>
|
||
|
/// <param name="accountId"></param>
|
||
|
/// <param name="deviceId"></param>
|
||
|
/// <returns></returns>
|
||
|
public static bool CheckDeviceIdLimited(int accountType,string accountId, string deviceId)
|
||
|
{
|
||
|
int countLimit = AccountServerUtils.GetServerConfig().deviceIdFBAccountLimit;
|
||
|
int timeLimit = AccountServerUtils.GetServerConfig().deviceIdFBAccountLimitTime;
|
||
|
//配置了关闭限制功能
|
||
|
if (countLimit <= 0
|
||
|
|| timeLimit <= 0)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
//游客不做限制
|
||
|
if(accountType == (int)AccountType.AccountType_Guest)
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
if(string.IsNullOrEmpty(deviceId))
|
||
|
{
|
||
|
TraceLog.Error("DeviceIdLimitSvc.CheckDeviceIdLimited id {0} invalid deviceId", accountId);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
long now = AccountServerUtils.GetTimeSecond();
|
||
|
var deviceIdMap = AccountServerUtils.GetAccountServerData().m_devicdIdMap;
|
||
|
List<DevicdIDFBAccountInfo> list;
|
||
|
if (deviceIdMap.ContainsKey(deviceId) == false)
|
||
|
{
|
||
|
list = new List<DevicdIDFBAccountInfo>();
|
||
|
DevicdIDFBAccountInfo info = new DevicdIDFBAccountInfo();
|
||
|
info.AccountID = accountId;
|
||
|
info.LastLoginTime = now;
|
||
|
list.Add(info);
|
||
|
|
||
|
deviceIdMap.Add(deviceId, list);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
list = deviceIdMap[deviceId];
|
||
|
}
|
||
|
|
||
|
foreach(var info in list)
|
||
|
{
|
||
|
//旧有的account,允许登录
|
||
|
if(info.AccountID == accountId)
|
||
|
{
|
||
|
info.LastLoginTime = now;
|
||
|
TraceLog.Trace("DeviceIdLimitSvc.CheckDeviceIdLimited id {0} already in list,can login", accountId);
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
//删除过期的帐号记录
|
||
|
for(int i = list.Count - 1; i >= 0; i--)
|
||
|
{
|
||
|
var info = list[i];
|
||
|
if (now - info.LastLoginTime >= timeLimit)
|
||
|
{
|
||
|
TraceLog.Trace("DeviceIdLimitSvc.CheckDeviceIdLimited delete timeout accountId {0}", info.AccountID);
|
||
|
list.RemoveAt(i);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//允许登录,添加帐号信息
|
||
|
if (list.Count < countLimit)
|
||
|
{
|
||
|
DevicdIDFBAccountInfo info = new DevicdIDFBAccountInfo();
|
||
|
info.AccountID = accountId;
|
||
|
info.LastLoginTime = now;
|
||
|
list.Add(info);
|
||
|
|
||
|
TraceLog.Trace("DeviceIdLimitSvc.CheckDeviceIdLimited id {0} add to list,can login", accountId);
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
TraceLog.Error("DeviceIdLimitSvc.CheckDeviceIdLimited id {0} be limited by deviceid {1}", accountId,deviceId);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
}
|