75 lines
2.1 KiB
C#
75 lines
2.1 KiB
C#
using Fantasy;
|
|
using Fantasy.Async;
|
|
using Fantasy.Network;
|
|
using NB.Game;
|
|
|
|
namespace NB.Gate;
|
|
|
|
public static class GateLoginHelper
|
|
{
|
|
/// <summary>
|
|
/// 网关通知其他服务器上线
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <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 gameSceneConfig = GameSceneHelper.GetSceneConfig(session);
|
|
var gameRouteId = gameSceneConfig.RouteId;
|
|
//连接到游戏中心服
|
|
var gameResponse = (Game2G_EnterResponse)await session.Scene.NetworkMessagingComponent.CallInnerRoute(
|
|
gameRouteId, new G2Game_EnterRequest()
|
|
{
|
|
AccountId = gateUnit.AccountID,
|
|
GateRouteId = session.RuntimeId
|
|
});
|
|
|
|
if (gameResponse.ErrorCode != 0)
|
|
{
|
|
return ErrorCode.OnlineSceneFailed;
|
|
}
|
|
|
|
routeComponent.AddAddress(RouteType.GameRoute, gameResponse.RoleRouteId);
|
|
gateUnit.GameSceneRouteId = gameRouteId;
|
|
|
|
|
|
return ErrorCode.Successful;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 网关通知其他服务器下线
|
|
/// </summary>
|
|
/// <param name="self"></param>
|
|
/// <param name="gateUnit"></param>
|
|
public static async FTask<uint> Offline(GateUnit gateUnit)
|
|
{
|
|
//通知服务器下线
|
|
return ErrorCode.Successful;
|
|
}
|
|
} |