Parcourir la source

去掉IMessageDispatcher接口,改成分发,去掉网络库对demo逻辑的依赖。这样在AddComponent NetInnerComponent NetOuterComponent的时候需要指定使用哪种分发逻辑,由自己在demo中实现相应的分发逻辑

tanghai il y a 4 ans
Parent
commit
51b2a11bfe
36 fichiers modifiés avec 325 ajouts et 207 suppressions
  1. 16 3
      Robot/Hotfix/Robot.Hotfix.csproj
  2. 9 1
      Robot/Model/Robot.Model.csproj
  3. 3 2
      Server/Hotfix/AppStart_Init.cs
  4. 2 2
      Server/Hotfix/Demo/Scene/SceneFactory.cs
  5. 0 0
      Server/Hotfix/Demo/Session/InnerMessageDispatcherHelper.cs
  6. 2 2
      Server/Hotfix/Demo/Session/SessionStreamDispatcherServerInner.cs
  7. 69 0
      Server/Hotfix/Demo/Session/SessionStreamDispatcherServerOuter.cs
  8. 7 16
      Server/Hotfix/Module/MessageInner/NetInnerComponentSystem.cs
  9. 0 70
      Server/Hotfix/Module/MessageInner/OuterMessageDispatcher.cs
  10. 4 15
      Server/Hotfix/Server.Hotfix.csproj
  11. 0 12
      Server/Model/Module/Message/OuterMessageStatisticComponent.cs
  12. 1 1
      Server/Model/Module/MessageInner/NetInnerComponent.cs
  13. 8 38
      Server/Model/Server.Model.csproj
  14. 1 1
      Unity/Assets/Hotfix/Demo/Scene/SceneFactory.cs
  15. 2 13
      Unity/Assets/Hotfix/Demo/Session/SessionStreamDispatcherClientOuter.cs
  16. 1 1
      Unity/Assets/Hotfix/Demo/Session/SessionStreamDispatcherClientOuter.cs.meta
  17. 7 16
      Unity/Assets/Hotfix/Module/Message/NetKcpComponentSystem.cs
  18. 84 0
      Unity/Assets/Hotfix/Module/Message/SessionStreamDispatcherSystem.cs
  19. 11 0
      Unity/Assets/Hotfix/Module/Message/SessionStreamDispatcherSystem.cs.meta
  20. 1 1
      Unity/Assets/Hotfix/Module/Ping.meta
  21. 0 0
      Unity/Assets/Hotfix/Module/Ping/PingComponentSystem.cs
  22. 1 1
      Unity/Assets/Hotfix/Module/Ping/PingComponentSystem.cs.meta
  23. 1 0
      Unity/Assets/HotfixView/AppStart_Init.cs
  24. 9 0
      Unity/Assets/Model/Demo/SessionStreamDispatcherType.cs
  25. 11 0
      Unity/Assets/Model/Demo/SessionStreamDispatcherType.cs.meta
  26. 0 9
      Unity/Assets/Model/Module/Message/IMessageDispatcher.cs
  27. 9 0
      Unity/Assets/Model/Module/Message/ISessionStreamDispatcher.cs
  28. 11 0
      Unity/Assets/Model/Module/Message/ISessionStreamDispatcher.cs.meta
  29. 2 2
      Unity/Assets/Model/Module/Message/NetKcpComponent.cs
  30. 8 0
      Unity/Assets/Model/Module/Message/SessionStreamDispatcher.cs
  31. 11 0
      Unity/Assets/Model/Module/Message/SessionStreamDispatcher.cs.meta
  32. 14 0
      Unity/Assets/Model/Module/Message/SessionStreamDispatcherAttribute.cs
  33. 11 0
      Unity/Assets/Model/Module/Message/SessionStreamDispatcherAttribute.cs.meta
  34. 8 0
      Unity/Assets/Model/Module/Ping.meta
  35. 0 0
      Unity/Assets/Model/Module/Ping/PingComponent.cs
  36. 1 1
      Unity/Assets/Model/Module/Ping/PingComponent.cs.meta

+ 16 - 3
Robot/Hotfix/Robot.Hotfix.csproj

@@ -25,6 +25,12 @@
     </ItemGroup>
     
     <ItemGroup>
+        <Compile Include="..\..\Server\Hotfix\Demo\Session\InnerMessageDispatcherHelper.cs">
+          <Link>Server\Session\InnerMessageDispatcherHelper.cs</Link>
+        </Compile>
+        <Compile Include="..\..\Server\Hotfix\Demo\Session\SessionStreamDispatcherServerInner.cs">
+          <Link>Server\Session\SessionStreamDispatcherServerInner.cs</Link>
+        </Compile>
         <Compile Include="..\..\Unity\Assets\Hotfix\Module\AI\**\*.cs">
             <Link>Module\AI\%(RecursiveDir)%(FileName)%(Extension)</Link>
         </Compile>
