Procházet zdrojové kódy

1.增加一个登录消息
2.Network程序集移动到Common中

tanghai před 11 roky
rodič
revize
5bb66d41cd
34 změnil soubory, kde provedl 193 přidání a 200 odebrání
  1. 1 16
      CSharp/CSharp.sln
  2. 20 8
      CSharp/Game/Controller/Action/MessageAction.cs
  3. 2 2
      CSharp/Game/Controller/Controller.csproj
  4. 3 4
      CSharp/Game/Controller/Factory/UnitFactory.cs
  5. 0 16
      CSharp/Game/Controller/Message/CMsgLogin.cs
  6. 29 0
      CSharp/Game/Controller/Message/CMsgLoginEvent.cs
  7. 7 0
      CSharp/Game/Controller/MessageType.cs
  8. 16 5
      CSharp/Game/Model/Component/ActorComponent.cs
  9. 15 0
      CSharp/Game/Model/Component/ChannelUnitInfoComponent.cs
  10. 30 9
      CSharp/Game/Model/Component/EventComponent.cs
  11. 1 2
      CSharp/Game/Model/Component/FactoryComponent.cs
  12. 6 4
      CSharp/Game/Model/Component/NetworkComponent.cs
  13. 3 5
      CSharp/Game/Model/Model.csproj
  14. 2 2
      CSharp/Game/Model/UnitType.cs
  15. 1 1
      CSharp/Game/MongoDBTest/MongoDBTest.cs
  16. 2 0
      CSharp/Platform/Common/Common.csproj
  17. 1 1
      CSharp/Platform/Common/Network/AChannel.cs
  18. 4 1
      CSharp/Platform/Common/Network/IService.cs
  19. 0 60
      CSharp/Platform/Network/Network.csproj
  20. 0 39
      CSharp/Platform/Network/Properties/AssemblyInfo.cs
  21. 1 1
      CSharp/Platform/TNet/TChannel.cs
  22. 0 4
      CSharp/Platform/TNet/TNet.csproj
  23. 14 1
      CSharp/Platform/TNet/TService.cs
  24. 0 4
      CSharp/Platform/TNetTest/TNetTest.csproj
  25. 1 1
      CSharp/Platform/TNetTest/TServiceTest.cs
  26. 1 1
      CSharp/Platform/UNet/NativeMethods.cs
  27. 1 1
      CSharp/Platform/UNet/UChannel.cs
  28. 11 4
      CSharp/Platform/UNet/UNet.csproj
  29. 1 1
      CSharp/Platform/UNet/UPacket.cs
  30. 14 1
      CSharp/Platform/UNet/UService.cs
  31. 1 1
      CSharp/Platform/UNet/USocket.cs
  32. 4 0
      CSharp/Platform/UNet/packages.config
  33. 0 4
      CSharp/Platform/UNetTest/UNetTest.csproj
  34. 1 1
      CSharp/Platform/UNetTest/UServiceTest.cs

+ 1 - 16
CSharp/CSharp.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 2013
-VisualStudioVersion = 12.0.30723.0
+VisualStudioVersion = 12.0.31101.0
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Modules", "Modules", "{C4C64188-4FAE-4CC3-A9E6-D9D4AF7429B6}"
 EndProject
@@ -48,8 +48,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ENet", "Platform\ENet\ENet.
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UNetTest", "Platform\UNetTest\UNetTest.csproj", "{901A8E5C-C4C6-4C3C-8E18-068D75119F5D}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Network", "Platform\Network\Network.csproj", "{3BD499FF-3C34-4920-8B21-C55FBA580843}"
-EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProfileExe", "Platform\ProfileExe\ProfileExe.csproj", "{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}"
 EndProject
 Global
