ActorLocationSenderComponentSystem.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Collections.Generic;
  2. using ETModel;
  3. namespace ETHotfix
  4. {
  5. [ObjectSystem]
  6. public class ActorLocationSenderComponentSystem : StartSystem<ActorLocationSenderComponent>
  7. {
  8. public override void Start(ActorLocationSenderComponent self)
  9. {
  10. StartAsync(self).Coroutine();
  11. }
  12. // 每10s扫描一次过期的actorproxy进行回收,过期时间是1分钟
  13. // 可能由于bug或者进程挂掉,导致ActorLocationSender发送的消息没有确认,结果无法自动删除,每一分钟清理一次这种ActorLocationSender
  14. public async ETVoid StartAsync(ActorLocationSenderComponent self)
  15. {
  16. List<long> timeoutActorProxyIds = new List<long>();
  17. while (true)
  18. {
  19. await Game.Scene.GetComponent<TimerComponent>().WaitAsync(10000);
  20. if (self.IsDisposed)
  21. {
  22. return;
  23. }
  24. timeoutActorProxyIds.Clear();
  25. long timeNow = TimeHelper.Now();
  26. foreach (long id in self.ActorLocationSenders.Keys)
  27. {
  28. ActorLocationSender actorLocationMessageSender = self.ActorLocationSenders[id];
  29. if (actorLocationMessageSender == null)
  30. {
  31. continue;
  32. }
  33. if (timeNow < actorLocationMessageSender.LastRecvTime + 60 * 1000)
  34. {
  35. continue;
  36. }
  37. timeoutActorProxyIds.Add(id);
  38. }
  39. foreach (long id in timeoutActorProxyIds)
  40. {
  41. self.Remove(id);
  42. }
  43. }
  44. }
  45. }
  46. }