Browse Source

两边经常改动的代码改为共用

tanghai 8 years ago
parent
commit
51b1c7cd59
62 changed files with 182 additions and 2803 deletions
  1. 0 144
      Server/Base/DoubleMap.cs
  2. 0 12
      Server/Base/Helper/ArrayHelper.cs
  3. 0 64
      Server/Base/Helper/ByteHelper.cs
  4. 0 30
      Server/Base/Helper/EnumHelper.cs
  5. 0 56
      Server/Base/Helper/FileHelper.cs
  6. 0 16
      Server/Base/Helper/IdGenerater.cs
  7. 0 19
      Server/Base/Helper/MD5Helper.cs
  8. 0 26
      Server/Base/Helper/MethodInfoHelper.cs
  9. 0 67
      Server/Base/Helper/MongoHelper.cs
  10. 0 22
      Server/Base/Helper/NetHelper.cs
  11. 0 83
      Server/Base/Helper/ProtobufHelper.cs
  12. 0 35
      Server/Base/Helper/RandomHelper.cs
  13. 0 62
      Server/Base/Helper/StringHelper.cs
  14. 0 36
      Server/Base/Helper/TimeHelper.cs
  15. 0 97
      Server/Base/Helper/ZipHelper.cs
  16. 0 111
      Server/Base/MultiMap.cs
  17. 0 84
      Server/Base/Network/AChannel.cs
  18. 0 32
      Server/Base/Network/AService.cs
  19. 0 85
      Server/Base/Network/TNet/PacketParser.cs
  20. 0 129
      Server/Base/Network/TNet/TBuffer.cs
  21. 0 237
      Server/Base/Network/TNet/TChannel.cs
  22. 0 99
      Server/Base/Network/TNet/TService.cs
  23. 0 33
      Server/Base/Network/UNet/Library.cs
  24. 0 109
      Server/Base/Network/UNet/NativeMethods.cs
  25. 0 76
      Server/Base/Network/UNet/NativeStructs.cs
  26. 0 27
      Server/Base/Network/UNet/UAddress.cs
  27. 0 100
      Server/Base/Network/UNet/UChannel.cs
  28. 0 72
      Server/Base/Network/UNet/UPacket.cs
  29. 0 214
      Server/Base/Network/UNet/UPoller.cs
  30. 0 94
      Server/Base/Network/UNet/UService.cs
  31. 0 168
      Server/Base/Network/UNet/USocket.cs
  32. 0 41
      Server/Base/Network/UNet/USocketManager.cs
  33. 0 47
      Server/Base/QueueDictionary.cs
  34. 99 34
      Server/Base/Server.Base.csproj
  35. 6 0
      Server/Base/Server.Base.csproj.user
  36. 0 35
      Server/Base/TryLocker.cs
  37. 0 131
      Server/Model/Component/NetworkComponent.cs
  38. 6 1
      Server/Model/Server.Model.csproj
  39. 2 2
      Unity/Assets/Scripts/Base/Network/AChannel.cs.meta
  40. 0 3
      Unity/Assets/Scripts/Base/Network/AService.cs
  41. 2 2
      Unity/Assets/Scripts/Base/Network/AService.cs.meta
  42. 1 1
      Unity/Assets/Scripts/Base/Network/TNet/PacketParser.cs.meta
  43. 1 1
      Unity/Assets/Scripts/Base/Network/TNet/TBuffer.cs.meta
  44. 0 4
      Unity/Assets/Scripts/Base/Network/TNet/TChannel.cs
  45. 1 1
      Unity/Assets/Scripts/Base/Network/TNet/TChannel.cs.meta
  46. 2 2
      Unity/Assets/Scripts/Base/Network/TNet/TService.cs
  47. 1 1
      Unity/Assets/Scripts/Base/Network/TNet/TService.cs.meta
  48. 2 2
      Unity/Assets/Scripts/Base/Network/UNet/Library.cs.meta
  49. 30 30
      Unity/Assets/Scripts/Base/Network/UNet/NativeMethods.cs
  50. 2 2
      Unity/Assets/Scripts/Base/Network/UNet/NativeMethods.cs.meta
  51. 2 2
      Unity/Assets/Scripts/Base/Network/UNet/NativeStructs.cs.meta
  52. 2 2
      Unity/Assets/Scripts/Base/Network/UNet/UAddress.cs.meta
  53. 2 2
      Unity/Assets/Scripts/Base/Network/UNet/UChannel.cs
  54. 2 2
      Unity/Assets/Scripts/Base/Network/UNet/UChannel.cs.meta
  55. 2 2
      Unity/Assets/Scripts/Base/Network/UNet/UPacket.cs.meta
  56. 0 1
      Unity/Assets/Scripts/Base/Network/UNet/UPoller.cs
  57. 2 2
      Unity/Assets/Scripts/Base/Network/UNet/UPoller.cs.meta
  58. 2 2
      Unity/Assets/Scripts/Base/Network/UNet/UService.cs.meta
  59. 2 2
      Unity/Assets/Scripts/Base/Network/UNet/USocket.cs.meta
  60. 2 2
      Unity/Assets/Scripts/Base/Network/UNet/USocketManager.cs.meta
  61. 2 1
      Unity/Hotfix/UI/UILobby/Component/UILobbyComponent.cs
  62. 7 4
      Unity/Unity.csproj

+ 0 - 144
Server/Base/DoubleMap.cs

@@ -1,144 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Model
-{
-	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/Base/Helper/ArrayHelper.cs

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

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

@@ -1,64 +0,0 @@
-using System;
-using System.Text;
-
-namespace Model
-{
-	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 ToStr(this byte[] bytes, int offset, int count)
-		{
-			return Encoding.Default.GetString(bytes, offset, count);
-		}
-
-		public static string Utf8ToStr(this byte[] bytes, int offset, int count)
-		{
-			return Encoding.UTF8.GetString(bytes, offset, count);
-		}
-
-		public static byte[] Reverse(this byte[] bytes)
-		{
-			Array.Reverse(bytes);
-			return bytes;
-		}
-	}
-}

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

