广播聊天
This commit is contained in:
76
Hotfix/Gate/Handler/Outer/C2G_LoginRequestHandler.cs
Normal file
76
Hotfix/Gate/Handler/Outer/C2G_LoginRequestHandler.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user