63 lines
2.4 KiB
C#
63 lines
2.4 KiB
C#
using Fantasy;
|
||
using Fantasy.Async;
|
||
using Fantasy.Network;
|
||
using Fantasy.Platform.Net;
|
||
|
||
namespace Hotfix;
|
||
|
||
public static class GateLoginHelper
|
||
{
|
||
private static List<Func<Scene, GameAccount, long, FTask<(uint error, long chatRouteId,int routeType)>>> scenes =
|
||
new List<Func<Scene, GameAccount, long, FTask<(uint error, long chatUnitId,int routeType)>>>()
|
||
{
|
||
OnlineChat
|
||
};
|
||
|
||
/// <summary>
|
||
/// 上线
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="account"></param>
|
||
/// <param name="gateRouteId"></param>
|
||
public static async FTask Online(Session session, GameAccount account,long gateRouteId)
|
||
{
|
||
foreach (var scene in scenes)
|
||
{
|
||
var result = await scene(session.Scene, account, gateRouteId);
|
||
if (result.error != GameErrorCode.Success) return;
|
||
var routeComponent = session.GetOrAddComponent<RouteComponent>();
|
||
routeComponent.AddAddress(result.routeType,result.chatRouteId);
|
||
account.Routes[result.routeType] = result.chatRouteId;
|
||
}
|
||
}
|
||
|
||
public static async FTask<uint> Offline(GameAccount account)
|
||
{
|
||
var netComponent = account.Scene.NetworkMessagingComponent;
|
||
foreach (var (routeType,routeId) in account.Routes)
|
||
{
|
||
switch (routeType)
|
||
{
|
||
case RouteType.ChatRoute:
|
||
var response = await netComponent.CallInnerRoute(routeId, new G2Chat_OfflineRequest());
|
||
if (response.ErrorCode != GameErrorCode.Success) return response.ErrorCode;
|
||
Log.Debug($"Gate : chat聊天服务器下线成功");
|
||
break;
|
||
}
|
||
}
|
||
account.Routes.Clear();
|
||
return GameErrorCode.Success;
|
||
}
|
||
|
||
public static async FTask<(uint error, long chatRouteId, int routeType)> OnlineChat(Scene scene, GameAccount account,long gateRouteId)
|
||
{
|
||
var chat = SceneConfigData.Instance.GetSceneBySceneType(scene.World.Id, SceneType.Chat)[0];
|
||
var response = (Chat2G_LoginResponse)await scene.NetworkMessagingComponent.CallInnerRoute(chat.RouteId, new G2Chat_LoginRequest()
|
||
{
|
||
GameName = account.GameName,
|
||
AccountId = account.Id,
|
||
GateRoutedId = gateRouteId,
|
||
});
|
||
return (response.ErrorCode, response.ChatRouteId,RouteType.ChatRoute);
|
||
}
|
||
} |