C2R_LoginHandler.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using Base;
  3. using Model;
  4. namespace Controller
  5. {
  6. [MessageHandler(AppType.Realm)]
  7. public class C2R_LoginHandler: AMRpcEvent<C2R_Login, R2C_Login>
  8. {
  9. protected override async void Run(Session session, C2R_Login message, Action<R2C_Login> reply)
  10. {
  11. R2C_Login r2CLogin;
  12. if (message.Account != "abcdef" || message.Password != "111111")
  13. {
  14. r2CLogin = new R2C_Login {Error = ErrorCode.ERR_AccountOrPasswordError, Message = "账号名或者密码错误!"};
  15. reply(r2CLogin);
  16. return;
  17. }
  18. // 随机分配一个Gate
  19. Entity config = Game.Scene.GetComponent<RealmGateAddressComponent>().GetAddress();
  20. Log.Info($"gate address: {MongoHelper.ToJson(config)}");
  21. string innerAddress = $"{config.GetComponent<InnerConfig>().Host}:{config.GetComponent<InnerConfig>().Port}";
  22. Session gateSession = Game.Scene.GetComponent<NetInnerComponent>().Get(innerAddress);
  23. // 向gate请求一个key,客户端可以拿着这个key连接gate
  24. G2R_GetLoginKey g2RGetLoginKey = await gateSession.Call<R2G_GetLoginKey, G2R_GetLoginKey>(new R2G_GetLoginKey());
  25. string outerAddress = $"{config.GetComponent<OuterConfig>().Host}:{config.GetComponent<OuterConfig>().Port}";
  26. r2CLogin = new R2C_Login {Address = outerAddress, Key = g2RGetLoginKey.Key};
  27. reply(r2CLogin);
  28. }
  29. }
  30. }