C2R_LoginHandler.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 async void Run(Session session, C2R_Login message, Action<R2C_Login> reply)
  11. {
  12. R2C_Login response = new R2C_Login();
  13. try
  14. {
  15. //if (message.Account != "abcdef" || message.Password != "111111")
  16. //{
  17. // response.Error = ErrorCode.ERR_AccountOrPasswordError;
  18. // reply(response);
  19. // return;
  20. //}
  21. // 随机分配一个Gate
  22. StartConfig config = Game.Scene.GetComponent<RealmGateAddressComponent>().GetAddress();
  23. //Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
  24. IPEndPoint innerAddress = config.GetComponent<InnerConfig>().IPEndPoint;
  25. Session gateSession = Game.Scene.GetComponent<NetInnerComponent>().Get(innerAddress);
  26. // 向gate请求一个key,客户端可以拿着这个key连接gate
  27. G2R_GetLoginKey g2RGetLoginKey = (G2R_GetLoginKey)await gateSession.Call(new R2G_GetLoginKey() {Account = message.Account});
  28. string outerAddress = config.GetComponent<OuterConfig>().Address2;
  29. response.Address = outerAddress;
  30. response.Key = g2RGetLoginKey.Key;
  31. reply(response);
  32. }
  33. catch (Exception e)
  34. {
  35. ReplyError(response, e, reply);
  36. }
  37. }
  38. }
  39. }