Kaynağa Gözat

之前去掉了flag字段,那么空消息长度就是2,所以消息解析这里需要处理一下

tanghai 6 yıl önce
ebeveyn
işleme
4e09fd80aa

+ 3 - 2
Unity/Assets/Model/Module/Message/Network/TCP/PacketParser.cs

@@ -13,6 +13,7 @@ namespace ETModel
 	{
 		public const int PacketSizeLength2 = 2;
 		public const int PacketSizeLength4 = 4;
+		public const int MinPacketSize = 2;
 		public const int OpcodeIndex = 0;
 		public const int MessageIndex = 2;
 	}
@@ -58,14 +59,14 @@ namespace ETModel
 							{
 								case Packet.PacketSizeLength4:
 									this.packetSize = BitConverter.ToInt32(this.memoryStream.GetBuffer(), 0);
-									if (this.packetSize > ushort.MaxValue * 16 || this.packetSize < 3)
+									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 < 3)
+									if (this.packetSize > ushort.MaxValue || this.packetSize < Packet.MinPacketSize)
 									{
 										throw new Exception($"recv packet size error: {this.packetSize}");
 									}