C2R_LoginHandler.cs 1.4 KB

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