C2G_LoginGateHandler.cs 1.0 KB

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