C2R_PingHandler.cs 731 B

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using ETModel;
  3. namespace ETHotfix
  4. {
  5. [MessageHandler(AppType.AllServer)]
  6. public class C2R_PingHandler : AMRpcHandler<C2R_Ping, R2C_Ping>
  7. {
  8. private bool isStart = false;
  9. protected override void Run(Session session, C2R_Ping message, Action<R2C_Ping> reply)
  10. {
  11. R2C_Ping r2CPing = new R2C_Ping();
  12. reply(r2CPing);
  13. if (!this.isStart)
  14. {
  15. isStart = true;
  16. Start(session);
  17. }
  18. }
  19. public async void Start(Session session)
  20. {
  21. TimerComponent timerComponent = Game.Scene.GetComponent<TimerComponent>();
  22. G2C_Test g2CTest = new G2C_Test();
  23. while (true)
  24. {
  25. await timerComponent.WaitAsync(1);
  26. for (int i = 0; i < 20; ++i)
  27. {
  28. session.Send(g2CTest);
  29. }
  30. }
  31. }
  32. }
  33. }