C2R_LoginHandler.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Net;
  3. using ETModel;
  4. namespace ETHotfix
  5. {
  6. [MessageHandler(AppType.Realm)]
  7. public class C2R_LoginHandler : AMRpcHandler<C2R_Login, R2C_Login>
  8. {
  9. protected override void Run(Session session, C2R_Login message, Action<R2C_Login> reply)
  10. {
  11. RunAsync(session, message, reply).NoAwait();
  12. }
  13. private async ETVoid RunAsync(Session session, C2R_Login message, Action<R2C_Login> reply)
  14. {
  15. R2C_Login response = new R2C_Login();
  16. try
  17. {
  18. //if (message.Account != "abcdef" || message.Password != "111111")
  19. //{
  20. // response.Error = ErrorCode.ERR_AccountOrPasswordError;
  21. // reply(response);
  22. // return;
  23. //}
  24. // 随机分配一个Gate
  25. StartConfig config = Game.Scene.GetComponent<RealmGateAddressComponent>().GetAddress();
  26. //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
  27. IPEndPoint innerAddress = config.GetComponent<InnerConfig>().IPEndPoint;
  28. Session gateSession = Game.Scene.GetComponent<NetInnerComponent>().Get(innerAddress);
  29. // 向gate请求一个key,客户端可以拿着这个key连接gate
  30. G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey() {Account = message.Account});
  31. string outerAddress = config.GetComponent<OuterConfig>().Address2;
  32. response.Address = outerAddress;
  33. response.Key = g2RGetLoginKey.Key;
  34. reply(response);
  35. }
  36. catch (Exception e)
  37. {
  38. ReplyError(response, e, reply);
  39. }
  40. }
  41. }
  42. }