C2R_LoginHandler.cs 1.5 KB

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