InitSceneStartEvent_InitGame.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. Game.Scene.AddComponent<MessageDispatherComponent, AppType>(AppType.Client);
  15. ClientConfig clientConfig = Game.Scene.AddComponent<ClientConfigComponent>().Config.GetComponent<ClientConfig>();
  16. NetOuterComponent networkComponent = Game.Scene.AddComponent<NetOuterComponent>();
  17. using (Session session = networkComponent.Create(clientConfig.Address))
  18. {
  19. try
  20. {
  21. R2C_Login s2CLogin = await session.Call<C2R_Login, R2C_Login>(new C2R_Login { Account = "abcdef", Password = "111111" });
  22. networkComponent.Remove(session.Id);
  23. // 连接Gate
  24. using (Session gateSession = networkComponent.Create(s2CLogin.Address))
  25. {
  26. await gateSession.Call<C2G_LoginGate, G2C_LoginGate>(new C2G_LoginGate(s2CLogin.Key));
  27. }
  28. Log.Info("连接Gate验证成功!");
  29. }
  30. catch (RpcException e)
  31. {
  32. Log.Error(e.ToString());
  33. }
  34. catch (Exception e)
  35. {
  36. Log.Error(e.ToString());
  37. }
  38. }
  39. }
  40. }
  41. }