C2G_LoginGateHandler.cs 965 B

1234567891011121314151617181920212223242526272829303132333435
  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 = Game.Scene.Get(request.GateId);
  10. if (scene == null)
  11. {
  12. return;
  13. }
  14. string account = scene.GetComponent<GateSessionKeyComponent>().Get(request.Key);
  15. if (account == null)
  16. {
  17. response.Error = ErrorCode.ERR_ConnectGateKeyError;
  18. response.Message = "Gate key验证失败!";
  19. reply();
  20. return;
  21. }
  22. Player player = EntityFactory.Create<Player, string>(Game.Scene, account);
  23. scene.GetComponent<PlayerComponent>().Add(player);
  24. session.AddComponent<SessionPlayerComponent>().Player = player;
  25. session.AddComponent<MailBoxComponent, MailboxType>(MailboxType.GateSession);
  26. response.PlayerId = player.Id;
  27. reply();
  28. await ETTask.CompletedTask;
  29. }
  30. }
  31. }