Bläddra i källkod

服务器代码通过文件引用的方式共用客户端代码

tanghai 9 år sedan
förälder
incheckning
6de25cefe6
100 ändrade filer med 438 tillägg och 5679 borttagningar
  1. 0 0
      Server/App/App.config
  2. 0 0
      Server/App/NLog.config
  3. 42 0
      Server/App/Program.cs
  4. 0 0
      Server/App/Properties/AssemblyInfo.cs
  5. 6 6
      Server/App/Server.App.csproj
  6. 27 0
      Server/Base/Log.cs
  7. 0 0
      Server/Base/Logger/ALogDecorater.cs
  8. 1 0
      Server/Base/Logger/ILog.cs
  9. 6 1
      Server/Base/Logger/NLogAdapter.cs
  10. 0 0
      Server/Base/Logger/StackInfoDecorater.cs
  11. 1 1
      Server/Base/Properties/AssemblyInfo.cs
  12. 268 0
      Server/Base/Server.Base.csproj
  13. 1 1
      Server/Controller/Properties/AssemblyInfo.cs
  14. 9 2
      Server/Controller/Server.Controller.csproj
  15. 1 1
      Server/Model/Properties/AssemblyInfo.cs
  16. 15 30
      Server/Model/Server.Model.csproj
  17. 0 33
      Server/Server.App/Program.cs
  18. 0 95
      Server/Server.Base/Config/ACategory.cs
  19. 0 22
      Server/Server.Base/Config/AConfig.cs
  20. 0 9
      Server/Server.Base/Config/ConfigAttribute.cs
  21. 0 10
      Server/Server.Base/Config/ICategory.cs
  22. 0 144
      Server/Server.Base/DoubleMap.cs
  23. 0 12
      Server/Server.Base/Helper/ArrayHelper.cs
  24. 0 59
      Server/Server.Base/Helper/ByteHelper.cs
  25. 0 30
      Server/Server.Base/Helper/EnumHelper.cs
  26. 0 59
      Server/Server.Base/Helper/FileHelper.cs
  27. 0 12
      Server/Server.Base/Helper/IdGenerater.cs
  28. 0 19
      Server/Server.Base/Helper/MD5Helper.cs
  29. 0 67
      Server/Server.Base/Helper/MongoHelper.cs
  30. 0 83
      Server/Server.Base/Helper/ProtobufHelper.cs
  31. 0 28
      Server/Server.Base/Helper/RandomHelper.cs
  32. 0 62
      Server/Server.Base/Helper/StringHelper.cs
  33. 0 22
      Server/Server.Base/Helper/TimeHelper.cs
  34. 0 97
      Server/Server.Base/Helper/ZipHelper.cs
  35. 0 45
      Server/Server.Base/Log/Log.cs
  36. 0 111
      Server/Server.Base/MultiMap.cs
  37. 0 51
      Server/Server.Base/Network/AChannel.cs
  38. 0 45
      Server/Server.Base/Network/AService.cs
  39. 0 85
      Server/Server.Base/Network/TNet/PacketParser.cs
  40. 0 129
      Server/Server.Base/Network/TNet/TBuffer.cs
  41. 0 217
      Server/Server.Base/Network/TNet/TChannel.cs
  42. 0 38
      Server/Server.Base/Network/TNet/TPoller.cs
  43. 0 116
      Server/Server.Base/Network/TNet/TService.cs
  44. 0 211
      Server/Server.Base/Network/TNet/TSocket.cs
  45. 0 33
      Server/Server.Base/Network/UNet/Library.cs
  46. 0 105
      Server/Server.Base/Network/UNet/NativeMethods.cs
  47. 0 76
      Server/Server.Base/Network/UNet/NativeStructs.cs
  48. 0 27
      Server/Server.Base/Network/UNet/UAddress.cs
  49. 0 90
      Server/Server.Base/Network/UNet/UChannel.cs
  50. 0 72
      Server/Server.Base/Network/UNet/UPacket.cs
  51. 0 226
      Server/Server.Base/Network/UNet/UPoller.cs
  52. 0 111
      Server/Server.Base/Network/UNet/UService.cs
  53. 0 137
      Server/Server.Base/Network/UNet/USocket.cs
  54. 0 41
      Server/Server.Base/Network/UNet/USocketManager.cs
  55. 0 32
      Server/Server.Base/Object/Component.cs
  56. 0 203
      Server/Server.Base/Object/Entity.cs
  57. 0 25
      Server/Server.Base/Object/IAwake.cs
  58. 0 10
      Server/Server.Base/Object/ILoader.cs
  59. 0 10
      Server/Server.Base/Object/IStart.cs
  60. 0 10
      Server/Server.Base/Object/IUpdate.cs
  61. 0 47
      Server/Server.Base/Object/Object.cs
  62. 0 9
      Server/Server.Base/Object/ObjectEventAttribute.cs
  63. 0 336
      Server/Server.Base/Object/ObjectManager.cs
  64. 0 47
      Server/Server.Base/QueueDictionary.cs
  65. 0 117
      Server/Server.Base/Server.Base.csproj
  66. 0 35
      Server/Server.Base/TryLocker.cs
  67. 0 237
      Server/Server.Model/Component/EventComponent.cs
  68. 0 284
      Server/Server.Model/Component/MessageComponent.cs
  69. 0 136
      Server/Server.Model/Component/MessageHandlerComponent.cs
  70. 0 106
      Server/Server.Model/Component/NetworkComponent.cs
  71. 0 49
      Server/Server.Model/Component/Scene.cs
  72. 0 30
      Server/Server.Model/Component/TimeComponent.cs
  73. 0 139
      Server/Server.Model/Component/TimerComponent.cs
  74. 0 15
      Server/Server.Model/Event/AEventAttribute.cs
  75. 0 23
      Server/Server.Model/Event/EntityType.cs
  76. 0 91
      Server/Server.Model/Event/Env.cs
  77. 0 10
      Server/Server.Model/Event/EnvKey.cs
  78. 0 9
      Server/Server.Model/Event/EventAttribute.cs
  79. 0 7
      Server/Server.Model/Event/EventIdType.cs
  80. 0 36
      Server/Server.Model/Event/IEvent.cs
  81. 0 65
      Server/Server.Model/GameException.cs
  82. 0 12
      Server/Server.Model/Message/AMEvent.cs
  83. 0 128
      Server/Server.Model/Message/ErrorCode.cs
  84. 0 20
      Server/Server.Model/Message/IErrorMessage.cs
  85. 0 7
      Server/Server.Model/Message/IMRegister.cs
  86. 0 102
      Server/Server.Model/Message/Message.cs
  87. 0 20
      Server/Server.Model/Message/MessageAttribute.cs
  88. 0 259
      Server/Server.Model/Message/Opcode.cs
  89. 0 37
      Server/Server.Model/Message/OpcodeHelper.cs
  90. 0 22
      Server/Server.Model/Scene/Server.cs
  91. 52 67
      Server/Server.sln
  92. 1 1
      Unity/Assets/Plugins/Base/Component/EventComponent.cs
  93. 1 1
      Unity/Assets/Plugins/Base/Component/KVComponent.cs
  94. 1 1
      Unity/Assets/Plugins/Base/Component/LogComponent.cs
  95. 1 2
      Unity/Assets/Plugins/Base/Component/MessageComponent.cs
  96. 1 3
      Unity/Assets/Plugins/Base/Component/MessageHandlerComponent.cs
  97. 1 2
      Unity/Assets/Plugins/Base/Component/NetworkComponent.cs
  98. 1 3
      Unity/Assets/Plugins/Base/Component/TimeComponent.cs
  99. 1 2
      Unity/Assets/Plugins/Base/Component/TimerComponent.cs
  100. 1 1
      Unity/Assets/Plugins/Base/DoubleMap.cs.meta

+ 0 - 0
Server/Server.App/App.config → Server/App/App.config


+ 0 - 0
Server/Server.App/NLog.config → Server/App/NLog.config


+ 42 - 0
Server/App/Program.cs

@@ -0,0 +1,42 @@
+using System;
+using System.IO;
+using System.Reflection;
+using Base;
+using Model;
+using Object = Base.Object;
+
+namespace App
+{
+	class Program
+	{
+		static void Main(string[] args)
+		{
+			try
+			{
+				Log.Info("server start........................");
+
+				Object.ObjectManager.Register("Base", typeof(Game).Assembly);
+				Object.ObjectManager.Register("Model", typeof(Opcode).Assembly);
+				byte[] dllBytes = File.ReadAllBytes("./Controller.dll");
+				byte[] pdbBytes = File.ReadAllBytes("./Controller.pdb");
+				Assembly controller = Assembly.Load(dllBytes, pdbBytes);
+				Object.ObjectManager.Register("Controller", controller);
+				
+				Game.Scene.AddComponent<EventComponent>();
+				TimeComponent timeComponent = Game.Scene.AddComponent<TimeComponent>();
+				Game.Scene.AddComponent<TimerComponent, TimeComponent>(timeComponent);
+				Game.Scene.AddComponent<NetworkComponent, NetworkProtocol>(NetworkProtocol.UDP);
+				Game.Scene.AddComponent<MessageHandlerComponent, MessageType>(MessageType.Realm);
+
+				while (true)
+				{
+					Object.ObjectManager.Update();
+				}
+			}
+			catch (Exception e)
+			{
+				Log.Error(e.ToString());
+			}
+		}
+	}
+}

+ 0 - 0
Server/Server.App/Properties/AssemblyInfo.cs → Server/App/Properties/AssemblyInfo.cs


+ 6 - 6
Server/Server.App/Server.App.csproj → Server/App/Server.App.csproj

@@ -7,8 +7,8 @@
     <ProjectGuid>{3F8DC04C-9E05-403F-B6A5-36293EB99937}</ProjectGuid>
     <OutputType>Exe</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>Server.App</RootNamespace>
-    <AssemblyName>Server.App</AssemblyName>
+    <RootNamespace>App</RootNamespace>
+    <AssemblyName>App</AssemblyName>
     <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
@@ -55,12 +55,12 @@
     </None>
   </ItemGroup>
   <ItemGroup>
-    <ProjectReference Include="..\Server.Base\Server.Base.csproj">
-      <Project>{afbad3d5-c827-4ba6-9940-7060b6c39306}</Project>
+    <ProjectReference Include="..\Base\Server.Base.csproj">
+      <Project>{e5078ec6-2b0e-4711-be8b-d99f69638316}</Project>
       <Name>Server.Base</Name>
     </ProjectReference>
-    <ProjectReference Include="..\Server.Model\Server.Model.csproj">
-      <Project>{e997a298-c1e1-4dc7-85a3-4b0e2a6e196d}</Project>
+    <ProjectReference Include="..\Model\Server.Model.csproj">
+      <Project>{820d3488-76b9-4ee8-872a-be06c2350b20}</Project>
       <Name>Server.Model</Name>
     </ProjectReference>
   </ItemGroup>

+ 27 - 0
Server/Base/Log.cs

@@ -0,0 +1,27 @@
+namespace Base
+{
+	public static class Log
+	{
+		private static readonly ILog globalLog = new NLogAdapter(new StackInfoDecorater());
+
+		public static void Warning(string message)
+		{
+			globalLog.Warning(message);
+		}
+
+		public static void Info(string message)
+		{
+			globalLog.Info(message);
+		}
+
+		public static void Debug(string format)
+		{
+			globalLog.Debug(format);
+		}
+
+		public static void Error(string format)
+		{
+			globalLog.Error(format);
+		}
+	}
+}

+ 0 - 0
Server/Server.Base/Log/ALogDecorater.cs → Server/Base/Logger/ALogDecorater.cs


+ 1 - 0
Server/Server.Base/Log/ILog.cs → Server/Base/Logger/ILog.cs

