1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- namespace ET.Server
- {
- /// <summary>
- /// 登入游戏服.获取角色列表
- /// </summary>
- [MessageHandler(SceneType.Game)]
- public class C2G_LoginGameHandler : AMRpcHandler<C2G_LoginGame, G2C_LoginGame>
- {
- 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<SessionAcceptTimeoutComponent>();
- // 添加session组件,用于绑定角色
- session.AddComponent<SessionPlayerComponent>().UserId = request.UserId;
- session.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GateSession);
- response.Players = new List<PlayerBasic>();
- // 获取角色列表
- List<PlayerInfo> list = await DBManagerComponent.Instance.GetZoneDB(session.DomainZone())
- .Query<PlayerInfo>(p => p.UserId == request.UserId);
- if (list is { Count: > 0 })
- {
- foreach (PlayerInfo info in list.Where(playerInfo => playerInfo != null))
- {
- session.GetComponent<SessionPlayerComponent>().Add(info);
- response.Players.Add(PlayerHelper.PlayerInfoToPlayerBasicProto(info));
- }
- }
- reply();
- }
- }
- }
|