C2G_LoginGateHandler.cs 1.1 KB

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