tanghai 10 лет назад
Родитель
Сommit
652533c2c8
34 измененных файлов с 297 добавлено и 504 удалено
  1. 4 1
      CSharp/App/Modules/BehaviorTreeModule/BehaviorTreeModule.csproj
  2. 1 0
      CSharp/App/Modules/BehaviorTreeModule/NodeDataEditor.xaml.cs
  3. 0 24
      CSharp/App/Modules/BehaviorTreeModule/NodeType.cs
  4. 1 0
      CSharp/App/Modules/BehaviorTreeModule/NodeTypeColorConverter.cs
  5. 1 0
      CSharp/App/Modules/BehaviorTreeModule/NodeTypeToStringConverter.cs
  6. 1 0
      CSharp/App/Modules/BehaviorTreeModule/TreeView.xaml.cs
  7. 0 6
      CSharp/Game/Controller/Controller.csproj
  8. 1 1
      CSharp/Game/Controller/Event/BuffTimeoutEvent.cs
  9. 0 23
      CSharp/Game/Controller/Event/GateRecvClientMessageEvent.cs
  10. 0 21
      CSharp/Game/Controller/Event/GateRecvServerMessageEvent.cs
  11. 0 22
      CSharp/Game/Controller/Event/LogicRecvClientMessageEvent.cs
  12. 0 31
      CSharp/Game/Controller/Event/LogicRecvRequestMessageEvent.cs
  13. 5 13
      CSharp/Game/Controller/Message/CMsgLoginEvent.cs
  14. 0 65
      CSharp/Game/Controller/MessageParseHelper.cs
  15. 0 9
      CSharp/Game/Controller/NodeType.cs
  16. 2 2
      CSharp/Game/Model/AEventAttribute.cs
  17. 13 16
      CSharp/Game/Model/Actor.cs
  18. 5 5
      CSharp/Game/Model/BehaviorTree/BehaviorTreeFactory.cs
  19. 3 3
      CSharp/Game/Model/BehaviorTree/NodeAttribute.cs
  20. 15 15
      CSharp/Game/Model/Component/EventComponent.cs
  21. 1 1
      CSharp/Game/Model/Component/GateNetworkComponent.cs
  22. 34 65
      CSharp/Game/Model/Component/MessageComponent.cs
  23. 46 76
      CSharp/Game/Model/Component/NetworkComponent.cs
  24. 4 4
      CSharp/Game/Model/Component/TimerComponent.cs
  25. 2 1
      CSharp/Game/Model/EventAttribute.cs
  26. 10 10
      CSharp/Game/Model/EventType.cs
  27. 4 24
      CSharp/Game/Model/GameException.cs
  28. 6 6
      CSharp/Game/Model/IEvent.cs
  29. 29 0
      CSharp/Game/Model/IRegister.cs
  30. 1 7
      CSharp/Game/Model/MessageAttribute.cs
  31. 4 1
      CSharp/Game/Model/Model.csproj
  32. 92 0
      CSharp/Game/Model/NodeType.cs
  33. 12 25
      CSharp/Game/Model/Opcode.cs
  34. 0 27
      CSharp/Platform/UNet/USocket.cs

+ 4 - 1
CSharp/App/Modules/BehaviorTreeModule/BehaviorTreeModule.csproj

@@ -107,7 +107,6 @@
     <Compile Include="NodeDataEditor.xaml.cs">
       <DependentUpon>NodeDataEditor.xaml</DependentUpon>
     </Compile>
-    <Compile Include="NodeType.cs" />
     <Compile Include="TreeNodeViewModel.cs" />
   </ItemGroup>
   <ItemGroup>
@@ -132,6 +131,10 @@
     </Page>
   </ItemGroup>
   <ItemGroup>
+    <ProjectReference Include="..\..\..\Game\Model\Model.csproj">
+      <Project>{0608c0c1-f584-4092-aaf9-1e99a78e3703}</Project>
+      <Name>Model</Name>
+    </ProjectReference>
     <ProjectReference Include="..\..\..\Platform\Common\Common.csproj">
       <Project>{f06b995e-6508-4c5c-a396-554316c9215d}</Project>
       <Name>Common</Name>

+ 1 - 0
CSharp/App/Modules/BehaviorTreeModule/NodeDataEditor.xaml.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Windows;
 using System.Windows.Controls;
