InitSceneStartEvent_InitGame.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using Base;
  3. using Model;
  4. namespace Controller
  5. {
  6. /// <summary>
  7. /// 初始化游戏
  8. /// </summary>
  9. [Event(EventIdType.InitSceneStart)]
  10. public class InitSceneStartEvent_InitGame: IEvent
  11. {
  12. public async void Run()
  13. {
  14. try
  15. {
  16. Game.Scene.AddComponent<MessageDispatherComponent, AppType>(AppType.Client);
  17. ClientConfig clientConfig = Game.Scene.AddComponent<ClientConfigComponent>().Config.GetComponent<ClientConfig>();
  18. NetOuterComponent networkComponent = Game.Scene.AddComponent<NetOuterComponent>();
  19. using (Session session = networkComponent.Create(clientConfig.Address))
  20. {
  21. try
  22. {
  23. R2C_Login s2CLogin = await session.Call<C2R_Login, R2C_Login>(new C2R_Login { Account = "abcdef", Password = "111111" });
  24. networkComponent.Remove(session.Id);
  25. // 连接Gate
  26. using (Session gateSession = networkComponent.Create(s2CLogin.Address))
  27. {
  28. await gateSession.Call<C2G_LoginGate, G2C_LoginGate>(new C2G_LoginGate(s2CLogin.Key));
  29. }
  30. Log.Info("连接Gate验证成功!");
  31. }
  32. catch (RpcException e)
  33. {
  34. Log.Error(e.ToString());
  35. }
  36. catch (Exception e)
  37. {
  38. Log.Error(e.ToString());
  39. }
  40. }
  41. }
  42. catch (Exception e)
  43. {
  44. Log.Error(e.ToString());
  45. }
  46. }
  47. }
  48. }