Преглед изворни кода

修复服务端启动错误

tanghai пре 5 година
родитељ
комит
e76a4fe0cb

BIN
Excel/StartMachineConfig.xlsx


+ 2 - 2
Server/Hotfix/Module/Message/NetInnerComponentSystem.cs

@@ -7,7 +7,7 @@ namespace ET
 		public override void Awake(NetInnerComponent self)
 		{
 			NetInnerComponent.Instance = self;
-			self.Awake(NetworkProtocol.TCP, Packet.PacketSizeLength4);
+			self.Awake(NetworkProtocol.TCP);
 			self.MessagePacker = new MongoPacker();
 			self.MessageDispatcher = new InnerMessageDispatcher();
 		}
@@ -18,7 +18,7 @@ namespace ET
 		public override void Awake(NetInnerComponent self, string a)
 		{
 			NetInnerComponent.Instance = self;
-			self.Awake(NetworkProtocol.TCP, a, Packet.PacketSizeLength4);
+			self.Awake(NetworkProtocol.TCP, a);
 			self.MessagePacker = new MongoPacker();
 			self.MessageDispatcher = new InnerMessageDispatcher();
 		}

+ 1 - 1
Server/Model/Demo/ConfigPartial/StartProcessConfig.cs

@@ -19,7 +19,7 @@ namespace ET
 			{
 				if (this.innerAddress == null)
 				{
-					this.innerAddress = $"{StartMachineConfigCategory.Instance.Get(this.MachineId)}:{this.InnerPort}";
+					this.innerAddress = $"{StartMachineConfigCategory.Instance.Get(this.MachineId).InnerIP}:{this.InnerPort}";
 				}
 				return this.innerAddress;
 			}

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

@@ -214,7 +214,6 @@
     <Compile Include="..\..\Unity\Assets\Model\Base\RecyclableMemoryStream\Events.cs" Link="Base\RecyclableMemoryStream\Events.cs" />
     <Compile Include="..\..\Unity\Assets\Model\Base\RecyclableMemoryStream\RecyclableMemoryStream.cs" Link="Base\RecyclableMemoryStream\RecyclableMemoryStream.cs" />
     <Compile Include="..\..\Unity\Assets\Model\Base\RecyclableMemoryStream\RecyclableMemoryStreamManager.cs" Link="Base\RecyclableMemoryStream\RecyclableMemoryStreamManager.cs" />
-    <Compile Include="..\..\Unity\Assets\Model\Base\TryLocker.cs" Link="Base\TryLocker.cs" />
     <Compile Include="..\..\Unity\Assets\Model\Base\UnOrderMultiMap.cs" Link="Base\UnOrderMultiMap.cs" />
     <Compile Include="..\..\Unity\Assets\Model\Module\Config\ACategory.cs" Link="Module\Config\ACategory.cs" />
     <Compile Include="..\..\Unity\Assets\Model\Module\Config\ConfigAttribute.cs" Link="Module\Config\ConfigAttribute.cs" />

+ 1 - 1
Unity/Assets/HotfixView/AppStart_Init.cs

@@ -11,7 +11,7 @@ namespace ET
             //await BundleHelper.DownloadBundle("1111");
 
             // 加载配置
-            Game.Scene.GetComponent<ResourcesComponent>().LoadBundle("config.unity3d");
+            Game.Scene.AddComponent<ResourcesComponent>().LoadBundle("config.unity3d");
             Game.Scene.AddComponent<ConfigComponent>();
             Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle("config.unity3d");
             Game.Scene.AddComponent<OpcodeTypeComponent>();

+ 1 - 1
Unity/Assets/Model/Base/Event/IEvent.cs

@@ -7,7 +7,7 @@ namespace ET
 		Type GetEventType();
 	}
 	
-	
+	[Event]
 	public abstract class AEvent<A>: IEvent where A: struct
 	{
 		public Type GetEventType()

+ 0 - 35
Unity/Assets/Model/Base/TryLocker.cs

@@ -1,35 +0,0 @@
-using System;
-using System.Threading;
-
-namespace ET
-{
-	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 - 12
Unity/Assets/Model/Base/TryLocker.cs.meta

@@ -1,12 +0,0 @@
-fileFormatVersion: 2
-guid: b17c37646ccfe6d4d96df611e5664f8c
-timeCreated: 1476430040
-licenseType: Pro
-MonoImporter:
-  serializedVersion: 2
-  defaultReferences: []
-  executionOrder: 0
-  icon: {instanceID: 0}
-  userData: 
-  assetBundleName: 
-  assetBundleVariant: 

+ 0 - 18
Unity/Assets/Model/Define.cs

@@ -7,23 +7,5 @@
 #else
         public static bool IsAsync = true;
 #endif
-
-#if UNITY_EDITOR
-		public static bool IsEditorMode = true;
-#else
-		public static bool IsEditorMode = false;
-#endif
-
-#if DEVELOPMENT_BUILD
-		public static bool IsDevelopmentBuild = true;
-#else
-		public static bool IsDevelopmentBuild = false;
-#endif
-
-#if ILRuntime
-		public static bool IsILRuntime = true;
-#else
-		public static bool IsILRuntime = false;
-#endif
 	}
 }