@@ -212,18 +210,6 @@ Global
 		{901A8E5C-C4C6-4C3C-8E18-068D75119F5D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
 		{901A8E5C-C4C6-4C3C-8E18-068D75119F5D}.Release|Win32.ActiveCfg = Release|Any CPU
 		{901A8E5C-C4C6-4C3C-8E18-068D75119F5D}.Release|x86.ActiveCfg = Release|Any CPU
-		{3BD499FF-3C34-4920-8B21-C55FBA580843}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{3BD499FF-3C34-4920-8B21-C55FBA580843}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{3BD499FF-3C34-4920-8B21-C55FBA580843}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
-		{3BD499FF-3C34-4920-8B21-C55FBA580843}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
-		{3BD499FF-3C34-4920-8B21-C55FBA580843}.Debug|Win32.ActiveCfg = Debug|Any CPU
-		{3BD499FF-3C34-4920-8B21-C55FBA580843}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{3BD499FF-3C34-4920-8B21-C55FBA580843}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{3BD499FF-3C34-4920-8B21-C55FBA580843}.Release|Any CPU.Build.0 = Release|Any CPU
-		{3BD499FF-3C34-4920-8B21-C55FBA580843}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
-		{3BD499FF-3C34-4920-8B21-C55FBA580843}.Release|Mixed Platforms.Build.0 = Release|Any CPU
-		{3BD499FF-3C34-4920-8B21-C55FBA580843}.Release|Win32.ActiveCfg = Release|Any CPU
-		{3BD499FF-3C34-4920-8B21-C55FBA580843}.Release|x86.ActiveCfg = Release|Any CPU
 		{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{CBA52DC8-1C80-4A79-9AC5-73514EBBD749}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@@ -254,7 +240,6 @@ Global
 		{D0B4CFAC-A368-4742-9863-68776CFA9938} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 		{C9992B7C-313E-4C9F-A954-640D01EDFB58} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 		{901A8E5C-C4C6-4C3C-8E18-068D75119F5D} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
-		{3BD499FF-3C34-4920-8B21-C55FBA580843} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 		{CBA52DC8-1C80-4A79-9AC5-73514EBBD749} = {ADBF5F67-B480-4A93-9D50-C81856FC61A9}
 	EndGlobalSection
 EndGlobal

+ 20 - 8
CSharp/Game/Controller/Action/MessageAction.cs

@@ -1,20 +1,32 @@
-using Common.Event;
+using System;
+using System.Threading.Tasks;
+using Common.Event;
+using Common.Network;
 using Model;
-using MongoDB.Bson;
-
 namespace Controller
 {
 	[Action(ActionType.MessageAction)]
-	public class MessageAction : IEventSync
+	public class MessageAction : IEventAsync
 	{
-		public void Run(Env env)
+		public async Task RunAsync(Env env)
 		{
-			Unit unit = World.Instance.GetComponent<UnitComponent>().Get(ObjectId.Empty);
-			if (unit == null)
+			AChannel channel = env.Get<AChannel>(EnvKey.Channel);
+			ChannelUnitInfoComponent channelUnitInfoComponent =
+					channel.GetComponent<ChannelUnitInfoComponent>();
+			if (channelUnitInfoComponent != null)
 			{
+				Unit unit = World.Instance.GetComponent<UnitComponent>().Get(channelUnitInfoComponent.PlayerId);
+				if (unit == null)
+				{
+					return;
+				}
+				unit.GetComponent<ActorComponent>().Add(env);
 				return;
 			}
-			unit.GetComponent<ActorComponent>().Add(env);
+
+			var message = env.Get<byte[]>(EnvKey.Message);
+			int opcode = BitConverter.ToUInt16(message, 0);
+			await World.Instance.GetComponent<EventComponent<MessageAttribute>>().RunAsync(opcode, env);
 		}
 	}
 }

+ 2 - 2
CSharp/Game/Controller/Controller.csproj

@@ -55,10 +55,10 @@
     <Compile Include="ConfigCategory\UnitCategory.cs" />
     <Compile Include="Action\BuffTimeoutAction.cs" />
     <Compile Include="Event\AfterAddBuff.cs" />
-    <Compile Include="Message\CMsgLogin.cs" />
+    <Compile Include="MessageType.cs" />
+    <Compile Include="Message\CMsgLoginEvent.cs" />
     <Compile Include="NodeType.cs" />
     <Compile Include="Factory\UnitFactory.cs" />
-    <Compile Include="UnitType.cs" />
   </ItemGroup>
   <ItemGroup>
     <Folder Include="Properties\" />

+ 3 - 4
CSharp/Game/Controller/Factory/UnitFactory.cs

@@ -2,15 +2,14 @@
 
 namespace Controller
 {
-	[Factory(typeof (Unit), UnitType.Player)]
-	public class UnitPlayerFactory: IFactory<Unit>
+	[Factory(typeof (Unit), UnitType.GatePlayer)]
+	public class UnitGatePlayerFactory: IFactory<Unit>
 	{
 		public Unit Create(int configId)
 		{
 			Unit player = new Unit(configId);
 			player.AddComponent<BuffComponent>();
-			Buff buff = new Buff(1, player.Id);
-			player.GetComponent<BuffComponent>().Add(buff);
+			player.AddComponent<ActorComponent>().Run();
 			World.Instance.GetComponent<UnitComponent>().Add(player);
 			return player;
 		}

+ 0 - 16
CSharp/Game/Controller/Message/CMsgLogin.cs

@@ -1,16 +0,0 @@
-using System;
-using System.Threading.Tasks;
-using Common.Event;
-using Model;
-
-namespace Controller.Message
-{
-	[Message(1)]
-	internal class CMsgLogin: IEventAsync
-	{
-		public Task RunAsync(Env env)
-		{
-			throw new NotImplementedException();
-		}
-	}
-}

+ 29 - 0
CSharp/Game/Controller/Message/CMsgLoginEvent.cs

@@ -0,0 +1,29 @@
+using Common.Event;
+using Common.Helper;
+using Model;
+using Common.Network;
+
+namespace Controller.Message
+{
+	public class CMsgLogin
+	{
+		public byte[] Account { get; set; }
+		public byte[] PassMd5 { get; set; }
+	}
+
+	[Message(MessageType.CMsgLogin)]
+	internal class CMsgLoginEvent: IEventSync
+	{
+		public void Run(Env env)
+		{
+			var messageBytes = env.Get<byte[]>(EnvKey.Message);
+			CMsgLogin cmsg = MongoHelper.FromBson<CMsgLogin>(messageBytes, 2);
+			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.PlayerId = unit.Id;
+		}
+	}
+}

+ 7 - 0
CSharp/Game/Controller/MessageType.cs

@@ -0,0 +1,7 @@
+namespace Controller
+{
+	public static class MessageType
+	{
+		public const int CMsgLogin = 1;
+	}
+}

+ 16 - 5
CSharp/Game/Model/Component/ActorComponent.cs

@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Threading.Tasks;
 using Common.Base;
 using Common.Event;
+using Common.Logger;
 
 namespace Model
 {
@@ -10,16 +11,26 @@ namespace Model
 	{
 		private readonly Queue<Env> msgEnvQueue = new Queue<Env>();
 
-		public Action msgAction = () => {}; 
+		public Action msgAction = () => {};
+
+		public Env Env { get; private set; }
 
 		public async void Run()
 		{
 			while (true)
 			{
-				Env env = await this.Get();
-				var message = env.Get<byte[]>(EnvKey.Message);
-				int opcode = BitConverter.ToUInt16(message, 0);
-				await World.Instance.GetComponent<EventComponent<MessageAttribute>>().Run(opcode, env);
+				try
+				{
+					Env env = await this.Get();
+					this.Env = env;
+					var message = env.Get<byte[]>(EnvKey.Message);
+					int opcode = BitConverter.ToUInt16(message, 0);
+					await World.Instance.GetComponent<EventComponent<MessageAttribute>>().RunAsync(opcode, env);
+				}
+				catch (Exception e)
+				{
+					Log.Trace(string.Format(e.ToString()));
+				}
 			}
 		}
 

+ 15 - 0
CSharp/Game/Model/Component/ChannelUnitInfoComponent.cs

@@ -0,0 +1,15 @@
+using Common.Base;
+using Common.Network;
+using MongoDB.Bson;
+
+namespace Model
+{
+	/// <summary>
+	/// channel中保存Unit一些信息,例如帐号
+	/// </summary>
+	public class ChannelUnitInfoComponent : Component<AChannel>
+	{
+		public byte[] Account { get; set; }
+		public ObjectId PlayerId { get; set; }
+	}
+}

+ 30 - 9
CSharp/Game/Model/Component/EventComponent.cs

@@ -61,10 +61,37 @@ namespace Model
 			}
 		}
 
-		public async Task Run(int type, Env env)
+		public void Run(int type, Env env)
 		{
 			List<IEventSync> iEventSyncs = null;
-			if (this.eventSyncs.TryGetValue(type, out iEventSyncs))
+			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)
+			{
+				iEventSync.Run(env);
+			}
+		}
+
+		public async Task RunAsync(int type, Env env)
+		{
+			List<IEventSync> iEventSyncs = null;
+			this.eventSyncs.TryGetValue(type, out iEventSyncs);
+
+			List<IEventAsync> iEventAsyncs = null;
+			this.eventAsyncs.TryGetValue(type, out iEventAsyncs);
+
+			if (iEventSyncs == null && iEventAsyncs == null)
+			{
+				throw new Exception(string.Format("no event handler, AttributeType: {0} type: {1}",
+					typeof(AttributeType).Name, type));
+			}
+
+			if (iEventSyncs != null)
 			{
 				foreach (IEventSync iEventSync in iEventSyncs)
 				{
@@ -72,19 +99,13 @@ namespace Model
 				}
 			}
 
-			List<IEventAsync> iEventAsyncs = null;
-			// ReSharper disable once InvertIf
-			if (this.eventAsyncs.TryGetValue(type, out iEventAsyncs))
+			if (iEventAsyncs != null)
 			{
 				foreach (IEventAsync iEventAsync in iEventAsyncs)
 				{
 					await iEventAsync.RunAsync(env);
 				}
 			}
-
-			throw new Exception(
-				string.Format("no event handler, AttributeType: {0} type: {1}", 
-					typeof(AttributeType).Name, type));
 		}
 	}
 }

+ 1 - 2
CSharp/Game/Model/Component/FactoryComponent.cs

@@ -39,9 +39,8 @@ namespace Model
 			}
 		}
 
