C2G_LoginGateHandler.cs 908 B

123456789101112131415161718192021222324252627282930
  1. using System;
  2. namespace ET
  3. {
  4. [MessageHandler]
  5. public class C2G_LoginGateHandler : AMRpcHandler<C2G_LoginGate, G2C_LoginGate>
  6. {
  7. protected override async ETTask Run(Session session, C2G_LoginGate request, G2C_LoginGate response, Action reply)
  8. {
  9. Scene scene = session.DomainScene();
  10. string account = scene.GetComponent<GateSessionKeyComponent>().Get(request.Key);
  11. if (account == null)
  12. {
  13. response.Error = ErrorCode.ERR_ConnectGateKeyError;
  14. response.Message = "Gate key验证失败!";
  15. reply();
  16. return;
  17. }
  18. Player player = EntityFactory.Create<Player, string>(Game.Scene, account);
  19. scene.GetComponent<PlayerComponent>().Add(player);
  20. session.AddComponent<SessionPlayerComponent>().Player = player;
  21. session.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GateSession);
  22. response.PlayerId = player.Id;
  23. reply();
  24. await ETTask.CompletedTask;
  25. }
  26. }
  27. }