Sfoglia il codice sorgente

大大简化了消息处理代码

tanghai 9 anni fa
parent
commit
97dd115bcb
28 ha cambiato i file con 236 aggiunte e 180 eliminazioni
  1. 3 0
      Server/App/Program.cs
  2. 1 1
      Server/Controller/Message/C2G_LoginGateHandler.cs
  3. 1 1
      Server/Controller/Message/C2M_ReloadHandler.cs
  4. 2 2
      Server/Controller/Message/C2R_LoginHandler.cs
  5. 1 1
      Server/Controller/Message/C2R_SubscribeLogHandler.cs
  6. 1 1
      Server/Controller/Message/M2A_ReloadHandler.cs
  7. 1 1
      Server/Controller/Message/R2G_GetLoginKeyHandler.cs
  8. 7 4
      Server/Model/Server.Model.csproj
  9. 12 0
      Unity/Assets/Plugins/Base/Log.cs
  10. 12 0
      Unity/Assets/Plugins/Base/Network/TNet/TChannel.cs
  11. 4 0
      Unity/Assets/Plugins/Base/Network/TNet/TSocket.cs
  12. 12 0
      Unity/Assets/Plugins/Base/Network/UNet/UChannel.cs
  13. 4 0
      Unity/Assets/Plugins/Base/Network/UNet/USocket.cs
  14. 0 5
      Unity/Assets/Plugins/Base/Object/Object.cs
  15. 27 97
      Unity/Assets/Scripts/Component/MessageDispatherComponent.cs
  16. 31 0
      Unity/Assets/Scripts/Component/RobotComponent.cs
  17. 12 0
      Unity/Assets/Scripts/Component/RobotComponent.cs.meta
  18. 10 2
      Unity/Assets/Scripts/Entity/Session.cs
  19. 0 29
      Unity/Assets/Scripts/Message/AMEvent.cs
  20. 64 0
      Unity/Assets/Scripts/Message/AMHandler.cs
  21. 0 0
      Unity/Assets/Scripts/Message/AMHandler.cs.meta
  22. 1 1
      Unity/Assets/Scripts/Message/AppType.cs
  23. 18 0
      Unity/Assets/Scripts/Message/IMHandler.cs
  24. 0 0
      Unity/Assets/Scripts/Message/IMHandler.cs.meta
  25. 0 21
      Unity/Assets/Scripts/Message/IMRegister.cs
  26. 1 1
      Unity/Controller/Message/R2C_ServerLogHandler.cs
  27. 2 5
      Unity/Unity.CSharp.Editor.csproj
  28. 9 8
      Unity/Unity.CSharp.csproj

+ 3 - 0
Server/App/Program.cs

@@ -56,6 +56,9 @@ namespace App
 						Game.Scene.AddComponent<RealmGateAddressComponent>();
 						Game.Scene.AddComponent<GateSessionKeyComponent>();
 						break;
+					case AppType.Robot:
+						Game.Scene.AddComponent<RobotComponent>();
+						break;
 					default:
 						throw new Exception($"命令行参数没有设置正确的AppType: {startConfig.AppType}");
 				}

+ 1 - 1
Server/Controller/Message/C2G_LoginGateHandler.cs