@@ -48,6 +54,11 @@
         <Compile Include="..\..\Server\Hotfix\Module\Message\**\*.cs">
             <Link>Module\Message\%(RecursiveDir)%(FileName)%(Extension)</Link>
         </Compile>
+
+        <Compile Include="..\..\Server\Hotfix\Module\MessageInner\**\*.cs">
+            <Link>Module\MessageInner\%(RecursiveDir)%(FileName)%(Extension)</Link>
+        </Compile>
+        
         <Compile Include="..\..\Server\Hotfix\Module\NetworkTCP\**\*.cs">
             <Link>Module\NetworkTCP\%(RecursiveDir)%(FileName)%(Extension)</Link>
         </Compile>
@@ -60,6 +71,10 @@
             <Link>Module\Config\%(RecursiveDir)%(FileName)%(Extension)</Link>
         </Compile>
 
+        <Compile Include="..\..\Unity\Assets\Hotfix\Module\Ping\**\*.cs">
+            <Link>Module\Ping\%(RecursiveDir)%(FileName)%(Extension)</Link>
+        </Compile>
+
         <Compile Include="..\..\Server\Hotfix\Module\Console\**\*.cs">
             <Link>Module\Console\%(RecursiveDir)%(FileName)%(Extension)</Link>
         </Compile>
@@ -70,9 +85,7 @@
     </ItemGroup>
     
     <ItemGroup>
-      <Folder Include="..\..\Server\Hotfix\Helper">
-        <Link>Helper</Link>
-      </Folder>
+      <Folder Include="Server" />
     </ItemGroup>
 
 </Project>

+ 9 - 1
Robot/Model/Robot.Model.csproj

@@ -6,7 +6,7 @@
     </PropertyGroup>
 
     <PropertyGroup>
-        <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
+        <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> 
         <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
     </PropertyGroup>
 
@@ -53,6 +53,14 @@
             <Link>Module\NetworkTCP\%(RecursiveDir)%(FileName)%(Extension)</Link>
         </Compile>
 
+        <Compile Include="..\..\Server\Model\Module\MessageInner\**\*.cs">
+            <Link>Module\MessageInner\%(RecursiveDir)%(FileName)%(Extension)</Link>
+        </Compile>
+
+        <Compile Include="..\..\Unity\Assets\Model\Module\Ping\**\*.cs">
+            <Link>Module\Ping\%(RecursiveDir)%(FileName)%(Extension)</Link>
+        </Compile>
+
         <Compile Include="..\..\Unity\Assets\Model\Module\Message\**\*.cs">
             <Link>Module\Message\%(RecursiveDir)%(FileName)%(Extension)</Link>
         </Compile>

+ 3 - 2
Server/Hotfix/AppStart_Init.cs

@@ -30,6 +30,7 @@ namespace ET
             Game.Scene.AddComponent<TimerComponent>();
             Game.Scene.AddComponent<OpcodeTypeComponent>();
             Game.Scene.AddComponent<MessageDispatcherComponent>();
+            Game.Scene.AddComponent<SessionStreamDispatcher>();
             Game.Scene.AddComponent<CoroutineLockComponent>();
             // 发送普通actor消息
             Game.Scene.AddComponent<ActorMessageSenderComponent>();
