NetKcpComponentSystem.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // using System;
  2. // using System.IO;
  3. // using System.Net;
  4. //
  5. // namespace ET
  6. // {
  7. // [ObjectSystem]
  8. // public class NetKcpComponentAwakeSystem: AwakeSystem<NetKcpComponent, int>
  9. // {
  10. // public override void Awake(NetKcpComponent self, int sessionStreamDispatcherType)
  11. // {
  12. // self.SessionStreamDispatcherType = sessionStreamDispatcherType;
  13. //
  14. // self.Service = new TService(NetThreadComponent.Instance.ThreadSynchronizationContext, ServiceType.Outer);
  15. // self.Service.ErrorCallback += (channelId, error) => self.OnError(channelId, error);
  16. // self.Service.ReadCallback += (channelId, Memory) => self.OnRead(channelId, Memory);
  17. //
  18. // NetThreadComponent.Instance.Add(self.Service);
  19. // }
  20. // }
  21. //
  22. // [ObjectSystem]
  23. // public class NetKcpComponentAwake1System: AwakeSystem<NetKcpComponent, IPEndPoint, int>
  24. // {
  25. // public override void Awake(NetKcpComponent self, IPEndPoint address, int sessionStreamDispatcherType)
  26. // {
  27. // self.SessionStreamDispatcherType = sessionStreamDispatcherType;
  28. //
  29. // self.Service = new TService(NetThreadComponent.Instance.ThreadSynchronizationContext, address, ServiceType.Outer);
  30. // self.Service.ErrorCallback += (channelId, error) => self.OnError(channelId, error);
  31. // self.Service.ReadCallback += (channelId, Memory) => self.OnRead(channelId, Memory);
  32. // self.Service.AcceptCallback += (channelId, IPAddress) => self.OnAccept(channelId, IPAddress);
  33. //
  34. // NetThreadComponent.Instance.Add(self.Service);
  35. // }
  36. // }
  37. //
  38. // [ObjectSystem]
  39. // public class NetKcpComponentDestroySystem: DestroySystem<NetKcpComponent>
  40. // {
  41. // public override void Destroy(NetKcpComponent self)
  42. // {
  43. // NetThreadComponent.Instance.Remove(self.Service);
  44. // self.Service.Destroy();
  45. // }
  46. // }
  47. //
  48. // public static class NetKcpComponentSystem
  49. // {
  50. // public static void OnRead(this NetKcpComponent self, long channelId, MemoryStream memoryStream)
  51. // {
  52. // Session session = self.GetChild<Session>(channelId);
  53. // if (session == null)
  54. // {
  55. // return;
  56. // }
  57. //
  58. // session.LastRecvTime = TimeHelper.ClientNow();
  59. // SessionStreamDispatcher.Instance.Dispatch(self.SessionStreamDispatcherType, session, memoryStream);
  60. // }
  61. //
  62. // public static void OnError(this NetKcpComponent self, long channelId, int error)
  63. // {
  64. // Session session = self.GetChild<Session>(channelId);
  65. // if (session == null)
  66. // {
  67. // return;
  68. // }
  69. //
  70. // session.Error = error;
  71. // session.Dispose();
  72. // }
  73. //
  74. // // 这个channelId是由CreateAcceptChannelId生成的
  75. // public static void OnAccept(this NetKcpComponent self, long channelId, IPEndPoint ipEndPoint)
  76. // {
  77. // Session session = self.AddChildWithId<Session, AService>(channelId, self.Service);
  78. // session.RemoteAddress = ipEndPoint;
  79. //
  80. // // 挂上这个组件,5秒就会删除session,所以客户端验证完成要删除这个组件。该组件的作用就是防止外挂一直连接不发消息也不进行权限验证
  81. // session.AddComponent<SessionAcceptTimeoutComponent>();
  82. // // 客户端连接,2秒检查一次recv消息,10秒没有消息则断开
  83. // session.AddComponent<SessionIdleCheckerComponent, int>(NetThreadComponent.checkInteral);
  84. // }
  85. //
  86. // public static Session Get(this NetKcpComponent self, long id)
  87. // {
  88. // Session session = self.GetChild<Session>(id);
  89. // return session;
  90. // }
  91. //
  92. // public static Session Create(this NetKcpComponent self, IPEndPoint realIPEndPoint)
  93. // {
  94. // long channelId = RandomHelper.RandInt64();
  95. // Session session = self.AddChildWithId<Session, AService>(channelId, self.Service);
  96. // session.RemoteAddress = realIPEndPoint;
  97. // session.AddComponent<SessionIdleCheckerComponent, int>(NetThreadComponent.checkInteral);
  98. //
  99. // self.Service.GetOrCreate(session.Id, realIPEndPoint);
  100. //
  101. // return session;
  102. // }
  103. // }
  104. // }