ソースを参照

1. 修复: errorcode范围错误,导致出现很多异常。
2. 调整了TChannel的一些逻辑,不容易出错

tanghai 7 年 前
コミット
178a5b6a98

+ 0 - 1
Server/Hotfix/Handler/Actor_TestHandler.cs

@@ -10,7 +10,6 @@ namespace ETHotfix
 		{
 			Log.Debug(message.Info);
 			await Task.CompletedTask;
-			unit.GetComponent<UnitGateComponent>().GetActorMessageSender().Send(message);
 		}
 	}
 }

+ 0 - 5
Server/Model/Module/FrameSync/UnitGateComponent.cs

@@ -19,10 +19,5 @@
 		{
 			this.GateSessionActorId = gateSessionId;
 		}
-
-		public ActorMessageSender GetActorMessageSender()
-		{
-			return Game.Scene.GetComponent<ActorMessageSenderComponent>().Get(this.GateSessionActorId);
-		}
 	}
 }

+ 13 - 13
Unity/Assets/Scripts/Module/Message/ErrorCode.cs

@@ -8,23 +8,23 @@ namespace ETModel
 		public const int ERR_MyErrorCode = 100000;
 		
 
-		
+		// 小于这个Rpc会抛异常
 		public const int ERR_Exception = 200000;
 		
-		public const int ERR_NotFoundActor = 100002;
-		public const int ERR_ActorNoMailBoxComponent = 100003;
-		public const int ERR_ActorTimeOut = 100004;
-		public const int ERR_PacketParserError = 100005;
+		public const int ERR_NotFoundActor = 200002;
+		public const int ERR_ActorNoMailBoxComponent = 200003;
+		public const int ERR_ActorTimeOut = 200004;
+		public const int ERR_PacketParserError = 200005;
 
-		public const int ERR_AccountOrPasswordError = 100102;
-		public const int ERR_SessionActorError = 100103;
-		public const int ERR_NotFoundUnit = 100104;
-		public const int ERR_ConnectGateKeyError = 100105;
+		public const int ERR_AccountOrPasswordError = 200102;
+		public const int ERR_SessionActorError = 200103;
+		public const int ERR_NotFoundUnit = 200104;
+		public const int ERR_ConnectGateKeyError = 200105;
 
-		public const int ERR_RpcFail = 102001;
-		public const int ERR_SocketDisconnected = 102002;
-		public const int ERR_ReloadFail = 102003;
-		public const int ERR_ActorLocationNotFound = 102004;
+		public const int ERR_RpcFail = 202001;
+		public const int ERR_SocketDisconnected = 202002;
+		public const int ERR_ReloadFail = 202003;
+		public const int ERR_ActorLocationNotFound = 202004;
 
 		public static bool IsRpcNeedThrowException(int error)
 		{

+ 19 - 7
Unity/Assets/Scripts/Module/Message/Network/TCP/TChannel.cs

@@ -33,6 +33,9 @@ namespace ETModel
 			this.outArgs.Completed += this.OnComplete;
 
 			this.RemoteAddress = ipEndPoint;
+
+			this.isConnected = false;
+			this.isSending = false;
 		}
 		
 		public TChannel(Socket socket, TService service): base(service, ChannelType.Accept)
@@ -46,6 +49,7 @@ namespace ETModel
 			this.RemoteAddress = (IPEndPoint)socket.RemoteEndPoint;
 			
 			this.isConnected = true;
+			this.isSending = false;
 		}
 		
 		public override void Dispose()
@@ -86,7 +90,8 @@ namespace ETModel
 			byte[] sizeBuffer = BitConverter.GetBytes(length);
 			this.sendBuffer.Write(sizeBuffer, 0, sizeBuffer.Length);
 			this.sendBuffer.Write(buffer, index, length);
-			if (this.isConnected && !this.isSending)
+
+			if(!this.isSending)
 			{
 				this.StartSend();
 			}
@@ -105,7 +110,8 @@ namespace ETModel
 			{
 				this.sendBuffer.Write(buffer, 0, buffer.Length);
 			}
-			if (this.isConnected && !this.isSending)
+
+			if(!this.isSending)
 			{
 				this.StartSend();
 			}
@@ -159,7 +165,8 @@ namespace ETModel
 			e.RemoteEndPoint = null;
 			this.isConnected = true;
 			
-			this.Start();
+			this.StartRecv();
+			this.StartSend();
 		}
 
 		private void OnDisconnectComplete(object o)
@@ -248,10 +255,8 @@ namespace ETModel
 
 		private void StartSend()
 		{
-			// 没有数据需要发送
-			if (this.sendBuffer.Length == 0)
+			if(!this.isConnected)
 			{
-				this.isSending = false;
 				return;
 			}
 
@@ -302,7 +307,14 @@ namespace ETModel
 				this.sendBuffer.FirstIndex = 0;
 				this.sendBuffer.RemoveFirst();
 			}
-
+			
+			// 没有数据需要发送
+			if (this.sendBuffer.Length == 0)
+			{
+				this.isSending = false;
+				return;
+			}
+			
 			this.StartSend();
 		}
 	}