فهرست منبع

1.去除DotNetZip库,使用.net本身的zip库
2.一些函数改名

tanghai 12 سال پیش
والد
کامیت
f787bb7b8a

+ 0 - 8
CSharp/App/BossClient/BossClient.csproj

@@ -32,14 +32,9 @@
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   <ItemGroup>
-    <Reference Include="Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
-      <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\packages\DotNetZip.1.9.1.8\lib\net20\Ionic.Zip.dll</HintPath>
-    </Reference>
     <Reference Include="System" />
     <Reference Include="System.Core" />
     <Reference Include="System.Numerics" />
-    <Reference Include="System.Runtime.Serialization" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="ENetChannel.cs" />
@@ -69,9 +64,6 @@
       <Name>BossBase</Name>
     </ProjectReference>
   </ItemGroup>
-  <ItemGroup>
-    <None Include="Packages.config" />
-  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\nuget.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

+ 22 - 12
CSharp/App/BossClient/ENetChannel.cs

@@ -1,9 +1,10 @@
 using System;
+using System.IO;
 using System.Threading.Tasks;
 using BossBase;
 using ENet;
 using Helper;
-using Ionic.Zlib;
+using System.IO.Compression;
 
 namespace BossClient
 {
@@ -39,18 +40,27 @@ namespace BossClient
 			const int opcodeSize = sizeof(ushort);
 			ushort opcode = BitConverter.ToUInt16(bytes, 0);
 			byte flag = bytes[2];
-			if (flag == 0)
-			{
-				var messageBytes = new byte[bytes.Length - opcodeSize - 1];
-				Array.Copy(bytes, opcodeSize + 1, messageBytes, 0, messageBytes.Length);
-				return Tuple.Create(opcode, messageBytes);
-			}
-			else
+
+			switch (flag)
 			{
-				var messageBytes = new byte[bytes.Length - opcodeSize - 5];
-				Array.Copy(bytes, opcodeSize + 5, messageBytes, 0, messageBytes.Length);
-				messageBytes = ZlibStream.UncompressBuffer(messageBytes);
-				return Tuple.Create(opcode, messageBytes);
+				case 0:
+				{
+					var messageBytes = new byte[bytes.Length - opcodeSize - 1];
+					Array.Copy(bytes, opcodeSize + 1, messageBytes, 0, messageBytes.Length);
+					return Tuple.Create(opcode, messageBytes);
+				}
+				default:
+				{
+					var decompressStream = new MemoryStream();
+					using (var zipStream = new GZipStream(
+						new MemoryStream(bytes, opcodeSize + 5, bytes.Length - opcodeSize - 5),
+							CompressionMode.Decompress))
+					{
+						zipStream.CopyTo(decompressStream);
+					}
+					var decompressBytes = decompressStream.ToArray();
+					return Tuple.Create(opcode, decompressBytes);
+				}
 			}
 		}
 	}

+ 0 - 4
CSharp/App/BossClient/Packages.config

@@ -1,4 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
-  <package id="DotNetZip" version="1.9.1.8" targetFramework="net45" />
-</packages>

+ 1 - 1
CSharp/Game/BehaviorTree/BehaviorTree.csproj

@@ -66,7 +66,7 @@
     </ProjectReference>
   </ItemGroup>
   <ItemGroup>
-    <None Include="packages.config" />
+    <None Include="Packages.config" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

+ 1 - 1
CSharp/Game/Component/AllConfigManager.cs

@@ -43,7 +43,7 @@ namespace Component
 			return configManager[type];
 		}
 
-		public Dictionary<int, T> GetAll<T>(int type) where T : IType
+		public Dictionary<int, T> GetAll<T>() where T : IType
 		{
 			var configManager = (ConfigManager<T>)allConfig[typeof (T).Name];
 			return configManager.GetAll();

+ 8 - 8
CSharp/Game/Component/BuffManager.cs

@@ -63,17 +63,17 @@ namespace Component
 			return true;
 		}
 
-		public Buff Get(ObjectId guid)
+		public Buff GetById(ObjectId id)
 		{
-			if (!this.BuffGuidDict.ContainsKey(guid))
+			if (!this.BuffGuidDict.ContainsKey(id))
 			{
 				return null;
 			}
 
-			return this.BuffGuidDict[guid];
+			return this.BuffGuidDict[id];
 		}
 