@@ -1,30 +0,0 @@
-using System;
-
-namespace Model
-{
-	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 - 56
Server/Base/Helper/FileHelper.cs

@@ -1,56 +0,0 @@
-using System;
-using System.IO;
-
-namespace Model
-{
-	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 - 16
Server/Base/Helper/IdGenerater.cs

@@ -1,16 +0,0 @@
-namespace Model
-{
-	public static class IdGenerater
-	{
-		public static long AppId { private get; set; }
-
-		private static ushort value;
-
-		public static long GenerateId()
-		{
-			long time = TimeHelper.ClientNowSeconds();
-
-			return (AppId << 48) + (time << 16) + ++value;
-		}
-	}
-}

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

@@ -1,19 +0,0 @@
-using System.IO;
-using System.Security.Cryptography;
-
-namespace Model
-{
-	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 - 26
Server/Base/Helper/MethodInfoHelper.cs

@@ -1,26 +0,0 @@
-using System.Reflection;
-
-namespace Model
-{
-	public static class MethodInfoHelper
-	{
-		public static void Run(this MethodInfo methodInfo, object obj, params object[] param)
-		{
-
-			if (methodInfo.IsStatic)
-			{
-				object[] p = new object[param.Length + 1];
-				p[0] = obj;
-				for (int i = 0; i < param.Length; ++i)
-				{
-					p[i + 1] = param[i];
-				}
-				methodInfo.Invoke(null, p);
-			}
-			else
-			{
-				methodInfo.Invoke(obj, param);
-			}
-		}
-	}
-}

+ 0 - 67
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 Model
-{
-	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 - 22
Server/Base/Helper/NetHelper.cs

@@ -1,22 +0,0 @@
-using System.Collections.Generic;
-using System.Net;
-
-namespace Model
-{
-	public static class NetHelper
-	{
-		public static string[] GetAddressIPs()
-		{
-			//获取本地的IP地址
-			List<string> addressIPs = new List<string>();
-			foreach (IPAddress address in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
-			{
-				if (address.AddressFamily.ToString() == "InterNetwork")
-				{
-					addressIPs.Add(address.ToString());
-				}
-			}
-			return addressIPs.ToArray();
-		}
-	}
-}

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

@@ -1,83 +0,0 @@
-using System;
-using System.ComponentModel;
-using System.IO;
-using ProtoBuf;
-
-namespace Model
-{
-	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 - 35
Server/Base/Helper/RandomHelper.cs

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

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

@@ -1,62 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Text;
-
-namespace Model
-{
-	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 - 36
Server/Base/Helper/TimeHelper.cs

@@ -1,36 +0,0 @@
-using System;
-
-namespace Model
-{
-	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 ClientNowSeconds()
-		{
-			return Convert.ToInt64((DateTime.UtcNow - epoch).TotalSeconds);
-		}
-
-		public static long ClientNowTicks()
-		{	
-			return Convert.ToInt64((DateTime.UtcNow - epoch).Ticks);
-		}
-
-		/// <summary>
-		/// 登陆前是客户端时间,登陆后是同步过的服务器时间
-		/// </summary>
-		/// <returns></returns>
-		public static long Now()
-		{
-			return ClientNow();
-		}
-    }
-}

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

@@ -1,97 +0,0 @@
-using System.IO;
-using ICSharpCode.SharpZipLib.Zip.Compression;
-
-namespace Model
-{
-	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 - 111
Server/Base/MultiMap.cs

@@ -1,111 +0,0 @@
-using System.Collections.Generic;
-
-namespace Model
-{
-	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 - 84
Server/Base/Network/AChannel.cs

@@ -1,84 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Net.Sockets;
-using System.Threading.Tasks;
-
-namespace Model
-{
-	[Flags]
-	public enum PacketFlags
-	{
-		None = 0,
-		Reliable = 1 << 0,
-		Unsequenced = 1 << 1,
-		NoAllocate = 1 << 2
-	}
-
-	public enum ChannelType
-	{
-		Connect,
-		Accept,
-	}
-
-	public abstract class AChannel: IDisposable
-	{
-		public long Id { get; private set; }
-
-		public ChannelType ChannelType { get; }
-
-		protected AService service;
-
-		public string RemoteAddress { get; protected set; }
-
-		private event Action<AChannel, SocketError> errorCallback;
-
-		public event Action<AChannel, SocketError> ErrorCallback
-		{
-			add
-			{
-				this.errorCallback += value;
-			}
-			remove
-			{
-				this.errorCallback -= value;
-			}
-		}
-
-		protected void OnError(AChannel channel, SocketError e)
-		{
-			this.errorCallback(channel, e);
-		}
-
-
-		protected AChannel(AService service, ChannelType channelType)
-		{
-			this.Id = IdGenerater.GenerateId();
-			this.ChannelType = channelType;
-			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 - 32
Server/Base/Network/AService.cs

@@ -1,32 +0,0 @@
-using System;
-using System.Threading.Tasks;
-
-namespace Model
-{
-	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 Task<AChannel> AcceptChannel();
-
-		public abstract AChannel ConnectChannel(string host, int port);
-
-		public abstract void Remove(long channelId);
-
-		public abstract void Update();
-
-		public abstract void Dispose();
-	}
-}

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

@@ -1,85 +0,0 @@
-using System;
-
-namespace Model
-{
-	internal enum ParserState
-	{
-		PacketSize,
-		PacketBody
-	}
-
-	internal class PacketParser
-	{
-		private readonly TBuffer buffer;
-
-		private ushort packetSize;
-		private readonly byte[] packetSizeBuffer = new byte[2];
-		private ParserState state;
-		private byte[] packet;
-		private bool isOK;
-
-		public PacketParser(TBuffer buffer)
-		{
-			this.buffer = buffer;
-		}
-
-		private void Parse()
-		{
-			if (this.isOK)
-			{
-				return;
-			}
-
-			bool finish = false;
-			while (!finish)
-			{
-				switch (this.state)
-				{
-					case ParserState.PacketSize:
-						if (this.buffer.Count < 2)
-						{
-							finish = true;
-						}
-						else
-						{
-							this.buffer.RecvFrom(this.packetSizeBuffer);
-							this.packetSize = BitConverter.ToUInt16(this.packetSizeBuffer, 0);
-							this.packetSize = NetworkHelper.NetworkToHostOrder(this.packetSize);
-							if (packetSize > 60000)
-							{
-								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;
-				}
-			}
-		}
-
-		public byte[] GetPacket()
-		{
-			this.Parse();
-			if (!this.isOK)
-			{
-				return null;
-			}
-			byte[] result = this.packet;
-			this.isOK = false;
-			return result;
-		}
-	}
-}

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

@@ -1,129 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Model
-{
-	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 - 237
Server/Base/Network/TNet/TChannel.cs

@@ -1,237 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Net.Sockets;
-using System.Threading.Tasks;
-
-namespace Model
-{
-	public class TChannel : AChannel
-	{
-		private readonly TcpClient tcpClient;
-
-		private readonly TBuffer recvBuffer = new TBuffer();
-		private readonly TBuffer sendBuffer = new TBuffer();
-
-		private bool isSending;
-		private readonly PacketParser parser;
-		private bool isConnected;
-		private TaskCompletionSource<byte[]> recvTcs;
-
-		/// <summary>
-		/// connect
-		/// </summary>
-		public TChannel(TcpClient tcpClient, string host, int port, TService service) : base(service, ChannelType.Connect)
-		{
-			this.tcpClient = tcpClient;
-			this.parser = new PacketParser(this.recvBuffer);
-			this.RemoteAddress = host + ":" + port;
-
-			this.ConnectAsync(host, port);
-		}
-
-		/// <summary>
-		/// accept
-		/// </summary>
-		public TChannel(TcpClient tcpClient, TService service) : base(service, ChannelType.Accept)
-		{
-			this.tcpClient = tcpClient;
-			this.parser = new PacketParser(this.recvBuffer);
-
-			IPEndPoint ipEndPoint = (IPEndPoint)this.tcpClient.Client.RemoteEndPoint;
-			this.RemoteAddress = ipEndPoint.Address + ":" + ipEndPoint.Port;
-			this.OnAccepted();
-		}
-
-		private async void ConnectAsync(string host, int port)
-		{
-			try
-			{
-				await this.tcpClient.ConnectAsync(host, port);
-				this.isConnected = true;
-				this.StartSend();
-				this.StartRecv();
-			}
-			catch (SocketException e)
-			{
-				Log.Error($"connect error: {e.SocketErrorCode}");
-			}
-			catch (Exception e)
-			{
-				Log.Error(e.ToString());
-			}
-		}
-
-		public override void Dispose()
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-
-			long id = this.Id;
-
-			base.Dispose();
-
-			this.tcpClient.Close();
-			this.service.Remove(id);
-		}
-
-		private void OnAccepted()
-		{
-			this.isConnected = true;
-			this.StartSend();
-			this.StartRecv();
-		}
-
-		public override void Send(byte[] buffer, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
-		{
-			if (this.Id == 0)
-			{
-				throw new Exception("TChannel已经被Dispose, 不能发送消息");
-			}
-			byte[] size = BitConverter.GetBytes((ushort)buffer.Length);
-			this.sendBuffer.SendTo(size);
-			this.sendBuffer.SendTo(buffer);
-			if (this.isConnected)
-			{
-				this.StartSend();
-			}
-		}
-
-		public override void Send(List<byte[]> buffers, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
-		{
-			if (this.Id == 0)
-			{
-				throw new Exception("TChannel已经被Dispose, 不能发送消息");
-			}
-			ushort size = (ushort)buffers.Select(b => b.Length).Sum();
-			size = NetworkHelper.HostToNetworkOrder(size);
-			byte[] sizeBuffer = BitConverter.GetBytes(size);
-			this.sendBuffer.SendTo(sizeBuffer);
-			foreach (byte[] buffer in buffers)
-			{
-				this.sendBuffer.SendTo(buffer);
-			}
-			if (this.isConnected)
-			{
-				this.StartSend();
-			}
-		}
-
-		private async void StartSend()
-		{
-			try
-			{
-				// 如果正在发送中,不需要再次发送
-				if (this.isSending)
-				{
-					return;
-				}
-
-				while (true)
-				{
-					if (this.Id == 0)
-					{
-						return;
-					}
-
-					// 没有数据需要发送
-					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;
-					}
-					await this.tcpClient.GetStream().WriteAsync(this.sendBuffer.First, this.sendBuffer.FirstIndex, sendSize);
-					this.sendBuffer.FirstIndex += sendSize;
-					if (this.sendBuffer.FirstIndex == TBuffer.ChunkSize)
-					{
-						this.sendBuffer.FirstIndex = 0;
-						this.sendBuffer.RemoveFirst();
-					}
-				}
-			}
-			catch (Exception e)
-			{
-				Log.Error(e.ToString());
-				this.OnError(this, SocketError.SocketError);
-			}
-		}
-
-		private async void StartRecv()
-		{
-			try
-			{
-				while (true)
-				{
-					if (this.Id == 0)
-					{
-						return;
-					}
-					int size = TBuffer.ChunkSize - this.recvBuffer.LastIndex;
-
-					int n = await this.tcpClient.GetStream().ReadAsync(this.recvBuffer.Last, this.recvBuffer.LastIndex, size);
-
-					if (n == 0)
-					{
-						this.OnError(this, SocketError.NetworkReset);
-						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)
-						{
-							var tcs = this.recvTcs;
-							this.recvTcs = null;
-							tcs.SetResult(packet);
-						}
-					}
-				}
-			}
-			catch (ObjectDisposedException)
-			{
-			}
-			catch (Exception e)
-			{
-				Log.Error(e.ToString());
-				this.OnError(this, SocketError.SocketError);
-			}
-		}
-
-		public override Task<byte[]> Recv()
-		{
-			if (this.Id == 0)
-			{
-				throw new Exception("TChannel已经被Dispose, 不能接收消息");
-			}
-
-			byte[] packet = this.parser.GetPacket();
-			if (packet != null)
-			{
-				return Task.FromResult(packet);
-			}
-
-			recvTcs = new TaskCompletionSource<byte[]>();
-			return recvTcs.Task;
-		}
-	}
-}

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

@@ -1,99 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Net.Sockets;
-using System.Threading.Tasks;
-
-namespace Model
-{
-	public sealed class TService: AService
-	{
-		private TcpListener acceptor;
-
-		private readonly Dictionary<long, TChannel> idChannels = new Dictionary<long, TChannel>();
-
-		/// <summary>
-		/// 即可做client也可做server
-		/// </summary>
-		/// <param name="host"></param>
-		/// <param name="port"></param>
-		public TService(string host, int port)
-		{
-			this.acceptor = new TcpListener(new IPEndPoint(IPAddress.Parse(host), port));
-			this.acceptor.Start();
-		}
-
-		public TService()
-		{
-		}
-
-		public override void Dispose()
-		{
-			if (this.acceptor == null)
-			{
-				return;
-			}
-
-			foreach (long id in this.idChannels.Keys.ToArray())
-			{
-				TChannel channel = this.idChannels[id];
-				channel.Dispose();
-			}
-			this.acceptor.Stop();
-			this.acceptor = null;
-		}
-
-		public override void Add(Action 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");
-			}
-			TcpClient tcpClient = await this.acceptor.AcceptTcpClientAsync();
-			TChannel channel = new TChannel(tcpClient, this);
-			this.idChannels[channel.Id] = channel;
-			return channel;
-		}
-
-		public override AChannel ConnectChannel(string host, int port)
-		{
-			TcpClient tcpClient = new TcpClient();
-			TChannel channel = new TChannel(tcpClient, host, port, this);
-			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 void Update()
-		{
-		}
-	}
-}

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

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

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

@@ -1,109 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-using System.Text;
-
-namespace Model
-{
-	public static class NativeMethods
-	{
-#if UNITY_IOS && !UNITY_EDITOR
-		private const string LIB = "__Internal";
-#else
-		private const string LIB = "ENet";
-#endif
-
-		public const int ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255;
-		public const int ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xfff;
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int enet_address_set_host(ref ENetAddress address, string hostName);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int enet_address_get_host(ref ENetAddress address, StringBuilder hostName, uint nameLength);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int enet_address_get_host_ip(ref ENetAddress address, StringBuilder hostIp, uint ipLength);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_deinitialize();
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int enet_initialize();
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern IntPtr enet_host_create(
-				ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern IntPtr enet_host_create(IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_host_destroy(IntPtr host);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern IntPtr enet_host_connect(IntPtr host, ref ENetAddress address, uint channelCount, uint data);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_host_broadcast(IntPtr host, byte channelID, IntPtr packet);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_host_compress(IntPtr host, IntPtr compressor);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int enet_host_compress_with_range_coder(IntPtr host);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_host_channel_limit(IntPtr host, uint channelLimit);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_host_bandwidth_limit(IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_host_flush(IntPtr host);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int enet_host_check_events(IntPtr host, ref ENetEvent ev);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int enet_host_service(IntPtr host, IntPtr ev, uint timeout);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern uint enet_time_get();
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_time_set(uint newTimeBase);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern IntPtr enet_packet_create(byte[] data, uint dataLength, PacketFlags flags);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_packet_destroy(IntPtr packet);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int enet_packet_resize(IntPtr packet, uint dataLength);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_peer_throttle_configure(IntPtr peer, uint interval, uint acceleration, uint deceleration);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern int enet_peer_send(IntPtr peer, byte channelID, IntPtr packet);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern IntPtr enet_peer_receive(IntPtr peer, out byte channelID);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_peer_reset(IntPtr peer);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_peer_ping(IntPtr peer);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_peer_disconnect_now(IntPtr peer, uint data);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_peer_disconnect(IntPtr peer, uint data);
-
-		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
-		internal static extern void enet_peer_disconnect_later(IntPtr peer, uint data);
-	}
-}

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

@@ -1,76 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-
-namespace Model
-{
-	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 struct 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/Base/Network/UNet/UAddress.cs

@@ -1,27 +0,0 @@
-using System;
-using System.Net;
-
-namespace Model
-{
-	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 - 100
Server/Base/Network/UNet/UChannel.cs

@@ -1,100 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Sockets;
-using System.Threading.Tasks;
-
-namespace Model
-{
-	internal class UChannel: AChannel
-	{
-		private readonly USocket socket;
-
-		private TaskCompletionSource<byte[]> recvTcs;
-
-		/// <summary>
-		/// connect
-		/// </summary>
-		public UChannel(USocket socket, string host, int port, UService service): base(service, ChannelType.Connect)
-		{
-			this.socket = socket;
-			this.service = service;
-			this.RemoteAddress = host + ":" + port;
-			this.socket.ConnectAsync(host, (ushort)port);
-			this.socket.Received += this.OnRecv;
-			this.socket.Disconnect += () => { this.OnError(this, SocketError.SocketError); };
-		}
-
-		/// <summary>
-		/// accept
-		/// </summary>
-		public UChannel(USocket socket, UService service) : base(service, ChannelType.Accept)
-		{
-			this.socket = socket;
-			this.service = service;
-			this.RemoteAddress = socket.RemoteAddress;
-			this.socket.Received += this.OnRecv;
-			this.socket.Disconnect += () => { this.OnError(this, SocketError.SocketError); };
-		}
-
-		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)
-		{
-			if (this.Id == 0)
-			{
-				throw new Exception("UChannel已经被Dispose, 不能发送消息");
-			}
-			this.socket.SendAsync(buffer, channelID, flags);
-		}
-
-		public override void Send(List<byte[]> buffers, byte channelID = 0, PacketFlags flags = PacketFlags.Reliable)
-		{
-			if (this.Id == 0)
-			{
-				throw new Exception("UChannel已经被Dispose, 不能发送消息");
-			}
-			int size = buffers.Select(b => b.Length).Sum();
-			var buffer = new byte[size];
-			int index = 0;
-			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()
-		{
-			if (this.Id == 0)
-			{
-				throw new Exception("UChannel已经被Dispose, 不能接收消息");
-			}
-			
-			var recvQueue = this.socket.RecvQueue;
-			if (recvQueue.Count > 0)
-			{
-				return Task.FromResult(recvQueue.Dequeue());
-			}
-
-			recvTcs = new TaskCompletionSource<byte[]>();
-			return recvTcs.Task;
-		}
-
-		private void OnRecv()
-		{
-			var tcs = this.recvTcs;
-			this.recvTcs = null;
-			tcs?.SetResult(this.socket.RecvQueue.Dequeue());
-		}
-	}
-}

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

@@ -1,72 +0,0 @@
-using System;
-using System.Runtime.InteropServices;
-
-namespace Model
-{
-	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.enet_packet_create(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.enet_packet_destroy(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 - 214
Server/Base/Network/UNet/UPoller.cs

@@ -1,214 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-
-namespace Model
-{
-	internal sealed class UPoller : IDisposable
-	{
-		static UPoller()
-		{
-			Library.Initialize();
-		}
-
-		public USocketManager USocketManager { get; }
-		private readonly Queue<IntPtr> connQueue = new Queue<IntPtr>();
-
-		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)
-		{
-			try
-			{
-				this.USocketManager = new USocketManager();
-
-				UAddress address = new UAddress(hostName, port);
-				ENetAddress nativeAddress = address.Struct;
-				this.host = NativeMethods.enet_host_create(ref nativeAddress,
-						NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID, 0, 0, 0);
-
-				if (this.host == IntPtr.Zero)
-				{
-					throw new Exception("Host creation call failed.");
-				}
-
-				NativeMethods.enet_host_compress_with_range_coder(this.host);
-			}
-			catch (Exception e)
-			{
-				throw new Exception($"UPoll construct error, address: {hostName}:{port}", e);
-			}
-		}
-
-		public UPoller()
-		{
-			this.USocketManager = new USocketManager();
-
-			this.host = NativeMethods.enet_host_create(IntPtr.Zero, NativeMethods.ENET_PROTOCOL_MAXIMUM_PEER_ID, 0, 0, 0);
-
-			if (this.host == IntPtr.Zero)
-			{
-				throw new Exception("Host creation call failed.");
-			}
-
-			NativeMethods.enet_host_compress_with_range_coder(this.host);
-		}
-
-		public void Dispose()
-		{
-			if (this.host == IntPtr.Zero)
-			{
-				return;
-			}
-
-			NativeMethods.enet_host_destroy(this.host);
-
-			this.host = IntPtr.Zero;
-		}
-
-		public IntPtr Host
-		{
-			get
-			{
-				return this.host;
-			}
-		}
-
-		public void Flush()
-		{
-			NativeMethods.enet_host_flush(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!");
-			}
-			
-			// 如果有请求连接缓存的包,从缓存中取
-			if (this.connQueue.Count > 0)
-			{
-				IntPtr ptr = this.connQueue.Dequeue();
-
-				USocket socket = new USocket(ptr, this);
-				this.USocketManager.Add(ptr, socket);
-				return Task.FromResult(socket);
-			}
-
-			this.AcceptTcs = new TaskCompletionSource<USocket>();
-			return this.AcceptTcs.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.enet_host_service(this.host, IntPtr.Zero, 0);
-			return ret;
-		}
-
-		public void Update()
-		{
-			this.OnEvents();
-
-			if (this.Service() < 0)
-			{
-				return;
-			}
-
-			while (true)
-			{
-				if (NativeMethods.enet_host_check_events(this.host, ref this.eNetEventCache) <= 0)
-				{
-					return;
-				}
-
-				switch (this.eNetEventCache.Type)
-				{
-					case EventType.Connect:
-						{
-							// 这是一个connect peer
-							if (this.USocketManager.ContainsKey(this.eNetEventCache.Peer))
-							{
-								USocket uSocket = this.USocketManager[this.eNetEventCache.Peer];
-								uSocket.OnConnected();
-								break;
-							}
-
-							// 这是accept peer
-							if (this.AcceptTcs != null)
-							{
-								this.OnAccepted(this.eNetEventCache);
-								break;
-							}
-
-							// 如果server端没有acceptasync,则请求放入队列
-							this.connQueue.Enqueue(this.eNetEventCache.Peer);
-							break;
-						}
-					case EventType.Receive:
-						{
-							USocket uSocket = this.USocketManager[this.eNetEventCache.Peer];
-							uSocket.OnReceived(this.eNetEventCache);
-							break;
-						}
-					case EventType.Disconnect:
-						{
-							USocket uSocket = this.USocketManager[this.eNetEventCache.Peer];
-							this.USocketManager.Remove(uSocket.PeerPtr);
-							uSocket.PeerPtr = IntPtr.Zero;
-							uSocket.OnDisconnect(this.eNetEventCache);
-							break;
-						}
-				}
-			}
-		}
-	}
-}

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

@@ -1,94 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace Model
-{
-	public sealed class UService: AService
-	{
-		private UPoller poller;
-
-		private readonly Dictionary<long, UChannel> idChannels = new Dictionary<long, 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 async Task<AChannel> AcceptChannel()
-		{
-			USocket socket = await this.poller.AcceptAsync();
-			UChannel channel = new UChannel(socket, this);
-			this.idChannels[channel.Id] = channel;
-			return channel;
-		}
-
-		public override AChannel ConnectChannel(string host, int port)
-		{
-			USocket newSocket = new USocket(this.poller);
-			UChannel channel = new UChannel(newSocket, host, port, this);
-			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 - 168
Server/Base/Network/UNet/USocket.cs

@@ -1,168 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Net;
-using System.Runtime.InteropServices;
-
-namespace Model
-{
-	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;
-		private Action disconnect;
-		private Action received;
-
-		public event Action Received
-		{
-			add
-			{
-				this.received += value;
-			}
-			remove
-			{
-				this.received -= value;
-			}
-		}
-
-		public event Action Disconnect
-		{
-			add
-			{
-				this.disconnect += value;
-			}
-			remove
-			{
-				this.disconnect -= value;
-			}
-		}
-
-		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.enet_peer_disconnect_now(this.PeerPtr, 0);
-			this.PeerPtr = IntPtr.Zero;
-		}
-
-		public string RemoteAddress
-		{
-			get
-			{
-				ENetPeer peer = this.Struct;
-				IPAddress ipaddr = new IPAddress(peer.Address.Host);
-				return $"{ipaddr}:{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.enet_host_connect(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 (this.PeerPtr == IntPtr.Zero)
-			{
-				throw new Exception($"USocket 已经被Dispose,不能发送数据!");
-			}
-			if (!isConnected)
-			{
-				sendQueue.Enqueue(new BufferInfo { Buffer = data, ChannelID = channelID, Flags = flags });
-				return;
-			}
-			UPacket packet = new UPacket(data, flags);
-			NativeMethods.enet_peer_send(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);
-			}
-			this.received();
-		}
-
-		internal void OnDisconnect(ENetEvent eNetEvent)
-		{
-			disconnect();
-		}
-	}
-}

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

@@ -1,41 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Model
-{
-	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 - 47
Server/Base/QueueDictionary.cs

@@ -1,47 +0,0 @@
-using System.Collections.Generic;
-
-namespace Model
-{
-	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];
-			}
-		}
-	}
-}

+ 99 - 34
Server/Base/Server.Base.csproj

@@ -47,50 +47,115 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\DoubleMap.cs">
+      <Link>DoubleMap.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\ArrayHelper.cs">
+      <Link>Helper\ArrayHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\ByteHelper.cs">
+      <Link>Helper\ByteHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\EnumHelper.cs">
+      <Link>Helper\EnumHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\FileHelper.cs">
+      <Link>Helper\FileHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\IdGenerater.cs">
+      <Link>Helper\IdGenerater.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\MD5Helper.cs">
+      <Link>Helper\MD5Helper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\MethodInfoHelper.cs">
+      <Link>Helper\MethodInfoHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\NetHelper.cs">
+      <Link>Helper\NetHelper.cs</Link>
+    </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\NetworkHelper.cs">
       <Link>Helper\NetworkHelper.cs</Link>
     </Compile>
-    <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\MethodInfoHelper.cs" />
-    <Compile Include="Helper\MongoHelper.cs" />
-    <Compile Include="Helper\NetHelper.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="..\..\Unity\Assets\Scripts\Base\Helper\ProtobufHelper.cs">
+      <Link>Helper\ProtobufHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\RandomHelper.cs">
+      <Link>Helper\RandomHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\StringHelper.cs">
+      <Link>Helper\StringHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\TimeHelper.cs">
+      <Link>Helper\TimeHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Helper\ZipHelper.cs">
+      <Link>Helper\ZipHelper.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\MultiMap.cs">
+      <Link>MultiMap.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\AChannel.cs">
+      <Link>Network\AChannel.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\AService.cs">
+      <Link>Network\AService.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\TNet\PacketParser.cs">
+      <Link>Network\TNet\PacketParser.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\TNet\TBuffer.cs">
+      <Link>Network\TNet\TBuffer.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\TNet\TChannel.cs">
+      <Link>Network\TNet\TChannel.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\TNet\TService.cs">
+      <Link>Network\TNet\TService.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\Library.cs">
+      <Link>Network\UNet\Library.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\NativeMethods.cs">
+      <Link>Network\UNet\NativeMethods.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\NativeStructs.cs">
+      <Link>Network\UNet\NativeStructs.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UAddress.cs">
+      <Link>Network\UNet\UAddress.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UChannel.cs">
+      <Link>Network\UNet\UChannel.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UPacket.cs">
+      <Link>Network\UNet\UPacket.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UPoller.cs">
+      <Link>Network\UNet\UPoller.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\UService.cs">
+      <Link>Network\UNet\UService.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\USocket.cs">
+      <Link>Network\UNet\USocket.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Network\UNet\USocketManager.cs">
+      <Link>Network\UNet\USocketManager.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\QueueDictionary.cs">
+      <Link>QueueDictionary.cs</Link>
+    </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\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="LogType.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\TService.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="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. 

+ 6 - 0
Server/Base/Server.Base.csproj.user

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <ProjectView>ProjectFiles</ProjectView>
+  </PropertyGroup>
+</Project>

+ 0 - 35
Server/Base/TryLocker.cs

@@ -1,35 +0,0 @@
-using System;
-using System.Threading;
-
-namespace Model
-{
-	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 - 131
Server/Model/Component/NetworkComponent.cs

@@ -1,131 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace Model
-{
-	public abstract class NetworkComponent : Component
-	{
-		private AService Service;
-
-		private readonly Dictionary<long, Session> sessions = new Dictionary<long, Session>();
-
-		public IMessagePacker MessagePacker { get; protected set; }
-
-		public IMessageDispatcher MessageDispatcher { get; protected set; }
-
-		protected void Awake(NetworkProtocol protocol)
-		{
-			switch (protocol)
-			{
-				case NetworkProtocol.TCP:
-					this.Service = new TService();
-					break;
-				case NetworkProtocol.UDP:
-					this.Service = new UService();
-					break;
-				default:
-					throw new ArgumentOutOfRangeException();
-			}
-		}
-
-		protected void Awake(NetworkProtocol protocol, string host, int port)
-		{
-			switch (protocol)
-			{
-				case NetworkProtocol.TCP:
-					this.Service = new TService(host, port);
-					break;
-				case NetworkProtocol.UDP:
-					this.Service = new UService(host, port);
-					break;
-				default:
-					throw new ArgumentOutOfRangeException();
-			}
-
-			this.StartAccept();
-		}
-
-		private async void StartAccept()
-		{
-			while (true)
-			{
-				if (this.Id == 0)
-				{
-					return;
-				}
-
-				await this.Accept();
-			}
-		}
-
-		public virtual async Task<Session> Accept()
-		{
-			AChannel channel = await this.Service.AcceptChannel();
-			Session session = new Session(this, channel);
-			channel.ErrorCallback += (c, e) => { this.Remove(session.Id); };
-			this.sessions.Add(session.Id, session);
-			return session;
-		}
-
-		public virtual void Remove(long id)
-		{
-			Session session;
-			if (!this.sessions.TryGetValue(id, out session))
-			{
-				return;
-			}
-			this.sessions.Remove(id);
-			session.Dispose();
-		}
-
-		public Session Get(long id)
-		{
-			Session session;
-			this.sessions.TryGetValue(id, out session);
-			return session;
-		}
-
-		/// <summary>
-		/// 创建一个新Session
-		/// </summary>
-		public virtual Session Create(string address)
-		{
-			string[] ss = address.Split(':');
-			int port = int.Parse(ss[1]);
-			string host = ss[0];
-			AChannel channel = this.Service.ConnectChannel(host, port);
-			Session session = new Session(this, channel);
-			channel.ErrorCallback += (c, e) => { this.Remove(session.Id); };
-			this.sessions.Add(session.Id, session);
-			return session;
-		}
-
-		protected void Update()
-		{
-			if (this.Service == null)
-			{
-				return;
-			}
-			this.Service.Update();
-		}
-
-		public override void Dispose()
-		{
-			if (this.Id == 0)
-			{
-				return;
-			}
-
-			base.Dispose();
-
-			foreach (Session session in this.sessions.Values.ToArray())
-			{
-				session.Dispose();
-			}
-
-			this.Service.Dispose();
-		}
-	}
-}

+ 6 - 1
Server/Model/Server.Model.csproj

@@ -61,12 +61,18 @@
     <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\ProtobufPacker.cs">
       <Link>Message\ProtobufPacker.cs</Link>
     </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Component\NetworkComponent.cs">
+      <Link>Component\NetworkComponent.cs</Link>
+    </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Entity\Message\Opcode.cs">
       <Link>Entity\Message\Opcode.cs</Link>
     </Compile>
     <Compile Include="..\..\Unity\Assets\Scripts\Entity\Message\OuterMessage.cs">
       <Link>Entity\Message\OuterMessage.cs</Link>
     </Compile>
+    <Compile Include="..\..\Unity\Assets\Scripts\Helper\MongoHelper.cs">
+      <Link>Helper\MongoHelper.cs</Link>
+    </Compile>
     <Compile Include="Component\ActorProxyComponent.cs" />
     <Compile Include="Component\PlayerComponent.cs" />
     <Compile Include="Component\Unit\UnitGateComponent.cs" />
@@ -93,7 +99,6 @@
     <Compile Include="Component\MessageDispatherComponent.cs" />
     <Compile Include="Component\NetInnerComponent.cs" />
     <Compile Include="Component\NetOuterComponent.cs" />
-    <Compile Include="Component\NetworkComponent.cs" />
     <Compile Include="Component\RobotComponent.cs" />
     <Compile Include="Component\Session\SessionPlayerComponent.cs" />
     <Compile Include="Component\TimerComponent.cs" />

+ 2 - 2
Unity/Assets/Scripts/Base/Network/AChannel.cs.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
 guid: 05a074f965a8c214f8f1f1af1ecf4dcc
-timeCreated: 1440989101
-licenseType: Pro
+timeCreated: 1503986857
+licenseType: Free
 MonoImporter:
   serializedVersion: 2
   defaultReferences: []

+ 0 - 3
Unity/Assets/Scripts/Base/Network/AService.cs

@@ -1,7 +1,4 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Sockets;
 using System.Threading.Tasks;
 
 namespace Model

+ 2 - 2
Unity/Assets/Scripts/Base/Network/AService.cs.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
 guid: b5af0de1c471e6c43989dc0349cc2bba
-timeCreated: 1440989101
-licenseType: Pro
+timeCreated: 1503986858
+licenseType: Free
 MonoImporter:
   serializedVersion: 2
   defaultReferences: []

+ 1 - 1
Unity/Assets/Scripts/Base/Network/TNet/PacketParser.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 8b71d12882faac44992e531533491a5f
-timeCreated: 1429240758
+timeCreated: 1503986857
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 1 - 1
Unity/Assets/Scripts/Base/Network/TNet/TBuffer.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: ea037025225a9c74b8ddb5349b0c18a6
-timeCreated: 1429240758
+timeCreated: 1503986858
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 0 - 4
Unity/Assets/Scripts/Base/Network/TNet/TChannel.cs

@@ -210,10 +210,6 @@ namespace Model
 			catch (ObjectDisposedException)
 			{
 			}
-			catch (System.IO.IOException)
-			{
-				this.OnError(this, SocketError.NetworkReset);
-			}
 			catch (Exception e)
 			{
 				Log.Error(e.ToString());

+ 1 - 1
Unity/Assets/Scripts/Base/Network/TNet/TChannel.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 4cacc90d7e561c64a8ea0e9079163bb9
-timeCreated: 1429240758
+timeCreated: 1503986857
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 2 - 2
Unity/Assets/Scripts/Base/Network/TNet/TService.cs

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
 
 namespace Model
 {
-	public sealed class TService : AService
+	public sealed class TService: AService
 	{
 		private TcpListener acceptor;
 
@@ -91,7 +91,7 @@ namespace Model
 			this.idChannels.Remove(id);
 			channel.Dispose();
 		}
-
+		
 		public override void Update()
 		{
 		}

+ 1 - 1
Unity/Assets/Scripts/Base/Network/TNet/TService.cs.meta

@@ -1,6 +1,6 @@
 fileFormatVersion: 2
 guid: 9c6cb526a0e4374438cbcbaa70239e4a
-timeCreated: 1429240758
+timeCreated: 1503986857
 licenseType: Free
 MonoImporter:
   serializedVersion: 2

+ 2 - 2
Unity/Assets/Scripts/Base/Network/UNet/Library.cs.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
 guid: 3d5dfbf30769f024da1a91ea2a6fc26b
-timeCreated: 1431427020
-licenseType: Pro
+timeCreated: 1503986857
+licenseType: Free
 MonoImporter:
   serializedVersion: 2
   defaultReferences: []

+ 30 - 30
Unity/Assets/Scripts/Base/Network/UNet/NativeMethods.cs

@@ -15,95 +15,95 @@ namespace Model
 		public const int ENET_PROTOCOL_MAXIMUM_CHANNEL_COUNT = 255;
 		public const int ENET_PROTOCOL_MAXIMUM_PEER_ID = 0xfff;
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern int enet_address_set_host(ref ENetAddress address, string hostName);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern int enet_address_get_host(ref ENetAddress address, StringBuilder hostName, uint nameLength);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern int enet_address_get_host_ip(ref ENetAddress address, StringBuilder hostIp, uint ipLength);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_deinitialize();
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern int enet_initialize();
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern IntPtr enet_host_create(
 				ref ENetAddress address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern IntPtr enet_host_create(IntPtr address, uint peerLimit, uint channelLimit, uint incomingBandwidth, uint outgoingBandwidth);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_host_destroy(IntPtr host);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern IntPtr enet_host_connect(IntPtr host, ref ENetAddress address, uint channelCount, uint data);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_host_broadcast(IntPtr host, byte channelID, IntPtr packet);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_host_compress(IntPtr host, IntPtr compressor);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern int enet_host_compress_with_range_coder(IntPtr host);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_host_channel_limit(IntPtr host, uint channelLimit);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_host_bandwidth_limit(IntPtr host, uint incomingBandwidth, uint outgoingBandwidth);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_host_flush(IntPtr host);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern int enet_host_check_events(IntPtr host, ref ENetEvent ev);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern int enet_host_service(IntPtr host, IntPtr ev, uint timeout);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern uint enet_time_get();
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_time_set(uint newTimeBase);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern IntPtr enet_packet_create(byte[] data, uint dataLength, PacketFlags flags);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_packet_destroy(IntPtr packet);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern int enet_packet_resize(IntPtr packet, uint dataLength);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_peer_throttle_configure(IntPtr peer, uint interval, uint acceleration, uint deceleration);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern int enet_peer_send(IntPtr peer, byte channelID, IntPtr packet);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern IntPtr enet_peer_receive(IntPtr peer, out byte channelID);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_peer_reset(IntPtr peer);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_peer_ping(IntPtr peer);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_peer_disconnect_now(IntPtr peer, uint data);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_peer_disconnect(IntPtr peer, uint data);
 
-		[DllImport(LIB)]
+		[DllImport(LIB, CallingConvention = CallingConvention.Cdecl)]
 		internal static extern void enet_peer_disconnect_later(IntPtr peer, uint data);
 	}
 }

+ 2 - 2
Unity/Assets/Scripts/Base/Network/UNet/NativeMethods.cs.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
 guid: 35389856785ea104698c98410fef22d6
-timeCreated: 1431427020
-licenseType: Pro
+timeCreated: 1503986857
+licenseType: Free
 MonoImporter:
   serializedVersion: 2
   defaultReferences: []

+ 2 - 2
Unity/Assets/Scripts/Base/Network/UNet/NativeStructs.cs.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
 guid: 0c22827e08133ae47aaba041ccbd7b66
-timeCreated: 1431427020
-licenseType: Pro
+timeCreated: 1503986857
+licenseType: Free
 MonoImporter:
   serializedVersion: 2
   defaultReferences: []

+ 2 - 2
Unity/Assets/Scripts/Base/Network/UNet/UAddress.cs.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
 guid: 25434e9690978f34eb6554089e5df159
-timeCreated: 1431427020
-licenseType: Pro
+timeCreated: 1503986857
+licenseType: Free
 MonoImporter:
   serializedVersion: 2
   defaultReferences: []

+ 2 - 2
Unity/Assets/Scripts/Base/Network/UNet/UChannel.cs

@@ -79,14 +79,14 @@ namespace Model
 			{
 				throw new Exception("UChannel已经被Dispose, 不能接收消息");
 			}
-
+			
 			var recvQueue = this.socket.RecvQueue;
 			if (recvQueue.Count > 0)
 			{
 				return Task.FromResult(recvQueue.Dequeue());
 			}
 
-			recvTcs = new TaskCompletionSource<byte[]>();		
+			recvTcs = new TaskCompletionSource<byte[]>();
 			return recvTcs.Task;
 		}
 

+ 2 - 2
Unity/Assets/Scripts/Base/Network/UNet/UChannel.cs.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
 guid: dc32f8527e761f74ba132eab17660a4a
-timeCreated: 1431427021
-licenseType: Pro
+timeCreated: 1503986858
+licenseType: Free
 MonoImporter:
   serializedVersion: 2
   defaultReferences: []

+ 2 - 2
Unity/Assets/Scripts/Base/Network/UNet/UPacket.cs.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
 guid: 9ce921dae0159cb44a2f23fb52a7b69c
-timeCreated: 1431427020
-licenseType: Pro
+timeCreated: 1503986857
+licenseType: Free
 MonoImporter:
   serializedVersion: 2
   defaultReferences: []

+ 0 - 1
Unity/Assets/Scripts/Base/Network/UNet/UPoller.cs

@@ -122,7 +122,6 @@ namespace Model
 			if (eEvent.Type == EventType.Disconnect)
 			{
 				this.AcceptTcs.TrySetException(new Exception("socket disconnected in accpet"));
-				return;
 			}
 
 			USocket socket = new USocket(eEvent.Peer, this);

+ 2 - 2
Unity/Assets/Scripts/Base/Network/UNet/UPoller.cs.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
 guid: 019e23efabdb4e24590c4735d5e78df4
-timeCreated: 1431427020
-licenseType: Pro
+timeCreated: 1503986857
+licenseType: Free
 MonoImporter:
   serializedVersion: 2
   defaultReferences: []

+ 2 - 2
Unity/Assets/Scripts/Base/Network/UNet/UService.cs.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
 guid: 467cbc524035d6644b5bd164eded38a4
-timeCreated: 1431427020
-licenseType: Pro
+timeCreated: 1503986857
+licenseType: Free
 MonoImporter:
   serializedVersion: 2
   defaultReferences: []

+ 2 - 2
Unity/Assets/Scripts/Base/Network/UNet/USocket.cs.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
 guid: 7611e7b646e2fa9448d445fded0c621a
-timeCreated: 1431427020
-licenseType: Pro
+timeCreated: 1503986857
+licenseType: Free
 MonoImporter:
   serializedVersion: 2
   defaultReferences: []

+ 2 - 2
Unity/Assets/Scripts/Base/Network/UNet/USocketManager.cs.meta

@@ -1,7 +1,7 @@
 fileFormatVersion: 2
 guid: 046affd300b9d2444974c08908b0eb88
-timeCreated: 1431427020
-licenseType: Pro
+timeCreated: 1503986857
+licenseType: Free
 MonoImporter:
   serializedVersion: 2
   defaultReferences: []

+ 2 - 1
Unity/Hotfix/UI/UILobby/Component/UILobbyComponent.cs

@@ -32,8 +32,9 @@ namespace Hotfix
 				Log.Info("登陆gate成功!");
 
 				// 发送一个actor消息
-				//gateSession.Send(new Actor_Test() { Info = "message client->gate->map->gate->client" });
+				gateSession.Send(new Actor_Test() { Info = "message client->gate->map->gate->client" });
 
+				// 向actor发起一次rpc调用
 				ActorRpc_TestResponse response = await gateSession.Call<ActorRpc_TestResponse>(new ActorRpc_TestRequest() { request = "request actor test rpc" });
 				Log.Info($"recv response: {JsonHelper.ToJson(response)}");
 			}

+ 7 - 4
Unity/Unity.csproj

@@ -12,12 +12,15 @@
     <ProjectTypeGuids>{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
     <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
     <TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
-    <TargetFrameworkProfile></TargetFrameworkProfile>
-    <CompilerResponseFile></CompilerResponseFile>
+    <TargetFrameworkProfile>
+    </TargetFrameworkProfile>
+    <CompilerResponseFile>
+    </CompilerResponseFile>
     <UnityProjectType>Game:1</UnityProjectType>
     <UnityBuildTarget>StandaloneWindows64:19</UnityBuildTarget>
     <UnityVersion>2017.1.0f3</UnityVersion>
-    <RootNamespace></RootNamespace>
+    <RootNamespace>
+    </RootNamespace>
     <LangVersion>6</LangVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
@@ -529,4 +532,4 @@
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <Target Name="GenerateTargetFrameworkMonikerAttribute" />
-</Project>
+</Project>