+ 7 - 24
Unity/Assets/Model/Module/Message/Network/TCP/PacketParser.cs

@@ -11,8 +11,7 @@ namespace ET
 	
 	public static class Packet
 	{
-		public const int PacketSizeLength2 = 2;
-		public const int PacketSizeLength4 = 4;
+		public const int PacketSizeLength = 4;
 		public const int MinPacketSize = 2;
 		public const int OpcodeIndex = 0;
 		public const int MessageIndex = 2;
@@ -25,11 +24,9 @@ namespace ET
 		private ParserState state;
 		public MemoryStream memoryStream;
 		private bool isOK;
-		private readonly int packetSizeLength;
 
-		public PacketParser(int packetSizeLength, CircularBuffer buffer, MemoryStream memoryStream)
+		public PacketParser(CircularBuffer buffer, MemoryStream memoryStream)
 		{
-			this.packetSizeLength = packetSizeLength;
 			this.buffer = buffer;
 			this.memoryStream = memoryStream;
 		}
@@ -47,32 +44,18 @@ namespace ET
 				switch (this.state)
 				{
 					case ParserState.PacketSize:
-						if (this.buffer.Length < this.packetSizeLength)
+						if (this.buffer.Length < Packet.PacketSizeLength)
 						{
 							finish = true;
 						}
 						else
 						{
-							this.buffer.Read(this.memoryStream.GetBuffer(), 0, this.packetSizeLength);
+							this.buffer.Read(this.memoryStream.GetBuffer(), 0, Packet.PacketSizeLength);
 							
-							switch (this.packetSizeLength)
+							this.packetSize = BitConverter.ToInt32(this.memoryStream.GetBuffer(), 0);
+							if (this.packetSize > ushort.MaxValue * 16 || this.packetSize < Packet.MinPacketSize)
 							{
-								case Packet.PacketSizeLength4:
-									this.packetSize = BitConverter.ToInt32(this.memoryStream.GetBuffer(), 0);
-									if (this.packetSize > ushort.MaxValue * 16 || this.packetSize < Packet.MinPacketSize)
-									{
-										throw new Exception($"recv packet size error, 可能是外网探测端口: {this.packetSize}");
-									}
-									break;
-								case Packet.PacketSizeLength2:
-									this.packetSize = BitConverter.ToUInt16(this.memoryStream.GetBuffer(), 0);
-									if (this.packetSize > ushort.MaxValue || this.packetSize < Packet.MinPacketSize)
-									{
-										throw new Exception($"recv packet size error:, 可能是外网探测端口: {this.packetSize}");
-									}
-									break;
-								default:
-									throw new Exception("packet size byte count must be 2 or 4!");
+								throw new Exception($"recv packet size error, 可能是外网探测端口: {this.packetSize}");
 							}
 							this.state = ParserState.PacketBody;
 						}

+ 7 - 23
Unity/Assets/Model/Module/Message/Network/TCP/TChannel.cs

@@ -34,13 +34,12 @@ namespace ET
 		
 		public TChannel(IPEndPoint ipEndPoint, TService service): base(service, ChannelType.Connect)
 		{
-			int packetSize = service.PacketSizeLength;
-			this.packetSizeCache = new byte[packetSize];
+			this.packetSizeCache = new byte[4];
 			this.memoryStream = service.MemoryStreamManager.GetStream("message", ushort.MaxValue);
 			
 			this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
 			this.socket.NoDelay = true;
-			this.parser = new PacketParser(packetSize, this.recvBuffer, this.memoryStream);
+			this.parser = new PacketParser(this.recvBuffer, this.memoryStream);
 			this.innArgs.Completed += this.OnComplete;
 			this.outArgs.Completed += this.OnComplete;
 
@@ -52,13 +51,12 @@ namespace ET
 		
 		public TChannel(Socket socket, TService service): base(service, ChannelType.Accept)
 		{
-			int packetSize = service.PacketSizeLength;
-			this.packetSizeCache = new byte[packetSize];
+			this.packetSizeCache = new byte[Packet.PacketSizeLength];
 			this.memoryStream = service.MemoryStreamManager.GetStream("message", ushort.MaxValue);
 			
 			this.socket = socket;
 			this.socket.NoDelay = true;
-			this.parser = new PacketParser(packetSize, this.recvBuffer, this.memoryStream);
+			this.parser = new PacketParser(this.recvBuffer, this.memoryStream);
 			this.innArgs.Completed += this.OnComplete;
 			this.outArgs.Completed += this.OnComplete;
 
@@ -118,25 +116,11 @@ namespace ET
 				throw new Exception("TChannel已经被Dispose, 不能发送消息");
 			}
 
-			switch (this.GetService().PacketSizeLength)
+			if (stream.Length > ushort.MaxValue * 16)
 			{
-				case Packet.PacketSizeLength4:
-					if (stream.Length > ushort.MaxValue * 16)
-					{
-						throw new Exception($"send packet too large: {stream.Length}");
-					}
-					this.packetSizeCache.WriteTo(0, (int) stream.Length);
-					break;
-				case Packet.PacketSizeLength2:
-					if (stream.Length > ushort.MaxValue)
-					{
-						throw new Exception($"send packet too large: {stream.Length}");
-					}
-					this.packetSizeCache.WriteTo(0, (ushort) stream.Length);
-					break;
-				default:
-					throw new Exception("packet size must be 2 or 4!");
+				throw new Exception($"send packet too large: {stream.Length}");
 			}
+			this.packetSizeCache.WriteTo(0, (int) stream.Length);
 
 			this.sendBuffer.Write(this.packetSizeCache, 0, this.packetSizeCache.Length);
 			this.sendBuffer.Write(stream);

+ 2 - 6
Unity/Assets/Model/Module/Message/Network/TCP/TService.cs

@@ -18,14 +18,11 @@ namespace ET
 		
 		public List<long> needStartSendChannel = new List<long>();
 		
-		public int PacketSizeLength { get; }
-		
 		/// <summary>
 		/// 即可做client也可做server
 		/// </summary>
-		public TService(int packetSizeLength, IPEndPoint ipEndPoint, Action<AChannel> acceptCallback)
+		public TService(IPEndPoint ipEndPoint, Action<AChannel> acceptCallback)
 		{
-			this.PacketSizeLength = packetSizeLength;
 			this.AcceptCallback += acceptCallback;
 			
 			this.acceptor = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
@@ -38,9 +35,8 @@ namespace ET
 			this.AcceptAsync();
 		}
 
-		public TService(int packetSizeLength)
+		public TService()
 		{
-			this.PacketSizeLength = packetSizeLength;
 		}
 		
 		public override void Dispose()

+ 4 - 4
Unity/Assets/Model/Module/Message/NetworkComponent.cs

@@ -14,7 +14,7 @@ namespace ET
 
 		public IMessageDispatcher MessageDispatcher { get; set; }
 
-		public void Awake(NetworkProtocol protocol, int packetSize = Packet.PacketSizeLength4)
+		public void Awake(NetworkProtocol protocol)
 		{
 			switch (protocol)
 			{
@@ -22,7 +22,7 @@ namespace ET
 					this.Service = new KService() { Parent = this };
 					break;
 				case NetworkProtocol.TCP:
-					this.Service = new TService(packetSize) { Parent = this };
+					this.Service = new TService() { Parent = this };
 					break;
 				case NetworkProtocol.WebSocket:
 					this.Service = new WService() { Parent = this };
@@ -30,7 +30,7 @@ namespace ET
 			}
 		}
 
-		public void Awake(NetworkProtocol protocol, string address, int packetSize = Packet.PacketSizeLength4)
+		public void Awake(NetworkProtocol protocol, string address)
 		{
 			try
 			{
@@ -43,7 +43,7 @@ namespace ET
 						break;
 					case NetworkProtocol.TCP:
 						ipEndPoint = NetworkHelper.ToIPEndPoint(address);
-						this.Service = new TService(packetSize, ipEndPoint, (channel)=> { this.OnAccept(channel); }) { Parent = this };
+						this.Service = new TService(ipEndPoint, (channel)=> { this.OnAccept(channel); }) { Parent = this };
 						break;
 					case NetworkProtocol.WebSocket:
 						string[] prefixs = address.Split(';');

+ 0 - 1
Unity/Unity.Model.csproj

@@ -127,7 +127,6 @@
      <Compile Include="Assets\Model\Base\RecyclableMemoryStream\RecyclableMemoryStream.cs" />
      <Compile Include="Assets\Model\Base\RecyclableMemoryStream\RecyclableMemoryStreamManager.cs" />
      <Compile Include="Assets\Model\Base\StructBsonSerialize.cs" />
-     <Compile Include="Assets\Model\Base\TryLocker.cs" />
      <Compile Include="Assets\Model\Base\UnOrderMultiMap.cs" />
      <Compile Include="Assets\Model\Base\UnOrderMultiMapSet.cs" />
      <Compile Include="Assets\Model\Config\StartMachineConfig.cs" />