namespace KMCCC.Authentication
{
#region
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
#endregion
///
/// 离线验证器
///
public class OfflineAuthenticator : IAuthenticator
{
///
/// 玩家的名字
///
public readonly string DisplayName;
///
/// 构造离线验证器
///
/// 玩家的名字
public OfflineAuthenticator(string displayName)
{
DisplayName = displayName;
}
///
/// 标注离线验证器
///
public string Type
{
get { return "KMCCC.Offline"; }
}
public AuthenticationInfo Do()
{
if (String.IsNullOrWhiteSpace(DisplayName))
{
return new AuthenticationInfo
{
Error = "DisplayName不符合规范"
};
}
if (DisplayName.Count(char.IsWhiteSpace) > 0)
{
return new AuthenticationInfo
{
Error = "DisplayName不符合规范"
};
}
return new AuthenticationInfo
{
AccessToken = null,
DisplayName = DisplayName,
UUID = null,
Properties = "{}",
UserType = "Mojang"
};
}
public Task DoAsync(CancellationToken token)
{
return Task.Factory.StartNew((Func)Do, token);
}
}
}