using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ET.Server
{
///
/// 登入游戏服.获取角色列表
///
[MessageHandler(SceneType.Game)]
public class C2G_LoginGameHandler : AMRpcHandler
{
protected override async ETTask Run(Session session, C2G_LoginGame request, G2C_LoginGame response, Action reply)
{
if (session.DomainScene().SceneType != SceneType.Game)
{
Log.Debug($"Game 请求的Scene错误...SceneType={session.DomainScene().SceneType}");
session.Dispose();
return;
}
// 判断参数
if (string.IsNullOrEmpty(request.Token.Trim()) || request.UserId <= 0)
{
Log.Debug($"Game token 登陆超时");
response.Error = ErrorCore.ERR_ConnectGateKeyError;
response.Message = "Game token 登陆超时";
reply();
session.Disconnect().Coroutine();
return;
}
// 移除session自动超时组件
session.RemoveComponent();
// 添加session组件,用于绑定角色
session.AddComponent();
session.GetComponent().UserId = request.UserId;
response.Players = new List();
// 获取角色列表
List list = await DBManagerComponent.Instance.GetZoneDB(session.DomainZone())
.Query(p => p.UserId == request.UserId);
if (list is { Count: > 0 })
{
foreach (PlayerInfo info in list.Where(playerInfo => playerInfo != null))
{
session.GetComponent().Add(info);
response.Players.Add(PlayerHelper.PlayerInfoToPlayerBasicProto(info));
}
}
reply();
}
}
}