-
Notifications
You must be signed in to change notification settings - Fork 29
Description
客户端的请求登录逻辑:
var reqLogin = new ReqLogin
{
Account = m_BotName,
Password = "12312",
DeviceInfo = "BotDevice",
Platform = LoginPlatform.Custom,
PlatformLoginMethod = LoginVerificationMethod.Password
};
string respLoginUrl = $"{m_LoginUrl}{nameof(ReqLogin)}";
var respLogin = await m_HttpClient.Post<RespLogin>(respLoginUrl, reqLogin);
if (respLogin.ErrorCode != 0)
{
LogHelper.Error("请求登录验证,错误信息:" + respLogin.ErrorCode);
return;
}
服务器处理逻辑:
private async Task OnLogin(ReqLogin reqLogin)
{
MetricsAccountRegister.LoginCounterOptions.Inc();
if (reqLogin.Platform == LoginPlatform.Custom &&
reqLogin.PlatformLoginMethod == LoginVerificationMethod.Password)
{
return await GameDb.FindAsync<LoginState>(m => m.PlatformList != null && m.PlatformList.Count > 0 &&
m.PlatformList.Any(p =>
p.Platform == reqLogin.Platform &&
p.PlatformLoginMethod ==
LoginVerificationMethod.Password &&
p.PlatformAccount == reqLogin.Account &&
p.PlatformPassword == reqLogin.Password));
}
if (reqLogin.PlatformLoginMethod == LoginVerificationMethod.OAuth)
{
return await GameDb.FindAsync<LoginState>(m => m.PlatformList != null && m.PlatformList.Count > 0 &&
m.PlatformList.Any(p =>
p.Platform == reqLogin.Platform &&
p.PlatformLoginMethod ==
LoginVerificationMethod.OAuth &&
p.PlatformOAuth == reqLogin.PlatformOAuth));
}
return null!;
}
LoginState的数据结构:
namespace GameFrameX.Apps.Account.Login.Entity;
public class LoginState : CacheState
{
///
/// 账号状态(例如:活跃、禁用等)
///
public int State { get; set; }
/// <summary>
/// 玩家在不同平台上的登录信息
/// </summary>
public List<PlatformLoginInfo> PlatformList { get; set; } = [];
}
///
/// 用于存储各平台的登录信息
///
public class PlatformLoginInfo
{
///
/// 平台名称(例如 "Facebook", "Google", "QQ" 等)
///
public string Platform { get; set; }
/// <summary>
/// 平台账号
/// </summary>
public string PlatformAccount { get; set; }
/// <summary>
/// 平台密码
/// </summary>
public string PlatformPassword { get; set; }
/// <summary>
/// 平台账号的唯一标识(例如 Facebook 的用户 ID,QQ 的QQ号等)
/// </summary>
public string PlatformOAuth { get; set; }
/// <summary>
/// 登录方式(如 密码登录,OAuth 等)
/// </summary>
public string PlatformLoginMethod { get; set; }
/// <summary>
/// 平台用户的昵称(可选,某些平台可能有)
/// </summary>
public string PlatformNickName { get; set; }
}
服务器异常报错:
ERR] [HTTPServer] TraceIdentifier:[0HN9OHLILRND5:00000001], 来源[::ffff:127.0.0.1], url:[/game/api/ReqLogin], 发生异常. Property 'System.String Platform' is not defined for type 'GameFrameX.Apps.Account.Login.Entity.LoginState' (Parameter 'property') at System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property)
at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node)
at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression1 node) at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes) at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node) at System.Linq.Expressions.ExpressionVisitor.VisitBinary(BinaryExpression node) at GameFrameX.Extension.ExpressionExtension.And[T](Expression1 leftExpression, Expression1 rightExpression) at GameFrameX.DataBase.Mongo.MongoDbService.GetDefaultFindExpression[TState](Expression1 filter)
at GameFrameX.DataBase.Mongo.MongoDbService.FindAsync[TState](Expression1 filter) at GameFrameX.Hotfix.Logic.Http.ReqLoginHttpHandler.OnLogin(ReqLogin reqLogin) in /Users/blizzardactivision/StarryGame/UnityProject/Elysium/Server/GameFrameX.Hotfix/Logic/Http/ReqLoginHttpHandler.cs:line 58 at GameFrameX.Hotfix.Logic.Http.ReqLoginHttpHandler.Action(String ip, String url, Dictionary2 parameters, MessageObject messageObject) in /Users/blizzardactivision/StarryGame/UnityProject/Elysium/Server/GameFrameX.Hotfix/Logic/Http/ReqLoginHttpHandler.cs:line 30
at GameFrameX.NetWork.HTTP.HttpHandler.HandleRequest(HttpContext context, Func2 baseHandler, List1 aopHandlerTypes)
at GameFrameX.NetWork.HTTP.HttpHandler.HandleRequest(HttpContext context, Func2 baseHandler, List1 aopHandlerTypes)
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine)
at GameFrameX.NetWork.HTTP.HttpHandler.HandleRequest(HttpContext context, Func2 baseHandler, List1 aopHandlerTypes)
at GameFrameX.NetWork.HTTP.HttpServer.<>c__DisplayClass9_0.b__3(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.Invoke(HttpContext context)
at Microsoft.AspNetCore.HostFiltering.HostFilteringMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication1 application)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsAsync[TContext](IHttpApplication1 application) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsAsync[TContext](IHttpApplication1 application)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.HttpConnection.ProcessRequestsAsync[TContext](IHttpApplication1 httpApplication) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.HttpConnection.ProcessRequestsAsync[TContext](IHttpApplication1 httpApplication)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelConnection1.ExecuteAsync() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelConnection1.ExecuteAsync()
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Infrastructure.KestrelConnection`1.System.Threading.IThreadPoolWorkItem.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
at System.Threading.Thread.StartCallback()