@@ -5,7 +5,7 @@ using Model;
 namespace Controller
 {
 	[MessageHandler(AppType.Gate)]
-	public class C2G_LoginGateHandler : AMRpcEvent<C2G_LoginGate, G2C_LoginGate>
+	public class C2G_LoginGateHandler : AMRpcHandler<C2G_LoginGate, G2C_LoginGate>
 	{
 		protected override void Run(Session session, C2G_LoginGate message, Action<G2C_LoginGate> reply)
 		{

+ 1 - 1
Server/Controller/Message/C2M_ReloadHandler.cs

@@ -5,7 +5,7 @@ using Model;
 namespace Controller
 {
 	[MessageHandler(AppType.Manager)]
-	public class C2M_ReloadHandler: AMRpcEvent<C2M_Reload, M2C_Reload>
+	public class C2M_ReloadHandler: AMRpcHandler<C2M_Reload, M2C_Reload>
 	{
 		protected override async void Run(Session session, C2M_Reload message, Action<M2C_Reload> reply)
 		{

+ 2 - 2
Server/Controller/Message/C2R_LoginHandler.cs

@@ -5,7 +5,7 @@ using Model;
 namespace Controller
 {
 	[MessageHandler(AppType.Realm)]
-	public class C2R_LoginHandler: AMRpcEvent<C2R_Login, R2C_Login>
+	public class C2R_LoginHandler: AMRpcHandler<C2R_Login, R2C_Login>
 	{
 		protected override async void Run(Session session, C2R_Login message, Action<R2C_Login> reply)
 		{
@@ -19,7 +19,7 @@ namespace Controller
 
 			// 随机分配一个Gate
 			Entity config = Game.Scene.GetComponent<RealmGateAddressComponent>().GetAddress();
-			Log.Info($"gate address: {MongoHelper.ToJson(config)}");
+			//Log.Debug($"gate address: {MongoHelper.ToJson(config)}");
 			string innerAddress = $"{config.GetComponent<InnerConfig>().Host}:{config.GetComponent<InnerConfig>().Port}";
 			Session gateSession = Game.Scene.GetComponent<NetInnerComponent>().Get(innerAddress);
 			

+ 1 - 1
Server/Controller/Message/C2R_SubscribeLogHandler.cs

@@ -5,7 +5,7 @@ using Model;
 namespace Controller
 {
 	[MessageHandler(AppType.Realm)]
-	public class C2R_SubscribeLogHandler : AMRpcEvent<C2R_SubscribeLog, R2C_SubscribeLog>
+	public class C2R_SubscribeLogHandler : AMRpcHandler<C2R_SubscribeLog, R2C_SubscribeLog>
 	{
 		protected override void Run(Session session, C2R_SubscribeLog message, Action<R2C_SubscribeLog> reply)
 		{

+ 1 - 1
Server/Controller/Message/M2A_ReloadHandler.cs

@@ -6,7 +6,7 @@ using Object = Base.Object;
 namespace Controller
 {
 	[MessageHandler(AppType.AllServer)]
-	public class M2A_ReloadHandler : AMRpcEvent<M2A_Reload, A2M_Reload>
+	public class M2A_ReloadHandler : AMRpcHandler<M2A_Reload, A2M_Reload>
 	{
 		protected override void Run(Session session, M2A_Reload message, Action<A2M_Reload> reply)
 		{

+ 1 - 1
Server/Controller/Message/R2G_GetLoginKeyHandler.cs

@@ -5,7 +5,7 @@ using Model;
 namespace Controller
 {
 	[MessageHandler(AppType.Gate)]
-	public class R2G_GetLoginKeyHandler : AMRpcEvent<R2G_GetLoginKey, G2R_GetLoginKey>
+	public class R2G_GetLoginKeyHandler : AMRpcHandler<R2G_GetLoginKey, G2R_GetLoginKey>
 	{
 		protected override void Run(Session session, R2G_GetLoginKey message, Action<G2R_GetLoginKey> reply)
 		{

+ 7 - 4
Server/Model/Server.Model.csproj

@@ -59,6 +59,9 @@
     <Compile Include="..\..\Unity\Assets\Scripts\Component\NetworkComponent.cs">
       <Link>Component\NetworkComponent.cs</Link>
     </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Component\RobotComponent.cs">
+      <Link>Component\RobotComponent.cs</Link>
+    </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Component\TimerComponent.cs">
       <Link>Component\TimerComponent.cs</Link>
     </Compile>
@@ -92,8 +95,8 @@
     <Compile Include="..\..\Unity\Assets\Scripts\Message\AMessage.cs">
       <Link>Message\AMessage.cs</Link>
     </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Message\AMEvent.cs">
-      <Link>Message\AMEvent.cs</Link>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\AMHandler.cs">
+      <Link>Message\AMHandler.cs</Link>
     </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Message\AppType.cs">
       <Link>Message\AppType.cs</Link>
@@ -101,8 +104,8 @@
     <Compile Include="..\..\Unity\Assets\Scripts\Message\ErrorCode.cs">
       <Link>Message\ErrorCode.cs</Link>
     </Compile>
-    <Compile Include="..\..\Unity\Assets\Scripts\Message\IMRegister.cs">
-      <Link>Message\IMRegister.cs</Link>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\IMHandler.cs">
+      <Link>Message\IMHandler.cs</Link>
     </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Message\Message.cs">
       <Link>Message\Message.cs</Link>

+ 12 - 0
Unity/Assets/Plugins/Base/Log.cs

@@ -74,6 +74,12 @@ namespace Base
 				error.Flush();
 			}
 
+			info.WriteLine(s);
+			if (IsNeedFlush)
+			{
+				info.Flush();
+			}
+
 #if UNITY_EDITOR
 			UnityEngine.Debug.LogError(s);
 #endif
@@ -91,6 +97,12 @@ namespace Base
 			DateTime dateTime = DateTime.Now;
 			string s = $"{dateTime.ToString("yyyy-MM-dd HH:mm:ss")} {TimeHelper.ClientNow()} {msg}";
 			UnityEngine.Debug.Log(s);
+
+			info.WriteLine(s);
+			if (IsNeedFlush)
+			{
+				info.Flush();
+			}
 #endif
 		}
 

+ 12 - 0
Unity/Assets/Plugins/Base/Network/TNet/TChannel.cs

@@ -87,6 +87,10 @@ namespace Base
 
 		public override void Send(byte[] buffer, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
 		{
+			if (this.Id == 0)
+			{
+				throw new Exception("TChannel已经被Dispose, 不能发送消息");
+			}
 			byte[] size = BitConverter.GetBytes(buffer.Length);
 			this.sendBuffer.SendTo(size);
 			this.sendBuffer.SendTo(buffer);
@@ -98,6 +102,10 @@ namespace Base
 
 		public override void Send(List<byte[]> buffers, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
 		{
+			if (this.Id == 0)
+			{
+				throw new Exception("TChannel已经被Dispose, 不能发送消息");
+			}
 			int size = buffers.Select(b => b.Length).Sum();
 			byte[] sizeBuffer = BitConverter.GetBytes(size);
 			this.sendBuffer.SendTo(sizeBuffer);
@@ -205,6 +213,10 @@ namespace Base
 
 		public override Task<byte[]> Recv()
 		{
+			if (this.Id == 0)
+			{
+				throw new Exception("TChannel已经被Dispose, 不能接收消息");
+			}
 			TaskCompletionSource<byte[]> tcs = new TaskCompletionSource<byte[]>();
 			byte[] packet = this.parser.GetPacket();
 			if (packet != null)

+ 4 - 0
Unity/Assets/Plugins/Base/Network/TNet/TSocket.cs

@@ -82,6 +82,10 @@ namespace Base
 
 		public Task<bool> AcceptAsync(TSocket accpetSocket)
 		{
+			if (this.socket == null)
+			{
+				throw new Exception($"TSocket已经被Dispose,不能接收连接!");
+			}
 			var tcs = new TaskCompletionSource<bool>();
 			this.innArgs.UserToken = tcs;
 			this.innArgs.AcceptSocket = accpetSocket.socket;

+ 12 - 0
Unity/Assets/Plugins/Base/Network/UNet/UChannel.cs

@@ -49,11 +49,19 @@ namespace Base
 
 		public override void Send(byte[] buffer, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
 		{
+			if (this.Id == 0)
+			{
+				throw new Exception("UChannel已经被Dispose, 不能发送消息");
+			}
 			this.socket.SendAsync(buffer, channelID, flags);
 		}
 
 		public override void Send(List<byte[]> buffers, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
 		{
+			if (this.Id == 0)
+			{
+				throw new Exception("UChannel已经被Dispose, 不能发送消息");
+			}
 			int size = buffers.Select(b => b.Length).Sum();
 			var buffer = new byte[size];
 			int index = 0;
@@ -67,6 +75,10 @@ namespace Base
 
 		public override Task<byte[]> Recv()
 		{
+			if (this.Id == 0)
+			{
+				throw new Exception("UChannel已经被Dispose, 不能接收消息");
+			}
 			TaskCompletionSource<byte[]> tcs = new TaskCompletionSource<byte[]>();
 			var recvQueue = this.socket.RecvQueue;
 			if (recvQueue.Count > 0)

+ 4 - 0
Unity/Assets/Plugins/Base/Network/UNet/USocket.cs

@@ -117,6 +117,10 @@ namespace Base
 
 		public void SendAsync(byte[] data, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
 		{
+			if (this.PeerPtr == IntPtr.Zero)
+			{
+				throw new Exception($"USocket 已经被Dispose,不能发送数据!");
+			}
 			if (!isConnected)
 			{
 				sendQueue.Enqueue(new BufferInfo { Buffer = data, ChannelID = channelID, Flags = flags });

+ 0 - 5
Unity/Assets/Plugins/Base/Object/Object.cs

@@ -24,11 +24,6 @@ namespace Base
 			ObjectManager.Add(this);
 		}
 
-		public bool IsDisposed()
-		{
-			return this.Id == 0;
-		}
-
 		public virtual void Dispose()
 		{
 			if (this.Id == 0)

+ 27 - 97
Unity/Assets/Scripts/Component/MessageDispatherComponent.cs

@@ -24,19 +24,10 @@ namespace Model
 	/// <summary>
 	/// 消息分发组件
 	/// </summary>
-	public class MessageDispatherComponent: Component, IMessageDispather
+	public class MessageDispatherComponent: Component
 	{
-		private class MessageInfo
-		{
-			public byte[] MessageBytes;
-			public int Offset;
-			public int Count;
-			public uint RpcId;
-		}
-
 		private AppType AppType;
-		private Dictionary<ushort, List<Action<Session, MessageInfo>>> handlers;
-		private Dictionary<ushort, Action<Session, MessageInfo>> rpcHandlers;
+		private Dictionary<ushort, List<IMHandler>> handlers;
 		private Dictionary<Type, MessageAttribute> messageOpcode { get; set; } = new Dictionary<Type, MessageAttribute>();
 		
 		public void Awake(AppType appType)
@@ -47,8 +38,7 @@ namespace Model
 
 		public void Load()
 		{
-			this.handlers = new Dictionary<ushort, List<Action<Session, MessageInfo>>>();
-			this.rpcHandlers = new Dictionary<ushort, Action<Session, MessageInfo>>();
+			this.handlers = new Dictionary<ushort, List<IMHandler>>();
 			this.messageOpcode = new Dictionary<Type, MessageAttribute>();
 
 			Assembly[] assemblies = Object.ObjectManager.GetAssemblies();
@@ -88,12 +78,21 @@ namespace Model
 
 					object obj = Activator.CreateInstance(type);
 
-					IMRegister iMRegister = obj as IMRegister;
-					if (iMRegister == null)
+					IMHandler imHandler = obj as IMHandler;
+					if (imHandler == null)
 					{
 						throw new Exception($"message handler not inherit AMEvent or AMRpcEvent abstract class: {obj.GetType().FullName}");
 					}
-					iMRegister.Register(this);
+
+					Type messageType = imHandler.GetMessageType();
+					ushort opcode = this.GetOpcode(messageType);
+					List<IMHandler> list;
+					if (!this.handlers.TryGetValue(opcode, out list))
+					{
+						list = new List<IMHandler>();
+						this.handlers.Add(opcode, list);
+					}
+					list.Add(imHandler);
 				}
 			}
 		}
@@ -108,76 +107,27 @@ namespace Model
 			return messageAttribute.Opcode;
 		}
 
-		public void RegisterHandler<Message>(ushort opcode, Action<Session, Message> action) where Message: AMessage
-		{
-			if (!this.handlers.ContainsKey(opcode))
-			{
-				this.handlers.Add(opcode, new List<Action<Session, MessageInfo>>());
-			}
-			List<Action<Session, MessageInfo>> actions = this.handlers[opcode];
-
-			actions.Add((session, messageInfo) =>
-			{
-				Message message;
-				try
-				{
-                    message = MongoHelper.FromBson<Message>(messageInfo.MessageBytes, messageInfo.Offset, messageInfo.Count);
-					Log.Info(MongoHelper.ToJson(message));
-                }
-			    catch (Exception ex)
-			    {
-			        throw new Exception("解释消息失败:" + opcode, ex);
-			    }
-
-				action(session, message);
-			});
-		}
-		
-		public void RegisterRpcHandler<Request, Response>(ushort opcode, Action<Session, Request, Action<Response>> action) 
-			where Request: ARequest 
-			where Response: AResponse
-		{
-			if (this.rpcHandlers.ContainsKey(opcode))
-			{
-				Log.Error($"rpc消息不能注册两次! opcode: {opcode}");
-				return;
-			}
-			this.rpcHandlers.Add(opcode, (session, messageInfo) =>
-			{
-				Request request;
-				try
-				{
-					request = MongoHelper.FromBson<Request>(messageInfo.MessageBytes, messageInfo.Offset, messageInfo.Count);
-					Log.Info(MongoHelper.ToJson(request));
-				}
-				catch (Exception ex)
-				{
-					throw new Exception("解释消息失败:" + opcode, ex);
-				}
-
-				action(session, request, response =>
-					{
-						session.Reply(messageInfo.RpcId, response); 
-					} 
-				);
-			});
-		}
-
-
-		public void Handle(Session session, ushort opcode, byte[] messageBytes, int offset)
+		public void Handle(Session session, ushort opcode, byte[] messageBytes, int offset, uint rpcId)
 		{
-			List<Action<Session, MessageInfo>> actions;
+			List<IMHandler> actions;
 			if (!this.handlers.TryGetValue(opcode, out actions))
 			{
 				Log.Error($"消息 {opcode} 没有处理");
 				return;
 			}
 
-			foreach (var ev in actions)
+			foreach (IMHandler ev in actions)
 			{
 				try
 				{
-					ev(session, new MessageInfo { MessageBytes = messageBytes, Offset = offset, Count = messageBytes.Length - offset });
+					ev.Handle(session, opcode, new MessageInfo
+						{
+							MessageBytes = messageBytes,
+							Offset = offset,
+							Count = messageBytes.Length - offset,
+							RpcId = rpcId
+						}
+					);
 				}
 				catch (Exception e)
 				{
@@ -185,27 +135,7 @@ namespace Model
 				}
 			}
 		}
-
-		public void HandleRpc(Session session, ushort opcode, byte[] messageBytes, int offset, uint rpcId)
-		{
-			Action<Session, MessageInfo> action;
-			if (!this.rpcHandlers.TryGetValue(opcode, out action))
-			{
-				Log.Error($"Rpc消息 {opcode} 没有处理");
-				return;
-			}
-
-			try
-			{
-				action(session, new MessageInfo { MessageBytes = messageBytes, Offset = offset, Count = messageBytes.Length - offset, RpcId = rpcId });
-			}
-			catch (Exception e)
-			{
-				Log.Error(e.ToString());
-			}
-		}
-
-
+		
 		public override void Dispose()
 		{
 			if (this.Id == 0)

+ 31 - 0
Unity/Assets/Scripts/Component/RobotComponent.cs

@@ -0,0 +1,31 @@
+using Base;
+
+namespace Model
+{
+	[ObjectEvent]
+	public class RobotComponentEvent : ObjectEvent<RobotComponent>, IAwake
+	{
+		public void Awake()
+		{
+			RobotComponent component = this.GetValue();
+			component.Awake();
+		}
+	}
+
+	public class RobotComponent : Component
+    {
+		public void Awake()
+		{
+		}
+		
+		public override void Dispose()
+		{
+			if (this.Id == 0)
+			{
+				return;
+			}
+
+			base.Dispose();
+		}
+    }
+}

+ 12 - 0
Unity/Assets/Scripts/Component/RobotComponent.cs.meta

@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 8f405bc76c5688946a2a5a0ef526877a
+timeCreated: 1477643346
+licenseType: Pro
+MonoImporter:
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 10 - 2
Unity/Assets/Scripts/Entity/Session.cs

@@ -88,7 +88,7 @@ namespace Model
 			// 普通消息
 			if (rpcId == 0)
 			{
-				Game.Scene.GetComponent<MessageDispatherComponent>().Handle(this, opcode, messageBytes, offset);
+				Game.Scene.GetComponent<MessageDispatherComponent>().Handle(this, opcode, messageBytes, offset, 0);
 				return;
 			}
 
@@ -106,7 +106,7 @@ namespace Model
 			}
 			else // 这是一个rpc请求消息
 			{
-				Game.Scene.GetComponent<MessageDispatherComponent>().HandleRpc(this, opcode, messageBytes, offset, rpcId);
+				Game.Scene.GetComponent<MessageDispatherComponent>().Handle(this, opcode, messageBytes, offset, rpcId);
 			}
 		}
 
@@ -177,11 +177,19 @@ namespace Model
 
 		public void Send<Message>(Message message) where Message : AMessage
 		{
+			if (this.Id == 0)
+			{
+				throw new Exception("session已经被Dispose了");
+			}
 			this.SendMessage(0, message);
 		}
 
 		public void Reply<Response>(uint rpcId, Response message) where Response : AResponse
 		{
+			if (this.Id == 0)
+			{
+				throw new Exception("session已经被Dispose了");
+			}
 			this.SendMessage(rpcId, message, false);
 		}
 

+ 0 - 29
Unity/Assets/Scripts/Message/AMEvent.cs

@@ -1,29 +0,0 @@
-using System;
-using Base;
-
-namespace Model
-{
-	public abstract class AMEvent<Message>: IMRegister where Message: AMessage
-	{
-		protected abstract void Run(Session session, Message message);
-
-		public void Register(IMessageDispather component)
-		{
-			ushort opcode = component.GetOpcode(typeof (Message));
-			component.RegisterHandler<Message>(opcode, Run);
-		}
-	}
-
-	public abstract class AMRpcEvent<Request, Response> : IMRegister
-			where Request : ARequest
-			where Response: AResponse
-	{
-		protected abstract void Run(Session scene, Request message, Action<Response> reply);
-
-		public void Register(IMessageDispather component)
-		{
-			ushort opcode = component.GetOpcode(typeof(Request));
-			component.RegisterRpcHandler<Request, Response>(opcode, Run);
-		}
-	}
-}

+ 64 - 0
Unity/Assets/Scripts/Message/AMHandler.cs

@@ -0,0 +1,64 @@
+using System;
+using Base;
+
+namespace Model
+{
+	public abstract class AMHandler<Message>: IMHandler where Message: AMessage
+	{
+		protected abstract void Run(Session session, Message message);
+		
+		public void Handle(Session session, ushort opcode, MessageInfo messageInfo)
+		{
+			Message message;
+			try
+			{
+				message = MongoHelper.FromBson<Message>(messageInfo.MessageBytes, messageInfo.Offset, messageInfo.Count);
+			}
+			catch (Exception e)
+			{
+				throw new Exception($"解释消息失败: {opcode}", e);
+			}
+
+			this.Run(session, message);
+		}
+
+		public Type GetMessageType()
+		{
+			return typeof (Message);
+		}
+	}
+
+	public abstract class AMRpcHandler<Request, Response> : IMHandler
+			where Request : ARequest
+			where Response: AResponse
+	{
+		protected abstract void Run(Session session, Request message, Action<Response> reply);
+
+		public void Handle(Session session, ushort opcode, MessageInfo messageInfo)
+		{
+			try
+			{
+				Request request = MongoHelper.FromBson<Request>(messageInfo.MessageBytes, messageInfo.Offset, messageInfo.Count);
+				this.Run(session, request, response =>
+					{
+						// 等回调回来,session可以已经断开了,所以需要判断session id是否为0
+						if (session.Id == 0)
+						{
+							return;
+						}
+						session.Reply(messageInfo.RpcId, response);
+					}
+				);
+			}
+			catch (Exception e)
+			{
+				throw new Exception($"解释消息失败: {opcode}", e);
+			}
+		}
+
+		public Type GetMessageType()
+		{
+			return typeof(Request);
+		}
+	}
+}

+ 0 - 0
Unity/Assets/Scripts/Message/AMEvent.cs.meta → Unity/Assets/Scripts/Message/AMHandler.cs.meta


+ 1 - 1
Unity/Assets/Scripts/Message/AppType.cs

@@ -16,7 +16,7 @@ namespace Model
 		Gate = 4,
 		// 7
 		AllServer = Manager | Realm | Gate,
-
+		
 		Client,
 		Robot,
 	}

+ 18 - 0
Unity/Assets/Scripts/Message/IMHandler.cs

@@ -0,0 +1,18 @@
+using System;
+
+namespace Model
+{
+	public class MessageInfo
+	{
+		public byte[] MessageBytes;
+		public int Offset;
+		public int Count;
+		public uint RpcId;
+	}
+
+	public interface IMHandler
+	{
+		void Handle(Session session, ushort opcode, MessageInfo messageInfo);
+		Type GetMessageType();
+	}
+}

+ 0 - 0
Unity/Assets/Scripts/Message/IMRegister.cs.meta → Unity/Assets/Scripts/Message/IMHandler.cs.meta


+ 0 - 21
Unity/Assets/Scripts/Message/IMRegister.cs

@@ -1,21 +0,0 @@
-using System;
-using Model;
-
-namespace Model
-{
-	public interface IMessageDispather
-	{
-		ushort GetOpcode(Type type);
-
-		void RegisterHandler<Message>(ushort opcode, Action<Session, Message> action) where Message : AMessage;
-
-		void RegisterRpcHandler<Request, Response>(ushort opcode, Action<Session, Request, Action<Response>> action) 
-			where Request : ARequest
-			where Response : AResponse;
-	}
-
-	public interface IMRegister
-	{
-		void Register(IMessageDispather messageDispather);
-	}
-}

+ 1 - 1
Unity/Controller/Message/R2C_ServerLogHandler.cs

@@ -4,7 +4,7 @@ using Model;
 namespace Controller
 {
 	[MessageHandler(AppType.Client)]
-	public class R2C_ServerLogHandler: AMEvent<R2C_ServerLog>
+	public class R2C_ServerLogHandler: AMHandler<R2C_ServerLog>
 	{
 		protected override void Run(Session scene, R2C_ServerLog message)
 		{

+ 2 - 5
Unity/Unity.CSharp.Editor.csproj

@@ -13,13 +13,11 @@
     <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
     <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
     <TargetFrameworkProfile>Unity Full v3.5</TargetFrameworkProfile>
-    <CompilerResponseFile>
-    </CompilerResponseFile>
+    <CompilerResponseFile></CompilerResponseFile>
     <UnityProjectType>Editor:5</UnityProjectType>
     <UnityBuildTarget>StandaloneWindows:5</UnityBuildTarget>
     <UnityVersion>5.4.1f1</UnityVersion>
-    <RootNamespace>
-    </RootNamespace>
+    <RootNamespace></RootNamespace>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -126,6 +124,5 @@
     <None Include="Assets\CSharp 6.0 Support\AsyncTools\Plugins\AsyncBridge.Net35.xml" />
     <None Include="Assets\CSharp 6.0 Support\AsyncTools\Plugins\System.Threading.xml" />
   </ItemGroup>
-  <ItemGroup />
   <Import Project="$(MSBuildExtensionsPath)\SyntaxTree\UnityVS\2015\UnityVS.CSharp.targets" />
 </Project>

+ 9 - 8
Unity/Unity.CSharp.csproj

@@ -79,9 +79,10 @@
     </ProjectReference>
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Assets\Scripts\Component\RobotComponent.cs" />
     <Compile Include="Assets\Scripts\Component\ChildrenComponent.cs" />
-    <Compile Include="Assets\Scripts\Component\EventComponent.cs" />
     <Compile Include="Assets\Scripts\Component\ClientConfigComponent.cs" />
+    <Compile Include="Assets\Scripts\Component\EventComponent.cs" />
     <Compile Include="Assets\Scripts\Component\GameObjectComponent.cs" />
     <Compile Include="Assets\Scripts\Component\GlobalConfigComponent.cs" />
     <Compile Include="Assets\Scripts\Component\KVComponent.cs" />
@@ -89,14 +90,14 @@
     <Compile Include="Assets\Scripts\Component\NetInnerComponent.cs" />
     <Compile Include="Assets\Scripts\Component\NetOuterComponent.cs" />
     <Compile Include="Assets\Scripts\Component\NetworkComponent.cs" />
-    <Compile Include="Assets\Scripts\Entity\Game.cs" />
-    <Compile Include="Assets\Scripts\Entity\Session.cs" />
-    <Compile Include="Assets\Scripts\Entity\Scene.cs" />
     <Compile Include="Assets\Scripts\Component\TimeComponent.cs" />
     <Compile Include="Assets\Scripts\Component\TimerComponent.cs" />
-    <Compile Include="Assets\Scripts\Entity\UI.cs" />
     <Compile Include="Assets\Scripts\Config\BuffProto.cs" />
     <Compile Include="Assets\Scripts\Config\GlobalProto.cs" />
+    <Compile Include="Assets\Scripts\Entity\Game.cs" />
+    <Compile Include="Assets\Scripts\Entity\Scene.cs" />
+    <Compile Include="Assets\Scripts\Entity\Session.cs" />
+    <Compile Include="Assets\Scripts\Entity\UI.cs" />
     <Compile Include="Assets\Scripts\Event\AEventAttribute.cs" />
     <Compile Include="Assets\Scripts\Event\Env.cs" />
     <Compile Include="Assets\Scripts\Event\EnvKey.cs" />
@@ -106,11 +107,11 @@
     <Compile Include="Assets\Scripts\GameObjectHelper.cs" />
     <Compile Include="Assets\Scripts\Helper\DllHelper.cs" />
     <Compile Include="Assets\Scripts\Init.cs" />
+    <Compile Include="Assets\Scripts\Message\AMHandler.cs" />
     <Compile Include="Assets\Scripts\Message\AMessage.cs" />
-    <Compile Include="Assets\Scripts\Message\AMEvent.cs" />
     <Compile Include="Assets\Scripts\Message\AppType.cs" />
     <Compile Include="Assets\Scripts\Message\ErrorCode.cs" />
-    <Compile Include="Assets\Scripts\Message\IMRegister.cs" />
+    <Compile Include="Assets\Scripts\Message\IMHandler.cs" />
     <Compile Include="Assets\Scripts\Message\Message.cs" />
     <Compile Include="Assets\Scripts\Message\MessageAttribute.cs" />
     <Compile Include="Assets\Scripts\Message\MessageHandlerAttribute.cs" />
@@ -118,10 +119,10 @@
     <Compile Include="Assets\Scripts\Message\RpcException.cs" />
     <Compile Include="Assets\Scripts\Other\BsonClassMapRegister.cs" />
     <Compile Include="Assets\Scripts\Other\ClientConfig.cs" />
-    <Compile Include="Assets\Scripts\Other\StartConfig.cs" />
     <Compile Include="Assets\Scripts\Other\EntityType.cs" />
     <Compile Include="Assets\Scripts\Other\GameException.cs" />
     <Compile Include="Assets\Scripts\Other\Options.cs" />
+    <Compile Include="Assets\Scripts\Other\StartConfig.cs" />
     <Compile Include="Assets\Scripts\Other\UIType.cs" />
     <Compile Include="Assets\Scripts\ReferenceCollector.cs" />
   </ItemGroup>