+using Model;
 
 namespace Modules.BehaviorTreeModule
 {

+ 0 - 24
CSharp/App/Modules/BehaviorTreeModule/NodeType.cs

@@ -1,24 +0,0 @@
-namespace Modules.BehaviorTreeModule
-{
-	public enum NodeType
-	{
-		Selector = 1,
-		Sequence = 2,
-		Not = 10,
-		Weight = 11,
-		True = 12,
-
-		MoveToTarget = 100,
-		Desdroy = 101,
-		DistanceWithTarget = 102,
-
-		PlayMotion = 210,
-		ApplyCloak = 211,
-		CancelCloak = 212,
-		ChangeModel = 213,
-		RevertModel = 214,
-		ChangeMaterial = 215,
-		RevertMaterial = 216,
-		CreateEffect = 219,
-	}
-}

+ 1 - 0
CSharp/App/Modules/BehaviorTreeModule/NodeTypeColorConverter.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Globalization;
 using System.Windows.Data;
+using Model;
 
 namespace Modules.BehaviorTreeModule
 {

+ 1 - 0
CSharp/App/Modules/BehaviorTreeModule/NodeTypeToStringConverter.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Globalization;
 using System.Windows.Data;
+using Model;
 
 namespace Modules.BehaviorTreeModule
 {

+ 1 - 0
CSharp/App/Modules/BehaviorTreeModule/TreeView.xaml.cs

@@ -2,6 +2,7 @@
 using System.Windows;
 using System.Windows.Input;
 using Common.Logger;
+using Model;
 
 namespace Modules.BehaviorTreeModule
 {

+ 0 - 6
CSharp/Game/Controller/Controller.csproj

@@ -48,14 +48,8 @@
     <Compile Include="ConfigCategory\NodeCategory.cs" />
     <Compile Include="ConfigCategory\ServerInfoCategory.cs" />
     <Compile Include="ConfigCategory\UnitCategory.cs" />
-    <Compile Include="Event\GateRecvServerMessageEvent.cs" />
-    <Compile Include="Event\LogicRecvRequestMessageEvent.cs" />
-    <Compile Include="Event\LogicRecvClientMessageEvent.cs" />
-    <Compile Include="Event\GateRecvClientMessageEvent.cs" />
     <Compile Include="Factory\UnitPlayerFactory.cs" />
-    <Compile Include="MessageParseHelper.cs" />
     <Compile Include="Message\CMsgLoginEvent.cs" />
-    <Compile Include="NodeType.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>

+ 1 - 1
CSharp/Game/Controller/Event/BuffTimeoutEvent.cs

@@ -4,7 +4,7 @@ using MongoDB.Bson;
 namespace Controller
 {
 	[Event(EventType.BuffTimeout, ServerType.City)]
-	public class BuffTimeoutEvent: IEventSync
+	public class BuffTimeoutEvent: IEvent
 	{
 		public void Run(Env env)
 		{

+ 0 - 23
CSharp/Game/Controller/Event/GateRecvClientMessageEvent.cs

@@ -1,23 +0,0 @@
-using Common.Network;
-using Model;
-
-namespace Controller
-{
-	[Event(EventType.GateRecvClientMessage, ServerType.Gate)]
-	public class GateRecvClientMessageEvent: IEventSync
-	{
-		public void Run(Env env)
-		{
-			byte[] messageBytes = env.Get<byte[]>(EnvKey.MessageBytes);
-			AChannel channel = env.Get<AChannel>(EnvKey.Channel);
-
-			// 进行消息分发
-			ChannelUnitInfoComponent channelUnitInfoComponent =
-					channel.GetComponent<ChannelUnitInfoComponent>();
-			byte[] bytes = MessageParseHelper.ClientToGateMessageChangeToLogicMessage(messageBytes,
-					channelUnitInfoComponent.UnitId);
-			string address = AddressHelper.GetAddressByServerName(channelUnitInfoComponent.ServerName);
-			World.Instance.GetComponent<NetworkComponent>().SendAsync(address, bytes);
-		}
-	}
-}

+ 0 - 21
CSharp/Game/Controller/Event/GateRecvServerMessageEvent.cs

@@ -1,21 +0,0 @@
-using System;
-using Model;
-using MongoDB.Bson;
-
-namespace Controller
-{
-	[Event(EventType.GateRecvServerMessage, ServerType.Gate)]
-	public class GateRecvServerMessageEvent: IEventSync
-	{
-		public void Run(Env env)
-		{
-			byte[] messageBytes = env.Get<byte[]>(EnvKey.MessageBytes);
-			byte[] idBuffer = new byte[12];
-			Array.Copy(messageBytes, 2, idBuffer, 0, 12);
-			ObjectId unitId = new ObjectId(idBuffer);
-
-			byte[] buffer = MessageParseHelper.LogicToGateMessageChangeToClientMessage(messageBytes);
-			World.Instance.GetComponent<GateNetworkComponent>().SendAsync(unitId, buffer);
-		}
-	}
-}

+ 0 - 22
CSharp/Game/Controller/Event/LogicRecvClientMessageEvent.cs

@@ -1,22 +0,0 @@
-using Model;
-using MongoDB.Bson;
-
-namespace Controller
-{
-	[Event(EventType.LogicRecvClientMessage, ServerType.All)]
-	public class LogicRecvClientMessageEvent: IEventSync
-	{
-		public void Run(Env env)
-		{
-			byte[] messageBytes = env.Get<byte[]>(EnvKey.MessageBytes);
-			// 如果是客户端消息,转交给unit actor处理
-			MessageParseHelper.LogicParseClientToGateToLogicMessage(messageBytes, env);
-			ObjectId unitId = env.Get<ObjectId>(EnvKey.MessageUnitId);
-			Actor actor = World.Instance.GetComponent<ActorComponent>().Get(unitId);
-			if (actor != null)
-			{
-				actor.Add(env);
-			}
-		}
-	}
-}

+ 0 - 31
CSharp/Game/Controller/Event/LogicRecvRequestMessageEvent.cs

@@ -1,31 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using Common.Network;
-using Model;
-
-namespace Controller
-{
-	[Event(EventType.LogicRecvRequestMessage, ServerType.All)]
-	public class LogicRecvRequestMessageEvent : IEventAsync
-	{
-		public async Task RunAsync(Env env)
-		{
-			byte[] messageBytes = env.Get<byte[]>(EnvKey.MessageBytes);
-			AChannel channel = env.Get<AChannel>(EnvKey.Channel);
-			ushort opcode = env.Get<ushort>(EnvKey.Opcode);
-
-			MessageParseHelper.LogicParseRpcRequestMessage(messageBytes, env);
-			
-			try
-			{
-				await World.Instance.GetComponent<MessageComponent>().RunAsync(opcode, env);
-			}
-			catch (Exception e)
-			{
-				int requestId = env.Get<int>(EnvKey.RpcRequestId);
-				World.Instance.GetComponent<NetworkComponent>().RpcException(channel, requestId, e);
-				throw;
-			}
-		}
-	}
-}

+ 5 - 13
CSharp/Game/Controller/Message/CMsgLoginEvent.cs

@@ -1,4 +1,4 @@
-using Common.Network;
+using System.Threading.Tasks;
 using Model;
 
 namespace Controller
@@ -9,20 +9,12 @@ namespace Controller
 		public byte[] PassMd5 { get; set; }
 	}
 
-	[Message(Opcode.CMsgLogin, typeof(CMsgLogin), ServerType.Gate)]
-	internal class CMsgLoginEvent: IEventSync
+	[Message(ServerType.Gate)]
+	internal class CMsgLoginEvent : MEvent<CMsgLogin, Task<bool>>
 	{
-		public void Run(Env env)
+		public override async Task<bool> Run(CMsgLogin msg)
 		{
-			CMsgLogin cmsg = env.Get<CMsgLogin>(EnvKey.Message);
-			Unit unit = World.Instance.GetComponent<FactoryComponent<Unit>>().Create(UnitType.GatePlayer, 1);
-
-			AChannel channel = env.Get<AChannel>(EnvKey.Channel);
-			ChannelUnitInfoComponent channelUnitInfoComponent =
-					channel.AddComponent<ChannelUnitInfoComponent>();
-			channelUnitInfoComponent.Account = cmsg.Account;
-			channelUnitInfoComponent.UnitId = unit.Id;
-			World.Instance.GetComponent<GateNetworkComponent>().AssociateUnitIdAndChannel(unit.Id, channel);
+			return true;
 		}
 	}
 }

+ 0 - 65
CSharp/Game/Controller/MessageParseHelper.cs

@@ -1,65 +0,0 @@
-using System;
-using Common.Helper;
-using Model;
-using MongoDB.Bson;
-
-namespace Controller
-{
-	public static class MessageParseHelper
-	{
-		public static void LogicParseClientToGateToLogicMessage(byte[] message, Env env)
-		{
-			ushort opcode = BitConverter.ToUInt16(message, 0);
-			env[EnvKey.Opcode] = opcode;
-			byte[] bytes = new byte[12];
-			Array.Copy(message, 2, bytes, 0, 12);
-			env[EnvKey.MessageUnitId] = new ObjectId(bytes);
-			Type messageType =
-					World.Instance.GetComponent<MessageComponent>().GetClassType(opcode);
-			env[EnvKey.Message] = MongoHelper.FromBson(messageType, message, 14, message.Length - 14);
-		}
-
-		public static void GateParseClientToGateMessage(byte[] message, Env env)
-		{
-			ushort opcode = BitConverter.ToUInt16(message, 0);
-			env[EnvKey.Opcode] = opcode;
-			Type messageType =
-					World.Instance.GetComponent<MessageComponent>().GetClassType(opcode);
-			env[EnvKey.Message] = MongoHelper.FromBson(messageType, message, 2, message.Length - 2);
-		}
-
-		public static void LogicParseRpcRequestMessage(byte[] message, Env env)
-		{
-			ushort opcode = BitConverter.ToUInt16(message, 0);
-			int requestId = BitConverter.ToInt32(message, 2);
-			env[EnvKey.Opcode] = opcode;
-			env[EnvKey.RpcRequestId] = requestId;
-			Type messageType = World.Instance.GetComponent<MessageComponent>().GetClassType(opcode);
-			env[EnvKey.Message] = MongoHelper.FromBson(messageType, message, 2, message.Length - 2);
-		}
-
-		/// <summary>
-		/// 客户端的消息经gate转发给logic server需要在协议中插入unitid
-		/// </summary>
-		public static byte[] ClientToGateMessageChangeToLogicMessage(byte[] messageBytes, ObjectId id)
-		{
-			byte[] idBuffer = id.ToByteArray();
-			byte[] buffer = new byte[messageBytes.Length + 12];
-			Array.Copy(messageBytes, 0, buffer, 0, 2);
-			Array.Copy(idBuffer, 0, buffer, 2, idBuffer.Length);
-			Array.Copy(messageBytes, 2, buffer, 14, messageBytes.Length - 2);
-			return buffer;
-		}
-
-		/// <summary>
-		/// Logic的消息经gate转发给client,需要在协议中删除unitid
-		/// </summary>
-		public static byte[] LogicToGateMessageChangeToClientMessage(byte[] messageBytes)
-		{
-			byte[] buffer = new byte[messageBytes.Length - 12];
-			Array.Copy(messageBytes, 0, buffer, 0, 2);
-			Array.Copy(messageBytes, 14, buffer, 2, messageBytes.Length - 14);
-			return buffer;
-		}
-	}
-}

+ 0 - 9
CSharp/Game/Controller/NodeType.cs

@@ -1,9 +0,0 @@
-namespace Controller
-{
-	public static class NodeType
-	{
-		public const int Selector = 1;
-		public const int Sequence = 2;
-		public const int Not = 10;
-	}
-}

+ 2 - 2
CSharp/Game/Model/AEventAttribute.cs

@@ -5,11 +5,11 @@ namespace Model
 	[AttributeUsage(AttributeTargets.Class)]
 	public abstract class AEventAttribute: Attribute
 	{
-		public int Type { get; private set; }
+		public EventType Type { get; private set; }
 
 		private ServerType ServerType { get; set; }
 
-		protected AEventAttribute(int type, ServerType serverType)
+		protected AEventAttribute(EventType type, ServerType serverType)
 		{
 			this.Type = type;
 			this.ServerType = serverType;

+ 13 - 16
CSharp/Game/Model/Actor.cs

@@ -9,12 +9,10 @@ namespace Model
 {
 	public class Actor : Entity<Unit>, IDisposable
 	{
-		private readonly Queue<Env> msgEnvQueue = new Queue<Env>();
+		private readonly Queue<byte[]> msgQueue = new Queue<byte[]>();
 
 		private Action msgAction = () => { };
-
-		private Env Env { get; set; }
-
+		
 		private bool isStop;
 
 		public Actor(ObjectId id): base(id)
@@ -28,10 +26,9 @@ namespace Model
 			{
 				try
 				{
-					Env env = await this.Get();
-					this.Env = env;
-					ushort opcode = env.Get<ushort>(EnvKey.Opcode);
-					await World.Instance.GetComponent<MessageComponent>().RunAsync(opcode, env);
+					byte[] messageBytes = await this.Get();
+					Opcode opcode = (Opcode)BitConverter.ToUInt16(messageBytes, 0);
+					await World.Instance.GetComponent<MessageComponent>().RunAsync(opcode, messageBytes);
 				}
 				catch (Exception e)
 				{
@@ -40,26 +37,26 @@ namespace Model
 			}
 		}
 
-		public void Add(Env msgEnv)
+		public void Add(byte[] msg)
 		{
-			this.msgEnvQueue.Enqueue(msgEnv);
+			this.msgQueue.Enqueue(msg);
 			this.msgAction();
 		}
 
-		private Task<Env> Get()
+		private Task<byte[]> Get()
 		{
-			var tcs = new TaskCompletionSource<Env>();
-			if (this.msgEnvQueue.Count > 0)
+			var tcs = new TaskCompletionSource<byte[]>();
+			if (this.msgQueue.Count > 0)
 			{
-				Env env = this.msgEnvQueue.Dequeue();
-				tcs.SetResult(env);
+				byte[] messageBytes = this.msgQueue.Dequeue();
+				tcs.SetResult(messageBytes);
 			}
 			else
 			{
 				this.msgAction = () =>
 				{
 					this.msgAction = () => { };
-					Env msg = this.msgEnvQueue.Dequeue();
+					byte[] msg = this.msgQueue.Dequeue();
 					tcs.SetResult(msg);
 				};
 			}

+ 5 - 5
CSharp/Game/Model/BehaviorTree/BehaviorTreeFactory.cs

@@ -16,7 +16,7 @@ namespace Model
 			}
 		}
 
-		private Dictionary<int, Func<NodeConfig, Node>> dictionary;
+		private Dictionary<NodeType, Func<NodeConfig, Node>> dictionary;
 
 		private BehaviorTreeFactory()
 		{
@@ -24,7 +24,7 @@ namespace Model
 
 		public void Load(Assembly assembly)
 		{
-			this.dictionary = new Dictionary<int, Func<NodeConfig, Node>>();
+			this.dictionary = new Dictionary<NodeType, Func<NodeConfig, Node>>();
 
 			Type[] types = assembly.GetTypes();
 			foreach (var type in types)
@@ -37,18 +37,18 @@ namespace Model
 				NodeAttribute attribute = (NodeAttribute) attrs[0];
 
 				Type classType = type;
-				this.dictionary.Add(attribute.NodeType,
+				this.dictionary.Add(attribute.Type,
 						config => (Node) Activator.CreateInstance(classType, new object[] { config }));
 			}
 		}
 
 		private Node CreateNode(NodeConfig config)
 		{
-			if (!this.dictionary.ContainsKey(config.Id))
+			if (!this.dictionary.ContainsKey((NodeType)config.Id))
 			{
 				throw new KeyNotFoundException(string.Format("CreateNode cannot found: {0}", config.Id));
 			}
-			return this.dictionary[config.Id](config);
+			return this.dictionary[(NodeType)config.Id](config);
 		}
 
 		private Node CreateTreeNode(NodeConfig config)

+ 3 - 3
CSharp/Game/Model/BehaviorTree/NodeAttribute.cs

@@ -5,11 +5,11 @@ namespace Model
 	[AttributeUsage(AttributeTargets.Class)]
 	public class NodeAttribute: Attribute
 	{
-		public int NodeType { get; private set; }
+		public NodeType Type { get; private set; }
 
-		public NodeAttribute(int nodeType)
+		public NodeAttribute(NodeType nodeType)
 		{
-			this.NodeType = nodeType;
+			this.Type = nodeType;
 		}
 	}
 }

+ 15 - 15
CSharp/Game/Model/Component/EventComponent.cs

@@ -9,13 +9,13 @@ namespace Model
 	public class EventComponent<AttributeType>: Component<World>, IAssemblyLoader
 			where AttributeType : AEventAttribute
 	{
-		private Dictionary<int, List<IEventSync>> eventSyncs;
-		private Dictionary<int, List<IEventAsync>> eventAsyncs;
+		private Dictionary<EventType, List<IEvent>> eventSyncs;
+		private Dictionary<EventType, List<IEventAsync>> eventAsyncs;
 
 		public void Load(Assembly assembly)
 		{
-			this.eventSyncs = new Dictionary<int, List<IEventSync>>();
-			this.eventAsyncs = new Dictionary<int, List<IEventAsync>>();
+			this.eventSyncs = new Dictionary<EventType, List<IEvent>>();
+			this.eventAsyncs = new Dictionary<EventType, List<IEventAsync>>();
 
 			ServerType serverType = World.Instance.Options.ServerType;
 
@@ -35,14 +35,14 @@ namespace Model
 				}
 
 				object obj = Activator.CreateInstance(t);
-				IEventSync iEventSync = obj as IEventSync;
-				if (iEventSync != null)
+				IEvent iEvent = obj as IEvent;
+				if (iEvent != null)
 				{
 					if (!this.eventSyncs.ContainsKey(aEventAttribute.Type))
 					{
-						this.eventSyncs.Add(aEventAttribute.Type, new List<IEventSync>());
+						this.eventSyncs.Add(aEventAttribute.Type, new List<IEvent>());
 					}
-					this.eventSyncs[aEventAttribute.Type].Add(iEventSync);
+					this.eventSyncs[aEventAttribute.Type].Add(iEvent);
 					continue;
 				}
 
@@ -58,29 +58,29 @@ namespace Model
 					continue;
 				}
 
-				throw new Exception(string.Format("event not inherit IEventSync or IEventAsync interface: {0}",
+				throw new Exception(string.Format("event not inherit IEvent or IEventAsync interface: {0}",
 						obj.GetType().FullName));
 			}
 		}
 
-		public void Run(int type, Env env)
+		public void Run(EventType type, Env env)
 		{
-			List<IEventSync> iEventSyncs = null;
+			List<IEvent> iEventSyncs = null;
 			if (!this.eventSyncs.TryGetValue(type, out iEventSyncs))
 			{
 				throw new Exception(string.Format("no event handler, AttributeType: {0} type: {1}",
 						typeof (AttributeType).Name, type));
 			}
 
-			foreach (IEventSync iEventSync in iEventSyncs)
+			foreach (IEvent iEventSync in iEventSyncs)
 			{
 				iEventSync.Run(env);
 			}
 		}
 
-		public async Task RunAsync(int type, Env env)
+		public async Task RunAsync(EventType type, Env env)
 		{
-			List<IEventSync> iEventSyncs = null;
+			List<IEvent> iEventSyncs = null;
 			this.eventSyncs.TryGetValue(type, out iEventSyncs);
 
 			List<IEventAsync> iEventAsyncs = null;
@@ -94,7 +94,7 @@ namespace Model
 
 			if (iEventSyncs != null)
 			{
-				foreach (IEventSync iEventSync in iEventSyncs)
+				foreach (IEvent iEventSync in iEventSyncs)
 				{
 					iEventSync.Run(env);
 				}

+ 1 - 1
CSharp/Game/Model/Component/GateNetworkComponent.cs

@@ -71,7 +71,7 @@ namespace Model
 				Env env = new Env();
 				env[EnvKey.Channel] = channel;
 				env[EnvKey.MessageBytes] = messageBytes;
-				ushort opcode = BitConverter.ToUInt16(messageBytes, 0);
+				Opcode opcode = (Opcode)BitConverter.ToUInt16(messageBytes, 0);
 				env[EnvKey.Opcode] = opcode;
 				if (!MessageTypeHelper.IsClientMessage(opcode))
 				{

+ 34 - 65
CSharp/Game/Model/Component/MessageComponent.cs

@@ -3,20 +3,19 @@ using System.Collections.Generic;
 using System.Reflection;
 using System.Threading.Tasks;
 using Common.Base;
+using Common.Helper;
 
 namespace Model
 {
 	public class MessageComponent: Component<World>, IAssemblyLoader
 	{
-		private Dictionary<ushort, List<IEventSync>> eventSyncs;
-		private Dictionary<ushort, List<IEventAsync>> eventAsyncs;
-		private Dictionary<ushort, Type> typeClassType;
+		private Dictionary<Opcode, Func<byte[], byte[]>> events;
+		private Dictionary<Opcode, Func<byte[], Task<byte[]>>> eventsAsync;
 
 		public void Load(Assembly assembly)
 		{
-			this.eventSyncs = new Dictionary<ushort, List<IEventSync>>();
-			this.eventAsyncs = new Dictionary<ushort, List<IEventAsync>>();
-			this.typeClassType = new Dictionary<ushort, Type>();
+			this.events = new Dictionary<Opcode, Func<byte[], byte[]>>();
+			this.eventsAsync = new Dictionary<Opcode, Func<byte[], Task<byte[]>>>();
 
 			ServerType serverType = World.Instance.Options.ServerType;
 
@@ -34,87 +33,57 @@ namespace Model
 				{
 					continue;
 				}
-
-				this.typeClassType[messageAttribute.Opcode] = messageAttribute.ClassType;
-
+				
 				object obj = Activator.CreateInstance(t);
 
-				IEventSync iEventSync = obj as IEventSync;
-				if (iEventSync != null)
+				IRegister iRegister = obj as IRegister;
+				if (iRegister != null)
 				{
-					if (!this.eventSyncs.ContainsKey(messageAttribute.Opcode))
-					{
-						this.eventSyncs.Add(messageAttribute.Opcode, new List<IEventSync>());
-					}
-					this.eventSyncs[messageAttribute.Opcode].Add(iEventSync);
-					continue;
+					iRegister.Register();
 				}
 
-				IEventAsync iEventAsync = obj as IEventAsync;
-				if (iEventAsync != null)
-				{
-					if (!this.eventAsyncs.ContainsKey(messageAttribute.Opcode))
-					{
-						this.eventAsyncs.Add(messageAttribute.Opcode, new List<IEventAsync>());
-					}
-					this.eventAsyncs[messageAttribute.Opcode].Add(iEventAsync);
-					continue;
-				}
-
-				throw new Exception(string.Format("message handler not inherit IEventSync or IEventAsync interface: {0}",
+				throw new Exception(
+					string.Format("message handler not inherit IRegister interface: {0}", 
 						obj.GetType().FullName));
 			}
 		}
 
-		public Type GetClassType(ushort opcode)
+		public void Register<T, R>(Func<T, R> func)
 		{
-			return this.typeClassType[opcode];
+			Opcode opcode = (Opcode) Enum.Parse(typeof (Opcode), typeof (T).Name);
+			events.Add(opcode, messageBytes =>
+			{
+				T t = MongoHelper.FromBson<T>(messageBytes, 6);
+				R k = func(t);
+				return MongoHelper.ToBson(k);
+			});
 		}
 
-		public void Run(ushort opcode, Env env)
+		public void RegisterAsync<T, R>(Func<T, Task<R>> func)
 		{
-			List<IEventSync> iEventSyncs = null;
-			if (!this.eventSyncs.TryGetValue(opcode, out iEventSyncs))
-			{
-				throw new Exception(string.Format("no message handler, MessageAttribute: {0} opcode: {1}",
-						typeof(MessageAttribute).Name, opcode));
-			}
-
-			foreach (IEventSync iEventSync in iEventSyncs)
+			Opcode opcode = (Opcode)Enum.Parse(typeof(Opcode), typeof(T).Name);
+			eventsAsync.Add(opcode, async messageBytes =>
 			{
-				iEventSync.Run(env);
-			}
+				T t = MongoHelper.FromBson<T>(messageBytes, 6);
+				R r = await func(t);
+				return MongoHelper.ToBson(r);
+			});
 		}
 
-		public async Task RunAsync(ushort opcode, Env env)
+		public async Task<byte[]> RunAsync(Opcode opcode, byte[] messageBytes)
 		{
-			List<IEventSync> iEventSyncs = null;
-			this.eventSyncs.TryGetValue(opcode, out iEventSyncs);
-
-			List<IEventAsync> iEventAsyncs = null;
-			this.eventAsyncs.TryGetValue(opcode, out iEventAsyncs);
-
-			if (iEventSyncs == null && iEventAsyncs == null)
-			{
-				throw new Exception(string.Format("no message handler, MessageAttribute: {0} opcode: {1}",
-						typeof(MessageAttribute).Name, opcode));
-			}
-
-			if (iEventSyncs != null)
+			Func<byte[], byte[]> func = null;
+			if (this.events.TryGetValue(opcode, out func))
 			{
-				foreach (IEventSync iEventSync in iEventSyncs)
-				{
-					iEventSync.Run(env);
-				}
+				return func(messageBytes);
 			}
 
-			if (iEventAsyncs != null)
+			Func<byte[], Task<byte[]>> funcAsync = null;
+			if (this.eventsAsync.TryGetValue(opcode, out funcAsync))
 			{
-				foreach (IEventAsync iEventAsync in iEventAsyncs)
-				{
-					await iEventAsync.RunAsync(env);
-				}
+				return await funcAsync(messageBytes);
 			}
+			throw new GameException(string.Format("not found opcode handler: {0}", opcode));
 		}
 	}
 }

+ 46 - 76
CSharp/Game/Model/Component/NetworkComponent.cs

@@ -7,6 +7,7 @@ using System.Threading.Tasks;
 using Common.Base;
 using Common.Helper;
 using Common.Network;
+using MongoDB.Bson;
 using TNet;
 using UNet;
 
@@ -88,73 +89,67 @@ namespace Model
 		{
 			while (true)
 			{
-				byte[] message = await channel.RecvAsync();
-				Env env = new Env();
-				env[EnvKey.Channel] = channel;
-				env[EnvKey.Message] = message;
-				ushort opcode = BitConverter.ToUInt16(message, 0);
-				env[EnvKey.Opcode] = opcode;
-
-				// 表示消息是rpc响应消息
-				if (opcode == Opcode.RpcResponse)
-				{
-					int id = BitConverter.ToInt32(message, 2);
-					this.RequestCallback(channel, id, message, RpcResponseStatus.Succee);
-					continue;
-				}
+				byte[] messageBytes = await channel.RecvAsync();
+				Opcode opcode = (Opcode)BitConverter.ToUInt16(messageBytes, 0);
 
 				// rpc异常
 				if (opcode == Opcode.RpcException)
 				{
-					int id = BitConverter.ToInt32(message, 2);
-					this.RequestCallback(channel, id, message, RpcResponseStatus.Exception);
+					int id = BitConverter.ToInt32(messageBytes, 2);
+					this.RpcCallback(channel, id, messageBytes, RpcResponseStatus.Exception);
 					continue;
 				}
 
-				// 如果是server message(发给client的消息),说明这是gate server,需要根据unitid查到channel,进行发送
-				if (MessageTypeHelper.IsServerMessage(opcode))
+				// 表示消息是rpc响应消息
+				if (opcode == Opcode.RpcResponse)
 				{
-#pragma warning disable 4014
-					World.Instance.GetComponent<EventComponent<EventAttribute>>()
-							.RunAsync(EventType.GateRecvServerMessage, env);
-#pragma warning restore 4014
+					int id = BitConverter.ToInt32(messageBytes, 2);
+					this.RpcCallback(channel, id, messageBytes, RpcResponseStatus.Succee);
 					continue;
 				}
 
-				// 进行消息分
-				if (MessageTypeHelper.IsClientMessage(opcode))
+				// 如果是server message(发给client的消息),说明这是gate server,需要根据unitid查到channel,进行发
+				if (MessageTypeHelper.IsServerMessage(opcode))
 				{
-#pragma warning disable 4014
-					World.Instance.GetComponent<EventComponent<EventAttribute>>()
-							.RunAsync(EventType.LogicRecvClientMessage, env);
-#pragma warning restore 4014
+					byte[] idBuffer = new byte[12];
+					Array.Copy(messageBytes, 2, idBuffer, 0, 12);
+					ObjectId unitId = new ObjectId(idBuffer);
+					byte[] buffer = new byte[messageBytes.Length - 6];
+					Array.Copy(messageBytes, 6, buffer, 0, buffer.Length);
+					World.Instance.GetComponent<GateNetworkComponent>().SendAsync(unitId, buffer);
 					continue;
 				}
 
-				if (MessageTypeHelper.IsRpcRequestMessage(opcode))
-				{
-#pragma warning disable 4014
-					World.Instance.GetComponent<EventComponent<EventAttribute>>()
-							.RunAsync(EventType.LogicRecvRequestMessage, env);
-#pragma warning restore 4014
-				}
+				// 处理Rpc请求,并且返回结果
+				RpcDo(channel, opcode, messageBytes);
 			}
 		}
 
-		public void SendAsync(string address, byte[] buffer)
-		{
-			AChannel channel = this.service.GetChannel(address);
-			channel.SendAsync(buffer);
-		}
-
-		public void SendAsync(string address, List<byte[]> buffers)
+		private async static void RpcDo(AChannel channel, Opcode opcode, byte[] messageBytes)
 		{
-			AChannel channel = this.service.GetChannel(address);
-			channel.SendAsync(buffers);
+			byte[] opcodeBuffer;
+			int id = BitConverter.ToInt32(messageBytes, 2);
+			byte[] idBuffer = BitConverter.GetBytes(id);
+			try
+			{
+				opcodeBuffer = BitConverter.GetBytes((ushort)Opcode.RpcResponse);
+				byte[] result = await World.Instance.GetComponent<MessageComponent>().RunAsync(opcode, messageBytes);
+				channel.SendAsync(new List<byte[]> { opcodeBuffer, idBuffer, result });
+			}
+			catch (Exception e)
+			{
+				opcodeBuffer = BitConverter.GetBytes((ushort)Opcode.RpcException);
+				BinaryFormatter formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.All));
+				using (MemoryStream stream = new MemoryStream())
+				{
+					formatter.Serialize(stream, e);
+					channel.SendAsync(new List<byte[]> { opcodeBuffer, idBuffer, stream.ToArray() });
+				}
+			}
 		}
 
 		// 消息回调或者超时回调
-		public void RequestCallback(AChannel channel, int id, byte[] buffer, RpcResponseStatus responseStatus)
+		public void RpcCallback(AChannel channel, int id, byte[] buffer, RpcResponseStatus responseStatus)
 		{
 			Action<byte[], RpcResponseStatus> action;
 			if (!this.requestCallback.TryGetValue(id, out action))
@@ -168,22 +163,23 @@ namespace Model
 		/// <summary>
 		/// Rpc请求
 		/// </summary>
-		public Task<T> RpcRequest<T, K>(string address, short type, K request, int waitTime = 0)
+		public Task<T> RpcCall<T, K>(string address, K request, int waitTime = 0)
 		{
 			AChannel channel = this.service.GetChannel(address);
 
 			++this.requestId;
 			byte[] requestBuffer = MongoHelper.ToBson(request);
-			byte[] typeBuffer = BitConverter.GetBytes(type);
+			Opcode opcode = (Opcode)Enum.Parse(typeof(Opcode), request.GetType().Name);
+			byte[] opcodeBuffer = BitConverter.GetBytes((ushort)opcode);
 			byte[] idBuffer = BitConverter.GetBytes(this.requestId);
-			channel.SendAsync(new List<byte[]> { typeBuffer, idBuffer, requestBuffer });
+			channel.SendAsync(new List<byte[]> { opcodeBuffer, idBuffer, requestBuffer });
 			var tcs = new TaskCompletionSource<T>();
 			this.requestCallback[this.requestId] = (messageBytes, status) =>
 			{
 				if (status == RpcResponseStatus.Timeout)
 				{
 					tcs.SetException(new Exception(
-						string.Format("rpc timeout {0} {1}", type, MongoHelper.ToJson(request))));
+						string.Format("rpc timeout {0} {1}", opcode, MongoHelper.ToJson(request))));
 					return;
 				}
 				if (status == RpcResponseStatus.Exception)
@@ -207,35 +203,9 @@ namespace Model
 			if (waitTime > 0)
 			{
 				this.service.Timer.Add(TimeHelper.Now() + waitTime,
-						() => { this.RequestCallback(channel, this.requestId, null, RpcResponseStatus.Timeout); });
+						() => { this.RpcCallback(channel, this.requestId, null, RpcResponseStatus.Timeout); });
 			}
 			return tcs.Task;
 		}
-
-		/// <summary>
-		/// Rpc响应
-		/// </summary>
-		public void RpcResponse<T>(AChannel channel, int id, T response)
-		{
-			byte[] responseBuffer = MongoHelper.ToBson(response);
-			byte[] typeBuffer = BitConverter.GetBytes(Opcode.RpcResponse);
-			byte[] idBuffer = BitConverter.GetBytes(id);
-			channel.SendAsync(new List<byte[]> { typeBuffer, idBuffer, responseBuffer });
-		}
-
-		/// <summary>
-		/// Rpc响应
-		/// </summary>
-		public void RpcException(AChannel channel, int id, Exception e)
-		{
-			byte[] opcodeBuffer = BitConverter.GetBytes(Opcode.RpcException);
-			byte[] idBuffer = BitConverter.GetBytes(id);
-			BinaryFormatter formatter = new BinaryFormatter(null, new StreamingContext(StreamingContextStates.All));
-			using (MemoryStream stream = new MemoryStream())
-			{
-				formatter.Serialize(stream, e);
-				channel.SendAsync(new List<byte[]> { opcodeBuffer, idBuffer, stream.ToArray() });
-			}
-		}
 	}
 }

+ 4 - 4
CSharp/Game/Model/Component/TimerComponent.cs

@@ -11,7 +11,7 @@ namespace Model
 		{
 			public ObjectId Id { get; set; }
 			public long Time { get; set; }
-			public int CallbackId { get; set; }
+			public EventType CallbackEvent { get; set; }
 			public Env Env { get; set; }
 		}
 
@@ -24,13 +24,13 @@ namespace Model
 
 		private readonly Queue<long> timeoutTimer = new Queue<long>();
 
-		public ObjectId Add(long time, int callbackId, Env env)
+		public ObjectId Add(long time, EventType callbackEvent, Env env)
 		{
 			Timer timer = new Timer
 			{
 				Id = ObjectId.GenerateNewId(),
 				Time = time,
-				CallbackId = callbackId,
+				CallbackEvent = callbackEvent,
 				Env = env
 			};
 			this.timers[timer.Id] = timer;
@@ -72,7 +72,7 @@ namespace Model
 						continue;
 					}
 					this.Remove(id);
-					World.Instance.GetComponent<EventComponent<EventAttribute>>().Run(timer.CallbackId, timer.Env);
+					World.Instance.GetComponent<EventComponent<EventAttribute>>().Run(timer.CallbackEvent, timer.Env);
 				}
 			}
 		}

+ 2 - 1
CSharp/Game/Model/EventAttribute.cs

@@ -2,7 +2,8 @@
 {
 	public class EventAttribute: AEventAttribute
 	{
-		public EventAttribute(int type, ServerType serverType): base(type, serverType)
+		public EventAttribute(EventType type, ServerType serverType)
+			: base(type, serverType)
 		{
 		}
 	}

+ 10 - 10
CSharp/Game/Model/EventType.cs

@@ -1,15 +1,15 @@
 namespace Model
 {
-	public static class EventType
+	public enum EventType
 	{
-		public const int BeforeAddBuff = 0;
-		public const int AfterAddBuff = 1;
-		public const int BeforeRemoveBuff = 2;
-		public const int AfterRemoveBuff = 3;
-		public const int BuffTimeout = 4;
-		public const int LogicRecvClientMessage = 5;
-		public const int LogicRecvRequestMessage = 6;
-		public const int GateRecvClientMessage = 7;
-		public const int GateRecvServerMessage = 8;
+		BeforeAddBuff = 0,
+		AfterAddBuff = 1,
+		BeforeRemoveBuff = 2,
+		AfterRemoveBuff = 3,
+		BuffTimeout = 4,
+		LogicRecvClientMessage = 5,
+		LogicRecvRequestMessage = 6,
+		GateRecvClientMessage = 7,
+		GateRecvServerMessage = 8,
 	}
 }

+ 4 - 24
CSharp/Game/Model/GameException.cs

@@ -1,46 +1,26 @@
 using System;
-using System.Runtime.Serialization;
 
 namespace Model
 {
-	[Serializable]
 	public class GameException : Exception
 	{
-		public int ErrorCode { get; private set; }
-
-		public string ErrorInfo { get; private set; }
-
-		public GameException(int errorCode, string message): base(message)
+		public GameException(string message): base(message)
 		{
-			this.ErrorCode = errorCode;
 		}
 
-		public GameException(int errorCode, string format, params object[] args)
+		public GameException(string format, params object[] args)
 			: base(string.Format(format, args))
 		{
-			this.ErrorCode = errorCode;
 		}
 
-		public GameException(int errorCode, string message, Exception innerException)
+		public GameException(string message, Exception innerException)
 			: base(message, innerException)
 		{
-			this.ErrorCode = errorCode;
 		}
 
-		public GameException(int errorCode, string format, Exception innerException, params object[] args)
+		public GameException(string format, Exception innerException, params object[] args)
 			: base(string.Format(format, args), innerException)
 		{
-			this.ErrorCode = errorCode;
-		}
-
-		protected GameException(SerializationInfo info, StreamingContext context)
-			: base(info, context)
-		{
-		}
-
-		public override string ToString()
-		{
-			return string.Format("error code: {0}, {1}", this.ErrorCode, base.ToString());
 		}
 	}
 }

+ 6 - 6
CSharp/Game/Model/IEventSync.cs → CSharp/Game/Model/IEvent.cs

@@ -1,7 +1,7 @@
-namespace Model
-{
-	public interface IEventSync
-	{
-		void Run(Env env);
-	}
+namespace Model
+{
+	public interface IEvent
+	{
+		void Run(Env env);
+	}
 }

+ 29 - 0
CSharp/Game/Model/IRegister.cs

@@ -0,0 +1,29 @@
+using System.Threading.Tasks;
+
+namespace Model
+{
+	public interface IRegister
+	{
+		void Register();
+	}
+
+	public abstract class MEvent<T, R>: IRegister
+	{
+		public void Register()
+		{
+			World.Instance.GetComponent<MessageComponent>().Register<T, R>(this.Run);
+		}
+
+		public abstract R Run(T t);
+	}
+
+	public abstract class MEventAsync<T, R> : IRegister
+	{
+		public void Register()
+		{
+			World.Instance.GetComponent<MessageComponent>().RegisterAsync<T, R>(this.Run);
+		}
+
+		public abstract Task<R> Run(T t);
+	}
+}

+ 1 - 7
CSharp/Game/Model/MessageAttribute.cs

@@ -7,16 +7,10 @@ namespace Model
 	/// </summary>
 	public class MessageAttribute: Attribute
 	{
-		public ushort Opcode { get; private set; }
-
-		public Type ClassType { get; private set; }
-
 		private ServerType ServerType { get; set; }
 
-		public MessageAttribute(ushort opcode, Type classType, ServerType serverType)
+		public MessageAttribute(ServerType serverType)
 		{
-			this.Opcode = opcode;
-			this.ClassType = classType;
 			this.ServerType = serverType;
 		}
 

+ 4 - 1
CSharp/Game/Model/Model.csproj

@@ -83,12 +83,15 @@
     <Compile Include="IAssemblyLoader.cs" />
     <Compile Include="ICategory.cs" />
     <Compile Include="IConfigLoader.cs" />
+    <Compile Include="IRegister.cs" />
     <Compile Include="IEventAsync.cs" />
-    <Compile Include="IEventSync.cs" />
+    <Compile Include="IMessage.cs" />
+    <Compile Include="IEvent.cs" />
     <Compile Include="IFactory.cs" />
     <Compile Include="IStart.cs" />
     <Compile Include="IUpdate.cs" />
     <Compile Include="MessageAttribute.cs" />
+    <Compile Include="NodeType.cs" />
     <Compile Include="Opcode.cs" />
     <Compile Include="NumDefine.cs" />
     <Compile Include="Options.cs" />

+ 92 - 0
CSharp/Game/Model/NodeType.cs

@@ -0,0 +1,92 @@
+namespace Model
+{
+	public enum NodeType
+	{
+		Selector = 1,
+		Sequence = 2,
+		Not = 10,
+		Weight = 11,
+		True = 12,
+		MoveToTarget = 100,
+		Desdroy = 101,
+		DistanceWithTarget = 102,
+
+		/// <summary>
+		/// 后退移动
+		/// </summary>
+		BackMove = 103,
+
+		/// <summary>
+		/// 平行移动
+		/// </summary>
+		MoveToTargetParallel = 104,
+
+		PlayMotion = 210,
+
+		/// <summary>
+		/// 隐身
+		/// </summary>
+		ApplyCloak = 211,
+
+		/// <summary>
+		/// 取消隐身
+		/// </summary>
+		CancelCloak = 212,
+
+		/// <summary>
+		/// 改变模型
+		/// </summary>
+		ChangeModel = 213,
+
+		/// <summary>
+		/// 还原模型
+		/// </summary>
+		RevertModel = 214,
+
+		/// <summary>
+		/// 改变材质
+		/// </summary>
+		ChangeMaterial = 215,
+
+		/// <summary>
+		/// 还原材质
+		/// </summary>
+		RevertMaterial = 216,
+
+		/// <summary>
+		/// 飞上天
+		/// </summary>
+		Fly = 217,
+
+		/// <summary>
+		/// 从天上落地
+		/// </summary>
+		FlyFinish = 218,
+
+		CreateEffect = 219,
+
+		CreateBuilding = 220,
+
+		/// <summary>
+		/// 巨型技能指示器
+		/// </summary>
+		RectSkillIndicator = 221,
+
+		/// <summary>
+		/// 圆形技能指示器
+		/// </summary>
+		RoundSkillIndicator = 222,
+		/// <summary>
+		/// 扇形指示器
+		/// </summary>
+		SectorSkillIndicator = 223,
+		/// <summary>
+		/// 连线特效
+		/// </summary>
+		LinkEffect = 224,
+		/// <summary>
+		/// 普通特效
+		/// </summary>
+		EffectCommond = 225,
+	}
+}

+ 12 - 25
CSharp/Game/Model/Opcode.cs

@@ -1,57 +1,44 @@
 namespace Model
 {
-	public static class Opcode
+	public enum Opcode: short
 	{
-		#region client message 0
-
-		public const ushort CMsgLogin = 1;
-
-		#endregion client message 10000
-
-		#region server message 10000
-
-		#endregion server message 20000
-
-		#region rpc request message 20000
-
-		#endregion rpc request message 30000
-
-		public const ushort RpcResponse = 30000;
-		public const ushort RpcException = 30001;
+		CMsgLogin = 1,
+		RpcResponse = 30000,
+		RpcException = 30001,
 	}
 
 	public static class MessageTypeHelper
 	{
-		public static bool IsClientMessage(ushort opcode)
+		public static bool IsClientMessage(Opcode opcode)
 		{
-			if (opcode > 0 && opcode < 10000)
+			if ((ushort)opcode > 0 && (ushort)opcode < 10000)
 			{
 				return true;
 			}
 			return false;
 		}
 
-		public static bool IsServerMessage(ushort opcode)
+		public static bool IsServerMessage(Opcode opcode)
 		{
-			if (opcode > 10000 && opcode < 20000)
+			if ((ushort)opcode > 10000 && (ushort)opcode < 20000)
 			{
 				return true;
 			}
 			return false;
 		}
 
-		public static bool IsRpcRequestMessage(ushort opcode)
+		public static bool IsRpcRequestMessage(Opcode opcode)
 		{
-			if (opcode > 20000 && opcode < 30000)
+			if ((ushort)opcode > 20000 && (ushort)opcode < 30000)
 			{
 				return true;
 			}
 			return false;
 		}
 
-		public static bool IsRpcResponseMessage(ushort opcode)
+		public static bool IsRpcResponseMessage(Opcode opcode)
 		{
-			if (opcode > 30000 && opcode < 40000)
+			if ((ushort)opcode > 30000 && (ushort)opcode < 40000)
 			{
 				return true;
 			}

+ 0 - 27
CSharp/Platform/UNet/USocket.cs

@@ -83,16 +83,6 @@ namespace UNet
 			}
 		}
 
-		public void Ping()
-		{
-			NativeMethods.ENetPeerPing(this.peerPtr);
-		}
-
-		public void ConfigureThrottle(uint interval, uint acceleration, uint deceleration)
-		{
-			NativeMethods.ENetPeerThrottleConfigure(this.peerPtr, interval, acceleration, deceleration);
-		}
-
 		public Task<bool> ConnectAsync(string hostName, ushort port)
 		{
 			var tcs = new TaskCompletionSource<bool>();
@@ -165,23 +155,6 @@ namespace UNet
 			return tcs.Task;
 		}
 
-		public Task<bool> DisconnectLaterAsync(uint data = 0)
-		{
-			NativeMethods.ENetPeerDisconnectLater(this.peerPtr, data);
-			// EnetPeerDisconnect会reset Peer,这里设置为0,防止再次Dispose
-			this.peerPtr = IntPtr.Zero;
-			var tcs = new TaskCompletionSource<bool>();
-			this.Disconnect = eEvent => tcs.TrySetResult(true);
-			return tcs.Task;
-		}
-
-		public void DisconnectNow(uint data)
-		{
-			NativeMethods.ENetPeerDisconnectNow(this.peerPtr, data);
-			// EnetPeerDisconnect会reset Peer,这里设置为0,防止再次Dispose
-			this.peerPtr = IntPtr.Zero;
-		}
-
 		internal void OnConnected(ENetEvent eNetEvent)
 		{
 			if (this.Connected == null)