-		public T Create(int configId)
+		public T Create(int type, int configId)
 		{
-			int type = World.Instance.GetComponent<ConfigComponent>().Get<UnitConfig>(configId).Type;
 			return this.allConfig[type].Create(configId);
 		}
 	}

+ 6 - 4
CSharp/Game/Model/Component/ServiceComponent.cs → CSharp/Game/Model/Component/NetworkComponent.cs

@@ -1,13 +1,13 @@
 using System;
 using Common.Base;
 using Common.Event;
-using Network;
+using Common.Network;
 using TNet;
 using UNet;
 
 namespace Model
 {
-	public class ServiceComponent: Component<World>
+	public class NetworkComponent: Component<World>
 	{
 		private IService service;
 
@@ -54,8 +54,10 @@ namespace Model
 				Env env = new Env();
 				env[EnvKey.Channel] = channel;
 				env[EnvKey.Message] = message;
-				await World.Instance.GetComponent<EventComponent<ActionAttribute>>()
-						.Run(ActionType.MessageAction, env);
+#pragma warning disable 4014
+				World.Instance.GetComponent<EventComponent<ActionAttribute>>()
+						.RunAsync(ActionType.MessageAction, env);
+#pragma warning restore 4014
 			}
 		}
 	}

+ 3 - 5
CSharp/Game/Model/Model.csproj