@@ -2,6 +2,7 @@
 {
 	public interface ILog
 	{
+		void Warning(string message);
 		void Info(string message);
 		void Debug(string message);
 		void Error(string message);

+ 6 - 1
Server/Server.Base/Log/NLogAdapter.cs → Server/Base/Logger/NLogAdapter.cs

@@ -4,12 +4,17 @@ namespace Base
 {
 	public class NLogAdapter: ALogDecorater, ILog
 	{
-		private readonly NLog.Logger logger = LogManager.GetCurrentClassLogger();
+		private readonly Logger logger = LogManager.GetCurrentClassLogger();
 
 		public NLogAdapter(ALogDecorater decorater = null): base(decorater)
 		{
 		}
 
+		public void Warning(string message)
+		{
+			this.logger.Warn(this.Decorate(SEP + message));
+		}
+
 		public void Info(string message)
 		{
 			this.logger.Info(this.Decorate(SEP + message));

+ 0 - 0
Server/Server.Base/Log/StackInfoDecorater.cs → Server/Base/Logger/StackInfoDecorater.cs


+ 1 - 1
Server/Server.Base/Properties/AssemblyInfo.cs → Server/Base/Properties/AssemblyInfo.cs

@@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
 [assembly: ComVisible(false)]
 
 // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
-[assembly: Guid("afbad3d5-c827-4ba6-9940-7060b6c39306")]
+[assembly: Guid("e5078ec6-2b0e-4711-be8b-d99f69638316")]
 
 // 程序集的版本信息由下列四个值组成: 
 //

+ 268 - 0
Server/Base/Server.Base.csproj

@@ -0,0 +1,268 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.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>{E5078EC6-2B0E-4711-BE8B-D99F69638316}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Base</RootNamespace>
+    <AssemblyName>Base</AssemblyName>
+    <TargetFrameworkVersion>v4.6.1</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="ICSharpCode.SharpZipLib">
+      <HintPath>..\Lib\ICSharpCode.SharpZipLib.dll</HintPath>
+    </Reference>
+    <Reference Include="MongoDB.Bson">
+      <HintPath>..\Lib\MongoDB.Bson.dll</HintPath>
+    </Reference>
+    <Reference Include="NLog">
+      <HintPath>..\Lib\NLog.dll</HintPath>
+    </Reference>
+    <Reference Include="protobuf-net">
+      <HintPath>..\Lib\protobuf-net.dll</HintPath>
+    </Reference>
+    <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.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Component\EventComponent.cs">
+      <Link>Component\EventComponent.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Component\KVComponent.cs">
+      <Link>Component\KVComponent.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Component\MessageComponent.cs">
+      <Link>Component\MessageComponent.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Component\MessageHandlerComponent.cs">
+      <Link>Component\MessageHandlerComponent.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Component\NetworkComponent.cs">
+      <Link>Component\NetworkComponent.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Component\TimeComponent.cs">
+      <Link>Component\TimeComponent.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Component\TimerComponent.cs">
+      <Link>Component\TimerComponent.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Config\ACategory.cs">
+      <Link>Config\ACategory.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Config\AConfig.cs">
+      <Link>Config\AConfig.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Config\ConfigAttribute.cs">
+      <Link>Config\ConfigAttribute.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Config\ICategory.cs">
+      <Link>Config\ICategory.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\DoubleMap.cs">
+      <Link>DoubleMap.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Event\AEventAttribute.cs">
+      <Link>Event\AEventAttribute.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Event\Env.cs">
+      <Link>Event\Env.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Event\EnvBaseKey.cs">
+      <Link>Event\EnvBaseKey.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Event\EventAttribute.cs">
+      <Link>Event\EventAttribute.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Event\EventBaseType.cs">
+      <Link>Event\EventBaseType.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Event\IEvent.cs">
+      <Link>Event\IEvent.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Game.cs">
+      <Link>Game.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\ArrayHelper.cs">
+      <Link>Helper\ArrayHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\ByteHelper.cs">
+      <Link>Helper\ByteHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\EnumHelper.cs">
+      <Link>Helper\EnumHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\FileHelper.cs">
+      <Link>Helper\FileHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\IdGenerater.cs">
+      <Link>Helper\IdGenerater.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\MD5Helper.cs">
+      <Link>Helper\MD5Helper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\MongoHelper.cs">
+      <Link>Helper\MongoHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\ProtobufHelper.cs">
+      <Link>Helper\ProtobufHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\RandomHelper.cs">
+      <Link>Helper\RandomHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\StringHelper.cs">
+      <Link>Helper\StringHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\TimeHelper.cs">
+      <Link>Helper\TimeHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Helper\ZipHelper.cs">
+      <Link>Helper\ZipHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Message\AMEvent.cs">
+      <Link>Message\AMEvent.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Message\IErrorMessage.cs">
+      <Link>Message\IErrorMessage.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Message\IMRegister.cs">
+      <Link>Message\IMRegister.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Message\MessageAttribute.cs">
+      <Link>Message\MessageAttribute.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Message\RpcException.cs">
+      <Link>Message\RpcException.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\MultiMap.cs">
+      <Link>MultiMap.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\AChannel.cs">
+      <Link>Network\AChannel.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\AService.cs">
+      <Link>Network\AService.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\TNet\PacketParser.cs">
+      <Link>Network\TNet\PacketParser.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\TNet\TBuffer.cs">
+      <Link>Network\TNet\TBuffer.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\TNet\TChannel.cs">
+      <Link>Network\TNet\TChannel.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\TNet\TPoller.cs">
+      <Link>Network\TNet\TPoller.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\TNet\TService.cs">
+      <Link>Network\TNet\TService.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\TNet\TSocket.cs">
+      <Link>Network\TNet\TSocket.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\UNet\Library.cs">
+      <Link>Network\UNet\Library.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\UNet\NativeMethods.cs">
+      <Link>Network\UNet\NativeMethods.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\UNet\NativeStructs.cs">
+      <Link>Network\UNet\NativeStructs.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\UNet\UAddress.cs">
+      <Link>Network\UNet\UAddress.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\UNet\UChannel.cs">
+      <Link>Network\UNet\UChannel.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\UNet\UPacket.cs">
+      <Link>Network\UNet\UPacket.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\UNet\UPoller.cs">
+      <Link>Network\UNet\UPoller.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\UNet\UService.cs">
+      <Link>Network\UNet\UService.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\UNet\USocket.cs">
+      <Link>Network\UNet\USocket.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Network\UNet\USocketManager.cs">
+      <Link>Network\UNet\USocketManager.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Object\Component.cs">
+      <Link>Object\Component.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Object\Entity.cs">
+      <Link>Object\Entity.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Object\IAwake.cs">
+      <Link>Object\IAwake.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Object\ILoader.cs">
+      <Link>Object\ILoader.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Object\IStart.cs">
+      <Link>Object\IStart.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Object\IUpdate.cs">
+      <Link>Object\IUpdate.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Object\Object.cs">
+      <Link>Object\Object.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Object\ObjectEventAttribute.cs">
+      <Link>Object\ObjectEventAttribute.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\Object\ObjectManager.cs">
+      <Link>Object\ObjectManager.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\QueueDictionary.cs">
+      <Link>QueueDictionary.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Plugins\Base\TryLocker.cs">
+      <Link>TryLocker.cs</Link>
+    </Compile>
+    <Compile Include="Log.cs" />
+    <Compile Include="Logger\ALogDecorater.cs" />
+    <Compile Include="Logger\ILog.cs" />
+    <Compile Include="Logger\NLogAdapter.cs" />
+    <Compile Include="Logger\StackInfoDecorater.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </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>

+ 1 - 1
Server/Server.Controller/Properties/AssemblyInfo.cs → Server/Controller/Properties/AssemblyInfo.cs

@@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
 [assembly: ComVisible(false)]
 
 // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
-[assembly: Guid("ed2a5401-3829-4a8b-915d-a2a18fb233f8")]
+[assembly: Guid("3878bd71-2f75-4edf-882f-bc708154b1b0")]
 
 // 程序集的版本信息由下列四个值组成: 
 //

+ 9 - 2
Server/Server.Controller/Server.Controller.csproj → Server/Controller/Server.Controller.csproj

@@ -4,7 +4,7 @@
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProjectGuid>{ED2A5401-3829-4A8B-915D-A2A18FB233F8}</ProjectGuid>
+    <ProjectGuid>{3878BD71-2F75-4EDF-882F-BC708154B1B0}</ProjectGuid>
     <OutputType>Library</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Controller</RootNamespace>
@@ -43,7 +43,14 @@
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
-    <Folder Include="Message\" />
+    <ProjectReference Include="..\Base\Server.Base.csproj">
+      <Project>{e5078ec6-2b0e-4711-be8b-d99f69638316}</Project>
+      <Name>Server.Base</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\Model\Server.Model.csproj">
+      <Project>{820d3488-76b9-4ee8-872a-be06c2350b20}</Project>
+      <Name>Server.Model</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. 

+ 1 - 1
Server/Server.Model/Properties/AssemblyInfo.cs → Server/Model/Properties/AssemblyInfo.cs

@@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
 [assembly: ComVisible(false)]
 
 // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
-[assembly: Guid("e997a298-c1e1-4dc7-85a3-4b0e2a6e196d")]
+[assembly: Guid("820d3488-76b9-4ee8-872a-be06c2350b20")]
 
 // 程序集的版本信息由下列四个值组成: 
 //

+ 15 - 30
Server/Server.Model/Server.Model.csproj → Server/Model/Server.Model.csproj

@@ -4,7 +4,7 @@
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProjectGuid>{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}</ProjectGuid>
+    <ProjectGuid>{820D3488-76B9-4EE8-872A-BE06C2350B20}</ProjectGuid>
     <OutputType>Library</OutputType>
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>Model</RootNamespace>
@@ -33,9 +33,6 @@
     <Reference Include="MongoDB.Bson">
       <HintPath>..\Lib\MongoDB.Bson.dll</HintPath>
     </Reference>
-    <Reference Include="protobuf-net">
-      <HintPath>..\Lib\protobuf-net.dll</HintPath>
-    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Xml.Linq" />
@@ -46,35 +43,23 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Event\AEventAttribute.cs" />
-    <Compile Include="Message\AMEvent.cs" />
-    <Compile Include="Component\EventComponent.cs" />
-    <Compile Include="Component\MessageHandlerComponent.cs" />
-    <Compile Include="Component\MessageComponent.cs" />
-    <Compile Include="Component\NetworkComponent.cs" />
-    <Compile Include="Component\Scene.cs" />
-    <Compile Include="Component\TimeComponent.cs" />
-    <Compile Include="Component\TimerComponent.cs" />
-    <Compile Include="Event\EntityType.cs" />
-    <Compile Include="Event\Env.cs" />
-    <Compile Include="Event\EnvKey.cs" />
-    <Compile Include="Message\ErrorCode.cs" />
-    <Compile Include="Event\EventAttribute.cs" />
-    <Compile Include="Event\EventIdType.cs" />
-    <Compile Include="GameException.cs" />
-    <Compile Include="Message\IErrorMessage.cs" />
-    <Compile Include="Event\IEvent.cs" />
-    <Compile Include="Message\IMRegister.cs" />
-    <Compile Include="Message\Message.cs" />
-    <Compile Include="Message\MessageAttribute.cs" />
-    <Compile Include="Message\Opcode.cs" />
-    <Compile Include="Message\OpcodeHelper.cs" />
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\ErrorCode.cs">
+      <Link>Message\ErrorCode.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\Message.cs">
+      <Link>Message\Message.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\Opcode.cs">
+      <Link>Message\Opcode.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Message\OpcodeHelper.cs">
+      <Link>Message\OpcodeHelper.cs</Link>
+    </Compile>
     <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="Scene\Server.cs" />
   </ItemGroup>
   <ItemGroup>
-    <ProjectReference Include="..\Server.Base\Server.Base.csproj">
-      <Project>{afbad3d5-c827-4ba6-9940-7060b6c39306}</Project>
+    <ProjectReference Include="..\Base\Server.Base.csproj">
+      <Project>{e5078ec6-2b0e-4711-be8b-d99f69638316}</Project>
       <Name>Server.Base</Name>
     </ProjectReference>
   </ItemGroup>

+ 0 - 33
Server/Server.App/Program.cs

@@ -1,33 +0,0 @@
-using System;
-using Base;
-using Object = Base.Object;
-
-namespace App
-{
-	class Program
-	{
-		static void Main(string[] args)
-		{
-			try
-			{
-				Object.ObjectManager.Register("Model", typeof(Scene).Assembly);
-				
-				Server.Scene.AddComponent<EventComponent>();
-				Server.Scene.AddComponent<TimerComponent>();
-				Server.Scene.AddComponent<NetworkComponent, NetworkProtocol>(NetworkProtocol.UDP);
-
-				Server.Scene.AddComponent<Scene, SceneType, string>(SceneType.Realm, "realm");
-				Server.Scene.AddComponent<MessageHandlerComponent, SceneType>(Server.Scene.GetComponent<Scene>().SceneType);
-
-				while (true)
-				{
-					Object.ObjectManager.Update();
-				}
-			}
-			catch (Exception e)
-			{
-				Log.Error(e.ToString());
-			}
-		}
-	}
-}

+ 0 - 95
Server/Server.Base/Config/ACategory.cs

@@ -1,95 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-
-namespace Base
-{
-	/// <summary>
-	/// 管理该所有的配置
-	/// </summary>
-	/// <typeparam name="T"></typeparam>
-	public abstract class ACategory<T>: ICategory where T : AConfig
-	{
-		protected Dictionary<long, T> dict;
-
-		public virtual void BeginInit()
-		{
-			this.dict = new Dictionary<long, T>();
-
-			string path = $@"Config/{typeof (T).Name}";
-			string configStr;
-			try
-			{
-				configStr = File.ReadAllText(path);
-			}
-			catch (Exception)
-			{
-				throw new Exception($"load config file fail, path: {path}");
-			}
-
-			foreach (string str in configStr.Split(new[] { "\r\n" }, StringSplitOptions.None))
-			{
-				try
-				{
-					string str2 = str.Trim();
-					if (str2 == "")
-					{
-						continue;
-					}
-					T t = MongoHelper.FromJson<T>(str2);
-					this.dict.Add(t.Id, t);
-				}
-				catch (Exception e)
-				{
-					throw new Exception($"parser json fail: {str}", e);
-				}
-			}
-		}
-
-		public Type ConfigType
-		{
-			get
-			{
-				return typeof (T);
-			}
-		}
-
-		public virtual void EndInit()
-		{
-		}
-
-		public T this[long type]
-		{
-			get
-			{
-				T t;
-				if (!this.dict.TryGetValue(type, out t))
-				{
-					throw new Exception($"{typeof (T)} 没有找到配置, key: {type}");
-				}
-				return t;
-			}
-		}
-
-		public T TryGet(int type)
-		{
-			T t;
-			if (!this.dict.TryGetValue(type, out t))
-			{
-				return null;
-			}
-			return t;
-		}
-
-		public T[] GetAll()
-		{
-			return this.dict.Values.ToArray();
-		}
-
-		public T GetOne()
-		{
-			return this.dict.Values.First();
-		}
-	}
-}

+ 0 - 22
Server/Server.Base/Config/AConfig.cs

@@ -1,22 +0,0 @@
-using System.ComponentModel;
-using MongoDB.Bson.Serialization.Attributes;
-
-namespace Base
-{
-	/// <summary>
-	/// 每个Config的基类
-	/// </summary>
-	public abstract class AConfig: ISupportInitialize
-	{
-		[BsonId]
-		public long Id { get; set; }
-
-		public virtual void BeginInit()
-		{
-		}
-
-		public virtual void EndInit()
-		{
-		}
-	}
-}

+ 0 - 9
Server/Server.Base/Config/ConfigAttribute.cs

@@ -1,9 +0,0 @@
-using System;
-
-namespace Base
-{
-	[AttributeUsage(AttributeTargets.Class)]
-	public class ConfigAttribute: Attribute
-	{
-	}
-}

+ 0 - 10
Server/Server.Base/Config/ICategory.cs

@@ -1,10 +0,0 @@
-using System;
-using System.ComponentModel;
-
-namespace Base
-{
-	public interface ICategory: ISupportInitialize
-	{
-		Type ConfigType { get; }
-	}
-}

+ 0 - 144
Server/Server.Base/DoubleMap.cs

@@ -1,144 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Base
-{
-	public class DoubleMap<K, V>
-	{
-		private readonly Dictionary<K, V> kv = new Dictionary<K, V>();
-		private readonly Dictionary<V, K> vk = new Dictionary<V, K>();
-
-		public DoubleMap()
-		{
-		}
-
-		public DoubleMap(int capacity)
-		{
-			kv = new Dictionary<K, V>(capacity);
-			vk = new Dictionary<V, K>(capacity);
-		}
-
-		public void ForEach(Action<K, V> action)
-		{
-			if (action == null)
-			{
-				return;
-			}
-			Dictionary<K, V>.KeyCollection keys = kv.Keys;
-			foreach (K key in keys)
-			{
-				action(key, kv[key]);
-			}
-		}
-
-		public List<K> Keys
-		{
-			get
-			{
-				return new List<K>(kv.Keys);
-			}
-		}
-
-		public List<V> Values
-		{
-			get
-			{
-				return new List<V>(vk.Keys);
-			}
-		}
-
-		public void Add(K key, V value)
-		{
-			if (key == null || value == null || kv.ContainsKey(key) || vk.ContainsKey(value))
-			{
-				return;
-			}
-			kv.Add(key, value);
-			vk.Add(value, key);
-		}
-
-		public V GetValueByKey(K key)
-		{
-			if (key != null && kv.ContainsKey(key))
-			{
-				return kv[key];
-			}
-			return default(V);
-		}
-
-		public K GetKeyByValue(V value)
-		{
-			if (value != null && vk.ContainsKey(value))
-			{
-				return vk[value];
-			}
-			return default(K);
-		}
-
-		public void RemoveByKey(K key)
-		{
-			if (key == null)
-			{
-				return;
-			}
-			V value;
-			if (!kv.TryGetValue(key, out value))
-			{
-				return;
-			}
-
-			kv.Remove(key);
-			vk.Remove(value);
-		}
-
-		public void RemoveByValue(V value)
-		{
-			if (value == null)
-			{
-				return;
-			}
-
-			K key;
-			if (!vk.TryGetValue(value, out key))
-			{
-				return;
-			}
-
-			kv.Remove(key);
-			vk.Remove(value);
-		}
-
-		public void Clear()
-		{
-			kv.Clear();
-			vk.Clear();
-		}
-
-		public bool ContainsKey(K key)
-		{
-			if (key == null)
-			{
-				return false;
-			}
-			return kv.ContainsKey(key);
-		}
-
-		public bool ContainsValue(V value)
-		{
-			if (value == null)
-			{
-				return false;
-			}
-			return vk.ContainsKey(value);
-		}
-
-		public bool Contains(K key, V value)
-		{
-			if (key == null || value == null)
-			{
-				return false;
-			}
-			return kv.ContainsKey(key) && vk.ContainsKey(value);
-		}
-	}
-}

+ 0 - 12
Server/Server.Base/Helper/ArrayHelper.cs

@@ -1,12 +0,0 @@
-namespace Base
-{
-	public static class ObjectHelper
-	{
-		public static void Swap<T>(ref T t1, ref T t2)
-		{
-			T t3 = t1;
-			t1 = t2;
-			t2 = t3;
-		}
-	}
-}

+ 0 - 59
Server/Server.Base/Helper/ByteHelper.cs

@@ -1,59 +0,0 @@
-using System;
-using System.Text;
-
-namespace Base
-{
-	public static class ByteHelper
-	{
-		public static string ToHex(this byte b)
-		{
-			return b.ToString("X2");
-		}
-
-		public static string ToHex(this byte[] bytes)
-		{
-			StringBuilder stringBuilder = new StringBuilder();
-			foreach (byte b in bytes)
-			{
-				stringBuilder.Append(b.ToString("X2"));
-			}
-			return stringBuilder.ToString();
-		}
-
-		public static string ToHex(this byte[] bytes, string format)
-		{
-			StringBuilder stringBuilder = new StringBuilder();
-			foreach (byte b in bytes)
-			{
-				stringBuilder.Append(b.ToString(format));
-			}
-			return stringBuilder.ToString();
-		}
-
-		public static string ToHex(this byte[] bytes, int offset, int count)
-		{
-			StringBuilder stringBuilder = new StringBuilder();
-			for (int i = offset; i < offset + count; ++i)
-			{
-				stringBuilder.Append(bytes[i].ToString("X2"));
-			}
-			return stringBuilder.ToString();
-		}
-
-		public static string ToStr(this byte[] bytes)
-		{
-			return Encoding.Default.GetString(bytes);
-		}
-
-		public static string Utf8ToStr(this byte[] bytes)
-		{
-			return Encoding.UTF8.GetString(bytes);
-		}
-
-		public static byte[] Reverse(this byte[] bytes)
-		{
-			Array.Reverse(bytes);
-			return bytes;
-		}
-	}
-}

+ 0 - 30
Server/Server.Base/Helper/EnumHelper.cs

@@ -1,30 +0,0 @@
-using System;
-
-namespace Base
-{
-	public static class EnumHelper
-	{
-		public static int EnumIndex<T>(int value)
-		{
-			int i = 0;
-			foreach (object v in Enum.GetValues(typeof (T)))
-			{
-				if ((int) v == value)
-				{
-					return i;
-				}
-				++i;
-			}
-			return -1;
-		}
-
-		public static T FromString<T>(string str)
-		{
-            if (!Enum.IsDefined(typeof(T), str))
-            {
-                return default(T);
-            }
-            return (T)Enum.Parse(typeof(T), str);
-        }
-    }
-}

+ 0 - 59
Server/Server.Base/Helper/FileHelper.cs

@@ -1,59 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-
-namespace Base
-{
-	public static class FileHelper
-	{
-		public static void CleanDirectory(string dir)
-		{
-			foreach (string subdir in Directory.GetDirectories(dir))
-			{
-				Directory.Delete(subdir, true);		
-			}
-
-			foreach (string subFile in Directory.GetFiles(dir))
-			{
-				File.Delete(subFile);
-			}
-		}
-
-		public static void CopyDirectory(string srcDir, string tgtDir)
-		{
-			DirectoryInfo source = new DirectoryInfo(srcDir);
-			DirectoryInfo target = new DirectoryInfo(tgtDir);
-	
-			if (target.FullName.StartsWith(source.FullName, StringComparison.CurrentCultureIgnoreCase))
-			{
-				throw new Exception("父目录不能拷贝到子目录!");
-			}
-	
-			if (!source.Exists)
-			{
-				return;
-			}
-	
-			if (!target.Exists)
-			{
-				target.Create();
-			}
-	
-			FileInfo[] files = source.GetFiles();
-	
-			for (int i = 0; i < files.Length; i++)
-			{
-				File.Copy(files[i].FullName, target.FullName + @"\" + files[i].Name, true);
-			}
-	
-			DirectoryInfo[] dirs = source.GetDirectories();
-	
-			for (int j = 0; j < dirs.Length; j++)
-			{
-				CopyDirectory(dirs[j].FullName, target.FullName + @"\" + dirs[j].Name);
-			}
-		}
-	}
-}

+ 0 - 12
Server/Server.Base/Helper/IdGenerater.cs

@@ -1,12 +0,0 @@
-namespace Base
-{
-	public static class IdGenerater
-	{
-		private static long value = long.MaxValue;
-
-		public static long GenerateId()
-		{
-			return --value;
-		}
-	}
-}

+ 0 - 19
Server/Server.Base/Helper/MD5Helper.cs

@@ -1,19 +0,0 @@
-using System.IO;
-using System.Security.Cryptography;
-
-namespace Base
-{
-	public static class MD5Helper
-	{
-		public static string FileMD5(string filePath)
-		{
-			byte[] retVal;
-            using (FileStream file = new FileStream(filePath, FileMode.Open))
-			{
-				MD5 md5 = new MD5CryptoServiceProvider();
-				retVal = md5.ComputeHash(file);
-			}
-			return retVal.ToHex("x2");
-		}
-	}
-}

+ 0 - 67
Server/Server.Base/Helper/MongoHelper.cs

@@ -1,67 +0,0 @@
-using System;
-using System.IO;
-using MongoDB.Bson;
-using MongoDB.Bson.IO;
-using MongoDB.Bson.Serialization;
-
-namespace Base
-{
-	public static class MongoHelper
-	{
-		public static string ToJson(object obj)
-		{
-			return obj.ToJson();
-		}
-
-		public static string ToJson(object obj, JsonWriterSettings settings)
-		{
-			return obj.ToJson(settings);
-		}
-
-		public static T FromJson<T>(string str)
-		{
-			return BsonSerializer.Deserialize<T>(str);
-		}
-
-		public static object FromJson(Type type, string str)
-		{
-			return BsonSerializer.Deserialize(str, type);
-		}
-
-		public static byte[] ToBson(object obj)
-		{
-			return obj.ToBson();
-		}
-
-		public static object FromBson(Type type, byte[] bytes)
-		{
-			return BsonSerializer.Deserialize(bytes, type);
-		}
-
-		public static object FromBson(Type type, byte[] bytes, int index, int count)
-		{
-			using (MemoryStream memoryStream = new MemoryStream(bytes, index, count))
-			{
-				return BsonSerializer.Deserialize(memoryStream, type);
-			}
-		}
-
-		public static T FromBson<T>(byte[] bytes)
-		{
-			using (MemoryStream memoryStream = new MemoryStream(bytes))
-			{
-				return (T) BsonSerializer.Deserialize(memoryStream, typeof (T));
-			}
-		}
-
-		public static T FromBson<T>(byte[] bytes, int index, int count)
-		{
-			return (T) FromBson(typeof (T), bytes, index, count);
-		}
-
-		public static T Clone<T>(T t)
-		{
-			return FromBson<T>(ToBson(t));
-		}
-	}
-}

+ 0 - 83
Server/Server.Base/Helper/ProtobufHelper.cs

@@ -1,83 +0,0 @@
-using System;
-using System.ComponentModel;
-using System.IO;
-using ProtoBuf;
-
-namespace Base
-{
-	public static class ProtobufHelper
-	{
-		public static byte[] ToBytes(object message)
-		{
-			using (MemoryStream ms = new MemoryStream())
-			{
-				Serializer.Serialize(ms, message);
-				return ms.ToArray();
-			}
-		}
-
-		public static T FromBytes<T>(byte[] bytes)
-		{
-			T t;
-			using (MemoryStream ms = new MemoryStream(bytes, 0, bytes.Length))
-			{
-				t = Serializer.Deserialize<T>(ms);
-			}
-			ISupportInitialize iSupportInitialize = t as ISupportInitialize;
-			if (iSupportInitialize == null)
-			{
-				return t;
-			}
-			iSupportInitialize.EndInit();
-			return t;
-		}
-
-		public static T FromBytes<T>(byte[] bytes, int index, int length)
-		{
-			T t;
-			using (MemoryStream ms = new MemoryStream(bytes, index, length))
-			{
-				t = Serializer.Deserialize<T>(ms);
-			}
-			ISupportInitialize iSupportInitialize = t as ISupportInitialize;
-			if (iSupportInitialize == null)
-			{
-				return t;
-			}
-			iSupportInitialize.EndInit();
-			return t;
-		}
-
-		public static object FromBytes(Type type, byte[] bytes)
-		{
-			object t;
-			using (MemoryStream ms = new MemoryStream(bytes, 0, bytes.Length))
-			{
-				t = Serializer.NonGeneric.Deserialize(type, ms);
-			}
-			ISupportInitialize iSupportInitialize = t as ISupportInitialize;
-			if (iSupportInitialize == null)
-			{
-				return t;
-			}
-			iSupportInitialize.EndInit();
-			return t;
-		}
-
-		public static object FromBytes(Type type, byte[] bytes, int index, int length)
-		{
-			object t;
-			using (MemoryStream ms = new MemoryStream(bytes, index, length))
-			{
-				t = Serializer.NonGeneric.Deserialize(type, ms);
-			}
-			ISupportInitialize iSupportInitialize = t as ISupportInitialize;
-			if (iSupportInitialize == null)
-			{
-				return t;
-			}
-			iSupportInitialize.EndInit();
-			return t;
-		}
-	}
-}

+ 0 - 28
Server/Server.Base/Helper/RandomHelper.cs

@@ -1,28 +0,0 @@
-using System;
-
-namespace Base
-{
-	public static class RandomHelper
-	{
-		public static UInt64 RandUInt64()
-		{
-			var bytes = new byte[8];
-			Random random = new Random();
-			random.NextBytes(bytes);
-			return BitConverter.ToUInt64(bytes, 0);
-		}
-
-		/// <summary>
-		/// 获取lower与Upper之间的随机数
-		/// </summary>
-		/// <param name="lower"></param>
-		/// <param name="upper"></param>
-		/// <returns></returns>
-		public static int RandomNumber(int lower, int upper)
-		{
-			Random ra = new Random(Guid.NewGuid().GetHashCode());
-			int value = ra.Next(lower, upper);
-			return value;
-		}
-	}
-}

+ 0 - 62
Server/Server.Base/Helper/StringHelper.cs

@@ -1,62 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Text;
-
-namespace Base
-{
-	public static class StringHelper
-	{
-		public static IEnumerable<byte> ToBytes(this string str)
-		{
-			byte[] byteArray = Encoding.Default.GetBytes(str);
-			return byteArray;
-		}
-
-		public static byte[] ToByteArray(this string str)
-		{
-			byte[] byteArray = Encoding.Default.GetBytes(str);
-			return byteArray;
-		}
-
-	    public static byte[] ToUtf8(this string str)
-	    {
-            byte[] byteArray = Encoding.UTF8.GetBytes(str);
-            return byteArray;
-        }
-
-		public static byte[] HexToBytes(this string hexString)
-		{
-			if (hexString.Length % 2 != 0)
-			{
-				throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "The binary key cannot have an odd number of digits: {0}", hexString));
-			}
-
-			var hexAsBytes = new byte[hexString.Length / 2];
-			for (int index = 0; index < hexAsBytes.Length; index++)
-			{
-				string byteValue = "";
-				byteValue += hexString[index * 2];
-				byteValue += hexString[index * 2 + 1];
-				hexAsBytes[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
-			}
-			return hexAsBytes;
-		}
-
-		public static string Fmt(this string text, params object[] args)
-		{
-			return string.Format(text, args);
-		}
-
-		public static string ListToString<T>(this List<T> list)
-		{
-			StringBuilder sb = new StringBuilder();
-			foreach (T t in list)
-			{
-				sb.Append(t);
-				sb.Append(",");
-			}
-			return sb.ToString();
-		}
-	}
-}

+ 0 - 22
Server/Server.Base/Helper/TimeHelper.cs

@@ -1,22 +0,0 @@
-using System;
-
-namespace Base
-{
-	public static class TimeHelper
-	{
-		private static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
-		/// <summary>
-		/// 客户端时间
-		/// </summary>
-		/// <returns></returns>
-		public static long ClientNow()
-		{
-			return Convert.ToInt64((DateTime.UtcNow - Epoch).TotalMilliseconds);
-		}
-
-		public static long ClientNowTicks()
-		{	
-			return Convert.ToInt64((DateTime.UtcNow - Epoch).Ticks);
-		}
-    }
-}

+ 0 - 97
Server/Server.Base/Helper/ZipHelper.cs

@@ -1,97 +0,0 @@
-using System.IO;
-using ICSharpCode.SharpZipLib.Zip.Compression;
-
-namespace Base
-{
-	public static class ZipHelper
-	{
-		public static byte[] Compress(byte[] content)
-		{
-			//return content;
-			Deflater compressor = new Deflater();
-			compressor.SetLevel(Deflater.BEST_COMPRESSION);
-
-			compressor.SetInput(content);
-			compressor.Finish();
-
-			using (MemoryStream bos = new MemoryStream(content.Length))
-			{
-				var buf = new byte[1024];
-				while (!compressor.IsFinished)
-				{
-					int n = compressor.Deflate(buf);
-					bos.Write(buf, 0, n);
-				}
-				return bos.ToArray();
-			}
-		}
-
-		public static byte[] Decompress(byte[] content)
-		{
-			return Decompress(content, 0, content.Length);
-		}
-
-		public static byte[] Decompress(byte[] content, int offset, int count)
-		{
-			//return content;
-			Inflater decompressor = new Inflater();
-			decompressor.SetInput(content, offset, count);
-
-			using (MemoryStream bos = new MemoryStream(content.Length))
-			{
-				var buf = new byte[1024];
-				while (!decompressor.IsFinished)
-				{
-					int n = decompressor.Inflate(buf);
-					bos.Write(buf, 0, n);
-				}
-				return bos.ToArray();
-			}
-		}
-	}
-}
-
-/*
-using System.IO;
-using System.IO.Compression;
-
-namespace Model
-{
-	public static class ZipHelper
-	{
-		public static byte[] Compress(byte[] content)
-		{
-			using (MemoryStream ms = new MemoryStream())
-			using (DeflateStream stream = new DeflateStream(ms, CompressionMode.Compress, true))
-			{
-				stream.Write(content, 0, content.Length);
-				return ms.ToArray();
-			}
-		}
-
-		public static byte[] Decompress(byte[] content)
-		{
-			return Decompress(content, 0, content.Length);
-		}
-
-		public static byte[] Decompress(byte[] content, int offset, int count)
-		{
-			using (MemoryStream ms = new MemoryStream())
-			using (DeflateStream stream = new DeflateStream(new MemoryStream(content, offset, count), CompressionMode.Decompress, true))
-			{
-				byte[] buffer = new byte[1024];
-				while (true)
-				{
-					int bytesRead = stream.Read(buffer, 0, 1024);
-					if (bytesRead == 0)
-					{
-						break;
-					}
-					ms.Write(buffer, 0, bytesRead);
-				}
-				return ms.ToArray();
-			}
-		}
-	}
-}
-*/

+ 0 - 45
Server/Server.Base/Log/Log.cs

@@ -1,45 +0,0 @@
-namespace Base
-{
-	public static class Log
-	{
-		private static readonly ILog globalLog = new NLogAdapter(new StackInfoDecorater());
-
-		private static ILog GlobalLog
-		{
-			get
-			{
-				return globalLog;
-			}
-		}
-
-		public static void Info(string message)
-		{
-			GlobalLog.Info(message);
-		}
-
-		public static void Info(string format, params object[] args)
-		{
-			GlobalLog.Info(string.Format(format, args));
-		}
-
-		public static void Debug(string format)
-		{
-			GlobalLog.Debug(format);
-		}
-
-		public static void Debug(string format, params object[] args)
-		{
-			GlobalLog.Debug(string.Format(format, args));
-		}
-
-		public static void Error(string format)
-		{
-			GlobalLog.Error(format);
-		}
-
-		public static void Error(string format, params object[] args)
-		{
-			GlobalLog.Error(string.Format(format, args));
-		}
-	}
-}

+ 0 - 111
Server/Server.Base/MultiMap.cs

@@ -1,111 +0,0 @@
-using System.Collections.Generic;
-
-namespace Base
-{
-	public class MultiMap<T, K>
-	{
-		private readonly SortedDictionary<T, List<K>> dictionary = new SortedDictionary<T, List<K>>();
-
-		public SortedDictionary<T, List<K>>.KeyCollection Keys
-		{
-			get
-			{
-				return this.dictionary.Keys;
-			}
-		}
-
-		public void Add(T t, K k)
-		{
-			List<K> list;
-			this.dictionary.TryGetValue(t, out list);
-			if (list == null)
-			{
-				list = new List<K>();
-			}
-			list.Add(k);
-			this.dictionary[t] = list;
-		}
-
-		public bool Remove(T t, K k)
-		{
-			List<K> list;
-			this.dictionary.TryGetValue(t, out list);
-			if (list == null)
-			{
-				return false;
-			}
-			if (!list.Remove(k))
-			{
-				return false;
-			}
-			if (list.Count == 0)
-			{
-				this.dictionary.Remove(t);
-			}
-			return true;
-		}
-
-		public bool Remove(T t)
-		{
-			return this.dictionary.Remove(t);
-		}
-
-		/// <summary>
-		/// 不返回内部的list,copy一份出来
-		/// </summary>
-		/// <param name="t"></param>
-		/// <returns></returns>
-		public K[] GetAll(T t)
-		{
-			List<K> list;
-			this.dictionary.TryGetValue(t, out list);
-			if (list == null)
-			{
-				return new K[0];
-			}
-			var newList = new List<K>();
-			foreach (K k in list)
-			{
-				newList.Add(k);
-			}
-			return newList.ToArray();
-		}
-
-		/// <summary>
-		/// 返回内部的list
-		/// </summary>
-		/// <param name="t"></param>
-		/// <returns></returns>
-		public List<K> this[T t]
-		{
-			get
-			{
-				List<K> list;
-				this.dictionary.TryGetValue(t, out list);
-				return list;
-			}
-		}
-
-		public K GetOne(T t)
-		{
-			List<K> list;
-			this.dictionary.TryGetValue(t, out list);
-			if ((list != null) && (list.Count > 0))
-			{
-				return list[0];
-			}
-			return default(K);
-		}
-
-		public bool Contains(T t, K k)
-		{
-			List<K> list;
-			this.dictionary.TryGetValue(t, out list);
-			if (list == null)
-			{
-				return false;
-			}
-			return list.Contains(k);
-		}
-	}
-}

+ 0 - 51
Server/Server.Base/Network/AChannel.cs

@@ -1,51 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-
-namespace Base
-{
-	[Flags]
-	public enum PacketFlags
-	{
-		None = 0,
-		Reliable = 1 << 0,
-		Unsequenced = 1 << 1,
-		NoAllocate = 1 << 2
-	}
-
-	public abstract class AChannel: IDisposable
-	{
-		public long Id { get; private set; }
-		protected AService service;
-
-		protected AChannel(AService service)
-		{
-			this.Id = IdGenerater.GenerateId();
-			this.service = service;
-		}
-		
-		/// <summary>
-		/// 发送消息
-		/// </summary>
-		public abstract void Send(byte[] buffer, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable);
-
-		public abstract void Send(List<byte[]> buffers, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable);
-
-		/// <summary>
-		/// 接收消息
-		/// </summary>
-		public abstract Task<byte[]> Recv();
-
-		public virtual void Dispose()
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-
-			this.service.Remove(this.Id);
-
-			this.Id = 0;
-		}
-	}
-}

+ 0 - 45
Server/Server.Base/Network/AService.cs

@@ -1,45 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Sockets;
-using System.Threading.Tasks;
-
-namespace Base
-{
-	public enum NetworkProtocol
-	{
-		TCP,
-		UDP
-	}
-
-	public abstract class AService: IDisposable
-	{
-		/// <summary>
-		/// 将函数调用加入IService线程
-		/// </summary>
-		/// <param name="action"></param>
-		public abstract void Add(Action action);
-
-		public abstract AChannel GetChannel(long id);
-
-		public abstract AChannel GetChannel(string host, int port);
-
-		public abstract AChannel GetChannel(string address);
-
-		public abstract Task<AChannel> AcceptChannel();
-
-		public abstract void Remove(long channelId);
-
-		public abstract void Update();
-
-		public Action<long, SocketError> OnError;
-
-		protected void OnChannelError(long channelId, SocketError error)
-		{
-			this.OnError?.Invoke(channelId, error);
-			this.Remove(channelId);
-		}
-
-		public abstract void Dispose();
-	}
-}

+ 0 - 85
Server/Server.Base/Network/TNet/PacketParser.cs

@@ -1,85 +0,0 @@
-using System;
-
-namespace Base
-{
-	internal enum ParserState
-	{
-		PacketSize,
-		PacketBody
-	}
-
-	internal class PacketParser
-	{
-		private readonly TBuffer buffer;
-
-		private uint packetSize;
-		private readonly byte[] packetSizeBuffer = new byte[4];
-		private ParserState state;
-		private byte[] packet;
-		private bool isOK;
-
-		public PacketParser(TBuffer buffer)
-		{
-			this.buffer = buffer;
-		}
-
-		private bool Parse()
-		{
-			if (this.isOK)
-			{
-				return true;
-			}
-
-			bool finish = false;
-			while (!finish)
-			{
-				switch (this.state)
-				{
-					case ParserState.PacketSize:
-						if (this.buffer.Count < 4)
-						{
-							finish = true;
-						}
-						else
-						{
-							this.buffer.RecvFrom(this.packetSizeBuffer);
-							this.packetSize = BitConverter.ToUInt32(this.packetSizeBuffer, 0);
-							if (packetSize > 1024 * 1024)
-							{
-								throw new Exception($"packet too large, size: {this.packetSize}");
-							}
-							this.state = ParserState.PacketBody;
-						}
-						break;
-					case ParserState.PacketBody:
-						if (this.buffer.Count < this.packetSize)
-						{
-							finish = true;
-						}
-						else
-						{
-							this.packet = new byte[this.packetSize];
-							this.buffer.RecvFrom(this.packet);
-							this.isOK = true;
-							this.state = ParserState.PacketSize;
-							finish = true;
-						}
-						break;
-				}
-			}
-			return this.isOK;
-		}
-
-		public byte[] GetPacket()
-		{
-			this.Parse();
-			if (!this.isOK)
-			{
-				return null;
-			}
-			byte[] result = this.packet;
-			this.isOK = false;
-			return result;
-		}
-	}
-}

+ 0 - 129
Server/Server.Base/Network/TNet/TBuffer.cs

@@ -1,129 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Base
-{
-	public class TBuffer
-	{
-		public const int ChunkSize = 8192;
-
-		private readonly LinkedList<byte[]> bufferList = new LinkedList<byte[]>();
-
-		public int LastIndex { get; set; }
-
-		public int FirstIndex { get; set; }
-
-		public TBuffer()
-		{
-			this.bufferList.AddLast(new byte[ChunkSize]);
-		}
-
-		public int Count
-		{
-			get
-			{
-				int c = 0;
-				if (this.bufferList.Count == 0)
-				{
-					c = 0;
-				}
-				else
-				{
-					c = (this.bufferList.Count - 1) * ChunkSize + this.LastIndex - this.FirstIndex;
-				}
-				if (c < 0)
-				{
-					Log.Error("TBuffer count < 0: {0}, {1}, {2}".Fmt(bufferList.Count, this.LastIndex, this.FirstIndex));
-				}
-				return c;
-			}
-		}
-
-		public void AddLast()
-		{
-			this.bufferList.AddLast(new byte[ChunkSize]);
-		}
-
-		public void RemoveFirst()
-		{
-			this.bufferList.RemoveFirst();
-		}
-
-		public byte[] First
-		{
-			get
-			{
-				if (this.bufferList.First == null)
-				{
-					this.AddLast();
-				}
-				return this.bufferList.First.Value;
-			}
-		}
-
-		public byte[] Last
-		{
-			get
-			{
-				if (this.bufferList.Last == null)
-				{
-					this.AddLast();
-				}
-				return this.bufferList.Last.Value;
-			}
-		}
-
-		public void RecvFrom(byte[] buffer)
-		{
-			if (this.Count < buffer.Length || buffer.Length == 0)
-			{
-				throw new Exception($"bufferList size < n, bufferList: {this.Count} buffer length: {buffer.Length}");
-			}
-			int alreadyCopyCount = 0;
-			while (alreadyCopyCount < buffer.Length)
-			{
-				int n = buffer.Length - alreadyCopyCount;
-				if (ChunkSize - this.FirstIndex > n)
-				{
-					Array.Copy(this.bufferList.First.Value, this.FirstIndex, buffer, alreadyCopyCount, n);
-					this.FirstIndex += n;
-					alreadyCopyCount += n;
-				}
-				else
-				{
-					Array.Copy(this.bufferList.First.Value, this.FirstIndex, buffer, alreadyCopyCount, ChunkSize - this.FirstIndex);
-					alreadyCopyCount += ChunkSize - this.FirstIndex;
-					this.FirstIndex = 0;
-					this.bufferList.RemoveFirst();
-				}
-			}
-		}
-
-		public void SendTo(byte[] buffer)
-		{
-			int alreadyCopyCount = 0;
-			while (alreadyCopyCount < buffer.Length)
-			{
-				if (this.LastIndex == ChunkSize)
-				{
-					this.bufferList.AddLast(new byte[ChunkSize]);
-					this.LastIndex = 0;
-				}
-
-				int n = buffer.Length - alreadyCopyCount;
-				if (ChunkSize - this.LastIndex > n)
-				{
-					Array.Copy(buffer, alreadyCopyCount, this.bufferList.Last.Value, this.LastIndex, n);
-					this.LastIndex += buffer.Length - alreadyCopyCount;
-					alreadyCopyCount += n;
-				}
-				else
-				{
-					Array.Copy(buffer, alreadyCopyCount, this.bufferList.Last.Value, this.LastIndex, ChunkSize - this.LastIndex);
-					alreadyCopyCount += ChunkSize - this.LastIndex;
-					this.LastIndex = ChunkSize;
-				}
-			}
-		}
-	}
-}

+ 0 - 217
Server/Server.Base/Network/TNet/TChannel.cs

@@ -1,217 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Sockets;
-using System.Threading.Tasks;
-
-namespace Base
-{
-	public class TChannel : AChannel
-	{
-		private readonly TSocket socket;
-
-		private readonly TBuffer recvBuffer = new TBuffer();
-		private readonly TBuffer sendBuffer = new TBuffer();
-
-		private bool isSending;
-		private readonly PacketParser parser;
-		private bool isConnected;
-
-		public Action<long, SocketError> OnError;
-
-		public string RemoteAddress { get; }
-		private TaskCompletionSource<byte[]> recvTcs;
-
-		/// <summary>
-		/// connect
-		/// </summary>
-		public TChannel(TSocket socket, string host, int port, TService service) : base(service)
-		{
-			this.socket = socket;
-			this.parser = new PacketParser(this.recvBuffer);
-			this.RemoteAddress = host + ":" + port;
-			
-			bool result = this.socket.ConnectAsync(host, port);
-			if (!result)
-			{
-				this.OnConnected(this.Id, SocketError.Success);
-				return;
-			}
-			this.socket.OnConn += e => OnConnected(this.Id, e);
-		}
-
-		/// <summary>
-		/// accept
-		/// </summary>
-		public TChannel(TSocket socket, TService service) : base(service)
-		{
-			this.socket = socket;
-			this.parser = new PacketParser(this.recvBuffer);
-			this.RemoteAddress = socket.RemoteAddress;
-		}
-
-		public override void Dispose()
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-
-			long id = this.Id;
-
-			base.Dispose();
-
-			this.socket.Dispose();
-			this.service.Remove(id);
-		}
-		
-		private void OnConnected(long channelId, SocketError error)
-		{
-			if (this.service.GetChannel(channelId) == null)
-			{
-				return;
-			}
-			if (error != SocketError.Success)
-			{
-				Log.Error($"connect error: {error}");
-				return;
-			}
-			this.isConnected = true;
-			this.StartSend();
-			this.StartRecv();
-		}
-
-		public override void Send(byte[] buffer, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
-		{
-			byte[] size = BitConverter.GetBytes(buffer.Length);
-			this.sendBuffer.SendTo(size);
-			this.sendBuffer.SendTo(buffer);
-			if (!this.isSending && this.isConnected)
-			{
-				this.StartSend();
-			}
-		}
-
-		public override void Send(List<byte[]> buffers, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
-		{
-			int size = buffers.Select(b => b.Length).Sum();
-			byte[] sizeBuffer = BitConverter.GetBytes(size);
-			this.sendBuffer.SendTo(sizeBuffer);
-			foreach (byte[] buffer in buffers)
-			{
-				this.sendBuffer.SendTo(buffer);
-			}
-			if (!this.isSending && this.isConnected)
-			{
-				this.StartSend();
-			}
-		}
-
-		private void StartSend()
-		{
-			// 没有数据需要发送
-			if (this.sendBuffer.Count == 0)
-			{
-				this.isSending = false;
-				return;
-			}
-
-			this.isSending = true;
-
-			int sendSize = TBuffer.ChunkSize - this.sendBuffer.FirstIndex;
-			if (sendSize > this.sendBuffer.Count)
-			{
-				sendSize = this.sendBuffer.Count;
-			}
-
-			if (!this.socket.SendAsync(this.sendBuffer.First, this.sendBuffer.FirstIndex, sendSize))
-			{
-				this.OnSend(sendSize, SocketError.Success);
-				return;
-			}
-			this.socket.OnSend = this.OnSend;
-		}
-
-		private void OnSend(int n, SocketError error)
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-			this.socket.OnSend = null;
-			if (error != SocketError.Success)
-			{
-				Log.Info($"socket send fail, error: {error}, n: {n}");
-				this.OnError(this.Id, error);
-				return;
-			}
-			this.sendBuffer.FirstIndex += n;
-			if (this.sendBuffer.FirstIndex == TBuffer.ChunkSize)
-			{
-				this.sendBuffer.FirstIndex = 0;
-				this.sendBuffer.RemoveFirst();
-			}
-
-			this.StartSend();
-		}
-
-		private void StartRecv()
-		{
-			int size = TBuffer.ChunkSize - this.recvBuffer.LastIndex;
-			if (!this.socket.RecvAsync(this.recvBuffer.Last, this.recvBuffer.LastIndex, size))
-			{
-				this.OnRecv(size, SocketError.Success);
-			}
-			this.socket.OnRecv = this.OnRecv;
-		}
-
-		private void OnRecv(int n, SocketError error)
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-			this.socket.OnRecv = null;
-			if (error != SocketError.Success)
-			{
-				Log.Info($"socket recv fail, error: {error}, {n}");
-				this.OnError(this.Id, error);
-				return;
-			}
-
-			this.recvBuffer.LastIndex += n;
-			if (this.recvBuffer.LastIndex == TBuffer.ChunkSize)
-			{
-				this.recvBuffer.AddLast();
-				this.recvBuffer.LastIndex = 0;
-			}
-
-			if (this.recvTcs != null)
-			{
-				byte[] packet = this.parser.GetPacket();
-				if (packet != null)
-				{
-					this.recvTcs.SetResult(packet);
-					this.recvTcs = null;
-				}
-			}
-
-			StartRecv();
-		}
-
-		public override Task<byte[]> Recv()
-		{
-			TaskCompletionSource<byte[]> tcs = new TaskCompletionSource<byte[]>();
-			byte[] packet = this.parser.GetPacket();
-			if (packet != null)
-			{
-				tcs.SetResult(packet);
-			}
-			else
-			{
-				recvTcs = tcs;
-			}
-			return tcs.Task;
-		}
-	}
-}

+ 0 - 38
Server/Server.Base/Network/TNet/TPoller.cs

@@ -1,38 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Base
-{
-	public class TPoller
-	{
-		// 线程同步队列,发送接收socket回调都放到该队列,由poll线程统一执行
-		private Queue<Action> queue = new Queue<Action>();
-
-		private Queue<Action> localQueue = new Queue<Action>();
-
-		private readonly object lockObject = new object();
-
-		public void Add(Action action)
-		{
-			lock (lockObject)
-			{
-				this.queue.Enqueue(action);
-			}
-		}
-
-		public void Update()
-		{
-			lock (lockObject)
-			{
-				localQueue = queue;
-				queue = new Queue<Action>();
-			}
-
-			while (this.localQueue.Count > 0)
-			{
-				Action a = this.localQueue.Dequeue();
-				a();
-			}
-		}
-	}
-}

+ 0 - 116
Server/Server.Base/Network/TNet/TService.cs

@@ -1,116 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace Base
-{
-	public sealed class TService: AService
-	{
-		private TPoller poller = new TPoller();
-		private readonly TSocket acceptor;
-
-		private readonly Dictionary<long, TChannel> idChannels = new Dictionary<long, TChannel>();
-		private readonly Dictionary<string, TChannel> addressChannels = new Dictionary<string, TChannel>();
-
-		/// <summary>
-		/// 即可做client也可做server
-		/// </summary>
-		/// <param name="host"></param>
-		/// <param name="port"></param>
-		public TService(string host, int port)
-		{
-			this.acceptor = new TSocket(this.poller, host, port);
-		}
-
-		public TService()
-		{
-		}
-
-		public override void Dispose()
-		{
-			if (this.poller == null)
-			{
-				return;
-			}
-
-			foreach (long id in this.idChannels.Keys.ToArray())
-			{
-				TChannel channel = this.idChannels[id];
-				channel.Dispose();
-			}
-
-			this.poller = null;
-		}
-
-		public override void Add(Action action)
-		{
-			this.poller.Add(action);
-		}
-
-		public override AChannel GetChannel(long id)
-		{
-			TChannel channel = null;
-			this.idChannels.TryGetValue(id, out channel);
-			return channel;
-		}
-
-		public override async Task<AChannel> AcceptChannel()
-		{
-			if (this.acceptor == null)
-			{
-				throw new Exception("service construct must use host and port param");
-			}
-			TSocket socket = new TSocket(this.poller);
-			await this.acceptor.AcceptAsync(socket);
-			TChannel channel = new TChannel(socket, this);
-			this.addressChannels[channel.RemoteAddress] = channel;
-			this.idChannels[channel.Id] = channel;
-			return channel;
-		}
-
-		public override void Remove(long id)
-		{
-			TChannel channel;
-			if (!this.idChannels.TryGetValue(id, out channel))
-			{
-				return;
-			}
-			if (channel == null)
-			{
-				return;
-			}
-			this.idChannels.Remove(id);
-			channel.Dispose();
-		}
-
-		public override AChannel GetChannel(string host, int port)
-		{
-			string address = $"{host}:{port}";
-			return this.GetChannel(address);
-		}
-
-		public override AChannel GetChannel(string address)
-		{
-			TChannel channel = null;
-			if (this.addressChannels.TryGetValue(address, out channel))
-			{
-				return channel;
-			}
-
-			string[] ss = address.Split(':');
-			string host = ss[0];
-			int port = int.Parse(ss[1]);
-			TSocket newSocket = new TSocket(this.poller);
-			channel = new TChannel(newSocket, host, port, this);
-			channel.OnError += this.OnChannelError;
-			this.idChannels[channel.Id] = channel;
-			return channel;
-		}
-
-		public override void Update()
-		{
-			this.poller.Update();
-		}
-	}
-}

+ 0 - 211
Server/Server.Base/Network/TNet/TSocket.cs

@@ -1,211 +0,0 @@
-using System;
-using System.Net;
-using System.Net.Sockets;
-using System.Threading.Tasks;
-
-namespace Base
-{
-	/// <summary>
-	/// 封装Socket,将回调push到主线程处理
-	/// </summary>
-	public class TSocket: IDisposable
-	{
-		private readonly TPoller poller;
-		private Socket socket;
-		private readonly SocketAsyncEventArgs innArgs = new SocketAsyncEventArgs();
-		private readonly SocketAsyncEventArgs outArgs = new SocketAsyncEventArgs();
-
-		public Action<SocketError> OnConn;
-		public Action<int, SocketError> OnRecv;
-		public Action<int, SocketError> OnSend;
-		public Action<SocketError> OnDisconnect;
-
-		public TSocket(TPoller poller)
-		{
-			this.poller = poller;
-			this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
-			this.innArgs.Completed += this.OnComplete;
-			this.outArgs.Completed += this.OnComplete;
-		}
-
-		public TSocket(TPoller poller, string host, int port): this(poller)
-		{
-			this.Bind(host, port);
-			this.Listen(100);
-		}
-		
-		public Socket Socket
-		{
-			get
-			{
-				return this.socket;
-			}
-		}
-
-		public string RemoteAddress
-		{
-			get
-			{
-				IPEndPoint ipEndPoint = (IPEndPoint)this.socket.RemoteEndPoint;
-				return ipEndPoint.Address + ":" + ipEndPoint.Port;
-			}
-		}
-
-		public void Dispose()
-		{
-			if (this.socket == null)
-			{
-				return;
-			}
-			
-			this.socket.Close();
-
-			this.socket = null;
-		}
-
-		private void Bind(string host, int port)
-		{
-			this.socket.Bind(new IPEndPoint(IPAddress.Parse(host), port));
-		}
-
-		private void Listen(int backlog)
-		{
-			this.socket.Listen(backlog);
-		}
-
-		public Task<bool> AcceptAsync(TSocket accpetSocket)
-		{
-			var tcs = new TaskCompletionSource<bool>();
-			this.innArgs.UserToken = tcs;
-			this.innArgs.AcceptSocket = accpetSocket.socket;
-			if (!this.socket.AcceptAsync(this.innArgs))
-			{
-				OnAcceptComplete(this.innArgs);
-			}
-			return tcs.Task;
-		}
-
-		private static void OnAcceptComplete(SocketAsyncEventArgs e)
-		{
-			var tcs = (TaskCompletionSource<bool>)e.UserToken;
-			e.UserToken = null;
-			if (e.SocketError != SocketError.Success)
-			{
-				tcs.SetException(new Exception($"socket error: {e.SocketError}"));
-				return;
-			}
-			tcs.SetResult(true);
-		}
-
-		private void OnComplete(object sender, SocketAsyncEventArgs e)
-		{
-			Action action;
-			switch (e.LastOperation)
-			{
-				case SocketAsyncOperation.Connect:
-					action = () => OnConnectComplete(e);
-					break;
-				case SocketAsyncOperation.Receive:
-					action = () => OnRecvComplete(e);
-					break;
-				case SocketAsyncOperation.Send:
-					action = () => OnSendComplete(e);
-					break;
-				case SocketAsyncOperation.Disconnect:
-					action = () => OnDisconnectComplete(e);
-					break;
-				case SocketAsyncOperation.Accept:
-					action = () => OnAcceptComplete(e);
-					break;
-				default:
-					throw new Exception($"socket error: {e.LastOperation}");
-			}
-
-			// 回调到主线程处理
-			this.poller.Add(action);
-		}
-
-		public bool ConnectAsync(string host, int port)
-		{
-			this.outArgs.RemoteEndPoint = new IPEndPoint(IPAddress.Parse(host), port);
-			if (this.socket.ConnectAsync(this.outArgs))
-			{
-				return true;
-			}
-			OnConnectComplete(this.outArgs);
-			return false;
-		}
-
-		private void OnConnectComplete(SocketAsyncEventArgs e)
-		{
-			if (this.OnConn == null)
-			{
-				return;
-			}
-			this.OnConn(e.SocketError);
-		}
-
-		public bool RecvAsync(byte[] buffer, int offset, int count)
-		{
-			try
-			{
-				this.innArgs.SetBuffer(buffer, offset, count);
-			}
-			catch (Exception e)
-			{
-				throw new Exception($"socket set buffer error: {buffer.Length}, {offset}, {count}", e);
-			}
-			if (this.socket.ReceiveAsync(this.innArgs))
-			{
-				return true;
-			}
-			OnRecvComplete(this.innArgs);
-			return false;
-		}
-
-		private void OnRecvComplete(SocketAsyncEventArgs e)
-		{
-			if (this.OnRecv == null)
-			{
-				return;
-			}
-			this.OnRecv(e.BytesTransferred, e.SocketError);
-		}
-
-		public bool SendAsync(byte[] buffer, int offset, int count)
-		{
-			try
-			{
-				this.outArgs.SetBuffer(buffer, offset, count);
-			}
-			catch (Exception e)
-			{
-				throw new Exception($"socket set buffer error: {buffer.Length}, {offset}, {count}", e);
-			}
-			if (this.socket.SendAsync(this.outArgs))
-			{
-				return true;
-			}
-			OnSendComplete(this.outArgs);
-			return false;
-		}
-
-		private void OnSendComplete(SocketAsyncEventArgs e)
-		{
-			if (this.OnSend == null)
-			{
-				return;
-			}
-			this.OnSend(e.BytesTransferred, e.SocketError);
-		}
-
-		private void OnDisconnectComplete(SocketAsyncEventArgs e)
-		{
-			if (this.OnDisconnect == null)
-			{
-				return;
-			}
-			this.OnDisconnect(e.SocketError);
-		}
-	}
-}

+ 0 - 33
Server/Server.Base/Network/UNet/Library.cs

@@ -1,33 +0,0 @@
-using System;
-
-namespace Base
-{
-	internal static class Library
-	{
-		public static void Initialize()
-		{
-			int ret = NativeMethods.ENetInitialize();
-			if (ret < 0)
-			{
-				throw new Exception($"Initialization failed, ret: {ret}");
-			}
-		}
-
-		public static void Deinitialize()
-		{
-			NativeMethods.ENetDeinitialize();
-		}
-
-		public static uint Time
-		{
-			get
-			{
-				return NativeMethods.ENetTimeGet();
-			}
-			set
-			{
-				NativeMethods.ENetTimeSet(value);
-			}
-		}
-	}
-}

+ 0 - 105
Server/Server.Base/Network/UNet/NativeMethods.cs

@@ -1,105 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace Base
-{
-	public static class NativeMethods
-	{
-		private const string LIB = "ENet";
-
-		public const int ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255;
-		public const int ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xfff;
-
-		[DllImport(LIB, EntryPoint = "enet_address_set_host", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int ENetAddressSetHost(ref ENetAddress address, string hostName);
-
-		[DllImport(LIB, EntryPoint = "enet_address_get_host", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int ENetAddressGetHost(ref ENetAddress address, StringBuilder hostName, uint nameLength);
-
-		[DllImport(LIB, EntryPoint = "enet_address_get_host_ip", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int ENetAddressGetHostIp(ref ENetAddress address, StringBuilder hostIp, uint ipLength);
-
-		[DllImport(LIB, EntryPoint = "enet_deinitialize", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void ENetDeinitialize();
-
-		[DllImport(LIB, EntryPoint = "enet_initialize", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int ENetInitialize();
-
-		[DllImport(LIB, EntryPoint = "enet_host_create", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern IntPtr ENetHostCreate(
-				ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
-
-		[DllImport(LIB, EntryPoint = "enet_host_create", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern IntPtr ENetHostCreate(IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
-
-		[DllImport(LIB, EntryPoint = "enet_host_destroy", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void ENetHostDestroy(IntPtr host);
-
-		[DllImport(LIB, EntryPoint = "enet_host_connect", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern IntPtr ENetHostConnect(IntPtr host, ref ENetAddress address, uint channelCount, uint data);
-
-		[DllImport(LIB, EntryPoint = "enet_host_broadcast", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void ENetHostBroadcast(IntPtr host, byte channelID, IntPtr packet);
-
-		[DllImport(LIB, EntryPoint = "enet_host_compress", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void ENetHostCompress(IntPtr host, IntPtr compressor);
-
-		[DllImport(LIB, EntryPoint = "enet_host_compress_with_range_coder", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int ENetHostCompressWithRangeCoder(IntPtr host);
-
-		[DllImport(LIB, EntryPoint = "enet_host_channel_limit", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void ENetHostChannelLimit(IntPtr host, uint channelLimit);
-
-		[DllImport(LIB, EntryPoint = "enet_host_bandwidth_limit", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void ENetHostBandwidthLimit(IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
-
-		[DllImport(LIB, EntryPoint = "enet_host_flush", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void ENetHostFlush(IntPtr host);
-
-		[DllImport(LIB, EntryPoint = "enet_host_check_events", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int ENetHostCheckEvents(IntPtr host, ENetEvent ev);
-
-		[DllImport(LIB, EntryPoint = "enet_host_service", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int ENetHostService(IntPtr host, ENetEvent ev, uint timeout);
-
-		[DllImport(LIB, EntryPoint = "enet_time_get", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern uint ENetTimeGet();
-
-		[DllImport(LIB, EntryPoint = "enet_time_set", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void ENetTimeSet(uint newTimeBase);
-
-		[DllImport(LIB, EntryPoint = "enet_packet_create", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern IntPtr ENetPacketCreate(byte[] data, uint dataLength, PacketFlags flags);
-
-		[DllImport(LIB, EntryPoint = "enet_packet_destroy", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void ENetPacketDestroy(IntPtr packet);
-
-		[DllImport(LIB, EntryPoint = "enet_packet_resize", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int ENetPacketResize(IntPtr packet, uint dataLength);
-
-		[DllImport(LIB, EntryPoint = "enet_peer_throttle_configure", CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void ENetPeerThrottleConfigure(IntPtr peer, uint interval, uint acceleration, uint deceleration);
-
-		[DllImport(LIB, EntryPoint = "enet_peer_send")]
-		internal static extern int ENetPeerSend(IntPtr peer, byte channelID, IntPtr packet);
-
-		[DllImport(LIB, EntryPoint = "enet_peer_receive")]
-		internal static extern IntPtr ENetPeerReceive(IntPtr peer, out byte channelID);
-
-		[DllImport(LIB, EntryPoint = "enet_peer_reset")]
-		internal static extern void ENetPeerReset(IntPtr peer);
-
-		[DllImport(LIB, EntryPoint = "enet_peer_ping")]
-		internal static extern void ENetPeerPing(IntPtr peer);
-
-		[DllImport(LIB, EntryPoint = "enet_peer_disconnect_now")]
-		internal static extern void ENetPeerDisconnectNow(IntPtr peer, uint data);
-
-		[DllImport(LIB, EntryPoint = "enet_peer_disconnect")]
-		internal static extern void ENetPeerDisconnect(IntPtr peer, uint data);
-
-		[DllImport(LIB, EntryPoint = "enet_peer_disconnect_later")]
-		internal static extern void ENetPeerDisconnectLater(IntPtr peer, uint data);
-	}
-}

+ 0 - 76
Server/Server.Base/Network/UNet/NativeStructs.cs

@@ -1,76 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-
-namespace Base
-{
-	internal enum EventType
-	{
-		None = 0,
-		Connect = 1,
-		Disconnect = 2,
-		Receive = 3
-	}
-
-	internal enum PeerState
-	{
-		Uninitialized = -1,
-		Disconnected = 0,
-		Connecting = 1,
-		AcknowledgingConnect = 2,
-		ConnectionPending = 3,
-		ConnectionSucceeded = 4,
-		Connected = 5,
-		DisconnectLater = 6,
-		Disconnecting = 7,
-		AcknowledgingDisconnect = 8,
-		Zombie = 9
-	}
-
-	[StructLayout(LayoutKind.Sequential)]
-	internal struct ENetAddress
-	{
-		public uint Host;
-		public ushort Port;
-	}
-
-	// ENetEvent
-	[StructLayout(LayoutKind.Sequential)]
-	internal class ENetEvent
-	{
-		public EventType Type;
-		public IntPtr Peer;
-		public byte ChannelID;
-		public uint Data;
-		public IntPtr Packet;
-	}
-
-	[StructLayout(LayoutKind.Sequential)]
-	internal class ENetListNode
-	{
-		public IntPtr Next;
-		public IntPtr Previous;
-	}
-
-	[StructLayout(LayoutKind.Sequential)]
-	internal struct ENetPacket
-	{
-		public IntPtr ReferenceCount; // size_t
-		public uint Flags;
-		public IntPtr Data;
-		public IntPtr DataLength; // size_t
-	}
-
-	[StructLayout(LayoutKind.Sequential)]
-	internal struct ENetPeer
-	{
-		public ENetListNode DispatchList;
-		public IntPtr Host;
-		public ushort OutgoingPeerID;
-		public ushort IncomingPeerID;
-		public uint ConnectID;
-		public byte OutgoingSessionID;
-		public byte IncomingSessionID;
-		public ENetAddress Address;
-		public IntPtr Data;
-	}
-}

+ 0 - 27
Server/Server.Base/Network/UNet/UAddress.cs

@@ -1,27 +0,0 @@
-using System;
-using System.Net;
-
-namespace Base
-{
-	internal struct UAddress
-	{
-		private readonly uint ip;
-		private readonly ushort port;
-
-		public UAddress(string host, int port)
-		{
-			IPAddress address = IPAddress.Parse(host);
-			this.ip = BitConverter.ToUInt32(address.GetAddressBytes(), 0);
-			this.port = (ushort) port;
-		}
-
-		public ENetAddress Struct
-		{
-			get
-			{
-				ENetAddress address = new ENetAddress { Host = this.ip, Port = this.port };
-				return address;
-			}
-		}
-	}
-}

+ 0 - 90
Server/Server.Base/Network/UNet/UChannel.cs

@@ -1,90 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace Base
-{
-	internal class UChannel: AChannel
-	{
-		private readonly USocket socket;
-		public string RemoteAddress { get; private set; }
-
-		private TaskCompletionSource<byte[]> recvTcs;
-
-		/// <summary>
-		/// connect
-		/// </summary>
-		public UChannel(USocket socket, string host, int port, UService service): base(service)
-		{
-			this.socket = socket;
-			this.service = service;
-			this.RemoteAddress = host + ":" + port;
-			this.socket.ConnectAsync(host, (ushort)port);
-			this.socket.Received += this.OnRecv;
-		}
-
-		/// <summary>
-		/// accept
-		/// </summary>
-		public UChannel(USocket socket, UService service) : base(service)
-		{
-			this.socket = socket;
-			this.service = service;
-			this.RemoteAddress = socket.RemoteAddress;
-			this.socket.Received += this.OnRecv;
-		}
-
-		public override void Dispose()
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-			
-			base.Dispose();
-
-			this.socket.Dispose();
-		}
-
-		public override void Send(byte[] buffer, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
-		{
-			this.socket.SendAsync(buffer, channelID, flags);
-		}
-
-		public override void Send(List<byte[]> buffers, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
-		{
-			int size = buffers.Select(b => b.Length).Sum();
-			var buffer = new byte[size];
-			int index = 0;
-			foreach (byte[] bytes in buffers)
-			{
-				Array.Copy(bytes, 0, buffer, index, bytes.Length);
-				index += bytes.Length;
-			}
-			this.socket.SendAsync(buffer, channelID, flags);
-		}
-
-		public override Task<byte[]> Recv()
-		{
-			TaskCompletionSource<byte[]> tcs = new TaskCompletionSource<byte[]>();
-			var recvQueue = this.socket.RecvQueue;
-			if (recvQueue.Count > 0)
-			{
-				tcs.SetResult(recvQueue.Dequeue());
-			}
-			else
-			{
-				recvTcs = tcs;
-			}
-			
-			return tcs.Task;
-		}
-
-		private void OnRecv()
-		{
-			this.recvTcs?.SetResult(this.socket.RecvQueue.Dequeue());
-			this.recvTcs = null;
-		}
-	}
-}

+ 0 - 72
Server/Server.Base/Network/UNet/UPacket.cs

@@ -1,72 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-
-namespace Base
-{
-	internal sealed class UPacket: IDisposable
-	{
-		public UPacket(IntPtr packet)
-		{
-			this.PacketPtr = packet;
-		}
-
-		public UPacket(byte[] data, PacketFlags flags = PacketFlags.None)
-		{
-			if (data == null)
-			{
-				throw new ArgumentNullException(nameof(data));
-			}
-			this.PacketPtr = NativeMethods.ENetPacketCreate(data, (uint) data.Length, flags);
-			if (this.PacketPtr == IntPtr.Zero)
-			{
-				throw new Exception("Packet creation call failed");
-			}
-		}
-
-		~UPacket()
-		{
-			this.Dispose(false);
-		}
-
-		public void Dispose()
-		{
-			this.Dispose(true);
-		}
-
-		private void Dispose(bool disposing)
-		{
-			if (this.PacketPtr == IntPtr.Zero)
-			{
-				return;
-			}
-
-			NativeMethods.ENetPacketDestroy(this.PacketPtr);
-			this.PacketPtr = IntPtr.Zero;
-		}
-
-		private ENetPacket Struct
-		{
-			get
-			{
-				return (ENetPacket) Marshal.PtrToStructure(this.PacketPtr, typeof (ENetPacket));
-			}
-			set
-			{
-				Marshal.StructureToPtr(value, this.PacketPtr, false);
-			}
-		}
-
-		public IntPtr PacketPtr { get; set; }
-
-		public byte[] Bytes
-		{
-			get
-			{
-				ENetPacket enetPacket = this.Struct;
-				var bytes = new byte[(long) enetPacket.DataLength];
-				Marshal.Copy(enetPacket.Data, bytes, 0, (int) enetPacket.DataLength);
-				return bytes;
-			}
-		}
-	}
-}

+ 0 - 226
Server/Server.Base/Network/UNet/UPoller.cs

@@ -1,226 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-
-namespace Base
-{
-	internal sealed class UPoller : IDisposable
-	{
-		static UPoller()
-		{
-			Library.Initialize();
-		}
-
-		public USocketManager USocketManager { get; }
-		private readonly QueueDictionary<IntPtr, ENetEvent> connQueue = new QueueDictionary<IntPtr, ENetEvent>();
-
-		private IntPtr host;
-
-		// 线程同步队列,发送接收socket回调都放到该队列,由poll线程统一执行
-		private Queue<Action> concurrentQueue = new Queue<Action>();
-		private Queue<Action> localQueue;
-		private readonly object lockObject = new object();
-
-		private ENetEvent eNetEventCache;
-
-		private TaskCompletionSource<USocket> AcceptTcs { get; set; }
-
-		public UPoller(string hostName, ushort port)
-		{
-			this.USocketManager = new USocketManager();
-			
-			UAddress address = new UAddress(hostName, port);
-			ENetAddress nativeAddress = address.Struct;
-			this.host = NativeMethods.ENetHostCreate(ref nativeAddress,
-					NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID, 0, 0, 0);
-
-			if (this.host == IntPtr.Zero)
-			{
-				throw new Exception("Host creation call failed.");
-			}
-
-			NativeMethods.ENetHostCompressWithRangeCoder(this.host);
-		}
-
-		public UPoller()
-		{
-			this.USocketManager = new USocketManager();
-
-			this.host = NativeMethods.ENetHostCreate(IntPtr.Zero, NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID, 0, 0, 0);
-
-			if (this.host == IntPtr.Zero)
-			{
-				throw new Exception("Host creation call failed.");
-			}
-		}
-
-		public void Dispose()
-		{
-			if (this.host == IntPtr.Zero)
-			{
-				return;
-			}
-
-			NativeMethods.ENetHostDestroy(this.host);
-
-			this.host = IntPtr.Zero;
-		}
-
-		public IntPtr Host
-		{
-			get
-			{
-				return this.host;
-			}
-		}
-
-		private ENetEvent TryGetEvent()
-		{
-			if (this.eNetEventCache == null)
-			{
-				this.eNetEventCache = new ENetEvent();
-			}
-			if (NativeMethods.ENetHostCheckEvents(this.host, this.eNetEventCache) <= 0)
-			{
-				return null;
-			}
-			ENetEvent eNetEvent = this.eNetEventCache;
-			this.eNetEventCache = null;
-			return eNetEvent;
-		}
-
-		public void Flush()
-		{
-			NativeMethods.ENetHostFlush(this.host);
-		}
-
-		public void Add(Action action)
-		{
-			lock (lockObject)
-			{
-				this.concurrentQueue.Enqueue(action);
-			}
-		}
-
-		public Task<USocket> AcceptAsync()
-		{
-			if (this.AcceptTcs != null)
-			{
-				throw new Exception("do not accept twice!");
-			}
-
-			var tcs = new TaskCompletionSource<USocket>();
-
-			// 如果有请求连接缓存的包,从缓存中取
-			if (this.connQueue.Count > 0)
-			{
-				IntPtr ptr = this.connQueue.FirstKey;
-				this.connQueue.Remove(ptr);
-
-				USocket socket = new USocket(ptr, this);
-				this.USocketManager.Add(ptr, socket);
-				tcs.SetResult(socket);
-			}
-			else
-			{
-				this.AcceptTcs = tcs;
-			}
-			return tcs.Task;
-		}
-
-		private void OnAccepted(ENetEvent eEvent)
-		{
-			if (eEvent.Type == EventType.Disconnect)
-			{
-				this.AcceptTcs.TrySetException(new Exception("socket disconnected in accpet"));
-			}
-			
-			USocket socket = new USocket(eEvent.Peer, this);
-			this.USocketManager.Add(socket.PeerPtr, socket);
-			socket.OnAccepted();
-
-			var tcs = this.AcceptTcs;
-			this.AcceptTcs = null;
-			tcs.SetResult(socket);
-		}
-
-		private void OnEvents()
-		{
-			lock (lockObject)
-			{
-				localQueue = concurrentQueue;
-				concurrentQueue = new Queue<Action>();
-			}
-
-			while (this.localQueue.Count > 0)
-			{
-				Action a = this.localQueue.Dequeue();
-				a();
-			}
-		}
-
-		private int Service()
-		{
-			int ret = NativeMethods.ENetHostService(this.host, null, 0);
-			return ret;
-		}
-
-		public void Update()
-		{
-			this.OnEvents();
-
-			if (this.Service() < 0)
-			{
-				return;
-			}
-
-			while (true)
-			{
-				ENetEvent eNetEvent = this.TryGetEvent();
-				if (eNetEvent == null)
-				{
-					return;
-				}
-
-				switch (eNetEvent.Type)
-				{
-					case EventType.Connect:
-						{
-							// 这是一个connect peer
-							if (this.USocketManager.ContainsKey(eNetEvent.Peer))
-							{
-								USocket uSocket = this.USocketManager[eNetEvent.Peer];
-								uSocket.OnConnected();
-								break;
-							}
-
-							// 这是accept peer
-							if (this.AcceptTcs != null)
-							{
-								this.OnAccepted(eNetEvent);
-								break;
-							}
-
-							// 如果server端没有acceptasync,则请求放入队列
-							this.connQueue.Add(eNetEvent.Peer, eNetEvent);
-							break;
-						}
-					case EventType.Receive:
-						{
-							USocket uSocket = this.USocketManager[eNetEvent.Peer];
-							uSocket.OnReceived(eNetEvent);
-							break;
-						}
-					case EventType.Disconnect:
-						{
-							USocket uSocket = this.USocketManager[eNetEvent.Peer];
-							this.USocketManager.Remove(uSocket.PeerPtr);
-							uSocket.PeerPtr = IntPtr.Zero;
-							uSocket.OnDisconnect(eNetEvent);
-							break;
-						}
-				}
-			}
-		}
-	}
-}

+ 0 - 111
Server/Server.Base/Network/UNet/UService.cs

@@ -1,111 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Sockets;
-using System.Threading.Tasks;
-
-namespace Base
-{
-	public sealed class UService: AService
-	{
-		private UPoller poller;
-
-		private readonly Dictionary<long, UChannel> idChannels = new Dictionary<long, UChannel>();
-		private readonly Dictionary<string, UChannel> addressChannels = new Dictionary<string, UChannel>();
-
-		/// <summary>
-		/// 即可做client也可做server
-		/// </summary>
-		public UService(string host, int port)
-		{
-			this.poller = new UPoller(host, (ushort)port);
-		}
-
-		/// <summary>
-		/// 只能做client
-		/// </summary>
-		public UService()
-		{
-			this.poller = new UPoller();
-		}
-
-		public override void Dispose()
-		{
-			if (this.poller == null)
-			{
-				return;
-			}
-
-			foreach (long id in this.idChannels.Keys.ToArray())
-			{
-				UChannel channel = this.idChannels[id];
-				channel.Dispose();
-			}
-			
-			this.poller = null;
-		}
-
-		public override void Add(Action action)
-		{
-			this.poller.Add(action);
-		}
-
-		public override AChannel GetChannel(string host, int port)
-		{
-			return this.GetChannel($"{host}:{port}");
-		}
-
-		public override AChannel GetChannel(string address)
-		{
-			UChannel channel = null;
-			if (this.addressChannels.TryGetValue(address, out channel))
-			{
-				return channel;
-			}
-			USocket newSocket = new USocket(this.poller);
-			string[] ss = address.Split(':');
-			int port = int.Parse(ss[1]);
-			string host = ss[0];
-			channel = new UChannel(newSocket, host, port, this);
-			newSocket.Disconnect += () => this.OnChannelError(channel.Id, SocketError.SocketError);
-			this.idChannels[channel.Id] = channel;
-			return channel;
-		}
-
-		public override async Task<AChannel> AcceptChannel()
-		{
-			USocket socket = await this.poller.AcceptAsync();
-			UChannel channel = new UChannel(socket, this);
-			this.addressChannels[channel.RemoteAddress] = channel;
-			this.idChannels[channel.Id] = channel;
-			return channel;
-		}
-
-		public override AChannel GetChannel(long id)
-		{
-			UChannel channel = null;
-			this.idChannels.TryGetValue(id, out channel);
-			return channel;
-		}
-
-		public override void Remove(long id)
-		{
-			UChannel channel;
-			if (!this.idChannels.TryGetValue(id, out channel))
-			{
-				return;
-			}
-			if (channel == null)
-			{
-				return;
-			}
-			this.idChannels.Remove(id);
-			channel.Dispose();
-		}
-
-		public override void Update()
-		{
-			this.poller.Update();
-		}
-	}
-}

+ 0 - 137
Server/Server.Base/Network/UNet/USocket.cs

@@ -1,137 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Runtime.InteropServices;
-
-namespace Base
-{
-	internal class BufferInfo
-	{
-		public byte[] Buffer { get; set; }
-		public byte ChannelID { get; set; }
-		public PacketFlags Flags { get; set; }
-	}
-
-	internal sealed class USocket: IDisposable
-	{
-		private readonly UPoller poller;
-		public IntPtr PeerPtr { get; set; }
-		private readonly Queue<byte[]> recvQueue = new Queue<byte[]>();
-		private readonly Queue<BufferInfo> sendQueue = new Queue<BufferInfo>();
-		private bool isConnected;
-		public Action Disconnect;
-		public Action Received;
-
-		public USocket(IntPtr peerPtr, UPoller poller)
-		{
-			this.poller = poller;
-			this.PeerPtr = peerPtr;
-		}
-
-		public USocket(UPoller poller)
-		{
-			this.poller = poller;
-		}
-
-		public void Dispose()
-		{
-			if (this.PeerPtr == IntPtr.Zero)
-			{
-				return;
-			}
-
-			poller.USocketManager.Remove(this.PeerPtr);
-			NativeMethods.ENetPeerDisconnectNow(this.PeerPtr, 0);
-			this.PeerPtr = IntPtr.Zero;
-		}
-
-		public string RemoteAddress
-		{
-			get
-			{
-				ENetPeer peer = this.Struct;
-				return peer.Address.Host + ":" + peer.Address.Port;
-			}
-		}
-
-		private ENetPeer Struct
-		{
-			get
-			{
-				if (this.PeerPtr == IntPtr.Zero)
-				{
-					return new ENetPeer();
-				}
-				ENetPeer peer = (ENetPeer)Marshal.PtrToStructure(this.PeerPtr, typeof(ENetPeer));
-				return peer;
-			}
-			set
-			{
-				Marshal.StructureToPtr(value, this.PeerPtr, false);
-			}
-		}
-		
-		public Queue<byte[]> RecvQueue
-		{
-			get
-			{
-				return recvQueue;
-			}
-		}
-
-		public void ConnectAsync(string host, ushort port)
-		{
-			UAddress address = new UAddress(host, port);
-			ENetAddress nativeAddress = address.Struct;
-
-			this.PeerPtr = NativeMethods.ENetHostConnect(this.poller.Host, ref nativeAddress, 2, 0);
-			if (this.PeerPtr == IntPtr.Zero)
-			{
-				throw new Exception($"host connect call failed, {host}:{port}");
-			}
-			this.poller.USocketManager.Add(this.PeerPtr, this);
-		}
-
-		public void SendAsync(byte[] data, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
-		{
-			if (!isConnected)
-			{
-				sendQueue.Enqueue(new BufferInfo { Buffer = data, ChannelID = channelID, Flags = flags });
-				return;
-			}
-			UPacket packet = new UPacket(data, flags);
-			NativeMethods.ENetPeerSend(this.PeerPtr, channelID, packet.PacketPtr);
-			// enet_peer_send函数会自动删除packet,设置为0,防止Dispose或者析构函数再次删除
-			packet.PacketPtr = IntPtr.Zero;
-		}
-
-		internal void OnConnected()
-		{
-			isConnected = true;
-			while (this.sendQueue.Count > 0)
-			{
-				BufferInfo info = this.sendQueue.Dequeue();
-				this.SendAsync(info.Buffer, info.ChannelID, info.Flags);
-			}
-		}
-
-		internal void OnAccepted()
-		{
-			isConnected = true;
-		}
-
-		internal void OnReceived(ENetEvent eNetEvent)
-		{
-			// 将包放到缓存队列
-			using (UPacket packet = new UPacket(eNetEvent.Packet))
-			{
-				byte[] bytes = packet.Bytes;
-				this.RecvQueue.Enqueue(bytes);
-			}
-		}
-
-		internal void OnDisconnect(ENetEvent eNetEvent)
-		{
-			Disconnect();
-		}
-	}
-}

+ 0 - 41
Server/Server.Base/Network/UNet/USocketManager.cs

@@ -1,41 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Base
-{
-	internal class USocketManager
-	{
-		private readonly Dictionary<IntPtr, USocket> sockets = new Dictionary<IntPtr, USocket>();
-
-		public void Add(IntPtr peerPtr, USocket uSocket)
-		{
-			this.sockets.Add(peerPtr, uSocket);
-		}
-
-		public void Remove(IntPtr peerPtr)
-		{
-			this.sockets.Remove(peerPtr);
-		}
-
-		public bool ContainsKey(IntPtr peerPtr)
-		{
-			if (this.sockets.ContainsKey(peerPtr))
-			{
-				return true;
-			}
-			return false;
-		}
-
-		public USocket this[IntPtr peerPtr]
-		{
-			get
-			{
-				if (!this.sockets.ContainsKey(peerPtr))
-				{
-					throw new KeyNotFoundException("No Peer Key");
-				}
-				return this.sockets[peerPtr];
-			}
-		}
-	}
-}

+ 0 - 32
Server/Server.Base/Object/Component.cs

@@ -1,32 +0,0 @@
-namespace Base
-{
-	/// <summary>
-	/// Component的Id与Owner Entity Id一样
-	/// </summary>
-	public abstract class Component: Object
-	{
-		public Entity Owner { get; set; }
-
-		protected Component()
-		{
-			ObjectManager.Add(this);
-		}
-
-		protected Component(long id): base(id)
-		{
-			ObjectManager.Add(this);
-		}
-
-		public T GetComponent<T>() where T: Component
-		{
-			return this.Owner.GetComponent<T>();
-		}
-
-		public override void Dispose()
-		{
-			base.Dispose();
-
-			ObjectManager.Remove(this.Id);
-		}
-	}
-}

+ 0 - 203
Server/Server.Base/Object/Entity.cs

@@ -1,203 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Base;
-using MongoDB.Bson.Serialization.Attributes;
-
-namespace Base
-{
-	public sealed class Entity: Object
-	{
-		[BsonElement, BsonIgnoreIfNull]
-		private HashSet<Component> components = new HashSet<Component>();
-		private Dictionary<Type, Component> componentDict = new Dictionary<Type, Component>();
-
-		public Entity()
-		{
-			ObjectManager.Add(this);
-		}
-
-		public Entity(long id): base(id)
-		{
-			ObjectManager.Add(this);
-		}
-		
-		public override void Dispose()
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-
-			base.Dispose();
-
-			foreach (Component component in this.GetComponents())
-			{
-				try
-				{
-					component.Dispose();
-				}
-				catch (Exception e)
-				{
-					Log.Error(e.ToString());
-				}
-			}
-			ObjectManager.Remove(this.Id);
-		}
-
-		public K AddComponent<K>() where K : Component, new()
-		{
-			K component = (K) Activator.CreateInstance(typeof (K));
-			component.Owner = this;
-
-			if (this.componentDict.ContainsKey(component.GetType()))
-			{
-				throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof (K).Name}");
-			}
-
-			if (this.components == null)
-			{
-				this.components = new HashSet<Component>();
-			}
-
-			this.components.Add(component);
-			this.componentDict.Add(component.GetType(), component);
-			ObjectManager.Awake(component.Id);
-			return component;
-		}
-
-		public K AddComponent<K, P1>(P1 p1) where K : Component, new()
-		{
-			K component = (K)Activator.CreateInstance(typeof(K));
-			component.Owner = this;
-
-			if (this.componentDict.ContainsKey(component.GetType()))
-			{
-				throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
-			}
-
-			if (this.components == null)
-			{
-				this.components = new HashSet<Component>();
-			}
-
-			this.components.Add(component);
-			this.componentDict.Add(component.GetType(), component);
-			ObjectManager.Awake(component.Id, p1);
-			return component;
-		}
-
-		public K AddComponent<K, P1, P2>(P1 p1, P2 p2) where K : Component, new()
-		{
-			K component = (K)Activator.CreateInstance(typeof(K));
-			component.Owner = this;
-
-			if (this.componentDict.ContainsKey(component.GetType()))
-			{
-				throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
-			}
-
-			if (this.components == null)
-			{
-				this.components = new HashSet<Component>();
-			}
-
-			this.components.Add(component);
-			this.componentDict.Add(component.GetType(), component);
-			ObjectManager.Awake(component.Id, p1, p2);
-			return component;
-		}
-
-
-		public K AddComponent<K, P1, P2, P3>(P1 p1, P2 p2, P3 p3) where K : Component, new()
-		{
-			K component = (K)Activator.CreateInstance(typeof(K));
-			component.Owner = this;
-
-			if (this.componentDict.ContainsKey(component.GetType()))
-			{
-				throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {typeof(K).Name}");
-			}
-
-			if (this.components == null)
-			{
-				this.components = new HashSet<Component>();
-			}
-
-			this.components.Add(component);
-			this.componentDict.Add(component.GetType(), component);
-			ObjectManager.Awake(component.Id, p1, p2, p3);
-			return component;
-		}
-
-		public void AddComponent(Component component)
-		{
-			if (this.componentDict.ContainsKey(component.GetType()))
-			{
-				throw new Exception($"AddComponent, component already exist, id: {this.Id}, component: {component.GetType().Name}");
-			}
-
-			if (this.components == null)
-			{
-				this.components = new HashSet<Component>();
-			}
-			this.components.Add(component);
-			this.componentDict.Add(component.GetType(), component);
-			ObjectManager.Awake(component.Id);
-		}
-
-		public void RemoveComponent<K>() where K : Component
-		{
-			Component component;
-			if (!this.componentDict.TryGetValue(typeof (K), out component))
-			{
-				return;
-			}
-
-			this.components.Remove(component);
-			this.componentDict.Remove(typeof (K));
-			if (this.components.Count == 0)
-			{
-				this.components = null;
-			}
-			component.Dispose();
-		}
-
-		public K GetComponent<K>() where K : Component
-		{
-			Component component;
-			if (!this.componentDict.TryGetValue(typeof (K), out component))
-			{
-				return default(K);
-			}
-			return (K) component;
-		}
-
-		public Component[] GetComponents()
-		{
-			return components.ToArray();
-		}
-
-		public override void BeginInit()
-		{
-			base.BeginInit();
-			this.components = new HashSet<Component>();
-			this.componentDict = new Dictionary<Type, Component>();
-		}
-
-		public override void EndInit()
-		{
-			base.EndInit();
-			if (this.components.Count == 0)
-			{
-				this.components = null;
-				return;
-			}
-			foreach (Component component in this.components)
-			{
-				component.Owner = this;
-				this.componentDict.Add(component.GetType(), component);
-			}
-		}
-	}
-}

+ 0 - 25
Server/Server.Base/Object/IAwake.cs

@@ -1,25 +0,0 @@
-namespace Base
-{
-	/// <summary>
-	/// World的Componet实现该接口后,会在World.Start时调用该Start方法
-	/// </summary>
-	public interface IAwake
-	{
-		void Awake();
-	}
-
-	public interface IAwake<in P1>
-	{
-		void Awake(P1 p1);
-	}
-
-	public interface IAwake<in P1, in P2>
-	{
-		void Awake(P1 p1, P2 p2);
-	}
-
-	public interface IAwake<in P1, in P2, in P3>
-	{
-		void Awake(P1 p1, P2 p2, P3 p3);
-	}
-}

+ 0 - 10
Server/Server.Base/Object/ILoader.cs

@@ -1,10 +0,0 @@
-namespace Base
-{
-	/// <summary>
-	/// World的Componet实现该接口,World.Load会调用Load方法
-	/// </summary>
-	public interface ILoader
-	{
-		void Load();
-	}
-}

+ 0 - 10
Server/Server.Base/Object/IStart.cs

@@ -1,10 +0,0 @@
-namespace Base
-{
-	/// <summary>
-	/// World的Componet实现该接口后,会在World.Start时调用该Start方法
-	/// </summary>
-	public interface IStart
-	{
-		void Start();
-	}
-}

+ 0 - 10
Server/Server.Base/Object/IUpdate.cs

@@ -1,10 +0,0 @@
-namespace Base
-{
-	/// <summary>
-	/// 实现了该接口的World Componet会每帧刷新
-	/// </summary>
-	public interface IUpdate
-	{
-		void Update();
-	}
-}

+ 0 - 47
Server/Server.Base/Object/Object.cs

@@ -1,47 +0,0 @@
-using System;
-using System.ComponentModel;
-using MongoDB.Bson.Serialization.Attributes;
-
-namespace Base
-{
-	public abstract class Object: IDisposable, ISupportInitialize
-	{
-		public static ObjectManager ObjectManager = new ObjectManager();
-
-		[BsonId]
-		public long Id { get; private set; }
-
-		protected Object()
-		{
-			Id = IdGenerater.GenerateId();
-		}
-
-		protected Object(long id)
-		{
-			this.Id = id;
-		}
-
-		public bool IsDisposed()
-		{
-			return this.Id == 0;
-		}
-
-		public virtual void Dispose()
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-
-			this.Id = 0;
-		}
-
-		public virtual void BeginInit()
-		{
-		}
-
-		public virtual void EndInit()
-		{
-		}
-	}
-}

+ 0 - 9
Server/Server.Base/Object/ObjectEventAttribute.cs

@@ -1,9 +0,0 @@
-using System;
-
-namespace Base
-{
-	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
-	public class ObjectEventAttribute: Attribute
-	{
-	}
-}

+ 0 - 336
Server/Server.Base/Object/ObjectManager.cs

@@ -1,336 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-
-namespace Base
-{
-	public interface IObjectEvent
-	{
-		Type ValueType();
-		void SetValue(object value);
-	}
-
-	public abstract class ObjectEvent<T> : IObjectEvent
-	{
-		private T value;
-
-		protected T GetValue()
-		{
-			return value;
-		}
-
-		public void SetValue(object v)
-		{
-			this.value = (T)v;
-		}
-
-		public Type ValueType()
-		{
-			return typeof(T);
-		}
-	}
-
-	public class ObjectManager : IDisposable
-	{
-		private readonly Dictionary<string, Assembly> assemblies = new Dictionary<string, Assembly>();
-
-		private Dictionary<Type, IObjectEvent> objectEvents;
-
-		private readonly Dictionary<long, Object> objects = new Dictionary<long, Object>();
-
-		private List<long> starts = new List<long>();
-		private List<long> newStarts = new List<long>();
-
-		private List<long> updates = new List<long>(3000);
-		private List<long> newUpdates = new List<long>(3000);
-
-		private readonly List<long> loaders = new List<long>();
-
-		public void Dispose()
-		{
-			foreach (Object o in this.objects.Values.ToArray())
-			{
-				o.Dispose();
-			}
-		}
-
-		public void Register(string name, Assembly assembly)
-		{
-			this.assemblies[name] = assembly;
-
-			objectEvents = new Dictionary<Type, IObjectEvent>();
-			foreach (Assembly ass in this.assemblies.Values)
-			{
-				Type[] types = ass.GetTypes();
-				foreach (Type type in types)
-				{
-					object[] attrs = type.GetCustomAttributes(typeof(ObjectEventAttribute), false);
-
-					if (attrs.Length == 0)
-					{
-						continue;
-					}
-
-					object obj = Activator.CreateInstance(type);
-					IObjectEvent objectEvent = obj as IObjectEvent;
-					if (objectEvent == null)
-					{
-						Log.Error($"组件事件没有继承IComponentEvent: {type.Name}");
-					}
-					objectEvents[objectEvent.ValueType()] = objectEvent;
-				}
-			}
-
-			this.Load();
-		}
-
-		public Assembly GetAssembly(string name)
-		{
-			return this.assemblies[name];
-		}
-
-		public Assembly[] GetAssemblies()
-		{
-			return this.assemblies.Values.ToArray();
-		}
-
-		private void Load()
-		{
-			foreach (long id in this.loaders)
-			{
-				Object obj;
-				if (!this.objects.TryGetValue(id, out obj))
-				{
-					continue;
-				}
-				IObjectEvent objectEvent;
-				if (!objectEvents.TryGetValue(obj.GetType(), out objectEvent))
-				{
-					continue;
-				}
-				ILoader iLoader = objectEvent as ILoader;
-				if (iLoader == null)
-				{
-					continue;
-				}
-				objectEvent.SetValue(obj);
-				iLoader.Load();
-			}
-		}
-
-		public void Add(Object obj)
-		{
-			if (objectEvents == null)
-			{
-				return;
-			}
-
-			this.objects.Add(obj.Id, obj);
-			IObjectEvent objectEvent;
-			if (!objectEvents.TryGetValue(obj.GetType(), out objectEvent))
-			{
-				return;
-			}
-
-			IStart iStart = objectEvent as IStart;
-			if (iStart != null)
-			{
-				this.newStarts.Add(obj.Id);
-			}
-
-			IUpdate iUpdate = objectEvent as IUpdate;
-			if (iUpdate != null)
-			{
-				this.newUpdates.Add(obj.Id);
-			}
-
-			ILoader iLoader = objectEvent as ILoader;
-			if (iLoader != null)
-			{
-				this.loaders.Add(obj.Id);
-			}
-		}
-
-		public void Remove(long id)
-		{
-			this.objects.Remove(id);
-		}
-
-		public void Awake(long id)
-		{
-			Object obj;
-			if (!objects.TryGetValue(id, out obj))
-			{
-				return;
-			}
-			IObjectEvent objectEvent;
-			if (!objectEvents.TryGetValue(obj.GetType(), out objectEvent))
-			{
-				return;
-			}
-			IAwake iAwake = objectEvent as IAwake;
-			if (iAwake == null)
-			{
-				return;
-			}
-			objectEvent.SetValue(obj);
-			iAwake.Awake();
-		}
-
-		public void Awake<P1>(long id, P1 p1)
-		{
-			Object obj;
-			if (!objects.TryGetValue(id, out obj))
-			{
-				return;
-			}
-			IObjectEvent objectEvent;
-			if (!objectEvents.TryGetValue(obj.GetType(), out objectEvent))
-			{
-				return;
-			}
-			IAwake<P1> iAwake = objectEvent as IAwake<P1>;
-			if (iAwake == null)
-			{
-				return;
-			}
-			objectEvent.SetValue(obj);
-			iAwake.Awake(p1);
-		}
-
-		public void Awake<P1, P2>(long id, P1 p1, P2 p2)
-		{
-			Object obj;
-			if (!objects.TryGetValue(id, out obj))
-			{
-				return;
-			}
-			IObjectEvent objectEvent;
-			if (!objectEvents.TryGetValue(obj.GetType(), out objectEvent))
-			{
-				return;
-			}
-			IAwake<P1, P2> iAwake = objectEvent as IAwake<P1, P2>;
-			if (iAwake == null)
-			{
-				return;
-			}
-			objectEvent.SetValue(obj);
-			iAwake.Awake(p1, p2);
-		}
-
-		public void Awake<P1, P2, P3>(long id, P1 p1, P2 p2, P3 p3)
-		{
-			Object obj;
-			if (!objects.TryGetValue(id, out obj))
-			{
-				return;
-			}
-			IObjectEvent objectEvent;
-			if (!objectEvents.TryGetValue(obj.GetType(), out objectEvent))
-			{
-				return;
-			}
-			IAwake<P1, P2, P3> iAwake = objectEvent as IAwake<P1, P2, P3>;
-			if (iAwake == null)
-			{
-				return;
-			}
-			objectEvent.SetValue(obj);
-			iAwake.Awake(p1, p2, p3);
-		}
-
-		private void Start()
-		{
-			starts = newStarts;
-			newStarts = new List<long>();
-			foreach (long id in starts)
-			{
-				Object obj;
-				if (!this.objects.TryGetValue(id, out obj))
-				{
-					continue;
-				}
-				IObjectEvent objectEvent;
-				if (!objectEvents.TryGetValue(obj.GetType(), out objectEvent))
-				{
-					continue;
-				}
-				IStart iStart = objectEvent as IStart;
-				if (iStart == null)
-				{
-					continue;
-				}
-				objectEvent.SetValue(obj);
-				iStart.Start();
-			}
-		}
-		
-		public void Update()
-		{
-			this.Start();
-
-			// 交换update
-			List<long> tmpUpdate = updates;
-			updates = newUpdates;
-			newUpdates = tmpUpdate;
-			newUpdates.Clear();
-			foreach (long id in updates)
-			{
-				Object obj;
-				if (!objects.TryGetValue(id, out obj))
-				{
-					continue;
-				}
-				IObjectEvent objectEvent;
-				if (!objectEvents.TryGetValue(obj.GetType(), out objectEvent))
-				{
-					continue;
-				}
-				IUpdate iUpdate = objectEvent as IUpdate;
-				if (iUpdate == null)
-				{
-					continue;
-				}
-				newUpdates.Add(id);
-				objectEvent.SetValue(obj);
-				try
-				{
-					iUpdate.Update();
-				}
-				catch (Exception e)
-				{
-					Log.Error(e.ToString());
-				}
-			}
-		}
-
-		public override string ToString()
-		{
-			var info = new Dictionary<string, int>();
-			foreach (Object obj in objects.Values)
-			{
-				if (info.ContainsKey(obj.GetType().Name))
-				{
-					info[obj.GetType().Name] += 1;
-				}
-				else
-				{
-					info[obj.GetType().Name] = 1;
-				}
-			}
-			info = info.OrderByDescending(s => s.Value).ToDictionary(p => p.Key, p => p.Value);
-			StringBuilder sb = new StringBuilder();
-			sb.Append("\r\n");
-			foreach (string key in info.Keys)
-			{
-				sb.Append($"{info[key],10} {key}\r\n");
-			}
-
-			sb.Append($"\r\n start: {newStarts.Count}, update: {newUpdates.Count} total: {this.objects.Count}");
-			return sb.ToString();
-		}
-	}
-}

+ 0 - 47
Server/Server.Base/QueueDictionary.cs

@@ -1,47 +0,0 @@
-using System.Collections.Generic;
-
-namespace Base
-{
-	public class QueueDictionary<T, K>
-	{
-		private readonly List<T> list = new List<T>();
-		private readonly Dictionary<T, K> dictionary = new Dictionary<T, K>();
-
-		public void Add(T t, K k)
-		{
-			this.list.Add(t);
-			this.dictionary.Add(t, k);
-		}
-
-		public bool Remove(T t)
-		{
-			this.list.Remove(t);
-			this.dictionary.Remove(t);
-			return true;
-		}
-
-		public int Count
-		{
-			get
-			{
-				return this.list.Count;
-			}
-		}
-
-		public T FirstKey
-		{
-			get
-			{
-				return this.list[0];
-			}
-		}
-
-		public K this[T t]
-		{
-			get
-			{
-				return this.dictionary[t];
-			}
-		}
-	}
-}

+ 0 - 117
Server/Server.Base/Server.Base.csproj

@@ -1,117 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="14.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>{AFBAD3D5-C827-4BA6-9940-7060B6C39306}</ProjectGuid>
-    <OutputType>Library</OutputType>
-    <AppDesignerFolder>Properties</AppDesignerFolder>
-    <RootNamespace>Base</RootNamespace>
-    <AssemblyName>Base</AssemblyName>
-    <TargetFrameworkVersion>v4.6.1</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="ICSharpCode.SharpZipLib">
-      <HintPath>..\Lib\ICSharpCode.SharpZipLib.dll</HintPath>
-    </Reference>
-    <Reference Include="MongoDB.Bson">
-      <HintPath>..\Lib\MongoDB.Bson.dll</HintPath>
-    </Reference>
-    <Reference Include="NLog">
-      <HintPath>..\Lib\NLog.dll</HintPath>
-    </Reference>
-    <Reference Include="protobuf-net">
-      <HintPath>..\Lib\protobuf-net.dll</HintPath>
-    </Reference>
-    <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.Net.Http" />
-    <Reference Include="System.Xml" />
-  </ItemGroup>
-  <ItemGroup>
-    <Compile Include="Config\ACategory.cs" />
-    <Compile Include="Config\AConfig.cs" />
-    <Compile Include="Config\ConfigAttribute.cs" />
-    <Compile Include="Config\ICategory.cs" />
-    <Compile Include="DoubleMap.cs" />
-    <Compile Include="Helper\ArrayHelper.cs" />
-    <Compile Include="Helper\ByteHelper.cs" />
-    <Compile Include="Helper\EnumHelper.cs" />
-    <Compile Include="Helper\FileHelper.cs" />
-    <Compile Include="Helper\IdGenerater.cs" />
-    <Compile Include="Helper\MD5Helper.cs" />
-    <Compile Include="Helper\MongoHelper.cs" />
-    <Compile Include="Helper\ProtobufHelper.cs" />
-    <Compile Include="Helper\RandomHelper.cs" />
-    <Compile Include="Helper\StringHelper.cs" />
-    <Compile Include="Helper\TimeHelper.cs" />
-    <Compile Include="Helper\ZipHelper.cs" />
-    <Compile Include="Log\Log.cs" />
-    <Compile Include="Log\ALogDecorater.cs" />
-    <Compile Include="Log\ILog.cs" />
-    <Compile Include="Log\NLogAdapter.cs" />
-    <Compile Include="Log\StackInfoDecorater.cs" />
-    <Compile Include="MultiMap.cs" />
-    <Compile Include="Network\AChannel.cs" />
-    <Compile Include="Network\AService.cs" />
-    <Compile Include="Network\TNet\PacketParser.cs" />
-    <Compile Include="Network\TNet\TBuffer.cs" />
-    <Compile Include="Network\TNet\TChannel.cs" />
-    <Compile Include="Network\TNet\TPoller.cs" />
-    <Compile Include="Network\TNet\TService.cs" />
-    <Compile Include="Network\TNet\TSocket.cs" />
-    <Compile Include="Network\UNet\Library.cs" />
-    <Compile Include="Network\UNet\NativeMethods.cs" />
-    <Compile Include="Network\UNet\NativeStructs.cs" />
-    <Compile Include="Network\UNet\UAddress.cs" />
-    <Compile Include="Network\UNet\UChannel.cs" />
-    <Compile Include="Network\UNet\UPacket.cs" />
-    <Compile Include="Network\UNet\UPoller.cs" />
-    <Compile Include="Network\UNet\UService.cs" />
-    <Compile Include="Network\UNet\USocket.cs" />
-    <Compile Include="Network\UNet\USocketManager.cs" />
-    <Compile Include="Object\Component.cs" />
-    <Compile Include="Object\Entity.cs" />
-    <Compile Include="Object\IAwake.cs" />
-    <Compile Include="Object\ILoader.cs" />
-    <Compile Include="Object\IStart.cs" />
-    <Compile Include="Object\IUpdate.cs" />
-    <Compile Include="Object\Object.cs" />
-    <Compile Include="Object\ObjectEventAttribute.cs" />
-    <Compile Include="Object\ObjectManager.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="QueueDictionary.cs" />
-    <Compile Include="TryLocker.cs" />
-  </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 - 35
Server/Server.Base/TryLocker.cs

@@ -1,35 +0,0 @@
-using System;
-using System.Threading;
-
-namespace Base
-{
-	public class TryLock : IDisposable
-	{
-		private object locked;
-
-		public bool HasLock { get; private set; }
-
-		public TryLock(object obj)
-		{
-			if (!Monitor.TryEnter(obj))
-			{
-				return;
-			}
-
-			this.HasLock = true;
-			this.locked = obj;
-		}
-
-		public void Dispose()
-		{
-			if (!this.HasLock)
-			{
-				return;
-			}
-
-			Monitor.Exit(this.locked);
-			this.locked = null;
-			this.HasLock = false;
-		}
-	}
-}

+ 0 - 237
Server/Server.Model/Component/EventComponent.cs

@@ -1,237 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-namespace Base
-{
-	[ObjectEvent]
-	public class EventComponentEvent : ObjectEvent<EventComponent>, ILoader, IAwake
-	{
-		public void Load()
-		{
-			this.GetValue().Load();
-		}
-
-		public void Awake()
-		{
-			this.GetValue().Load();
-		}
-	}
-
-	/// <summary>
-	/// 事件分发
-	/// </summary>
-	public class EventComponent: Component
-	{
-		private Dictionary<EventIdType, List<object>> allEvents;
-
-		public void Load()
-		{
-			this.allEvents = new Dictionary<EventIdType, List<object>>();
-			Assembly[] assemblies = Object.ObjectManager.GetAssemblies();
-			foreach (Assembly assembly in assemblies)
-			{
-				Type[] types = assembly.GetTypes();
-				foreach (Type type in types)
-				{
-					object[] attrs = type.GetCustomAttributes(typeof(EventAttribute), false);
-
-					foreach (object attr in attrs)
-					{
-						EventAttribute aEventAttribute = (EventAttribute)attr;
-
-						object obj = Activator.CreateInstance(type);
-						if (!this.allEvents.ContainsKey(aEventAttribute.Type))
-						{
-							this.allEvents.Add(aEventAttribute.Type, new List<object>());
-						}
-						this.allEvents[aEventAttribute.Type].Add(obj);
-					}
-				}
-			}
-		}
-
-		public void Run(EventIdType type)
-		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
-			{
-				return;
-			}
-
-			foreach (object obj in iEvents)
-			{
-				try
-				{
-					IEvent iEvent = obj as IEvent;
-					if (iEvent == null)
-					{
-						throw new GameException($"event type: {type} is not IEvent");
-					}
-					iEvent.Run();
-				}
-				catch (Exception err)
-				{
-					Log.Error(err.ToString());
-				}
-			}
-		}
-
-		public void Run<A>(EventIdType type, A a)
-		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
-			{
-				return;
-			}
-
-			foreach (object obj in iEvents)
-			{
-				try
-				{
-					var iEvent = obj as IEvent<A>;
-					if (iEvent == null)
-					{
-						throw new GameException($"event type: {type} is not IEvent<{typeof (A).Name}>");
-					}
-					iEvent.Run(a);
-				}
-				catch (Exception err)
-				{
-					Log.Error(err.ToString());
-				}
-			}
-		}
-
-		public void Run<A, B>(EventIdType type, A a, B b)
-		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
-			{
-				return;
-			}
-
-			foreach (object obj in iEvents)
-			{
-				try
-				{
-					var iEvent = obj as IEvent<A, B>;
-					if (iEvent == null)
-					{
-						throw new GameException($"event type: {type} is not IEvent<{typeof (A).Name}, {typeof (B).Name}>");
-					}
-					iEvent.Run(a, b);
-				}
-				catch (Exception err)
-				{
-					Log.Error(err.ToString());
-				}
-			}
-		}
-
-		public void Run<A, B, C>(EventIdType type, A a, B b, C c)
-		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
-			{
-				return;
-			}
-
-			foreach (object obj in iEvents)
-			{
-				try
-				{
-					var iEvent = obj as IEvent<A, B, C>;
-					if (iEvent == null)
-					{
-						throw new GameException($"event type: {type} is not IEvent<{typeof (A).Name}, {typeof (B).Name}, {typeof (C).Name}>");
-					}
-					iEvent.Run(a, b, c);
-				}
-				catch (Exception err)
-				{
-					Log.Error(err.ToString());
-				}
-			}
-		}
-
-		public void Run<A, B, C, D>(EventIdType type, A a, B b, C c, D d)
-		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
-			{
-				return;
-			}
-
-			foreach (object obj in iEvents)
-			{
-				try
-				{
-					var iEvent = obj as IEvent<A, B, C, D>;
-					if (iEvent == null)
-					{
-						throw new GameException($"event type: {type} is not IEvent<{typeof (A).Name}, {typeof (B).Name}, {typeof (C).Name}, {typeof (D).Name}>");
-					}
-					iEvent.Run(a, b, c, d);
-				}
-				catch (Exception err)
-				{
-					Log.Error(err.ToString());
-				}
-			}
-		}
-
-		public void Run<A, B, C, D, E>(EventIdType type, A a, B b, C c, D d, E e)
-		{
-			List<object> iEvents = null;
-			if (!this.allEvents.TryGetValue(type, out iEvents))
-			{
-				return;
-			}
-
-			foreach (object obj in iEvents)
-			{
-				try
-				{
-					var iEvent = obj as IEvent<A, B, C, D, E>;
-					if (iEvent == null)
-					{
-						throw new GameException(
-								$"event type: {type} is not IEvent<{typeof (A).Name}, {typeof (B).Name}, {typeof (C).Name}, {typeof (D).Name}, {typeof (E).Name}>");
-					}
-					iEvent.Run(a, b, c, d, e);
-				}
-				catch (Exception err)
-				{
-					Log.Error(err.ToString());
-				}
-			}
-		}
-        public void Run<A, B, C, D, E,F>(EventIdType type, A a, B b, C c, D d, E e,F f)
-        {
-            List<object> iEvents = null;
-            if (!this.allEvents.TryGetValue(type, out iEvents))
-            {
-                return;
-            }
-
-            foreach (object obj in iEvents)
-            {
-                try
-                {
-                    var iEvent = obj as IEvent<A, B, C, D, E,F>;
-                    if (iEvent == null)
-                    {
-                        throw new GameException(
-                                $"event type: {type} is not IEvent<{typeof(A).Name}, {typeof(B).Name}, {typeof(C).Name}, {typeof(D).Name}, {typeof(E).Name}>");
-                    }
-                    iEvent.Run(a, b, c, d, e,f);
-                }
-                catch (Exception err)
-                {
-                    Log.Error(err.ToString());
-                }
-            }
-        }
-    }
-}

+ 0 - 284
Server/Server.Model/Component/MessageComponent.cs

@@ -1,284 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace Base
-{
-	public enum NetChannelType
-	{
-		Login,
-		Gate,
-		Battle,
-	}
-
-	[ObjectEvent]
-	public class MessageComponentEvent : ObjectEvent<MessageComponent>, IAwake<AChannel>
-	{
-		public void Awake(AChannel aChannel)
-		{
-			this.GetValue().Awake(aChannel);
-		}
-	}
-	
-	/// <summary>
-	/// 消息收发
-	/// </summary>
-	public class MessageComponent: Component
-	{
-		private uint RpcId { get; set; }
-		private readonly Dictionary<uint, Action<byte[], int, int>> requestCallback = new Dictionary<uint, Action<byte[], int, int>>();
-		private readonly Dictionary<Opcode, Action<byte[], int, int>> waitCallback = new Dictionary<Opcode, Action<byte[], int, int>>();
-		private AChannel channel;
-		
-		public void Awake(AChannel aChannel)
-		{
-			this.channel = aChannel;
-			this.UpdateChannel();
-		}
-		
-		private async void UpdateChannel()
-		{
-			while (true)
-			{
-				byte[] messageBytes;
-				try
-				{
-					messageBytes = await channel.Recv();
-				}
-				catch (Exception e)
-				{
-					Log.Error(e.ToString());
-					continue;
-				}
-
-				if (messageBytes.Length < 6)
-				{
-					continue;
-				}
-
-				Opcode opcode = (Opcode)BitConverter.ToUInt16(messageBytes, 0);
-				try
-				{
-					this.Run(opcode, messageBytes);
-				}
-				catch (Exception e)
-				{
-					Log.Error(e.ToString());
-				}
-			}
-		}
-
-		private void Run(Opcode opcode, byte[] messageBytes)
-		{
-			int offset = 0;
-			uint flagUInt = BitConverter.ToUInt32(messageBytes, 2);
-			bool isCompressed = (byte)(flagUInt >> 24) == 1;
-			if (isCompressed) // 表示有压缩,需要解压缩
-			{
-				messageBytes = ZipHelper.Decompress(messageBytes, 6, messageBytes.Length - 6);
-				offset = 0;
-			}
-			else
-			{
-				offset = 6;
-			}
-			uint rpcId = flagUInt & 0x0fff;
-			this.RunDecompressedBytes(opcode, rpcId, messageBytes, offset);
-		}
-
-		private void RunDecompressedBytes(Opcode opcode, uint rpcId, byte[] messageBytes, int offset)
-		{
-			Action<byte[], int, int> action;
-			if (this.requestCallback.TryGetValue(rpcId, out action))
-			{
-				this.requestCallback.Remove(rpcId);
-				action(messageBytes, offset, messageBytes.Length - offset);
-				return;
-			}
-
-			if (this.waitCallback.TryGetValue(opcode, out action))
-			{
-				this.waitCallback.Remove(opcode);
-				action(messageBytes, offset, messageBytes.Length - offset);
-				return;
-			}
-
-			Server.Scene.GetComponent<MessageHandlerComponent>().Handle(this.Owner, opcode, messageBytes, offset);
-		}
-
-
-		public Task<Response> CallAsync<Response>(object request, CancellationToken cancellationToken) where Response : IErrorMessage
-		{
-			this.Send(request, ++this.RpcId);
-
-			var tcs = new TaskCompletionSource<Response>();
-
-			this.requestCallback[this.RpcId] = (bytes, offset, count) =>
-			{
-				try
-				{
-					Response response = MongoHelper.FromBson<Response>(bytes, offset, count);
-					Opcode opcode = EnumHelper.FromString<Opcode>(response.GetType().Name);
-					if (OpcodeHelper.IsNeedDebugLogMessage(opcode))
-					{
-						Log.Debug(MongoHelper.ToJson(response));
-					}
-					if (response.ErrorMessage.errno != (int)ErrorCode.ERR_Success)
-					{
-						tcs.SetException(new RpcException((ErrorCode)response.ErrorMessage.errno, response.ErrorMessage.msg.Utf8ToStr()));
-						return;
-					}
-					tcs.SetResult(response);
-				}
-				catch (Exception e)
-				{
-					tcs.SetException(new GameException($"Rpc Error: {typeof(Response).FullName}", e));
-				}
-			};
-
-			cancellationToken.Register(() => { this.requestCallback.Remove(this.RpcId); });
-
-			return tcs.Task;
-		}
-
-		/// <summary>
-		/// Rpc调用,发送一个消息,等待返回一个消息
-		/// </summary>
-		/// <typeparam name="Response"></typeparam>
-		/// <param name="request"></param>
-		/// <returns></returns>
-		public Task<Response> CallAsync<Response>(object request) where Response : IErrorMessage
-		{
-			this.Send(request, ++this.RpcId);
-
-			var tcs = new TaskCompletionSource<Response>();
-			this.requestCallback[this.RpcId] = (bytes, offset, count) =>
-			{
-				try
-				{
-					Response response = MongoHelper.FromBson<Response>(bytes, offset, count);
-					Opcode opcode = EnumHelper.FromString<Opcode>(response.GetType().Name);
-					if (OpcodeHelper.IsNeedDebugLogMessage(opcode))
-					{
-						Log.Debug(MongoHelper.ToJson(response));
-					}
-					if (response.ErrorMessage.errno != (int) ErrorCode.ERR_Success)
-					{
-						tcs.SetException(new RpcException((ErrorCode)response.ErrorMessage.errno,  response.ErrorMessage.msg.Utf8ToStr()));
-						return;
-					}
-					tcs.SetResult(response);
-				}
-				catch (Exception e)
-				{
-					tcs.SetException(new GameException($"Rpc Error: {typeof(Response).FullName}", e));
-				}
-			};
-			
-			return tcs.Task;
-		}
-
-		/// <summary>
-		/// 不发送消息,直接等待返回一个消息
-		/// </summary>
-		/// <typeparam name="Response"></typeparam>
-		/// <param name="cancellationToken"></param>
-		/// <returns></returns>
-		public Task<Response> WaitAsync<Response>(CancellationToken cancellationToken) where Response : class
-		{
-			var tcs = new TaskCompletionSource<Response>();
-			Opcode opcode = EnumHelper.FromString<Opcode>(typeof(Response).Name);
-
-			this.waitCallback[opcode] = (bytes, offset, count) =>
-			{
-				try
-				{
-					Response response = MongoHelper.FromBson<Response>(bytes, offset, count);
-					Opcode op = EnumHelper.FromString<Opcode>(response.GetType().Name);
-					if (OpcodeHelper.IsNeedDebugLogMessage(op))
-					{
-						Log.Debug(MongoHelper.ToJson(response));
-					}
-					
-					tcs.SetResult(response);
-				}
-				catch (Exception e)
-				{
-					tcs.SetException(new GameException($"Wait Error: {typeof(Response).FullName}", e));
-				}
-			};
-
-			cancellationToken.Register(() => { this.waitCallback.Remove(opcode); });
-
-			return tcs.Task;
-		}
-
-		/// <summary>
-		/// 不发送消息,直接等待返回一个消息
-		/// </summary>
-		/// <typeparam name="Response"></typeparam>
-		/// <returns></returns>
-		public Task<Response> WaitAsync<Response>() where Response : class
-		{
-			var tcs = new TaskCompletionSource<Response>();
-			Opcode opcode = EnumHelper.FromString<Opcode>(typeof(Response).Name);
-			this.waitCallback[opcode] = (bytes, offset, count) =>
-			{
-				try
-				{
-					Response response = MongoHelper.FromBson<Response>(bytes, offset, count);
-					Opcode op = EnumHelper.FromString<Opcode>(response.GetType().Name);
-					if (OpcodeHelper.IsNeedDebugLogMessage(op))
-					{
-						Log.Debug(MongoHelper.ToJson(response));
-					}
-					tcs.SetResult(response);
-				}
-				catch (Exception e)
-				{
-					tcs.SetException(new GameException($"Wait Error: {typeof(Response).FullName}", e));
-				}
-			};
-
-			return tcs.Task;
-		}
-
-		public void Send(object message)
-		{
-			this.Send(message, 0);
-		}
-
-		private void Send(object message, uint rpcId)
-		{
-			Opcode opcode = EnumHelper.FromString<Opcode>(message.GetType().Name);
-			byte[] opcodeBytes = BitConverter.GetBytes((ushort)opcode);
-			byte[] seqBytes = BitConverter.GetBytes(rpcId);
-			byte[] messageBytes = MongoHelper.ToBson(message);
-			
-			if (channel == null)
-			{
-				throw new GameException("game channel not found!");
-			}
-
-			channel.Send(new List<byte[]> { opcodeBytes, seqBytes, messageBytes });
-
-			if (OpcodeHelper.IsNeedDebugLogMessage(opcode))
-			{
-				Log.Debug(MongoHelper.ToJson(message));
-			}
-		}
-
-		public override void Dispose()
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-
-			base.Dispose();
-
-			channel.Dispose();
-		}
-	}
-}

+ 0 - 136
Server/Server.Model/Component/MessageHandlerComponent.cs

@@ -1,136 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-namespace Base
-{
-	[ObjectEvent]
-	public class MessageHandlerComponentEvent : ObjectEvent<MessageHandlerComponent>, ILoader, IAwake<SceneType>
-	{
-		public void Load()
-		{
-			this.GetValue().Load();
-		}
-
-		public void Awake(SceneType sceneType)
-		{
-			this.GetValue().Awake(sceneType);
-		}
-	}
-	
-	/// <summary>
-	/// 消息分发组件
-	/// </summary>
-	public class MessageHandlerComponent: Component
-	{
-		private SceneType SceneType;
-		private Dictionary<Opcode, List<Action<Entity, byte[], int, int>>> events;
-		
-		public void Awake(SceneType sceneType)
-		{
-			this.SceneType = sceneType;
-			this.Load();
-		}
-
-		public void Load()
-		{
-			this.events = new Dictionary<Opcode, List<Action<Entity, byte[], int, int>>>();
-
-			Assembly[] assemblies = Object.ObjectManager.GetAssemblies();
-			foreach (Assembly assembly in assemblies)
-			{
-				Type[] types = assembly.GetTypes();
-				foreach (Type type in types)
-				{
-					object[] attrs = type.GetCustomAttributes(typeof(MessageAttribute), false);
-					if (attrs.Length == 0)
-					{
-						continue;
-					}
-
-					MessageAttribute messageAttribute = (MessageAttribute)attrs[0];
-					if (messageAttribute.SceneType != this.SceneType)
-					{
-						continue;
-					}
-
-					object obj = Activator.CreateInstance(type);
-
-					IMRegister<MessageHandlerComponent> iMRegister = obj as IMRegister<MessageHandlerComponent>;
-					if (iMRegister == null)
-					{
-						throw new GameException($"message handler not inherit IEventSync or IEventAsync interface: {obj.GetType().FullName}");
-					}
-					iMRegister.Register(this);
-				}
-			}
-		}
-
-		public void Register<T>(Action<Entity, T> action)
-		{
-			Opcode opcode = EnumHelper.FromString<Opcode>(typeof (T).Name);
-			if (!this.events.ContainsKey(opcode))
-			{
-				this.events.Add(opcode, new List<Action<Entity, byte[], int, int>>());
-			}
-			List<Action<Entity, byte[], int, int>> actions = this.events[opcode];
-
-			actions.Add((entity, messageBytes, offset, count) =>
-			{
-				T t;
-				try
-			    {
-                    t = MongoHelper.FromBson<T>(messageBytes, offset, count);
-                }
-			    catch (Exception ex)
-			    {
-			        throw new GameException("解释消息失败:" + opcode, ex);
-			    }
-
-				if (OpcodeHelper.IsNeedDebugLogMessage(opcode))
-				{
-					Log.Debug(MongoHelper.ToJson(t));
-				}
-
-				action(entity, t);
-			});
-		}
-
-
-		public void Handle(Entity entity, Opcode opcode, byte[] messageBytes, int offset)
-		{
-			List<Action<Entity, byte[], int, int>> actions;
-			if (!this.events.TryGetValue(opcode, out actions))
-			{
-				if (this.SceneType == SceneType.Game)
-				{
-					Log.Error($"消息{opcode}没有处理");
-				}
-				return;
-			}
-
-			foreach (var ev in actions)
-			{
-				try
-				{
-					ev(entity, messageBytes, offset, messageBytes.Length - offset);
-				}
-				catch (Exception e)
-				{
-					Log.Error(e.ToString());
-				}
-			}
-		}
-		
-
-		public override void Dispose()
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-
-			base.Dispose();
-		}
-	}
-}

+ 0 - 106
Server/Server.Model/Component/NetworkComponent.cs

@@ -1,106 +0,0 @@
-using System;
-using System.Net.Sockets;
-
-namespace Base
-{
-	[ObjectEvent]
-	public class NetworkComponentEvent : ObjectEvent<NetworkComponent>, IUpdate, IAwake<NetworkProtocol>
-	{
-		public void Update()
-		{
-			NetworkComponent component = this.GetValue();
-			component.Update();
-		}
-
-		public void Awake(NetworkProtocol protocol)
-		{
-			this.GetValue().Awake(protocol);
-		}
-	}
-
-	public class NetworkComponent: Component
-	{
-		private AService service;
-		
-		private void Dispose(bool disposing)
-		{
-			if (this.service == null)
-			{
-				return;
-			}
-
-			base.Dispose();
-
-			if (disposing)
-			{
-				this.service.Dispose();
-			}
-
-			this.service = null;
-		}
-
-		public override void Dispose()
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-			this.Dispose(true);
-		}
-
-		public void Awake(NetworkProtocol protocol)
-		{
-			switch (protocol)
-			{
-				case NetworkProtocol.TCP:
-					this.service = new TService { OnError = this.OnError };
-					break;
-				case NetworkProtocol.UDP:
-					this.service = new UService { OnError = this.OnError };
-					break;
-				default:
-					throw new ArgumentOutOfRangeException();
-			}
-		}
-
-		public void Update()
-		{
-			if (this.service == null)
-			{
-				return;
-			}
-			this.service.Update();
-		}
-
-		public AChannel GetChannel(long channelId)
-		{
-			AChannel channel = this.service?.GetChannel(channelId);
-			return channel;
-		}
-
-
-		public AChannel ConnectChannel(string host, int port)
-		{
-			AChannel channel = this.service.GetChannel(host, port);
-			return channel;
-		}
-
-		public void OnError(long id, SocketError error)
-		{
-			Env env = new Env();
-			env[EnvKey.ChannelError] = error;
-			Server.Scene.GetComponent<EventComponent>().Run(EventIdType.NetworkChannelError, env);
-		}
-
-		public void RemoveChannel(long channelId)
-		{
-			AChannel channel = this.service?.GetChannel(channelId);
-			if (channel == null)
-			{
-				return;
-			}
-			this.service.Remove(channelId);
-			channel.Dispose();
-		}
-	}
-}

+ 0 - 49
Server/Server.Model/Component/Scene.cs

@@ -1,49 +0,0 @@
-namespace Base
-{
-	public enum SceneType
-	{
-		Share,
-		Game,
-		Login,
-		Lobby,
-		Map,
-		Launcher,
-		Robot,
-		BehaviorTreeScene,
-		RobotClient,
-
-		Realm,
-		Gate,
-	}
-
-	[ObjectEvent]
-	public class SceneEvent : ObjectEvent<Scene>, IAwake<SceneType, string>
-	{
-		public void Awake(SceneType sceneType, string name)
-		{
-			this.GetValue().Awake(sceneType, name);
-		}
-	}
-
-	public sealed class Scene: Component
-	{
-		public SceneType SceneType { get; set; }
-		public string Name { get; set; }
-
-		public void Awake(SceneType sceneType, string name)
-		{
-			this.SceneType = sceneType;
-			this.Name = name;
-		}
-
-		public override void Dispose()
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-
-			base.Dispose();
-		}
-	}
-}

+ 0 - 30
Server/Server.Model/Component/TimeComponent.cs

@@ -1,30 +0,0 @@
-namespace Base
-{
-	/// <summary>
-	/// 用于同步服务端和客户端时间
-	/// </summary>
-    public class TimeComponent : Component
-    {
-		private long syncTime;
-
-	    private long syncClientTime;
-
-	    public long SyncTime
-	    {
-		    get
-		    {
-			    return this.syncTime;
-		    }
-		    set
-		    {
-			    this.syncTime = value;
-			    this.syncClientTime = TimeHelper.ClientNow();
-		    }
-	    }
-
-	    public long Now()
-		{
-			return TimeHelper.ClientNow() - this.syncClientTime + syncTime;
-		}
-    }
-}

+ 0 - 139
Server/Server.Model/Component/TimerComponent.cs

@@ -1,139 +0,0 @@
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace Base
-{
-	public class Timer
-	{
-		public long Id { get; set; }
-		public long Time { get; set; }
-		public TaskCompletionSource<bool> tcs;
-	}
-
-	[ObjectEvent]
-	public class TimerComponentEvent : ObjectEvent<TimerComponent>, IUpdate, IAwake<TimeComponent>
-	{
-		public void Update()
-		{
-			TimerComponent component = this.GetValue();
-			component.Update();
-		}
-
-		public void Awake(TimeComponent p1)
-		{
-			this.GetValue().TimeComponent = p1;
-		}
-	}
-
-	public static class TimerComponentExtension
-	{
-		public static void Update(this TimerComponent component)
-		{
-			long timeNow = component.TimeComponent.Now();
-			foreach (long time in component.timeId.Keys)
-			{
-				if (time > timeNow)
-				{
-					break;
-				}
-				component.timeoutTimer.Enqueue(time);
-			}
-
-			while (component.timeoutTimer.Count > 0)
-			{
-				long key = component.timeoutTimer.Dequeue();
-				long[] timeOutId = component.timeId.GetAll(key);
-				foreach (long id in timeOutId)
-				{
-					Timer timer;
-					if (!component.timers.TryGetValue(id, out timer))
-					{
-						continue;
-					}
-					component.Remove(id);
-					timer.tcs.SetResult(true);
-				}
-			}
-		}
-	}
-
-	public class TimerComponent: Component
-	{
-		public readonly Dictionary<long, Timer> timers = new Dictionary<long, Timer>();
-
-		/// <summary>
-		/// key: time, value: timer id
-		/// </summary>
-		public readonly MultiMap<long, long> timeId = new MultiMap<long, long>();
-
-		public readonly Queue<long> timeoutTimer = new Queue<long>();
-
-		public TimeComponent TimeComponent { get; set; }
-
-		public void Remove(long id)
-		{
-			Timer timer;
-			if (!this.timers.TryGetValue(id, out timer))
-			{
-				return;
-			}
-			this.timers.Remove(id);
-			this.timeId.Remove(timer.Time, timer.Id);
-		}
-
-		public Task WaitTillAsync(long tillTime, CancellationToken cancellationToken)
-		{
-			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
-			Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs };
-			this.timers[timer.Id] = timer;
-			this.timeId.Add(timer.Time, timer.Id);
-			cancellationToken.Register(() =>
-			{
-				this.Remove(timer.Id);
-			});
-			return tcs.Task;
-		}
-
-		public Task WaitTillAsync(long tillTime)
-		{
-			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
-			Timer timer = new Timer { Id = IdGenerater.GenerateId(), Time = tillTime, tcs = tcs };
-			this.timers[timer.Id] = timer;
-			this.timeId.Add(timer.Time, timer.Id);
-			return tcs.Task;
-		}
-
-		public Task WaitAsync(long time, CancellationToken cancellationToken)
-		{
-			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
-			Timer timer = new Timer
-			{
-				Id = IdGenerater.GenerateId(),
-				Time = TimeHelper.ClientNow() + time,
-				tcs = tcs
-			};
-			this.timers[timer.Id] = timer;
-			this.timeId.Add(timer.Time, timer.Id);
-			cancellationToken.Register(() =>
-			{
-				this.Remove(timer.Id);
-			});
-			return tcs.Task;
-		}
-
-		public Task WaitAsync(long time)
-		{
-			TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
-			Timer timer = new Timer
-			{
-				Id = IdGenerater.GenerateId(),
-				Time = TimeHelper.ClientNow() + time,
-				tcs = tcs
-			};
-			this.timers[timer.Id] = timer;
-			this.timeId.Add(timer.Time, timer.Id);
-			return tcs.Task;
-		}
-	}
-}

+ 0 - 15
Server/Server.Model/Event/AEventAttribute.cs

@@ -1,15 +0,0 @@
-using System;
-
-namespace Base
-{
-	[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
-	public abstract class AEventAttribute: Attribute
-	{
-		public EventIdType Type { get; private set; }
-
-        protected AEventAttribute(EventIdType type)
-        {
-			this.Type = type;
-		}
-	}
-}

+ 0 - 23
Server/Server.Model/Event/EntityType.cs

@@ -1,23 +0,0 @@
-namespace Base
-{
-	public enum EntityType
-	{
-		None = 0,
-		Hero = 1,
-		Building = 2,
-		Soldier = 3,
-		Summon = 4,
-		Wild_lv1 = 5,
-		Item = 6,
-		Bullet = 7,
-		Wild_lv2 = 8,
-		Wild_lv3 = 9,
-		Watcher = 10,
-
-		Actor = 100,
-		Buff = 102,
-		Illusion = 103,
-		Effect = 104,
-		Skill = 200,
-	}
-}

+ 0 - 91
Server/Server.Model/Event/Env.cs

@@ -1,91 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using MongoDB.Bson.Serialization.Attributes;
-
-namespace Base
-{
-	public class Env: Object
-	{
-		[BsonElement, BsonIgnoreIfNull]
-		private Dictionary<string, object> values = new Dictionary<string, object>();
-
-		public object this[string key]
-		{
-			get
-			{
-				return this.values[key];
-			}
-			set
-			{
-				if (this.values == null)
-				{
-					this.values = new Dictionary<string, object>();
-				}
-				this.values[key] = value;
-			}
-		}
-
-		public T Get<T>(string key)
-		{
-			if (this.values == null || !this.values.ContainsKey(key))
-			{
-				return default(T);
-			}
-			object value = values[key];
-			try
-			{
-				return (T)value;
-			}
-			catch (InvalidCastException e)
-			{
-				throw new GameException($"不能把{value.GetType()}转换为{typeof(T)}", e);
-			}
-		}
-
-		public void Set(string key, object obj)
-		{
-			if (this.values == null)
-			{
-				this.values = new Dictionary<string, object>();
-			}
-			this.values[key] = obj;
-		}
-
-		public bool ContainKey(string key)
-		{
-			if (this.values == null)
-			{
-				return false;
-			}
-			return this.values.ContainsKey(key);
-		}
-
-		public void Remove(string key)
-		{
-			if (this.values == null)
-			{
-				return;
-			}
-			this.values.Remove(key);
-			if (this.values.Count == 0)
-			{
-				this.values = null;
-			}
-		}
-
-		public void Add(string key, object value)
-		{
-			if (this.values == null)
-			{
-				this.values = new Dictionary<string, object>();
-			}
-			this.values[key] = value;
-		}
-
-		public IEnumerator GetEnumerator()
-		{
-			return this.values.GetEnumerator();
-		}
-	}
-}

+ 0 - 10
Server/Server.Model/Event/EnvKey.cs

@@ -1,10 +0,0 @@
-namespace Base
-{
-	/// <summary>
-	/// 一般使用事件名+变量名
-	/// </summary>
-	public static class EnvKey
-	{
-		public const string ChannelError = "ChannelError";
-	}
-}

+ 0 - 9
Server/Server.Model/Event/EventAttribute.cs

@@ -1,9 +0,0 @@
-namespace Base
-{
-    public class EventAttribute : AEventAttribute
-    {
-        public EventAttribute(EventIdType type) : base(type)
-        {
-        }
-    }
-}

+ 0 - 7
Server/Server.Model/Event/EventIdType.cs

@@ -1,7 +0,0 @@
-namespace Base
-{
-    public enum EventIdType
-    {
-		NetworkChannelError,
-	}
-}

+ 0 - 36
Server/Server.Model/Event/IEvent.cs

@@ -1,36 +0,0 @@
-namespace Base
-{
-	public interface IEvent
-	{
-		void Run();
-	}
-
-	public interface IEvent<in A>
-	{
-		void Run(A uid);
-	}
-
-	public interface IEvent<in A, in B>
-	{
-		void Run(A a, B b);
-	}
-
-	public interface IEvent<in A, in B, in C>
-	{
-		void Run(A a, B b, C c);
-	}
-
-	public interface IEvent<in A, in B, in C, in D>
-	{
-		void Run(A a, B b, C c, D d);
-	}
-
-	public interface IEvent<in A, in B, in C, in D, in E>
-	{
-		void Run(A a, B b, C c, D d, E e);
-	}
-    public interface IEvent<in A, in B, in C, in D, in E,in F>
-    {
-        void Run(A a, B b, C c, D d, E e,F f);
-    }
-}

+ 0 - 65
Server/Server.Model/GameException.cs

@@ -1,65 +0,0 @@
-using System;
-
-namespace Base
-{
-	[Serializable]
-	public class GameException: Exception
-	{
-		public GameException(string message): base(message)
-		{
-		}
-
-		public GameException(string message, Exception e): base(message, e)
-		{
-		}
-	}
-
-	/// <summary>
-	/// 输入异常,比如没有输入密码账号
-	/// </summary>
-	[Serializable]
-	public class InputErrorException : Exception
-	{
-		public InputErrorException(string message) : base(message)
-		{
-		}
-
-		public InputErrorException(string message, Exception e) : base(message, e)
-		{
-		}
-	}
-
-	/// <summary>
-	/// 配置异常
-	/// </summary>
-	[Serializable]
-	public class ConfigException : Exception
-	{
-		public ConfigException(string message) : base(message)
-		{
-		}
-
-		public ConfigException(string message, Exception e) : base(message, e)
-		{
-		}
-	}
-
-	/// <summary>
-	/// RPC异常,带ErrorCode
-	/// </summary>
-	[Serializable]
-	public class RpcException : Exception
-	{
-		public ErrorCode Error { get; private set; }
-
-		public RpcException(ErrorCode error, string message) : base($"{(int)error} : {message}")
-		{
-			this.Error = error;
-		}
-
-		public RpcException(ErrorCode error, string message, Exception e) : base($"{(int)error} : {message}", e)
-		{
-			this.Error = error;
-		}
-	}
-}

+ 0 - 12
Server/Server.Model/Message/AMEvent.cs

@@ -1,12 +0,0 @@
-namespace Base
-{
-	public abstract class AMEvent<T>: IMRegister<MessageHandlerComponent>
-	{
-		public void Register(MessageHandlerComponent component)
-		{
-			component.Register<T>(Run);
-		}
-
-		public abstract void Run(Entity scene, T message);
-	}
-}

+ 0 - 128
Server/Server.Model/Message/ErrorCode.cs

@@ -1,128 +0,0 @@
-// 本文件由工具自动生成,请勿直接改动
-namespace Base
-{
-	public enum ErrorCode
-	{
-		ERR_Success                                   = 0,
-		ERR_RpcProxyTimeout                           = 93,
-		ERR_RpcProxySendBuffFull                      = 94,
-		ERR_RpcProxyConnectFailed                     = 95,
-		ERR_RpcProxyDisconnect                        = 96,
-		ERR_RpcProxyParseResponseFailed               = 97,
-		ERR_ServerRpcTimeout                          = 98,
-		ERR_DBError                                   = 100,
-		ERR_DBProxyTrace                              = 101,
-		ERR_RpcPraseFailed                            = 103,
-		ERR_ServerRpcTrace                            = 104,
-		ERR_PlayerNotInGate                           = 105,
-		ERR_DataTypeNotExists                         = 106,
-		ERR_LoadJsonFailed                            = 107,
-		ERR_BattleServerNotExists                     = 108,
-		ERR_FreeBattleRoomNotMatch                    = 109,
-		ERR_LoadPlayerDataFailed                      = 111,
-		ERR_AccountPasswdMissMatch                    = 112,
-		ERR_GenerateGuidFailed                        = 113,
-		ERR_AssetNotEnough                            = 114,
-		ERR_CreateBankJournalFailed                   = 115,
-		ERR_LogoutTypeDisconnect                      = 116,
-		ERR_LogoutTypeKillBySameAccount               = 117,
-		ERR_LogoutTypeNormalQuit                      = 118,
-		ERR_NoFreeBattleServer                        = 119,
-		ERR_CannotFindRpcHandler                      = 121,
-		ERR_RpcHandlerTraceback                       = 122,
-		ERR_PlayerIsLogouting                         = 123,
-		ERR_PlayerIsInLogin                           = 124,
-		ERR_PlayerNameNotValid                        = 125,
-		ERR_PlayerNameTooLong                         = 126,
-		ERR_PlayerNameExists                          = 127,
-		ERR_PlayerNameAllDigit                        = 128,
-		ERR_PlayerNameSensitive                       = 129,
-		ERR_ClientVersionLow                          = 130,
-		ERR_UnknowObject                              = 131,
-		ERR_PlatinumNotEnough                         = 132,
-		ERR_RemotePlayerMethodNotImpl                 = 133,
-		ERR_GoldNotEnough                             = 134,
-		ERR_FindMapConfigFailed                       = 199,
-		ERR_FindMatchConfigFailed                     = 200,
-		ERR_MatchConfigError                          = 201,
-		ERR_FetchGateInfoFailed                       = 202,
-		ERR_NotSuchLoginToken                         = 203,
-		ERR_LoginTokenExpired                         = 204,
-		ERR_TempAccountMustAlnum                      = 205,
-		ERR_UseMatch                                  = 206,
-		ERR_MatchPlayerInWrongStatus                  = 207,
-		ERR_FetchPlayerNameFailed                     = 208,
-		ERR_GateTracebak                              = 209,
-		ERR_RemoteClientNoResponse                    = 210,
-		ERR_PlayerNotOnline                           = 211,
-		ERR_MatchForbitPlayer                         = 212,
-		ERR_StoneMounted                              = 213,
-		ERR_StoneMountWrongType                       = 214,
-		ERR_StoneMountWrongIdex                       = 215,
-		ERR_DeckItemOverLimit                         = 216,
-		ERR_BoxNotExist                               = 217,
-		ERR_WrongRpcName                              = 500,
-		ERR_RpcTraceback                              = 501,
-		ERR_TableExistsError                          = 1050,
-		ERR_MatchNoIdleBattle                         = 3000,
-		ERR_MatchPlayerNotExists                      = 3001,
-		ERR_MatchLoadScoreFailed                      = 3002,
-		ERR_NotGroupOwner                             = 3003,
-		ERR_MatchTurnOffByGM                          = 3004,
-		ERR_MatchMustInGroup                          = 3005,
-		ERR_MatchInWorkTime                           = 3006,
-		ERR_MatchFriendNotEnougth                     = 3007,
-		ERR_PlayerNoPet                               = 3008,
-		ERR_MatchMustPlayXFirst                       = 3008,
-		ERR_PlayerShopIdInvalid                       = 3009,
-		ERR_FriendPlayerOffline                       = 4000,
-		ERR_FriendPlayerNotExists                     = 4001,
-		ERR_FriendAlreadyIsFriends                    = 4002,
-		ERR_FriendNotFriends                          = 4003,
-		ERR_FriendLoadDataFailed                      = 4004,
-		ERR_FriendAddGroupFailedSameGroup             = 4005,
-		ERR_FriendDelGroupFailedGroupNotExists        = 4006,
-		ERR_FriendMoveGroupFailed                     = 4007,
-		ERR_FriendCanNotAddSelf                       = 4008,
-		ERR_FriendCanNotAddFriendInBlack              = 4009,
-		ERR_FriendAddFriendExists                     = 4010,
-		ERR_FriendAddFailed                           = 4011,
-		ERR_FriendCountExceedLimit                    = 4012,
-		ERR_RoomCreateFail                            = 5000,
-		ERR_RoomFull                                  = 5001,
-		ERR_RoomNotExist                              = 5002,
-		ERR_RoomAlreadyStartGame                      = 5003,
-		ERR_RoomPassNotCorrect                        = 5004,
-		ERR_RoomNotMatch                              = 5005,
-		ERR_RoomNotInFighting                         = 5006,
-		ERR_RoomPlayerNotExists                       = 5007,
-		ERR_RoomPlayerIsOnline                        = 5008,
-		ERR_RoomPlayerAlreadyInRoom                   = 5009,
-		ERR_RoomNotGroupOwner                         = 5010,
-		ERR_RoomNotEnoughSlot                         = 5011,
-		ERR_RoomNotRoomOwner                          = 5012,
-		ERR_RoomPlayerNotInRoom                       = 5013,
-		ERR_PickHeroFailed                            = 5020,
-		ERR_PickHeroDisconnect                        = 5021,
-		ERR_NotAllPlayerLoadingDone                   = 5022,
-		ERR_PickHeroTraceback                         = 5023,
-		ERR_NotAllPlayerConnectedBattle               = 5024,
-		ERR_SurrenderNotYet                           = 5030,
-		ERR_SurrenderEnded                            = 5031,
-		ERR_AccountAlreadyExist                       = 5032,
-		ERR_AccountNotValid                           = 5033,
-		ERR_PasswordNotValid                          = 5034,
-		ERR_AccountNotExists                          = 5035,
-		ERR_Password2NotSame                          = 5036,
-		ERR_CheckCodeNotCorrect                       = 5037,
-		ERR_PlayerNotExists                           = 5038,
-		ERR_MailNotExists                             = 5040,
-		ERR_MailTitleTooLong                          = 5041,
-		ERR_MailContentTooLong                        = 5042,
-		ERR_RedisError                                = 5043,
-		ERR_CantBattleOb                              = 5044,
-		ERR_AlreadyInOb                               = 5055,
-		ERR_LoginBattleServerRoomGuidError            = 5088,
-		ERR_LoginBattleServerNoSuchPlayer             = 5089,
-	}
-}

+ 0 - 20
Server/Server.Model/Message/IErrorMessage.cs

@@ -1,20 +0,0 @@
-using System.ComponentModel;
-using MongoDB.Bson;
-using ProtoBuf;
-
-namespace Base
-{
-	/// <summary>
-	/// 服务端回的RPC消息需要继承这个接口
-	/// </summary>
-	public interface IErrorMessage
-	{
-		ErrorMessage ErrorMessage { get; }
-	}
-	
-	public class ErrorMessage
-	{
-		public int errno = 0;
-		public byte[] msg = "".ToByteArray();
-	}
-}

+ 0 - 7
Server/Server.Model/Message/IMRegister.cs

@@ -1,7 +0,0 @@
-namespace Base
-{
-	public interface IMRegister<in T>
-	{
-		void Register(T component);
-	}
-}

+ 0 - 102
Server/Server.Model/Message/Message.cs

@@ -1,102 +0,0 @@
-using MongoDB.Bson.Serialization.Attributes;
-
-namespace Base
-{
-	[BsonIgnoreExtraElements]
-	public class C2S_LoginGate
-	{
-		public string Account;
-		
-		public string Passwd;
-		
-		public string Token;
-		
-		public string Mac;
-
-	}
-
-	[BsonIgnoreExtraElements]
-	public class ReconnectBattle
-	{
-		public long RoomGuid;
-		
-		public string BattleIp;
-		
-		public short BattlePort;
-
-	}
-
-	[BsonIgnoreExtraElements]
-	public class S2C_LoginGate: IErrorMessage
-	{
-		public ErrorMessage Errmsg;
-		
-		public long PlayerGuid;
-		
-		public string PlayerName;
-
-		//1 登录大厅
-		//2 断线重连
-		//3 取名字
-		public int Type;
-		
-		public ReconnectBattle Reconnect;
-
-		public ErrorMessage ErrorMessage { get { return this.Errmsg; } }
-	}
-
-	[BsonIgnoreExtraElements]
-	public class C2S_FetchServerTime
-	{
-	}
-
-	[BsonIgnoreExtraElements]
-	public class S2C_FetchServerTime: IErrorMessage
-	{
-		public ErrorMessage Errmsg;
-
-		//服务器的真实时间
-		public long ServerTime;
-
-		public ErrorMessage ErrorMessage { get { return this.Errmsg; } }
-	}
-
-	[BsonIgnoreExtraElements]
-	public class C2S_LogoutGate
-	{
-	}
-
-	[BsonIgnoreExtraElements]
-	public class S2C_LogoutGate: IErrorMessage
-	{
-		public ErrorMessage Errmsg;
-
-		public ErrorMessage ErrorMessage { get { return this.Errmsg; } }
-	}
-	
-	public class S2C_InitBuffInfo
-	{
-		/// <summary>
-		/// buff所有者
-		/// </summary>
-		public int UnitGuid;
-
-		public int BuffGuid;
-
-		public int BuffId;
-
-		public int Level = 1;
-
-		//叠层数量
-		public int StackCount = 1;
-
-		//总时间和剩余持续时间,单位毫秒,如果是0,表示一个永久的BUFF
-		public int TotalTime = 0;
-
-		public long ExpiredTick = 0;
-
-		//来源GUID
-		public int CasterGuid = 0;
-
-	}
-}

+ 0 - 20
Server/Server.Model/Message/MessageAttribute.cs

@@ -1,20 +0,0 @@
-using System;
-
-namespace Base
-{
-	/// <summary>
-	/// 搭配MessageComponent用来分发消息
-	/// </summary>
-	public class MessageAttribute : Attribute
-	{
-		/// <summary>
-		/// MessageComponent所有者的SceneType必须相同,这个Message Handle才会注册到MessageComponent里面
-		/// </summary>
-		public SceneType SceneType { get; private set; }
-
-		public MessageAttribute(SceneType sceneType)
-		{
-			this.SceneType = sceneType;
-		}
-	}
-}

+ 0 - 259
Server/Server.Model/Message/Opcode.cs

@@ -1,259 +0,0 @@
-// 本文件由工具自动生成,请勿直接改动
-namespace Base
-{
-	public enum Opcode: ushort
-	{
-		S2C_StartGame             = 4,
-		S2C_MoveCommand           = 6,
-		S2C_RefreshSkillInfo      = 7,
-		S2C_BulletInit            = 8,
-		S2C_UpdateBuffInfo        = 10,
-		S2C_RemoveBuff            = 11,
-		S2C_SkillShaking          = 12,
-		S2C_UnitDestroy           = 13,
-		S2C_ActorInfo             = 14,
-		S2C_UpdateItem            = 15,
-		S2C_RefreshUnitAttr       = 16,
-		S2C_BattleChat            = 17,
-		S2C_Ping                  = 18,
-		S2C_CombatNumberInfo      = 19,
-		S2C_SkillHit              = 22,
-		S2C_RemoveItem            = 23,
-		S2C_RemoveBullet          = 24,
-		S2C_RepickUnit            = 25,
-		S2C_UnitDieReborn         = 26,
-		S2C_UnitReborn            = 27,
-		S2C_UnitInit              = 31,
-		S2C_ActorDetailInfo       = 32,
-		S2C_TimerOn               = 33,
-		S2C_KillReport            = 34,
-		S2C_LineEffect            = 37,
-		S2C_RemoveEffect          = 38,
-		S2C_SkillEnterChannel     = 39,
-		S2C_SkillBreakChannel     = 40,
-		S2C_BulletSyncPosition    = 41,
-		S2C_BulletMoveToTarget    = 42,
-		S2C_BulletMoveToPosition  = 43,
-		S2C_BigPackage            = 44,
-		S2C_RefreshSkillCd        = 46,
-		S2C_SystemNotice          = 47,
-		S2C_LoginBattleServer     = 48,
-		S2C_StartPickHero         = 49,
-		S2C_StartLoading          = 50,
-		S2C_PlayerSelectHero      = 51,
-		S2C_NotifyCreateRole      = 53,
-		S2C_ForwardData           = 54,
-		S2C_ActorGoldInfo         = 55,
-		S2C_GameOverJieSuan       = 58,
-		S2C_LoadingProcess        = 61,
-		S2C_RevokeItemOp          = 62,
-		S2C_LogoutBattle          = 63,
-		S2C_BTreeDebugLog         = 64,
-		S2C_ReconnectBattleServer = 65,
-		S2C_StartGameFailed       = 66,
-		S2C_DiePlayback           = 67,
-		S2C_WildState             = 68,
-		S2C_NormalSkillEnd        = 69,
-		S2C_UpdateShopItem        = 70,
-		S2C_OpenShop              = 71,
-		S2C_Test                  = 72,
-		S2C_BreakSkill            = 73,
-		S2C_RequestSurrender      = 74,
-		S2C_SurrenderVote         = 75,
-		S2C_SurrenderResult       = 76,
-		S2C_ModifyFaction         = 77,
-		S2C_SurrenderTimeLeft     = 78,
-		S2C_ConnectBattleInfo     = 79,
-		S2C_LoadingFinishStartGame = 80,
-		S2C_MapState              = 81,
-		S2C_InitBuffInfo          = 82,
-		S2C_SelectShop            = 83,
-		S2C_GetShopList           = 84,
-		S2C_StartOb               = 85,
-		S2C_ObFrames              = 86,
-		S2C_UpdateBattleBag       = 87,
-		C2S_Move                  = 503,
-		C2S_LevelupSkill          = 504,
-		C2S_CastSkill             = 505,
-		C2S_LoadOk                = 506,
-		C2S_Stop                  = 507,
-		C2S_BuyItem               = 508,
-		C2S_DropItem              = 509,
-		C2S_PickupItem            = 510,
-		C2S_BattleChat            = 511,
-		C2S_Ping                  = 512,
-		C2S_AttackLocation        = 513,
-		C2S_SellItem              = 514,
-		C2S_LearnSkill            = 515,
-		C2S_ReportError           = 516,
-		C2S_LoginBattleServer     = 517,
-		C2S_LoadingProcess        = 518,
-		C2S_PlayerSelectHero      = 519,
-		C2S_ForwardData           = 521,
-		C2S_ChangeItemPos         = 524,
-		C2S_RevokeItemOp          = 526,
-		C2S_ReconnectGame         = 527,
-		C2S_BattleConfig          = 528,
-		C2S_ModifyHeroAttrs       = 529,
-		C2S_UnitAICmd             = 530,
-		C2S_BTreeDebug            = 531,
-		C2S_ReconnectBattleServer = 532,
-		C2S_BattleClientInfo      = 533,
-		C2S_OpenShop              = 534,
-		C2S_RandomPickHero        = 535,
-		C2S_RequestSurrender      = 536,
-		C2S_SurrenderVote         = 537,
-		C2S_BuyStone              = 538,
-		C2S_SelectShop            = 539,
-		C2S_GetShopList           = 540,
-		C2S_StartOb               = 541,
-		C2S_Benchmark             = 4003,
-		S2C_Benchmark             = 4004,
-		C2S_PushClientRemoteCommand = 4005,
-		S2C_PushClientRemoteCommand = 4006,
-		C2S_ClientRemoteCommand   = 4007,
-		S2C_ClientRemoteCommand   = 4008,
-		C2S_CreateRoom            = 4501,
-		S2C_CreateRoom            = 4502,
-		C2S_EnterRoom             = 4503,
-		S2C_EnterRoom             = 4504,
-		C2S_LeaveRoom             = 4505,
-		S2C_LeaveRoom             = 4506,
-		C2S_InviteFriend          = 4507,
-		S2C_InviteFriend          = 4508,
-		C2S_JoinFaction           = 4509,
-		S2C_JoinFaction           = 4510,
-		C2S_RoomStartGame         = 4511,
-		S2C_RoomStartGame         = 4512,
-		C2S_GetRoomList           = 4513,
-		S2C_GetRoomList           = 4514,
-		C2S_KickPlayer            = 4515,
-		C2S_RoomAddRobot          = 4516,
-		S2C_LoginLobby            = 4527,
-		S2C_ReconnectBattle       = 4528,
-		S2C_UpdateRoomInfo        = 4529,
-		S2C_KickPlayer            = 4535,
-		C2S_RequestOb             = 4540,
-		S2C_RequestOb             = 4541,
-		C2S_GetObRoomList         = 4542,
-		S2C_GetObRoomList         = 4543,
-		C2S_LoginGate             = 5001,
-		S2C_LoginGate             = 5002,
-		C2S_GetPlayerProfile      = 5003,
-		S2C_GetPlayerProfile      = 5004,
-		C2S_SavePlayerProfile     = 5005,
-		S2C_SavePlayerProfile     = 5006,
-		S2C_LogoutGate            = 5007,
-		C2S_LogoutGate            = 5011,
-		C2S_ClientLog             = 5012,
-		S2C_RemoteGM              = 5013,
-		C2S_ClientSysInfo         = 5015,
-		S2C_PlatformBuff          = 5016,
-		C2S_ChangePlayerName      = 5017,
-		S2C_ChangePlayerName      = 5018,
-		S2C_PlayerAttr            = 5019,
-		C2S_Praise                = 5021,
-		S2C_Praise                = 5022,
-		C2S_Complaint             = 5025,
-		S2C_Complaint             = 5026,
-		C2S_RandGenRoleName       = 5027,
-		S2C_RandGenRoleName       = 5028,
-		S2C_TaskInfo              = 5030,
-		S2C_RefreshTask           = 5031,
-		C2S_FetchServerTime       = 5032,
-		S2C_FetchServerTime       = 5033,
-		C2S_FetchPlayerBattleInfo = 5034,
-		S2C_FetchPlayerBattleInfo = 5035,
-		C2S_ChangePlayerInfo      = 5036,
-		S2C_ChangePlayerInfo      = 5037,
-		C2S_HeroInfo              = 5038,
-		S2C_HeroInfo              = 5039,
-		C2S_WriteMail             = 5040,
-		S2C_WriteMail             = 5041,
-		S2C_NotifyNewMail         = 5042,
-		C2S_ReadMail              = 5043,
-		S2C_ReadMail              = 5044,
-		C2S_RemoveMail            = 5045,
-		S2C_RemoveMail            = 5046,
-		C2S_Bag                   = 5050,
-		S2C_Bag                   = 5051,
-		S2C_FlushBagItem          = 5052,
-		S2C_RemoveBagItem         = 5053,
-		C2S_EquipDeckList         = 5054,
-		S2C_EquipDeckList         = 5055,
-		C2S_CreateEquipDeck       = 5056,
-		S2C_CreateEquipDeck       = 5057,
-		C2S_UpdateEquipDeck       = 5058,
-		S2C_UpdateEquipDeck       = 5059,
-		C2S_RemoveEquipDeck       = 5060,
-		S2C_RemoveEquipDeck       = 5061,
-		C2S_MountStone            = 5062,
-		S2C_MountStone            = 5063,
-		C2S_OpenBox               = 5064,
-		S2C_OpenBox               = 5065,
-		C2S_BuyBox                = 5066,
-		S2C_BuyBox                = 5067,
-		C2S_RemoveBagItem         = 5068,
-		C2S_GroupInvite           = 5502,
-		S2C_GroupInvite           = 5503,
-		C2S_JoinGroup             = 5504,
-		S2C_JoinGroup             = 5505,
-		C2S_QuitGroup             = 5506,
-		S2C_QuitGroup             = 5507,
-		C2S_GroupInviteRes        = 5508,
-		S2C_GroupInviteRes        = 5509,
-		S2C_CloseGroup            = 5510,
-		C2S_GroupCreate           = 5511,
-		S2C_Match                 = 5512,
-		C2S_CancelMatch           = 5513,
-		S2C_CancelMatch           = 5514,
-		C2S_StartMatch            = 5515,
-		S2C_StartMatch            = 5516,
-		C2S_GroupChat             = 5517,
-		S2C_GroupChat             = 5518,
-		C2S_DownloadMapProcess    = 5519,
-		S2C_DownloadMapProcess    = 5520,
-		C2S_AddFriendReq          = 6001,
-		C2S_AddFriendRes          = 6002,
-		C2S_DeleteFriend          = 6003,
-		C2S_GetFriendList         = 6004,
-		C2S_FriendChat            = 6005,
-		C2S_ChannelMsg            = 6006,
-		C2S_AddFriendGroup        = 6007,
-		C2S_DelFriendGroup        = 6008,
-		C2S_FriendMoveGroup       = 6009,
-		C2S_AddToBlackNames       = 6010,
-		C2S_DelFromBlackNames     = 6011,
-		C2S_ModifyRemarks         = 6012,
-		C2S_UpdateStatus          = 6013,
-		C2S_FetchPlayerFriendInfo = 6014,
-		C2S_FindPlayerByName      = 6015,
-		C2S_RobotGetOnlinePlayers = 6016,
-		S2C_AddFriendReqBk        = 6500,
-		S2C_AddFriendReq          = 6501,
-		S2C_AddFriendRes          = 6502,
-		S2C_DeleteFriend          = 6503,
-		S2C_GetFriendList         = 6504,
-		S2C_FriendChat            = 6505,
-		S2C_UpdateFriendStatus    = 6506,
-		S2C_ChannelMsg            = 6507,
-		S2C_AddFriendReqWaitResp  = 6508,
-		S2C_AddFriendGroup        = 6509,
-		S2C_DelFriendGroup        = 6510,
-		S2C_FriendMoveGroup       = 6511,
-		S2C_AddToBlackNames       = 6512,
-		S2C_DelFromBlackNames     = 6513,
-		S2C_NotifyDeleteFriend    = 6514,
-		S2C_ModifyRemarks         = 6515,
-		S2C_UpdateStatus          = 6516,
-		S2C_FetchPlayerFriendInfo = 6517,
-		S2C_FindPlayerByName      = 6518,
-		S2C_RobotGetOnlinePlayers = 6519,
-		C2S_AuthAccount           = 7001,
-		S2C_AuthAccount           = 7002,
-		C2S_RegisterAccount       = 7003,
-		S2C_RegisterAccount       = 7004,
-		C2S_QueryAccount          = 7005,
-		S2C_QueryAccount          = 7006,
-	}
-}

+ 0 - 37
Server/Server.Model/Message/OpcodeHelper.cs

@@ -1,37 +0,0 @@
-using System.Collections.Generic;
-
-namespace Base
-{
-	public static class OpcodeHelper
-	{
-		private static readonly HashSet<Opcode> needDebugLogMessageSet = new HashSet<Opcode>
-		{
-			Opcode.S2C_StartGame,
-			Opcode.S2C_LoginBattleServer,
-			Opcode.S2C_StartPickHero,
-			Opcode.S2C_PlayerSelectHero,
-			
-			Opcode.C2S_PlayerSelectHero,
-			Opcode.C2S_LoginBattleServer,
-			Opcode.C2S_StartOb,
-			Opcode.S2C_StartOb,
-			Opcode.S2C_LoadingFinishStartGame,
-		};
-
-		public static bool IsNeedDebugLogMessage(Opcode opcode)
-		{
-			//return true;
-			if ((ushort)opcode > 1000)
-			{
-				return true;
-			}
-
-			if (needDebugLogMessageSet.Contains(opcode))
-			{
-				return true;
-			}
-
-			return false;
-		}
-	}
-}

+ 0 - 22
Server/Server.Model/Scene/Server.cs

@@ -1,22 +0,0 @@
-namespace Base
-{
-	public sealed class Server
-	{
-		private static Entity server = new Entity();
-
-		public static Entity Scene
-		{
-			get
-			{
-				return server;
-			}
-		}
-
-		public static void Close()
-		{
-			Entity scene = server;
-			server = null;
-			scene?.Dispose();
-		}
-	}
-}

+ 52 - 67
Server/Server.sln

@@ -3,19 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
 # Visual Studio 14
 VisualStudioVersion = 14.0.25420.1
 MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.App", "Server.App\Server.App.csproj", "{3F8DC04C-9E05-403F-B6A5-36293EB99937}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Base", "Base\Server.Base.csproj", "{E5078EC6-2B0E-4711-BE8B-D99F69638316}"
 EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ThirdParty", "ThirdParty", "{D736BBFE-822E-4F67-8376-44CDDBAA09F4}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Model", "Model\Server.Model.csproj", "{820D3488-76B9-4EE8-872A-BE06C2350B20}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Base", "Server.Base\Server.Base.csproj", "{AFBAD3D5-C827-4BA6-9940-7060B6C39306}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Controller", "Controller\Server.Controller.csproj", "{3878BD71-2F75-4EDF-882F-BC708154B1B0}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Controller", "Server.Controller\Server.Controller.csproj", "{ED2A5401-3829-4A8B-915D-A2A18FB233F8}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.Model", "Server.Model\Server.Model.csproj", "{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ThirdParty", "ThirdParty", "{01CCAD69-09B1-42F9-8A39-489268BEE18D}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ENet", "ThirdParty\ENet\ENet.vcxproj", "{C9992B7C-313E-4C9F-A954-640D01EDFB58}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Nuget", "ThirdParty\Nuget\Nuget.csproj", "{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server.App", "App\Server.App.csproj", "{3F8DC04C-9E05-403F-B6A5-36293EB99937}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -27,6 +25,52 @@ Global
 		Release|x86 = Release|x86
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|x64.Build.0 = Debug|Any CPU
+		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Debug|x86.Build.0 = Debug|Any CPU
+		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|Any CPU.Build.0 = Release|Any CPU
+		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|x64.ActiveCfg = Release|Any CPU
+		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|x64.Build.0 = Release|Any CPU
+		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|x86.ActiveCfg = Release|Any CPU
+		{E5078EC6-2B0E-4711-BE8B-D99F69638316}.Release|x86.Build.0 = Release|Any CPU
+		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|x64.Build.0 = Debug|Any CPU
+		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Debug|x86.Build.0 = Debug|Any CPU
+		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|Any CPU.Build.0 = Release|Any CPU
+		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|x64.ActiveCfg = Release|Any CPU
+		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|x64.Build.0 = Release|Any CPU
+		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|x86.ActiveCfg = Release|Any CPU
+		{820D3488-76B9-4EE8-872A-BE06C2350B20}.Release|x86.Build.0 = Release|Any CPU
+		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|x64.ActiveCfg = Debug|Any CPU
+		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|x64.Build.0 = Debug|Any CPU
+		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|x86.ActiveCfg = Debug|Any CPU
+		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Debug|x86.Build.0 = Debug|Any CPU
+		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|Any CPU.Build.0 = Release|Any CPU
+		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|x64.ActiveCfg = Release|Any CPU
+		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|x64.Build.0 = Release|Any CPU
+		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|x86.ActiveCfg = Release|Any CPU
+		{3878BD71-2F75-4EDF-882F-BC708154B1B0}.Release|x86.Build.0 = Release|Any CPU
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|Any CPU.ActiveCfg = Debug|Win32
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x64.ActiveCfg = Debug|x64
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x64.Build.0 = Debug|x64
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x86.ActiveCfg = Debug|Win32
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x86.Build.0 = Debug|Win32
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|Any CPU.ActiveCfg = Release|Win32
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x64.ActiveCfg = Release|x64
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x64.Build.0 = Release|x64
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x86.ActiveCfg = Release|Win32
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x86.Build.0 = Release|Win32
 		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -39,70 +83,11 @@ Global
 		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x64.Build.0 = Release|Any CPU
 		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x86.ActiveCfg = Release|Any CPU
 		{3F8DC04C-9E05-403F-B6A5-36293EB99937}.Release|x86.Build.0 = Release|Any CPU
-		{AFBAD3D5-C827-4BA6-9940-7060B6C39306}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{AFBAD3D5-C827-4BA6-9940-7060B6C39306}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{AFBAD3D5-C827-4BA6-9940-7060B6C39306}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{AFBAD3D5-C827-4BA6-9940-7060B6C39306}.Debug|x64.Build.0 = Debug|Any CPU
-		{AFBAD3D5-C827-4BA6-9940-7060B6C39306}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{AFBAD3D5-C827-4BA6-9940-7060B6C39306}.Debug|x86.Build.0 = Debug|Any CPU
-		{AFBAD3D5-C827-4BA6-9940-7060B6C39306}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{AFBAD3D5-C827-4BA6-9940-7060B6C39306}.Release|Any CPU.Build.0 = Release|Any CPU
-		{AFBAD3D5-C827-4BA6-9940-7060B6C39306}.Release|x64.ActiveCfg = Release|Any CPU
-		{AFBAD3D5-C827-4BA6-9940-7060B6C39306}.Release|x64.Build.0 = Release|Any CPU
-		{AFBAD3D5-C827-4BA6-9940-7060B6C39306}.Release|x86.ActiveCfg = Release|Any CPU
-		{AFBAD3D5-C827-4BA6-9940-7060B6C39306}.Release|x86.Build.0 = Release|Any CPU
-		{ED2A5401-3829-4A8B-915D-A2A18FB233F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{ED2A5401-3829-4A8B-915D-A2A18FB233F8}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{ED2A5401-3829-4A8B-915D-A2A18FB233F8}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{ED2A5401-3829-4A8B-915D-A2A18FB233F8}.Debug|x64.Build.0 = Debug|Any CPU
-		{ED2A5401-3829-4A8B-915D-A2A18FB233F8}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{ED2A5401-3829-4A8B-915D-A2A18FB233F8}.Debug|x86.Build.0 = Debug|Any CPU
-		{ED2A5401-3829-4A8B-915D-A2A18FB233F8}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{ED2A5401-3829-4A8B-915D-A2A18FB233F8}.Release|Any CPU.Build.0 = Release|Any CPU
-		{ED2A5401-3829-4A8B-915D-A2A18FB233F8}.Release|x64.ActiveCfg = Release|Any CPU
-		{ED2A5401-3829-4A8B-915D-A2A18FB233F8}.Release|x64.Build.0 = Release|Any CPU
-		{ED2A5401-3829-4A8B-915D-A2A18FB233F8}.Release|x86.ActiveCfg = Release|Any CPU
-		{ED2A5401-3829-4A8B-915D-A2A18FB233F8}.Release|x86.Build.0 = Release|Any CPU
-		{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}.Debug|x64.Build.0 = Debug|Any CPU
-		{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}.Debug|x86.Build.0 = Debug|Any CPU
-		{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}.Release|Any CPU.Build.0 = Release|Any CPU
-		{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}.Release|x64.ActiveCfg = Release|Any CPU
-		{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}.Release|x64.Build.0 = Release|Any CPU
-		{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}.Release|x86.ActiveCfg = Release|Any CPU
-		{E997A298-C1E1-4DC7-85A3-4B0E2A6E196D}.Release|x86.Build.0 = Release|Any CPU
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|Any CPU.ActiveCfg = Debug|Win32
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x64.ActiveCfg = Debug|x64
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x64.Build.0 = Debug|x64
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x86.ActiveCfg = Debug|Win32
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Debug|x86.Build.0 = Debug|Win32
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|Any CPU.ActiveCfg = Release|Win32
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x64.ActiveCfg = Release|x64
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x64.Build.0 = Release|x64
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x86.ActiveCfg = Release|Win32
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58}.Release|x86.Build.0 = Release|Win32
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x64.ActiveCfg = Debug|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x64.Build.0 = Debug|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x86.ActiveCfg = Debug|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Debug|x86.Build.0 = Debug|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|Any CPU.Build.0 = Release|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x64.ActiveCfg = Release|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x64.Build.0 = Release|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x86.ActiveCfg = Release|Any CPU
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135}.Release|x86.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
 	EndGlobalSection
 	GlobalSection(NestedProjects) = preSolution
-		{C9992B7C-313E-4C9F-A954-640D01EDFB58} = {D736BBFE-822E-4F67-8376-44CDDBAA09F4}
-		{F6F8E6AB-632C-4C6E-BFB1-B39570FF2135} = {D736BBFE-822E-4F67-8376-44CDDBAA09F4}
+		{C9992B7C-313E-4C9F-A954-640D01EDFB58} = {01CCAD69-09B1-42F9-8A39-489268BEE18D}
 	EndGlobalSection
 EndGlobal

+ 1 - 1
Unity/Assets/Plugins/Base/Component/EventComponent.cs

@@ -4,7 +4,7 @@ using System.Reflection;
 using Base;
 using Object = Base.Object;
 
-namespace Model
+namespace Base
 {
 	[ObjectEvent]
 	public class EventComponentEvent : ObjectEvent<EventComponent>, ILoader, IAwake

+ 1 - 1
Unity/Assets/Plugins/Base/Component/KVComponent.cs

@@ -2,7 +2,7 @@
 using Base;
 using MongoDB.Bson.Serialization.Attributes;
 
-namespace Model
+namespace Base
 {
 	/// <summary>
 	/// Key Value组件用于保存一些数据

+ 1 - 1
Unity/Assets/Plugins/Base/Component/LogComponent.cs

@@ -3,7 +3,7 @@ using System.IO;
 using System.Text;
 using Base;
 
-namespace Model
+namespace Base
 {
 	[ObjectEvent]
 	public class LogComponentEvent : ObjectEvent<LogComponent>, IAwake

+ 1 - 2
Unity/Assets/Plugins/Base/Component/MessageComponent.cs

@@ -2,9 +2,8 @@
 using System.Collections.Generic;
 using System.Threading;
 using System.Threading.Tasks;
-using Base;
 
-namespace Model
+namespace Base
 {
 	[ObjectEvent]
 	public class MessageComponentEvent : ObjectEvent<MessageComponent>, IAwake<MessageHandlerComponent, AChannel>

+ 1 - 3
Unity/Assets/Plugins/Base/Component/MessageHandlerComponent.cs

@@ -1,10 +1,8 @@
 using System;
 using System.Collections.Generic;
 using System.Reflection;
-using Base;
-using Object = Base.Object;
 
-namespace Model
+namespace Base
 {
 	[ObjectEvent]
 	public class MessageHandlerComponentEvent : ObjectEvent<MessageHandlerComponent>, ILoader, IAwake<MessageType>

+ 1 - 2
Unity/Assets/Plugins/Base/Component/NetworkComponent.cs

@@ -1,8 +1,7 @@
 using System;
 using System.Net.Sockets;
-using Base;
 
-namespace Model
+namespace Base
 {
 	[ObjectEvent]
 	public class NetworkComponentEvent : ObjectEvent<NetworkComponent>, IUpdate, IAwake<NetworkProtocol>

+ 1 - 3
Unity/Assets/Plugins/Base/Component/TimeComponent.cs

@@ -1,6 +1,4 @@
-using Base;
-
-namespace Model
+namespace Base
 {
 	/// <summary>
 	/// 用于同步服务端和客户端时间

+ 1 - 2
Unity/Assets/Plugins/Base/Component/TimerComponent.cs

@@ -1,10 +1,9 @@
 using System.Collections.Generic;
 using System.Threading;
 using System.Threading.Tasks;
-using Base;
 using MongoDB.Bson;
 
-namespace Model
+namespace Base
 {
 	public class Timer
 	{

+ 1 - 1
Unity/Assets/Plugins/Base/DoubleMap.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 4490fa27a0147ae41b8c923f8daa7bc1
-timeCreated: 1474943113
+timeCreated: 1476430040
 licenseType: Pro
 MonoImporter:
   serializedVersion: 2

Vissa filer visades inte eftersom för många filer har ändrats