Files
Fishing2Server/Hotfix/Common/Handler/G2Common_EnterRequestHandler.cs
2026-03-05 15:03:45 +08:00

87 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 System;
using Fantasy;
using Fantasy.Async;
using Fantasy.Network.Interface;
using NB.Chat;
using NB.Game;
using NBF.Social;
namespace NB.Common;
public class G2Common_EnterRequestHandler : AddressRPC<Scene, G2Common_EnterRequest, G2Common_EnterResponse>
{
protected override async FTask Run(Scene scene, G2Common_EnterRequest request, G2Common_EnterResponse response,
Action reply)
{
response.RouteType = request.RouteType;
switch (scene.SceneType)
{
case SceneType.Game:
{
await RunGame(scene, request, response);
break;
}
case SceneType.Social:
{
await RunSocial(scene, request, response);
break;
}
// case SceneType.Map:
// {
// await RunMap(scene, request, response);
// break;
// }
}
await FTask.CompletedTask;
}
private async FTask RunGame(Scene scene, G2Common_EnterRequest request, G2Common_EnterResponse response)
{
// 在缓存中检查该账号是否存在
var gameAccountManageComponent = scene.GetComponent<PlayerManageComponent>();
var account = await gameAccountManageComponent.Online(request.AccountId, request.GateRouteId);
if (account == null)
{
response.ErrorCode = ErrorCode.ErrServer;
return;
}
response.UnitRouteId = account.RuntimeId;
Log.Info($"登录到游戏服成功id={response.UnitRouteId}");
}
private async FTask RunSocial(Scene scene, G2Common_EnterRequest request, G2Common_EnterResponse response)
{
// 在缓存中检查该账号是否存在
var chatUnitManageComponent = scene.GetComponent<SocialUnitManageComponent>();
var account = await chatUnitManageComponent.Online(scene, request.AccountId, request.GateRouteId);
if (account == null)
{
response.ErrorCode = ErrorCode.ErrServer;
return;
}
response.UnitRouteId = account.RuntimeId;
Log.Info($"登录到社交服成功id={response.UnitRouteId}");
}
// private async FTask RunMap(Scene scene, G2Common_EnterRequest request, G2Common_EnterResponse response)
// {
// // 在缓存中检查该账号是否存在
// var chatUnitManageComponent = scene.GetComponent<MapUnitManageComponent>();
// var account = await chatUnitManageComponent.Online(scene, request.AccountId, request.GateRouteId);
//
// if (account == null)
// {
// response.ErrorCode = ErrorCode.ErrServer;
// return;
// }
//
// response.UnitRouteId = account.RuntimeId;
// Log.Info($"登录到地图服成功id={response.UnitRouteId}");
// }
}