@@ -47,7 +48,7 @@ namespace ET
             {
                 case AppType.Server:
                 {
-                    Game.Scene.AddComponent<NetInnerComponent, IPEndPoint>(processConfig.InnerIPPort);
+                    Game.Scene.AddComponent<NetInnerComponent, IPEndPoint, int>(processConfig.InnerIPPort, SessionStreamDispatcherType.SessionStreamDispatcherServerInner);
 
                     var processScenes = StartSceneConfigCategory.Instance.GetByProcess(Game.Options.Process);
                     foreach (StartSceneConfig startConfig in processScenes)
@@ -63,7 +64,7 @@ namespace ET
                     StartMachineConfig startMachineConfig = WatcherHelper.GetThisMachineConfig();
                     WatcherComponent watcherComponent = Game.Scene.AddComponent<WatcherComponent>();
                     watcherComponent.Start(Game.Options.CreateScenes);
-                    Game.Scene.AddComponent<NetInnerComponent, IPEndPoint>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"));
+                    Game.Scene.AddComponent<NetInnerComponent, IPEndPoint, int>(NetworkHelper.ToIPEndPoint($"{startMachineConfig.InnerIP}:{startMachineConfig.WatcherPort}"), SessionStreamDispatcherType.SessionStreamDispatcherServerInner);
                     break;
                 }
                 case AppType.GameTool:

+ 2 - 2
Server/Hotfix/Demo/Scene/SceneFactory.cs

@@ -22,10 +22,10 @@ namespace ET
             switch (scene.SceneType)
             {
                 case SceneType.Realm:
-                    scene.AddComponent<NetKcpComponent, IPEndPoint>(startSceneConfig.OuterIPPort);
+                    scene.AddComponent<NetKcpComponent, IPEndPoint, int>(startSceneConfig.OuterIPPort, SessionStreamDispatcherType.SessionStreamDispatcherServerOuter);
                     break;
                 case SceneType.Gate:
-                    scene.AddComponent<NetKcpComponent, IPEndPoint>(startSceneConfig.OuterIPPort);
+                    scene.AddComponent<NetKcpComponent, IPEndPoint, int>(startSceneConfig.OuterIPPort, SessionStreamDispatcherType.SessionStreamDispatcherServerOuter);
                     scene.AddComponent<PlayerComponent>();
                     scene.AddComponent<GateSessionKeyComponent>();
                     break;

+ 0 - 0
Server/Hotfix/Module/Message/InnerMessageDispatcherHelper.cs → Server/Hotfix/Demo/Session/InnerMessageDispatcherHelper.cs


+ 2 - 2
Server/Hotfix/Module/Message/InnerMessageDispatcher.cs → Server/Hotfix/Demo/Session/SessionStreamDispatcherServerInner.cs

@@ -1,10 +1,10 @@
 using System;
 using System.IO;
-using System.Net;
 
 namespace ET
 {
-    public class InnerMessageDispatcher: IMessageDispatcher
+    [SessionStreamDispatcher(SessionStreamDispatcherType.SessionStreamDispatcherServerInner)]
+    public class SessionStreamDispatcherServerInner: ISessionStreamDispatcher
     {
         public void Dispatch(Session session, MemoryStream memoryStream)
         {

+ 69 - 0
Server/Hotfix/Demo/Session/SessionStreamDispatcherServerOuter.cs

@@ -0,0 +1,69 @@
+using System;
+using System.IO;
+
+namespace ET
+{
+    [SessionStreamDispatcher(SessionStreamDispatcherType.SessionStreamDispatcherServerOuter)]
+    public class SessionStreamDispatcherServerOuter: ISessionStreamDispatcher
+    {
+        public void Dispatch(Session session, MemoryStream memoryStream)
+        {
+            ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.KcpOpcodeIndex);
+            Type type = OpcodeTypeComponent.Instance.GetType(opcode);
+            object message = MessageSerializeHelper.DeserializeFrom(opcode, type, memoryStream);
+
+            if (message is IResponse response)
+            {
+                session.OnRead(opcode, response);
+                return;
+            }
+
+            OpcodeHelper.LogMsg(session.DomainZone(), opcode, message);
+			
+            DispatchAsync(session, opcode, message).Coroutine();
+        }
+		
+        public async ETVoid DispatchAsync(Session session, ushort opcode, object message)
+        {
+            // 根据消息接口判断是不是Actor消息,不同的接口做不同的处理
+            switch (message)
+            {
+                case IActorLocationRequest actorLocationRequest: // gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
+                {
+                    long unitId = session.GetComponent<SessionPlayerComponent>().Player.UnitId;
+                    int rpcId = actorLocationRequest.RpcId; // 这里要保存客户端的rpcId
+                    long instanceId = session.InstanceId;
+                    IResponse response = await ActorLocationSenderComponent.Instance.Call(unitId, actorLocationRequest);
+                    response.RpcId = rpcId;
+                    // session可能已经断开了,所以这里需要判断
+                    if (session.InstanceId == instanceId)
+                    {
+                        session.Reply(response);
+                    }
+                    break;
+                }
+                case IActorLocationMessage actorLocationMessage:
+                {
+                    long unitId = session.GetComponent<SessionPlayerComponent>().Player.UnitId;
+                    ActorLocationSenderComponent.Instance.Send(unitId, actorLocationMessage);
+                    break;
+                }
+                case IActorRequest actorRequest:  // 分发IActorRequest消息,目前没有用到,需要的自己添加
+                {
+                    break;
+                }
+                case IActorMessage actorMessage:  // 分发IActorMessage消息,目前没有用到,需要的自己添加
+                {
+                    break;
+                }
+				
+                default:
+                {
+                    // 非Actor消息
+                    MessageDispatcherComponent.Instance.Handle(session, opcode, message);
+                    break;
+                }
+            }
+        }
+    }
+}

+ 7 - 16
Server/Hotfix/Module/Message/NetInnerComponentSystem.cs → Server/Hotfix/Module/MessageInner/NetInnerComponentSystem.cs

@@ -7,12 +7,12 @@ using System.Threading;
 namespace ET
 {
     [ObjectSystem]
-    public class NetInnerComponentAwakeSystem: AwakeSystem<NetInnerComponent>
+    public class NetInnerComponentAwakeSystem: AwakeSystem<NetInnerComponent, int>
     {
-        public override void Awake(NetInnerComponent self)
+        public override void Awake(NetInnerComponent self, int sessionStreamDispatcherType)
         {
             NetInnerComponent.Instance = self;
-            self.MessageDispatcher = new InnerMessageDispatcher();
+            self.SessionStreamDispatcherType = sessionStreamDispatcherType;
             
             self.Service = new TService(NetThreadComponent.Instance.ThreadSynchronizationContext, ServiceType.Inner);
             self.Service.ErrorCallback += self.OnError;
@@ -23,12 +23,12 @@ namespace ET
     }
 
     [ObjectSystem]
-    public class NetInnerComponentAwake1System: AwakeSystem<NetInnerComponent, IPEndPoint>
+    public class NetInnerComponentAwake1System: AwakeSystem<NetInnerComponent, IPEndPoint, int>
     {
-        public override void Awake(NetInnerComponent self, IPEndPoint address)
+        public override void Awake(NetInnerComponent self, IPEndPoint address, int sessionStreamDispatcherType)
         {
             NetInnerComponent.Instance = self;
-            self.MessageDispatcher = new InnerMessageDispatcher();
+            self.SessionStreamDispatcherType = sessionStreamDispatcherType;
 
             self.Service = new TService(NetThreadComponent.Instance.ThreadSynchronizationContext, address, ServiceType.Inner);
             self.Service.ErrorCallback += self.OnError;
@@ -39,15 +39,6 @@ namespace ET
         }
     }
 
-    [ObjectSystem]
-    public class NetInnerComponentLoadSystem: LoadSystem<NetInnerComponent>
-    {
-        public override void Load(NetInnerComponent self)
-        {
-            self.MessageDispatcher = new InnerMessageDispatcher();
-        }
-    }
-
     [ObjectSystem]
     public class NetInnerComponentDestroySystem: DestroySystem<NetInnerComponent>
     {
@@ -69,7 +60,7 @@ namespace ET
             }
 
             session.LastRecvTime = TimeHelper.ClientNow();
-            self.MessageDispatcher.Dispatch(session, memoryStream);
+            SessionStreamDispatcher.Instance.Dispatch(self.SessionStreamDispatcherType, session, memoryStream);
         }
 
         public static void OnError(this NetInnerComponent self, long channelId, int error)

+ 0 - 70
Server/Hotfix/Module/MessageInner/OuterMessageDispatcher.cs

@@ -1,70 +0,0 @@
-
-
-using System;
-using System.IO;
-
-namespace ET
-{
-	public class OuterMessageDispatcher: IMessageDispatcher
-	{
-		public void Dispatch(Session session, MemoryStream memoryStream)
-		{
-			ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.KcpOpcodeIndex);
-			Type type = OpcodeTypeComponent.Instance.GetType(opcode);
-			object message = MessageSerializeHelper.DeserializeFrom(opcode, type, memoryStream);
-
-			if (message is IResponse response)
-			{
-				session.OnRead(opcode, response);
-				return;
-			}
-
-			OpcodeHelper.LogMsg(session.DomainZone(), opcode, message);
-			
-			DispatchAsync(session, opcode, message).Coroutine();
-		}
-		
-		public async ETVoid DispatchAsync(Session session, ushort opcode, object message)
-		{
-			// 根据消息接口判断是不是Actor消息,不同的接口做不同的处理
-			switch (message)
-			{
-				case IActorLocationRequest actorLocationRequest: // gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
-				{
-					long unitId = session.GetComponent<SessionPlayerComponent>().Player.UnitId;
-					int rpcId = actorLocationRequest.RpcId; // 这里要保存客户端的rpcId
-					long instanceId = session.InstanceId;
-					IResponse response = await ActorLocationSenderComponent.Instance.Call(unitId, actorLocationRequest);
-					response.RpcId = rpcId;
-					// session可能已经断开了,所以这里需要判断
-					if (session.InstanceId == instanceId)
-					{
-						session.Reply(response);
-					}
-					break;
-				}
-				case IActorLocationMessage actorLocationMessage:
-				{
-					long unitId = session.GetComponent<SessionPlayerComponent>().Player.UnitId;
-					ActorLocationSenderComponent.Instance.Send(unitId, actorLocationMessage);
-					break;
-				}
-				case IActorRequest actorRequest:  // 分发IActorRequest消息,目前没有用到,需要的自己添加
-				{
-					break;
-				}
-				case IActorMessage actorMessage:  // 分发IActorMessage消息,目前没有用到,需要的自己添加
-				{
-					break;
-				}
-				
-				default:
-				{
-					// 非Actor消息
-					MessageDispatcherComponent.Instance.Handle(session, opcode, message);
-					break;
-				}
-			}
-		}
-	}
-}

+ 4 - 15
Server/Hotfix/Server.Hotfix.csproj

@@ -25,21 +25,6 @@
     <Compile Include="..\..\Unity\Assets\Hotfix\Module\Config\ConfigComponentSystem.cs">
       <Link>Module\Config\ConfigComponentSystem.cs</Link>
     </Compile>
-    <Compile Include="..\..\Unity\Assets\Hotfix\Module\Message\MessageDispatcherComponentSystem.cs">
-      <Link>Module\Message\MessageDispatcherComponentSystem.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Hotfix\Module\Message\NetKcpComponentSystem.cs">
-      <Link>Module\Message\NetKcpComponentSystem.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Hotfix\Module\Message\NetThreadComponentSystem.cs">
-      <Link>Module\Message\NetThreadComponentSystem.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Hotfix\Module\Message\SessionAcceptTimeoutComponentSystem.cs">
-      <Link>Module\Message\SessionAcceptTimeoutComponentSystem.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Hotfix\Module\Message\SessionIdleCheckerComponentSystem.cs">
-      <Link>Module\Message\SessionIdleCheckerComponentSystem.cs</Link>
-    </Compile>
     <Compile Include="..\..\Unity\Assets\Hotfix\Module\Numeric\NumericChangeEvent_NotifyWatcher.cs">
       <Link>Module\Numeric\NumericChangeEvent_NotifyWatcher.cs</Link>
     </Compile>
@@ -50,6 +35,10 @@
     <Compile Include="..\..\Unity\Assets\Hotfix\Module\AI\**\*.cs">
       <Link>Module\AI\%(RecursiveDir)%(FileName)%(Extension)</Link>
     </Compile>
+
+    <Compile Include="..\..\Unity\Assets\Hotfix\Module\Message\**\*.cs">
+      <Link>Module\Message\%(RecursiveDir)%(FileName)%(Extension)</Link>
+    </Compile>
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\Model\Server.Model.csproj" />

+ 0 - 12
Server/Model/Module/Message/OuterMessageStatisticComponent.cs

@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace ET
-{
-    public class OuterMessageStatisticComponent: Entity
-    {
-        public long LastCheckTime;
-        public int MessageCountPerSec;
-        public Dictionary<Type, int> MessageTypeCount = new Dictionary<Type, int>();
-    }
-}

+ 1 - 1
Server/Model/Module/Message/NetInnerComponent.cs → Server/Model/Module/MessageInner/NetInnerComponent.cs

@@ -24,6 +24,6 @@ namespace ET
 
         public static NetInnerComponent Instance;
 
-        public IMessageDispatcher MessageDispatcher { get; set; }
+        public int SessionStreamDispatcherType { get; set; }
     }
 }

+ 8 - 38
Server/Model/Server.Model.csproj

@@ -30,6 +30,10 @@
       <Link>Core\%(RecursiveDir)%(FileName)%(Extension)</Link>
     </Compile>
 
+    <Compile Include="..\..\Unity\Assets\Model\Demo\SessionStreamDispatcherType.cs">
+      <Link>Demo\SessionStreamDispatcherType.cs</Link>
+    </Compile>
+
     <Compile Include="..\..\Unity\Assets\Mono\Core\**\*.cs">
       <Link>Core\%(RecursiveDir)%(FileName)%(Extension)</Link>
     </Compile>
@@ -62,22 +66,8 @@
     <Compile Include="..\..\Unity\Assets\Model\Module\Actor\IActorMessage.cs">
       <Link>Module\Actor\IActorMessage.cs</Link>
     </Compile>
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\MessageDispatcherComponent.cs">
-      <Link>Module\Message\MessageDispatcherComponent.cs</Link>
-    </Compile>
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\AMHandler.cs" Link="Module\Message\AMHandler.cs" />
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\ErrorCode.cs" Link="Module\Message\ErrorCode.cs" />
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\IMessage.cs" Link="Module\Message\IMessage.cs" />
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\IMessageDispatcher.cs" Link="Module\Message\IMessageDispatcher.cs" />
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\IMHandler.cs" Link="Module\Message\IMHandler.cs" />
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\MessageAttribute.cs" Link="Module\Message\MessageAttribute.cs" />
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\MessageHandlerAttribute.cs" Link="Module\Message\MessageHandlerAttribute.cs" />
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\OpcodeHelper.cs" Link="Module\Message\OpcodeHelper.cs" />
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\OpcodeTypeComponent.cs" Link="Module\Message\OpcodeTypeComponent.cs" />
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\RpcException.cs" Link="Module\Message\RpcException.cs" />
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\Session.cs" Link="Module\Message\Session.cs" />
     <Compile Include="..\..\Unity\Assets\Model\Module\NetworkTCP\PacketParser.cs">
       <Link>Module\NetworkTCP\PacketParser.cs</Link>
     </Compile>
@@ -105,34 +95,14 @@
   </ItemGroup>
 
   <ItemGroup>
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\MessageSerializeHelper.cs"> 
-      <Link>Module\Message\MessageSerializeHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\MessagePool.cs">
-      <Link>Module\Message\MessagePool.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\MessagePackHelper.cs">
-      <Link>Module\Message\MessagePackHelper.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\NetKcpComponent.cs">
-      <Link>Module\Message\NetKcpComponent.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\NetThreadComponent.cs">
-      <Link>Module\Message\NetThreadComponent.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\ResponseTypeAttribute.cs">
-      <Link>Module\Message\ResponseTypeAttribute.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\SessionAcceptTimeoutComponent.cs">
-      <Link>Module\Message\SessionAcceptTimeoutComponent.cs</Link>
-    </Compile>
-    <Compile Include="..\..\Unity\Assets\Model\Module\Message\SessionIdleCheckerComponent.cs">
-      <Link>Module\Message\SessionIdleCheckerComponent.cs</Link>
-    </Compile>
 
     <Compile Include="..\..\Unity\Assets\Model\Module\Network\**\*.cs">
       <Link>Module\Network\%(RecursiveDir)%(FileName)%(Extension)</Link>
     </Compile>
+
+    <Compile Include="..\..\Unity\Assets\Model\Module\Message\**\*.cs">
+      <Link>Module\Message\%(RecursiveDir)%(FileName)%(Extension)</Link>
+    </Compile>
   </ItemGroup>
   
   <ItemGroup>

+ 1 - 1
Unity/Assets/Hotfix/Demo/Scene/SceneFactory.cs

@@ -6,7 +6,7 @@ namespace ET
         {
             Scene zoneScene = EntitySceneFactory.CreateScene(Game.IdGenerater.GenerateInstanceId(), zone, SceneType.Zone, name, parent);
             zoneScene.AddComponent<ZoneSceneFlagComponent>();
-            zoneScene.AddComponent<NetKcpComponent>();
+            zoneScene.AddComponent<NetKcpComponent, int>(SessionStreamDispatcherType.SessionStreamDispatcherClientOuter);
             zoneScene.AddComponent<UnitComponent>();
             zoneScene.AddComponent<AIComponent, int>(1);
             

+ 2 - 13
Unity/Assets/Hotfix/Module/MessageOuter/OuterMessageDispatcher.cs → Unity/Assets/Hotfix/Demo/Session/SessionStreamDispatcherClientOuter.cs

@@ -3,25 +3,14 @@ using System.IO;
 
 namespace ET
 {
-    public class OuterMessageDispatcher: IMessageDispatcher
+    [SessionStreamDispatcher(SessionStreamDispatcherType.SessionStreamDispatcherClientOuter)]
+    public class SessionStreamDispatcherClientOuter: ISessionStreamDispatcher
     {
-        // 查找卡死问题临时处理
-        public long lastMessageTime = long.MaxValue;
-        public object LastMessage;
-        
         public void Dispatch(Session session, MemoryStream memoryStream)
         {
             ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.KcpOpcodeIndex);
             Type type = OpcodeTypeComponent.Instance.GetType(opcode);
             object message = MessageSerializeHelper.DeserializeFrom(opcode, type, memoryStream);
-
-            if (TimeHelper.ClientFrameTime() - this.lastMessageTime > 3000)
-            {
-                Log.Info($"可能导致卡死的消息: {this.LastMessage}");
-            }
-
-            this.lastMessageTime = TimeHelper.ClientFrameTime();
-            this.LastMessage = message;
             
             if (message is IResponse response)
             {

+ 1 - 1
Unity/Assets/Hotfix/Module/MessageOuter/OuterMessageDispatcher.cs.meta → Unity/Assets/Hotfix/Demo/Session/SessionStreamDispatcherClientOuter.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: aefbf5630f2854ad78f151e0721ccfbf
+guid: 4e5f67f66e8680548ad49a97f038e2c7
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 7 - 16
Unity/Assets/Hotfix/Module/Message/NetKcpComponentSystem.cs

@@ -5,11 +5,11 @@ using System.Net;
 namespace ET
 {
     [ObjectSystem]
-    public class NetKcpComponentAwakeSystem: AwakeSystem<NetKcpComponent>
+    public class NetKcpComponentAwakeSystem: AwakeSystem<NetKcpComponent, int>
     {
-        public override void Awake(NetKcpComponent self)
+        public override void Awake(NetKcpComponent self, int sessionStreamDispatcherType)
         {
-            self.MessageDispatcher = new OuterMessageDispatcher();
+            self.SessionStreamDispatcherType = sessionStreamDispatcherType;
             
             self.Service = new TService(NetThreadComponent.Instance.ThreadSynchronizationContext, ServiceType.Outer);
             self.Service.ErrorCallback += self.OnError;
@@ -20,11 +20,11 @@ namespace ET
     }
 
     [ObjectSystem]
-    public class NetKcpComponentAwake1System: AwakeSystem<NetKcpComponent, IPEndPoint>
+    public class NetKcpComponentAwake1System: AwakeSystem<NetKcpComponent, IPEndPoint, int>
     {
-        public override void Awake(NetKcpComponent self, IPEndPoint address)
+        public override void Awake(NetKcpComponent self, IPEndPoint address, int sessionStreamDispatcherType)
         {
-            self.MessageDispatcher = new OuterMessageDispatcher();
+            self.SessionStreamDispatcherType = sessionStreamDispatcherType;
             
             self.Service = new TService(NetThreadComponent.Instance.ThreadSynchronizationContext, address, ServiceType.Outer);
             self.Service.ErrorCallback += self.OnError;
@@ -35,15 +35,6 @@ namespace ET
         }
     }
 
-    [ObjectSystem]
-    public class NetKcpComponentLoadSystem: LoadSystem<NetKcpComponent>
-    {
-        public override void Load(NetKcpComponent self)
-        {
-            self.MessageDispatcher = new OuterMessageDispatcher();
-        }
-    }
-
     [ObjectSystem]
     public class NetKcpComponentDestroySystem: DestroySystem<NetKcpComponent>
     {
@@ -65,7 +56,7 @@ namespace ET
             }
 
             session.LastRecvTime = TimeHelper.ClientNow();
-            self.MessageDispatcher.Dispatch(session, memoryStream);
+            SessionStreamDispatcher.Instance.Dispatch(self.SessionStreamDispatcherType, session, memoryStream);
         }
 
         public static void OnError(this NetKcpComponent self, long channelId, int error)

+ 84 - 0
Unity/Assets/Hotfix/Module/Message/SessionStreamDispatcherSystem.cs

@@ -0,0 +1,84 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace ET
+{
+    [ObjectSystem]
+    public class SessionStreamDispatcherAwakeSystem: AwakeSystem<SessionStreamDispatcher>
+    {
+        public override void Awake(SessionStreamDispatcher self)
+        {
+            SessionStreamDispatcher.Instance = self;
+            self.Load();
+        }
+    }
+
+    [ObjectSystem]
+    public class SessionStreamDispatcherLoadSystem: LoadSystem<SessionStreamDispatcher>
+    {
+        public override void Load(SessionStreamDispatcher self)
+        {
+            self.Load();
+        }
+    }
+
+    [ObjectSystem]
+    public class SessionStreamDispatcherDestroySystem: DestroySystem<SessionStreamDispatcher>
+    {
+        public override void Destroy(SessionStreamDispatcher self)
+        {
+            SessionStreamDispatcher.Instance = null;
+        }
+    }
+    
+    public static class SessionStreamDispatcherSystem
+    {
+        public static void Load(this SessionStreamDispatcher self)
+        {
+            self.Dispatchers = new ISessionStreamDispatcher[100];
+            
+            HashSet<Type> types = Game.EventSystem.GetTypes(typeof (SessionStreamDispatcherAttribute));
+
+            foreach (Type type in types)
+            {
+                object[] attrs = type.GetCustomAttributes(typeof (SessionStreamDispatcherAttribute), false);
+                if (attrs.Length == 0)
+                {
+                    continue;
+                }
+                
+                SessionStreamDispatcherAttribute sessionStreamDispatcherAttribute = attrs[0] as SessionStreamDispatcherAttribute;
+                if (sessionStreamDispatcherAttribute == null)
+                {
+                    continue;
+                }
+
+                if (sessionStreamDispatcherAttribute.Type >= 100)
+                {
+                    Log.Error("session dispatcher type must < 100");
+                    continue;
+                }
+                
+                ISessionStreamDispatcher iSessionStreamDispatcher = Activator.CreateInstance(type) as ISessionStreamDispatcher;
+                if (iSessionStreamDispatcher == null)
+                {
+                    Log.Error($"sessionDispatcher {type.Name} 需要继承 ISessionDispatcher");
+                    continue;
+                }
+
+                self.Dispatchers[sessionStreamDispatcherAttribute.Type] = iSessionStreamDispatcher;
+            }
+        }
+
+        public static void Dispatch(this SessionStreamDispatcher self, int type, Session session, MemoryStream memoryStream)
+        {
+            ISessionStreamDispatcher sessionStreamDispatcher = self.Dispatchers[type];
+            if (sessionStreamDispatcher == null)
+            {
+                throw new Exception("maybe your NetInnerComponent or NetOuterComponent not set SessionStreamDispatcherType");
+            }
+            sessionStreamDispatcher.Dispatch(session, memoryStream);
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Hotfix/Module/Message/SessionStreamDispatcherSystem.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 1c872edf78ddf124f90146d19ec45bd9
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 1
Unity/Assets/Hotfix/Module/MessageOuter.meta → Unity/Assets/Hotfix/Module/Ping.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: a5b34826b9ce24c7cb122e72c98d7922
+guid: 93ef9f6db0e437c42a317e0db9d4aad6
 folderAsset: yes
 DefaultImporter:
   externalObjects: {}

+ 0 - 0
Unity/Assets/Hotfix/Module/Message/PingComponentSystem.cs → Unity/Assets/Hotfix/Module/Ping/PingComponentSystem.cs


+ 1 - 1
Unity/Assets/Hotfix/Module/Message/PingComponentSystem.cs.meta → Unity/Assets/Hotfix/Module/Ping/PingComponentSystem.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: 5e493e7e2772cd34f87800aa999fdcf8
+guid: 5752a8ea697a7c24f966a8f6ac193caa
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2

+ 1 - 0
Unity/Assets/HotfixView/AppStart_Init.cs

@@ -18,6 +18,7 @@ namespace ET
             Game.Scene.AddComponent<MessageDispatcherComponent>();
             
             Game.Scene.AddComponent<NetThreadComponent>();
+            Game.Scene.AddComponent<SessionStreamDispatcher>();
 
             Game.Scene.AddComponent<ZoneSceneManagerComponent>();
             

+ 9 - 0
Unity/Assets/Model/Demo/SessionStreamDispatcherType.cs

@@ -0,0 +1,9 @@
+namespace ET
+{
+    public static class SessionStreamDispatcherType
+    {
+        public const int SessionStreamDispatcherClientOuter = 1;
+        public const int SessionStreamDispatcherServerOuter = 2;
+        public const int SessionStreamDispatcherServerInner = 3;
+    }
+}

+ 11 - 0
Unity/Assets/Model/Demo/SessionStreamDispatcherType.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 6edd6b7e05f30f943965f8fe58c2e567
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 9
Unity/Assets/Model/Module/Message/IMessageDispatcher.cs

@@ -1,9 +0,0 @@
-using System.IO;
-
-namespace ET
-{
-    public interface IMessageDispatcher
-    {
-        void Dispatch(Session session, MemoryStream message);
-    }
-}

+ 9 - 0
Unity/Assets/Model/Module/Message/ISessionStreamDispatcher.cs

@@ -0,0 +1,9 @@
+using System.IO;
+
+namespace ET
+{
+    public interface ISessionStreamDispatcher
+    {
+        void Dispatch(Session session, MemoryStream stream);
+    }
+}

+ 11 - 0
Unity/Assets/Model/Module/Message/ISessionStreamDispatcher.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 9247baad290869b40a1aef9f545c1555
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 2 - 2
Unity/Assets/Model/Module/Message/NetKcpComponent.cs

@@ -1,9 +1,9 @@
-namespace ET
+namespace ET
 {
     public class NetKcpComponent: Entity
     {
         public AService Service;
         
-        public IMessageDispatcher MessageDispatcher { get; set; }
+        public int SessionStreamDispatcherType { get; set; }
     }
 }

+ 8 - 0
Unity/Assets/Model/Module/Message/SessionStreamDispatcher.cs

@@ -0,0 +1,8 @@
+namespace ET
+{
+    public class SessionStreamDispatcher: Entity
+    {
+        public static SessionStreamDispatcher Instance;
+        public ISessionStreamDispatcher[] Dispatchers;
+    }
+}

+ 11 - 0
Unity/Assets/Model/Module/Message/SessionStreamDispatcher.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 06cc869ee5c229f49ad83122f97cfe3a
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 14 - 0
Unity/Assets/Model/Module/Message/SessionStreamDispatcherAttribute.cs

@@ -0,0 +1,14 @@
+using System;
+
+namespace ET
+{
+    public class SessionStreamDispatcherAttribute: BaseAttribute
+    {
+        public int Type;
+
+        public SessionStreamDispatcherAttribute(int type)
+        {
+            this.Type = type;
+        }
+    }
+}

+ 11 - 0
Unity/Assets/Model/Module/Message/SessionStreamDispatcherAttribute.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 971798875d92c9b4b8b912207b1cee25
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Unity/Assets/Model/Module/Ping.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 2676d1a498faf164c9c2483b9a52e3c6
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 0 - 0
Unity/Assets/Model/Module/Message/PingComponent.cs → Unity/Assets/Model/Module/Ping/PingComponent.cs


+ 1 - 1
Unity/Assets/Model/Module/Message/PingComponent.cs.meta → Unity/Assets/Model/Module/Ping/PingComponent.cs.meta

@@ -1,5 +1,5 @@
 fileFormatVersion: 2
-guid: c285e6a3876055d4791f6d023d4db5d2
+guid: 79c61c146af15ed4585701e8022402e4
 MonoImporter:
   externalObjects: {}
   serializedVersion: 2