LoginHelper.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. namespace ET.Client
  3. {
  4. public static class LoginHelper
  5. {
  6. public static async ETTask Login(Scene zoneScene, string address, string account, string password)
  7. {
  8. try
  9. {
  10. // 创建一个ETModel层的Session
  11. R2C_Login r2CLogin;
  12. Session session = null;
  13. try
  14. {
  15. session = zoneScene.GetComponent<NetKcpComponent>().Create(NetworkHelper.ToIPEndPoint(address));
  16. {
  17. r2CLogin = (R2C_Login) await session.Call(new C2R_Login() { Account = account, Password = password });
  18. }
  19. }
  20. finally
  21. {
  22. session?.Dispose();
  23. }
  24. // 创建一个gate Session,并且保存到SessionComponent中
  25. Session gateSession = zoneScene.GetComponent<NetKcpComponent>().Create(NetworkHelper.ToIPEndPoint(r2CLogin.Address));
  26. gateSession.AddComponent<PingComponent>();
  27. zoneScene.AddComponent<SessionComponent>().Session = gateSession;
  28. G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await gateSession.Call(
  29. new C2G_LoginGate() { Key = r2CLogin.Key, GateId = r2CLogin.GateId});
  30. Log.Debug("登陆gate成功!");
  31. await Game.EventSystem.PublishAsync(new EventType.LoginFinish() {ZoneScene = zoneScene});
  32. }
  33. catch (Exception e)
  34. {
  35. Log.Error(e);
  36. }
  37. }
  38. }
  39. }