Просмотр исходного кода

修复TService Benchmark的错误

tanghai 2 лет назад
Родитель
Сommit
c61e952220

+ 0 - 3
Unity/Assets/Scripts/Core/Network/AChannel.cs

@@ -13,12 +13,9 @@ namespace ET
 	public struct Packet
 	{
 		public const int MinPacketSize = 2;
-		public const int OpcodeIndex = 16;
-		public const int KcpOpcodeIndex = 0;
 		public const int OpcodeLength = 2;
 		public const int ActorIdIndex = 0;
 		public const int ActorIdLength = 16;
-		public const int MessageIndex = 18;
 
 		public ushort Opcode;
 		public long ActorId;

+ 4 - 11
Unity/Assets/Scripts/Core/Network/KChannel.cs

@@ -333,19 +333,12 @@ namespace ET
 						}
 					}
 				}
-
-
-				switch (this.Service.ServiceType)
-				{
-					case ServiceType.Inner:
-						this.readMemory.Seek(Packet.ActorIdLength + Packet.OpcodeLength, SeekOrigin.Begin);
-						break;
-					case ServiceType.Outer:
-						this.readMemory.Seek(Packet.OpcodeLength, SeekOrigin.Begin);
-						break;
-				}
+				
 				MemoryBuffer memoryBuffer = this.readMemory;
 				this.readMemory = null;
+				
+				memoryBuffer.Seek(0, SeekOrigin.Begin);
+				
 				this.OnRead(memoryBuffer);
 			}
 		}

+ 4 - 2
Unity/Assets/Scripts/Core/Network/MessageSerializeHelper.cs

@@ -76,18 +76,20 @@ namespace ET
             {
                 case ServiceType.Outer:
                 {
-                    ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.KcpOpcodeIndex);
+                    memoryStream.Seek(Packet.OpcodeLength, SeekOrigin.Begin);
+                    ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), 0);
                     Type type = OpcodeType.Instance.GetType(opcode);
                     message = Deserialize(type, memoryStream);
                     break;
                 }
                 case ServiceType.Inner:
                 {
+                    memoryStream.Seek(Packet.ActorIdLength + Packet.OpcodeLength, SeekOrigin.Begin);
                     byte[] buffer = memoryStream.GetBuffer();
                     actorId.Process = BitConverter.ToInt32(buffer, Packet.ActorIdIndex);
                     actorId.Fiber = BitConverter.ToInt32(buffer, Packet.ActorIdIndex + 4);
                     actorId.InstanceId = BitConverter.ToInt64(buffer, Packet.ActorIdIndex + 8);
-                    ushort opcode = BitConverter.ToUInt16(buffer, Packet.OpcodeIndex);
+                    ushort opcode = BitConverter.ToUInt16(buffer, Packet.ActorIdLength);
                     Type type = OpcodeType.Instance.GetType(opcode);
                     message = Deserialize(type, memoryStream);
                     break;

+ 1 - 8
Unity/Assets/Scripts/Core/Network/PacketParser.cs

@@ -82,14 +82,7 @@ namespace ET
 						this.buffer.Read(memoryBuffer, this.packetSize);
 						//memoryStream.SetLength(this.packetSize - Packet.MessageIndex);
 
-						if (this.service.ServiceType == ServiceType.Inner)
-						{
-							memoryBuffer.Seek(Packet.ActorIdLength, SeekOrigin.Begin);
-						}
-						else
-						{
-							memoryBuffer.Seek(0, SeekOrigin.Begin);
-						}
+						memoryBuffer.Seek(0, SeekOrigin.Begin);
 
 						this.state = ParserState.PacketSize;
 						return true;

+ 1 - 1
Unity/Assets/Scripts/Core/Network/WChannel.cs

@@ -196,7 +196,7 @@ namespace ET
 
                     MemoryBuffer memoryBuffer = this.Service.Fetch(receiveCount);
                     memoryBuffer.SetLength(receiveCount);
-                    memoryBuffer.Seek(2, SeekOrigin.Begin);
+                    memoryBuffer.Seek(0, SeekOrigin.Begin);
                     Array.Copy(this.cache, 0, memoryBuffer.GetBuffer(), 0, receiveCount);
                     this.OnRead(memoryBuffer);
                 }