88 lines
2.4 KiB
C#
88 lines
2.4 KiB
C#
using Fantasy;
|
||
using Fantasy.Async;
|
||
using Fantasy.Network;
|
||
using NB.Chat;
|
||
using NB.Game;
|
||
|
||
namespace NB.Gate;
|
||
|
||
public static class GateLoginHelper
|
||
{
|
||
#region 上线
|
||
|
||
/// <summary>
|
||
/// 网关通知其他服务器上线
|
||
/// </summary>
|
||
/// <param name="gateUnit"></param>
|
||
public static async FTask<uint> Online(GateUnit gateUnit)
|
||
{
|
||
if (gateUnit == null)
|
||
{
|
||
return ErrorCode.ErrArgs;
|
||
}
|
||
|
||
Session session = gateUnit.Session;
|
||
if (session == null)
|
||
{
|
||
return ErrorCode.ErrArgs;
|
||
}
|
||
|
||
var gateUnitSessionComponent = session.GetComponent<GateUnitSessionComponent>();
|
||
if (gateUnitSessionComponent == null)
|
||
{
|
||
gateUnitSessionComponent = session.AddComponent<GateUnitSessionComponent>();
|
||
}
|
||
|
||
var routeComponent = session.GetComponent<RouteComponent>();
|
||
if (routeComponent == null)
|
||
{
|
||
routeComponent = session.AddComponent<RouteComponent>();
|
||
}
|
||
|
||
gateUnitSessionComponent.AccountID = gateUnit.AccountID;
|
||
|
||
|
||
//安排游戏服务器,并通知进入
|
||
var (gameRouteId, roleSimpleInfo) =
|
||
await GameSceneHelper.Online(session.Scene, gateUnit.AccountID, session.RuntimeId);
|
||
if (gameRouteId <= 0 || roleSimpleInfo == null)
|
||
{
|
||
return ErrorCode.OnlineSceneFailed;
|
||
}
|
||
|
||
Log.Info($"连接游戏服成功,gameRouteId:{gameRouteId}");
|
||
routeComponent.AddAddress(RouteType.GameRoute, gameRouteId);
|
||
gateUnit.GameSceneRouteId = gameRouteId;
|
||
|
||
|
||
//安排进入的聊天服
|
||
var chatRouteId = await ChatSceneHelper.Online(session.Scene, roleSimpleInfo, session.RuntimeId);
|
||
if (chatRouteId <= 0)
|
||
{
|
||
return ErrorCode.OnlineSceneFailed;
|
||
}
|
||
|
||
routeComponent.AddAddress(RouteType.ChatRoute, chatRouteId);
|
||
gateUnit.ChatSceneRouteId = chatRouteId;
|
||
Log.Info($"连接聊天服成功,gameRouteId:{gameRouteId}");
|
||
return ErrorCode.Successful;
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 下线
|
||
|
||
/// <summary>
|
||
/// 网关通知其他服务器下线
|
||
/// </summary>
|
||
/// <param name="self"></param>
|
||
/// <param name="gateUnit"></param>
|
||
public static async FTask<uint> Offline(GateUnit gateUnit)
|
||
{
|
||
await FTask.CompletedTask;
|
||
//通知服务器下线
|
||
return ErrorCode.Successful;
|
||
}
|
||
|
||
#endregion
|
||
} |