-		public Buff Get(int type)
+		public Buff GetByType(int type)
 		{
 			if (!this.BuffTypeDict.ContainsKey(type))
 			{
@@ -97,15 +97,15 @@ namespace Component
 			return true;
 		}
 
-		public bool Remove(ObjectId guid)
+		public bool RemoveById(ObjectId id)
 		{
-			var buff = this.Get(guid);
+			var buff = this.GetById(id);
 			return this.Remove(buff);
 		}
 
-		public bool Remove(int type)
+		public bool RemoveByType(int type)
 		{
-			var buff = this.Get(type);
+			var buff = this.GetByType(type);
 			return this.Remove(buff);
 		}
 	}

+ 1 - 1
CSharp/Game/Component/Component.csproj

@@ -66,7 +66,7 @@
     </ProjectReference>
   </ItemGroup>
   <ItemGroup>
-    <None Include="packages.config" />
+    <None Include="Packages.config" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />

+ 1 - 1
CSharp/Game/ComponentTest/BuffManagerTest.cs

@@ -29,7 +29,7 @@ namespace ComponentTest
 			var buffManager = new BuffManager();
 			var buff = new Buff { Type = 1 };
 			buffManager.Add(buff);
-			var getBuff = buffManager.Get(buff.Id);
+			var getBuff = buffManager.GetById(buff.Id);
 			Assert.AreSame(buff, getBuff);
 		}
 	}

+ 19 - 20
CSharp/Platform/ENetTest/ENetClientServerTest.cs

@@ -1,7 +1,6 @@
 using System.Threading;
 using ENet;
-using Helper;
-using Log;
+using Helper;
 using Microsoft.VisualStudio.TestTools.UnitTesting;
 
 namespace ENetCSTest
@@ -9,31 +8,31 @@ namespace ENetCSTest
 	[TestClass]
 	public class ENetClientServerTest
 	{
-		private static async void ClientEvent(IOService service, string hostName, ushort port)
-		{
-			var eSocket = new ESocket(service);
-			await eSocket.ConnectAsync(hostName, port);
-			eSocket.WriteAsync("0123456789".ToByteArray());
-
-			var bytes = await eSocket.ReadAsync();
-			CollectionAssert.AreEqual("9876543210".ToByteArray(), bytes);
-
+		private static async void ClientEvent(IOService service, string hostName, ushort port)
+		{
+			var eSocket = new ESocket(service);
+			await eSocket.ConnectAsync(hostName, port);
+			eSocket.WriteAsync("0123456789".ToByteArray());
+
+			var bytes = await eSocket.ReadAsync();
+			CollectionAssert.AreEqual("9876543210".ToByteArray(), bytes);
+
 			await eSocket.DisconnectAsync();
 
 			service.Stop();
-		}
-
+		}
+
 		private static async void ServerEvent(IOService service, Barrier barrier)
 		{
-			barrier.SignalAndWait();
+			barrier.SignalAndWait();
 			var eSocket = new ESocket(service);
 			await eSocket.AcceptAsync();
-			// Client断开,Server端收到Disconnect事件,结束Server线程
-			eSocket.ESocketEvent.Disconnect += ev => service.Stop();
-
-			var bytes = await eSocket.ReadAsync();
+			// Client断开,Server端收到Disconnect事件,结束Server线程
+			eSocket.ESocketEvent.Disconnect += ev => service.Stop();
+
+			var bytes = await eSocket.ReadAsync();
 			CollectionAssert.AreEqual("0123456789".ToByteArray(), bytes);
-
+
 			eSocket.WriteAsync("9876543210".ToByteArray(), 0, PacketFlags.Reliable);
 		}
 
@@ -41,7 +40,7 @@ namespace ENetCSTest
 		public void ClientSendToServer()
 		{
 			const string hostName = "127.0.0.1";
-			const ushort port = 8888;
+			const ushort port = 8888;
 			var clientHost = new IOService();
 			var serverHost = new IOService(hostName, port);