@@ -45,6 +45,7 @@
     <Reference Include="System.Core" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Component\ChannelUnitInfoComponent.cs" />
     <Compile Include="Component\ActorComponent.cs" />
     <Compile Include="Component\BehaviorTreeComponent.cs" />
     <Compile Include="BehaviorTree\BehaviorTree.cs" />
@@ -53,7 +54,7 @@
     <Compile Include="BehaviorTree\Node.cs" />
     <Compile Include="BehaviorTree\NodeAttribute.cs" />
     <Compile Include="Buff.cs" />
-    <Compile Include="Component\ServiceComponent.cs" />
+    <Compile Include="Component\NetworkComponent.cs" />
     <Compile Include="Component\BuffComponent.cs" />
     <Compile Include="Component\ConfigComponent.cs" />
     <Compile Include="Component\EventComponent.cs" />
@@ -72,6 +73,7 @@
     <Compile Include="Config\GlobalConfig.cs" />
     <Compile Include="Config\NodeConfig.cs" />
     <Compile Include="Unit.cs" />
+    <Compile Include="UnitType.cs" />
     <Compile Include="World.cs" />
     <Compile Include="EventAttribute.cs" />
   </ItemGroup>
@@ -83,10 +85,6 @@
       <Project>{19f8f043-1f99-4550-99df-dea5c7d77e55}</Project>
       <Name>Common</Name>
     </ProjectReference>
