Files
Fishing2Server/Hotfix/Gate/Handler/Outer/C2G_LoginRequestHandler.cs
2025-08-07 17:51:25 +08:00

76 lines
2.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Fantasy;
using Fantasy.Async;
using Fantasy.Network;
using Fantasy.Network.Interface;
using Fantasy.Platform.Net;
using NB.Game;
namespace NB.Gate.Handler;
public sealed class C2G_LoginRequestHandler : MessageRPC<C2G_LoginRequest, G2C_LoginResponse>
{
protected override async FTask Run(Session session, C2G_LoginRequest request, G2C_LoginResponse response,
Action reply)
{
if (string.IsNullOrEmpty(request.ToKen))
{
session.Dispose();
return;
}
var scene = session.Scene;
if (!GateJWTHelper.ValidateToken(scene, request.ToKen, out var accountId))
{
// 如果失败,表示肯定是恶意攻击、所以毫不犹疑,直接断开当前会话。
session.Dispose();
return;
}
// 在缓存中检查该账号是否存在
var gateUnitManageComponent = scene.GetComponent<GateUnitManageComponent>();
if (!gateUnitManageComponent.TryGet(accountId, out var gateUnit))
{
gateUnit = gateUnitManageComponent.Add(session, accountId);
}
if (gateUnit == null)
{
Log.Error("创建GateUnit失败");
session.Dispose();
return;
}
response.ErrorCode = await GateLoginHelper.Online(gateUnit);
Log.Debug($"当前的Gate服务器:{session.Scene.SceneConfigId} accountId:{accountId}");
// var gameSceneConfig = GameSceneHelper.GetSceneConfig(session);
//
// // 通过chatSceneConfig拿到这个Scene的RouteId
// var gameRouteId = gameSceneConfig.RouteId;
// //连接到游戏中心服
// var gameResponse = (Game2G_EnterResponse)await session.Scene.NetworkMessagingComponent.CallInnerRoute(
// gameRouteId, new G2Game_EnterRequest()
// {
// AccountId = accountId,
// GateRouteId = session.RuntimeId
// });
//
// if (gameResponse.ErrorCode != 0)
// {
// // 如果ErrorCode不是0表示请求的协议发生错误应该提示给客户端。
// response.ErrorCode = gameResponse.ErrorCode;
// return;
// }
//
// // 要实现Route协议的转发需要给Session添加一个RouteComponent这个非常重要。
// var routeComponent = session.AddComponent<RouteComponent>();
// routeComponent.AddAddress(RouteType.GameRoute, gameResponse.RoleRouteId);
//
// // 给当前Session添加一个组件当Session销毁的时候会销毁这个组件。
// var accountFlagComponent = session.AddComponent<SessionPlayerComponent>();
// accountFlagComponent.AccountID = accountId;
}
}