C2R_LoginHandler.cs 1.3 KB

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