-    <ProjectReference Include="..\..\Platform\Network\Network.csproj">
-      <Project>{3bd499ff-3c34-4920-8b21-c55fba580843}</Project>
-      <Name>Network</Name>
-    </ProjectReference>
     <ProjectReference Include="..\..\Platform\TNet\TNet.csproj">
       <Project>{b42d431a-3a54-4649-942a-c5356d7f9fbc}</Project>
       <Name>TNet</Name>

+ 2 - 2
CSharp/Game/Controller/UnitType.cs → CSharp/Game/Model/UnitType.cs

@@ -1,8 +1,8 @@
-namespace Controller
+namespace Model
 {
 	public static class UnitType
 	{
-		public const int Player = 1;
+		public const int GatePlayer = 1;
 		public const int Npc = 2;
 		public const int Dog = 3;
 	}

+ 1 - 1
CSharp/Game/MongoDBTest/MongoDBTest.cs

@@ -31,7 +31,7 @@ namespace MongoDBTest
 			world.AddComponent<BehaviorTreeComponent>();
 			world.Load();
 
-			Unit player1 = world.GetComponent<FactoryComponent<Unit>>().Create(1);
+			Unit player1 = world.GetComponent<FactoryComponent<Unit>>().Create(UnitType.GatePlayer, 1);
 			player1["hp"] = 10;
 
 			collection.Insert(player1);

+ 2 - 0
CSharp/Platform/Common/Common.csproj

@@ -88,6 +88,8 @@
     <Compile Include="Helper\StringHelper.cs" />
     <Compile Include="Helper\TimeHelper.cs" />
     <Compile Include="Helper\XmlHelper.cs" />
+    <Compile Include="Network\AChannel.cs" />
+    <Compile Include="Network\IService.cs" />
   </ItemGroup>
   <ItemGroup>
     <None Include="Helper\Packages.config" />

+ 1 - 1
CSharp/Platform/Network/AChannel.cs → CSharp/Platform/Common/Network/AChannel.cs

@@ -2,7 +2,7 @@
 using System.Threading.Tasks;
 using Common.Base;
 
-namespace Network
+namespace Common.Network
 {
 	[Flags]
 	public enum PacketFlags

+ 4 - 1
CSharp/Platform/Network/IService.cs → CSharp/Platform/Common/Network/IService.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Threading.Tasks;
+using MongoDB.Bson;
 
-namespace Network
+namespace Common.Network
 {
 	public enum NetworkProtocol
 	{
@@ -17,6 +18,8 @@ namespace Network
 		/// <param name="action"></param>
 		void Add(Action action);
 
+		AChannel GetChannel(ObjectId id);
+
 		Task<AChannel> GetChannel(string host, int port);
 
 		Task<AChannel> GetChannel();

+ 0 - 60
CSharp/Platform/Network/Network.csproj

@@ -1,60 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
-  <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProjectGuid>{3BD499FF-3C34-4920-8B21-C55FBA580843}</ProjectGuid>
-    <OutputType>Library</OutputType>
-    <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>Network</RootNamespace>
-    <AssemblyName>Network</AssemblyName>
-    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>bin\Debug\</OutputPath>
-    <DefineConstants>DEBUG;TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <DebugType>pdbonly</DebugType>
-    <Optimize>true</Optimize>
-    <OutputPath>bin\Release\</OutputPath>
-    <DefineConstants>TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-  </PropertyGroup>
-  <ItemGroup>
-    <Reference Include="System" />
-    <Reference Include="System.Core" />
-    <Reference Include="System.Xml.Linq" />
-    <Reference Include="System.Data.DataSetExtensions" />
-    <Reference Include="Microsoft.CSharp" />
-    <Reference Include="System.Data" />
-    <Reference Include="System.Xml" />
-  </ItemGroup>
-  <ItemGroup>
-    <Compile Include="IService.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="AChannel.cs" />
-  </ItemGroup>
-  <ItemGroup>
-    <ProjectReference Include="..\Common\Common.csproj">
-      <Project>{19f8f043-1f99-4550-99df-dea5c7d77e55}</Project>
-      <Name>Common</Name>
-    </ProjectReference>
-  </ItemGroup>
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
-       Other similar extension points exist, see Microsoft.Common.targets.
-  <Target Name="BeforeBuild">
-  </Target>
-  <Target Name="AfterBuild">
-  </Target>
-  -->
-</Project>

+ 0 - 39
CSharp/Platform/Network/Properties/AssemblyInfo.cs

@@ -1,39 +0,0 @@
-using System.Reflection;
-using System.Runtime.InteropServices;
-
-// 有关程序集的常规信息通过以下
-// 特性集控制。更改这些特性值可修改
-// 与程序集关联的信息。
-
-[assembly: AssemblyTitle("Network")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Microsoft")]
-[assembly: AssemblyProduct("Network")]
-[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// 将 ComVisible 设置为 false 使此程序集中的类型
-// 对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
-// 则将该类型上的 ComVisible 特性设置为 true。
-
-[assembly: ComVisible(false)]
-
-// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
-
-[assembly: Guid("16f6d5fb-6535-4e2b-afb5-e9a1b240c584")]
-
-// 程序集的版本信息由下面四个值组成: 
-//
-//      主版本
-//      次版本 
-//      生成号
-//      修订号
-//
-// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
-// 方法是按如下所示使用“*”: 
-// [assembly: AssemblyVersion("1.0.*")]
-
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]

+ 1 - 1
CSharp/Platform/TNet/TChannel.cs

@@ -3,7 +3,7 @@ using System.Threading.Tasks;
 using Common.Helper;
 using Common.Logger;
 using MongoDB.Bson;
-using Network;
+using Common.Network;
 
 namespace TNet
 {

+ 0 - 4
CSharp/Platform/TNet/TNet.csproj

@@ -64,10 +64,6 @@
       <Project>{19f8f043-1f99-4550-99df-dea5c7d77e55}</Project>
       <Name>Common</Name>
     </ProjectReference>
-    <ProjectReference Include="..\Network\Network.csproj">
-      <Project>{3bd499ff-3c34-4920-8b21-c55fba580843}</Project>
-      <Name>Network</Name>
-    </ProjectReference>
   </ItemGroup>
   <ItemGroup>
     <None Include="packages.config" />

+ 14 - 1
CSharp/Platform/TNet/TService.cs

@@ -2,7 +2,8 @@
 using System.Collections.Generic;
 using System.Threading.Tasks;
 using Common.Base;
-using Network;
+using Common.Network;
+using MongoDB.Bson;
 
 namespace TNet
 {
@@ -13,6 +14,8 @@ namespace TNet
 
 		private readonly Dictionary<string, TChannel> channels = new Dictionary<string, TChannel>();
 
+		private readonly Dictionary<ObjectId, TChannel> idChannels = new Dictionary<ObjectId, TChannel>();
+
 		private readonly TimerManager timerManager = new TimerManager();
 
 		/// <summary>
@@ -65,12 +68,20 @@ namespace TNet
 			this.poller.Add(action);
 		}
 
+		public AChannel GetChannel(ObjectId id)
+		{
+			TChannel channel = null;
+			this.idChannels.TryGetValue(id, out channel);
+			return channel;
+		}
+
 		private async Task<AChannel> ConnectAsync(string host, int port)
 		{
 			TSocket newSocket = new TSocket(this.poller);
 			await newSocket.ConnectAsync(host, port);
 			TChannel channel = new TChannel(newSocket, this);
 			this.channels[newSocket.RemoteAddress] = channel;
+			this.idChannels[channel.Id] = channel;
 			return channel;
 		}
 
@@ -84,6 +95,7 @@ namespace TNet
 			await this.acceptor.AcceptAsync(socket);
 			TChannel channel = new TChannel(socket, this);
 			this.channels[channel.RemoteAddress] = channel;
+			this.idChannels[channel.Id] = channel;
 			return channel;
 		}
 
@@ -94,6 +106,7 @@ namespace TNet
 			{
 				return;
 			}
+			this.idChannels.Remove(channel.Id);
 			this.channels.Remove(channel.RemoteAddress);
 			this.timerManager.Remove(tChannel.SendTimer);
 		}

+ 0 - 4
CSharp/Platform/TNetTest/TNetTest.csproj

@@ -59,10 +59,6 @@
       <Project>{19f8f043-1f99-4550-99df-dea5c7d77e55}</Project>
       <Name>Common</Name>
     </ProjectReference>
-    <ProjectReference Include="..\Network\Network.csproj">
-      <Project>{3bd499ff-3c34-4920-8b21-c55fba580843}</Project>
-      <Name>Network</Name>
-    </ProjectReference>
     <ProjectReference Include="..\TNet\TNet.csproj">
       <Project>{b42d431a-3a54-4649-942a-c5356d7f9fbc}</Project>
       <Name>TNet</Name>

+ 1 - 1
CSharp/Platform/TNetTest/TServiceTest.cs

@@ -3,7 +3,7 @@ using System.Threading;
 using System.Threading.Tasks;
 using Common.Helper;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Network;
+using Common.Network;
 using TNet;
 
 namespace TNetTest

+ 1 - 1
CSharp/Platform/UNet/NativeMethods.cs

@@ -1,7 +1,7 @@
 using System;
 using System.Runtime.InteropServices;
 using System.Text;
-using Network;
+using Common.Network;
 
 namespace UNet
 {

+ 1 - 1
CSharp/Platform/UNet/UChannel.cs

@@ -1,6 +1,6 @@
 using System;
 using System.Threading.Tasks;
-using Network;
+using Common.Network;
 
 namespace UNet
 {

+ 11 - 4
CSharp/Platform/UNet/UNet.csproj

@@ -34,6 +34,14 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
+    <Reference Include="MongoDB.Bson, Version=1.10.0.52, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc1\lib\net35\MongoDB.Bson.dll</HintPath>
+    </Reference>
+    <Reference Include="MongoDB.Driver, Version=1.10.0.52, Culture=neutral, PublicKeyToken=f686731cfb9cc103, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\packages\mongocsharpdriver.1.10.0-rc1\lib\net35\MongoDB.Driver.dll</HintPath>
+    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
   </ItemGroup>
@@ -58,10 +66,9 @@
       <Project>{19F8F043-1F99-4550-99DF-DEA5C7D77E55}</Project>
       <Name>Common</Name>
     </ProjectReference>
-    <ProjectReference Include="..\Network\Network.csproj">
-      <Project>{3bd499ff-3c34-4920-8b21-c55fba580843}</Project>
-      <Name>Network</Name>
-    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="packages.config" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\nuget.targets" />

+ 1 - 1
CSharp/Platform/UNet/UPacket.cs

@@ -1,6 +1,6 @@
 using System;
 using System.Runtime.InteropServices;
-using Network;
+using Common.Network;
 
 namespace UNet
 {

+ 14 - 1
CSharp/Platform/UNet/UService.cs

@@ -1,7 +1,8 @@
 using System;
 using System.Collections.Generic;
 using System.Threading.Tasks;
-using Network;
+using Common.Network;
+using MongoDB.Bson;
 
 namespace UNet
 {
@@ -11,6 +12,8 @@ namespace UNet
 
 		private readonly Dictionary<string, UChannel> channels = new Dictionary<string, UChannel>();
 
+		private readonly Dictionary<ObjectId, UChannel> idChannels = new Dictionary<ObjectId, UChannel>();
+
 		/// <summary>
 		/// 即可做client也可做server
 		/// </summary>
@@ -64,6 +67,7 @@ namespace UNet
 			USocket newSocket = await this.poller.ConnectAsync(host, (ushort) port);
 			UChannel channel = new UChannel(newSocket, this);
 			this.channels[channel.RemoteAddress] = channel;
+			this.idChannels[channel.Id] = channel;
 			return channel;
 		}
 
@@ -82,6 +86,14 @@ namespace UNet
 			USocket socket = await this.poller.AcceptAsync();
 			UChannel channel = new UChannel(socket, this);
 			this.channels[channel.RemoteAddress] = channel;
+			this.idChannels[channel.Id] = channel;
+			return channel;
+		}
+
+		public AChannel GetChannel(ObjectId id)
+		{
+			UChannel channel = null;
+			this.idChannels.TryGetValue(id, out channel);
 			return channel;
 		}
 
@@ -92,6 +104,7 @@ namespace UNet
 			{
 				return;
 			}
+			this.idChannels.Remove(channel.Id);
 			this.channels.Remove(channel.RemoteAddress);
 		}
 

+ 1 - 1
CSharp/Platform/UNet/USocket.cs

@@ -2,7 +2,7 @@
 using System.Collections.Generic;
 using System.Runtime.InteropServices;
 using System.Threading.Tasks;
-using Network;
+using Common.Network;
 
 namespace UNet
 {

+ 4 - 0
CSharp/Platform/UNet/packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="mongocsharpdriver" version="1.10.0-rc1" targetFramework="net451" />
+</packages>

+ 0 - 4
CSharp/Platform/UNetTest/UNetTest.csproj

@@ -61,10 +61,6 @@
       <Project>{19f8f043-1f99-4550-99df-dea5c7d77e55}</Project>
       <Name>Common</Name>
     </ProjectReference>
-    <ProjectReference Include="..\Network\Network.csproj">
-      <Project>{3bd499ff-3c34-4920-8b21-c55fba580843}</Project>
-      <Name>Network</Name>
-    </ProjectReference>
     <ProjectReference Include="..\TNet\TNet.csproj">
       <Project>{b42d431a-3a54-4649-942a-c5356d7f9fbc}</Project>
       <Name>TNet</Name>

+ 1 - 1
CSharp/Platform/UNetTest/UServiceTest.cs

@@ -3,7 +3,7 @@ using System.Threading;
 using System.Threading.Tasks;
 using Common.Helper;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Network;
+using Common.Network;
 using UNet;
 
 namespace UNetTest