Quellcode durchsuchen

1.去掉了网络协议中的flag字段,可以使用IResponse接口来判断消息是否是rpc返回的消息
2.整理了ErrorCode

tanghai vor 6 Jahren
Ursprung
Commit
0f232c1968

+ 18 - 28
Unity/Assets/Hotfix/Module/Message/Session.cs

@@ -15,7 +15,7 @@ namespace ETHotfix
 		{
 			self.session = session;
 			SessionCallbackComponent sessionComponent = self.session.AddComponent<SessionCallbackComponent>();
-			sessionComponent.MessageCallback = (s, flag, opcode, memoryStream) => { self.Run(s, flag, opcode, memoryStream); };
+			sessionComponent.MessageCallback = (s, opcode, memoryStream) => { self.Run(s, opcode, memoryStream); };
 			sessionComponent.DisposeCallback = s => { self.Dispose(); };
 		}
 	}
@@ -49,7 +49,7 @@ namespace ETHotfix
 			this.session.Dispose();
 		}
 
-		public void Run(ETModel.Session s, byte flag, ushort opcode, MemoryStream memoryStream)
+		public void Run(ETModel.Session s, ushort opcode, MemoryStream memoryStream)
 		{
 			OpcodeTypeComponent opcodeTypeComponent = Game.Scene.GetComponent<OpcodeTypeComponent>();
 			object instance = opcodeTypeComponent.GetInstance(opcode);
@@ -60,46 +60,36 @@ namespace ETHotfix
 				Log.Msg(message);
 			}
 
-			if ((flag & 0x01) > 0)
+			IResponse response = message as IResponse;
+			if (response == null)
 			{
-				IResponse response = message as IResponse;
-				if (response == null)
-				{
-					throw new Exception($"flag is response, but hotfix message is not! {opcode}");
-				}
-				
-				Action<IResponse> action;
-				if (!this.requestCallback.TryGetValue(response.RpcId, out action))
-				{
-					return;
-				}
-				this.requestCallback.Remove(response.RpcId);
-
-				action(response);
+				Game.Scene.GetComponent<MessageDispatcherComponent>().Handle(session, new MessageInfo(opcode, message));
 				return;
 			}
+			
+			Action<IResponse> action;
+			if (!this.requestCallback.TryGetValue(response.RpcId, out action))
+			{
+				throw new Exception($"not found rpc, response message: {StringHelper.MessageToStr(response)}");
+			}
+			this.requestCallback.Remove(response.RpcId);
 
-			Game.Scene.GetComponent<MessageDispatcherComponent>().Handle(session, new MessageInfo(opcode, message));
+			action(response);
 		}
 
 		public void Send(IMessage message)
-		{
-			Send(0x00, message);
-		}
-
-		public void Send(byte flag, IMessage message)
 		{
 			ushort opcode = Game.Scene.GetComponent<OpcodeTypeComponent>().GetOpcode(message.GetType());
-			this.Send(flag, opcode, message);
+			this.Send(opcode, message);
 		}
 
-		public void Send(byte flag, ushort opcode, IMessage message)
+		public void Send(ushort opcode, IMessage message)
 		{
 			if (OpcodeHelper.IsNeedDebugLogMessage(opcode))
 			{
 				Log.Msg(message);
 			}
-			session.Send(flag, opcode, message);
+			session.Send(opcode, message);
 		}
 
 		public ETTask<IResponse> Call(IRequest request)
@@ -126,7 +116,7 @@ namespace ETHotfix
 
 			request.RpcId = rpcId;
 			
-			this.Send(0x00, request);
+			this.Send(request);
 			return tcs.Task;
 		}
 
@@ -156,7 +146,7 @@ namespace ETHotfix
 
 			request.RpcId = rpcId;
 
-			this.Send(0x00, request);
+			this.Send(request);
 			return tcs.Task;
 		}
 	}

+ 9 - 0
Unity/Assets/Model/Base/Helper/StringHelper.cs

@@ -58,5 +58,14 @@ namespace ETModel
 			}
 			return sb.ToString();
 		}
+		
+		public static string MessageToStr(object message)
+		{
+#if SERVER
+			return MongoHelper.ToJson(message);
+#else
+			return Dumper.DumpAsString(message);
+#endif
+		}
 	}
 }

+ 1 - 0
Unity/Assets/Model/ILBinding/CLRBindings.cs

@@ -140,6 +140,7 @@ namespace ILRuntime.Runtime.Generated
             ETModel_Component_Binding.Register(app);
             ETModel_IMessagePacker_Binding.Register(app);
             ETModel_OpcodeHelper_Binding.Register(app);
+            ETModel_StringHelper_Binding.Register(app);
             ETModel_ETTaskCompletionSource_1_Google_Protobuf_Adapt_IMessage_Binding_Adaptor_Binding.Register(app);
             System_Threading_CancellationToken_Binding.Register(app);
             ETModel_ErrorCode_Binding.Register(app);

+ 1 - 1
Unity/Assets/Model/ILBinding/ETModel_SessionCallbackComponent_Binding.cs

@@ -41,7 +41,7 @@ namespace ILRuntime.Runtime.Generated
         }
         static void set_MessageCallback_0(ref object o, object v)
         {
-            ((ETModel.SessionCallbackComponent)o).MessageCallback = (System.Action<ETModel.Session, System.Byte, System.UInt16, System.IO.MemoryStream>)v;
+            ((ETModel.SessionCallbackComponent)o).MessageCallback = (System.Action<ETModel.Session, System.UInt16, System.IO.MemoryStream>)v;
         }
         static object get_DisposeCallback_1(ref object o)
         {

+ 3 - 6
Unity/Assets/Model/ILBinding/ETModel_Session_Binding.cs

@@ -34,7 +34,7 @@ namespace ILRuntime.Runtime.Generated
             args = new Type[]{};
             method = type.GetMethod("get_Network", flag, null, args, null);
             app.RegisterCLRMethodRedirection(method, get_Network_3);
-            args = new Type[]{typeof(System.Byte), typeof(System.UInt16), typeof(System.Object)};
+            args = new Type[]{typeof(System.UInt16), typeof(System.Object)};
             method = type.GetMethod("Send", flag, null, args, null);
             app.RegisterCLRMethodRedirection(method, Send_4);
 
@@ -126,7 +126,7 @@ namespace ILRuntime.Runtime.Generated
         {
             ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
             StackObject* ptr_of_this_method;
-            StackObject* __ret = ILIntepreter.Minus(__esp, 4);
+            StackObject* __ret = ILIntepreter.Minus(__esp, 3);
 
             ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
             System.Object @message = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
@@ -136,13 +136,10 @@ namespace ILRuntime.Runtime.Generated
             System.UInt16 @opcode = (ushort)ptr_of_this_method->Value;
 
             ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
-            System.Byte @flag = (byte)ptr_of_this_method->Value;
-
-            ptr_of_this_method = ILIntepreter.Minus(__esp, 4);
             ETModel.Session instance_of_this_method = (ETModel.Session)typeof(ETModel.Session).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
             __intp.Free(ptr_of_this_method);
 
-            instance_of_this_method.Send(@flag, @opcode, @message);
+            instance_of_this_method.Send(@opcode, @message);
 
             return __ret;
         }

+ 52 - 0
Unity/Assets/Model/ILBinding/ETModel_StringHelper_Binding.cs

@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Runtime.InteropServices;
+
+using ILRuntime.CLR.TypeSystem;
+using ILRuntime.CLR.Method;
+using ILRuntime.Runtime.Enviorment;
+using ILRuntime.Runtime.Intepreter;
+using ILRuntime.Runtime.Stack;
+using ILRuntime.Reflection;
+using ILRuntime.CLR.Utils;
+
+namespace ILRuntime.Runtime.Generated
+{
+    unsafe class ETModel_StringHelper_Binding
+    {
+        public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app)
+        {
+            BindingFlags flag = BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
+            MethodBase method;
+            Type[] args;
+            Type type = typeof(ETModel.StringHelper);
+            args = new Type[]{typeof(System.Object)};
+            method = type.GetMethod("MessageToStr", flag, null, args, null);
+            app.RegisterCLRMethodRedirection(method, MessageToStr_0);
+
+
+        }
+
+
+        static StackObject* MessageToStr_0(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
+        {
+            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
+            StackObject* ptr_of_this_method;
+            StackObject* __ret = ILIntepreter.Minus(__esp, 1);
+
+            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
+            System.Object @message = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
+            __intp.Free(ptr_of_this_method);
+
+
+            var result_of_this_method = ETModel.StringHelper.MessageToStr(@message);
+
+            return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
+        }
+
+
+
+    }
+}

+ 11 - 0
Unity/Assets/Model/ILBinding/ETModel_StringHelper_Binding.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 14da91b78333e45b19f13aff42c1b0f3
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 14 - 72
Unity/Assets/Model/ILBinding/System_String_Binding.cs

@@ -28,9 +28,9 @@ namespace ILRuntime.Runtime.Generated
             args = new Type[]{typeof(System.Int32)};
             method = type.GetMethod("get_Chars", flag, null, args, null);
             app.RegisterCLRMethodRedirection(method, get_Chars_1);
-            args = new Type[]{typeof(System.String), typeof(System.String), typeof(System.String)};
-            method = type.GetMethod("Concat", flag, null, args, null);
-            app.RegisterCLRMethodRedirection(method, Concat_2);
+            args = new Type[]{typeof(System.String), typeof(System.Object)};
+            method = type.GetMethod("Format", flag, null, args, null);
+            app.RegisterCLRMethodRedirection(method, Format_2);
             args = new Type[]{typeof(System.String), typeof(System.String)};
             method = type.GetMethod("Concat", flag, null, args, null);
             app.RegisterCLRMethodRedirection(method, Concat_3);
@@ -40,21 +40,15 @@ namespace ILRuntime.Runtime.Generated
             args = new Type[]{};
             method = type.GetMethod("get_Length", flag, null, args, null);
             app.RegisterCLRMethodRedirection(method, get_Length_5);
-            args = new Type[]{typeof(System.String), typeof(System.Object)};
-            method = type.GetMethod("Format", flag, null, args, null);
-            app.RegisterCLRMethodRedirection(method, Format_6);
             args = new Type[]{typeof(System.String[]), typeof(System.StringSplitOptions)};
             method = type.GetMethod("Split", flag, null, args, null);
-            app.RegisterCLRMethodRedirection(method, Split_7);
+            app.RegisterCLRMethodRedirection(method, Split_6);
             args = new Type[]{};
             method = type.GetMethod("Trim", flag, null, args, null);
-            app.RegisterCLRMethodRedirection(method, Trim_8);
+            app.RegisterCLRMethodRedirection(method, Trim_7);
             args = new Type[]{typeof(System.String), typeof(System.String)};
             method = type.GetMethod("op_Equality", flag, null, args, null);
-            app.RegisterCLRMethodRedirection(method, op_Equality_9);
-            args = new Type[]{typeof(System.String), typeof(System.String), typeof(System.String), typeof(System.String)};
-            method = type.GetMethod("Concat", flag, null, args, null);
-            app.RegisterCLRMethodRedirection(method, Concat_10);
+            app.RegisterCLRMethodRedirection(method, op_Equality_8);
 
             app.RegisterCLRCreateArrayInstance(type, s => new System.String[s]);
 
@@ -103,26 +97,22 @@ namespace ILRuntime.Runtime.Generated
             return __ret + 1;
         }
 
-        static StackObject* Concat_2(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
+        static StackObject* Format_2(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
         {
             ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
             StackObject* ptr_of_this_method;
-            StackObject* __ret = ILIntepreter.Minus(__esp, 3);
+            StackObject* __ret = ILIntepreter.Minus(__esp, 2);
 
             ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
-            System.String @str2 = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
+            System.Object @arg0 = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
             __intp.Free(ptr_of_this_method);
 
             ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
-            System.String @str1 = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
-            __intp.Free(ptr_of_this_method);
-
-            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
-            System.String @str0 = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
+            System.String @format = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
             __intp.Free(ptr_of_this_method);
 
 
-            var result_of_this_method = System.String.Concat(@str0, @str1, @str2);
+            var result_of_this_method = System.String.Format(@format, @arg0);
 
             return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
         }
@@ -188,27 +178,7 @@ namespace ILRuntime.Runtime.Generated
             return __ret + 1;
         }
 
-        static StackObject* Format_6(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
-        {
-            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
-            StackObject* ptr_of_this_method;
-            StackObject* __ret = ILIntepreter.Minus(__esp, 2);
-
-            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
-            System.Object @arg0 = (System.Object)typeof(System.Object).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
-            __intp.Free(ptr_of_this_method);
-
-            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
-            System.String @format = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
-            __intp.Free(ptr_of_this_method);
-
-
-            var result_of_this_method = System.String.Format(@format, @arg0);
-
-            return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
-        }
-
-        static StackObject* Split_7(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
+        static StackObject* Split_6(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
         {
             ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
             StackObject* ptr_of_this_method;
@@ -231,7 +201,7 @@ namespace ILRuntime.Runtime.Generated
             return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
         }
 
-        static StackObject* Trim_8(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
+        static StackObject* Trim_7(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
         {
             ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
             StackObject* ptr_of_this_method;
@@ -246,7 +216,7 @@ namespace ILRuntime.Runtime.Generated
             return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
         }
 
-        static StackObject* op_Equality_9(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
+        static StackObject* op_Equality_8(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
         {
             ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
             StackObject* ptr_of_this_method;
@@ -268,34 +238,6 @@ namespace ILRuntime.Runtime.Generated
             return __ret + 1;
         }
 
-        static StackObject* Concat_10(ILIntepreter __intp, StackObject* __esp, IList<object> __mStack, CLRMethod __method, bool isNewObj)
-        {
-            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
-            StackObject* ptr_of_this_method;
-            StackObject* __ret = ILIntepreter.Minus(__esp, 4);
-
-            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
-            System.String @str3 = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
-            __intp.Free(ptr_of_this_method);
-
-            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
-            System.String @str2 = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
-            __intp.Free(ptr_of_this_method);
-
-            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
-            System.String @str1 = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
-            __intp.Free(ptr_of_this_method);
-
-            ptr_of_this_method = ILIntepreter.Minus(__esp, 4);
-            System.String @str0 = (System.String)typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
-            __intp.Free(ptr_of_this_method);
-
-
-            var result_of_this_method = System.String.Concat(@str0, @str1, @str2, @str3);
-
-            return ILIntepreter.PushObject(__ret, __mStack, result_of_this_method);
-        }
-
 
 
     }

+ 27 - 29
Unity/Assets/Model/Module/Message/ErrorCode.cs

@@ -5,43 +5,41 @@ namespace ETModel
 		public const int ERR_Success = 0;
 		
 		// 1-11004 是SocketError请看SocketError定义
-		
+		//-----------------------------------
 		// 100000 以上,避免跟SocketError冲突
 		public const int ERR_MyErrorCode = 100000;
 		
+		public const int ERR_ActorNoMailBoxComponent = 100003;
+		public const int ERR_ActorRemove = 100004;
+		public const int ERR_PacketParserError = 100005;
+		
+		public const int ERR_KcpCantConnect = 102005;
+		public const int ERR_KcpChannelTimeout = 102006;
+		public const int ERR_KcpRemoteDisconnect = 102007;
+		public const int ERR_PeerDisconnect = 102008;
+		public const int ERR_SocketCantSend = 102009;
+		public const int ERR_SocketError = 102010;
+		public const int ERR_KcpWaitSendSizeTooLarge = 102011;
 
-		// 小于这个Rpc会抛异常
+		public const int ERR_WebsocketPeerReset = 103001;
+		public const int ERR_WebsocketMessageTooBig = 103002;
+		public const int ERR_WebsocketError = 103003;
+		public const int ERR_WebsocketConnectError = 103004;
+		public const int ERR_WebsocketSendError = 103005;
+		public const int ERR_WebsocketRecvError = 103006;
+		
+		public const int ERR_RpcFail = 102001;
+		public const int ERR_ReloadFail = 102003;
+		public const int ERR_ConnectGateKeyError = 100105;
+		public const int ERR_ActorLocationNotFound = 102004;
+		//-----------------------------------
+		// 小于这个Rpc会抛异常,大于这个异常的error需要自己判断处理,也就是说需要处理的错误应该要大于该值
 		public const int ERR_Exception = 200000;
 		
 		public const int ERR_NotFoundActor = 200002;
-		public const int ERR_ActorNoMailBoxComponent = 200003;
-		public const int ERR_ActorRemove = 200004;
-		public const int ERR_PacketParserError = 200005;
-
+		
 		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 = 202001;
-		public const int ERR_SocketDisconnected = 202002;
-		public const int ERR_ReloadFail = 202003;
-		public const int ERR_ActorLocationNotFound = 202004;
-		public const int ERR_KcpCantConnect = 202005;
-		public const int ERR_KcpChannelTimeout = 202006;
-		public const int ERR_KcpRemoteDisconnect = 202007;
-		public const int ERR_PeerDisconnect = 202008;
-		public const int ERR_SocketCantSend = 202009;
-		public const int ERR_SocketError = 202010;
-		public const int ERR_KcpWaitSendSizeTooLarge = 202011;
-
-		public const int ERR_WebsocketPeerReset = 203001;
-		public const int ERR_WebsocketMessageTooBig = 203002;
-		public const int ERR_WebsocketError = 203003;
-		public const int ERR_WebsocketConnectError = 203004;
-		public const int ERR_WebsocketSendError = 203005;
-		public const int ERR_WebsocketRecvError = 203006;
-
+		//-----------------------------------
 		public static bool IsRpcNeedThrowException(int error)
 		{
 			if (error == 0)

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

@@ -13,9 +13,8 @@ namespace ETModel
 	{
 		public const int PacketSizeLength2 = 2;
 		public const int PacketSizeLength4 = 4;
-		public const int FlagIndex = 0;
-		public const int OpcodeIndex = 1;
-		public const int MessageIndex = 3;
+		public const int OpcodeIndex = 0;
+		public const int MessageIndex = 2;
 	}
 
 	public class PacketParser
@@ -74,7 +73,6 @@ namespace ETModel
 								default:
 									throw new Exception("packet size byte count must be 2 or 4!");
 							}
-
 							this.state = ParserState.PacketBody;
 						}
 						break;

+ 18 - 35
Unity/Assets/Model/Module/Message/Session.cs

@@ -23,7 +23,7 @@ namespace ETModel
 		private AChannel channel;
 
 		private readonly Dictionary<int, Action<IResponse>> requestCallback = new Dictionary<int, Action<IResponse>>();
-		private readonly List<byte[]> byteses = new List<byte[]>() { new byte[1], new byte[2] };
+		private readonly byte[] opcodeBytes = new byte[2];
 
 		public NetworkComponent Network
 		{
@@ -128,13 +128,12 @@ namespace ETModel
 		private void Run(MemoryStream memoryStream)
 		{
 			memoryStream.Seek(Packet.MessageIndex, SeekOrigin.Begin);
-			byte flag = memoryStream.GetBuffer()[Packet.FlagIndex];
 			ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), Packet.OpcodeIndex);
 			
 #if !SERVER
 			if (OpcodeHelper.IsClientHotfixMessage(opcode))
 			{
-				this.GetComponent<SessionCallbackComponent>().MessageCallback.Invoke(this, flag, opcode, memoryStream);
+				this.GetComponent<SessionCallbackComponent>().MessageCallback.Invoke(this, opcode, memoryStream);
 				return;
 			}
 #endif
@@ -159,33 +158,28 @@ namespace ETModel
 				this.Network.Remove(this.Id);
 				return;
 			}
-
-			// flag第一位为1表示这是rpc返回消息,否则交由MessageDispatcher分发
-			if ((flag & 0x01) == 0)
-			{
-				this.Network.MessageDispatcher.Dispatch(this, opcode, message);
-				return;
-			}
 				
 			IResponse response = message as IResponse;
 			if (response == null)
 			{
-				throw new Exception($"flag is response, but message is not! {opcode}");
+				this.Network.MessageDispatcher.Dispatch(this, opcode, message);
+				return;
 			}
+			
 			Action<IResponse> action;
 			if (!this.requestCallback.TryGetValue(response.RpcId, out action))
 			{
-				return;
+				throw new Exception($"not found rpc, response message: {StringHelper.MessageToStr(response)}");
 			}
 			this.requestCallback.Remove(response.RpcId);
 
 			action(response);
 		}
 
-		public Task<IResponse> Call(IRequest request)
+		public ETTask<IResponse> Call(IRequest request)
 		{
 			int rpcId = ++RpcId;
-			var tcs = new TaskCompletionSource<IResponse>();
+			var tcs = new ETTaskCompletionSource<IResponse>();
 
 			this.requestCallback[rpcId] = (response) =>
 			{
@@ -205,14 +199,14 @@ namespace ETModel
 			};
 
 			request.RpcId = rpcId;
-			this.Send(0x00, request);
+			this.Send(request);
 			return tcs.Task;
 		}
 
-		public Task<IResponse> Call(IRequest request, CancellationToken cancellationToken)
+		public ETTask<IResponse> Call(IRequest request, CancellationToken cancellationToken)
 		{
 			int rpcId = ++RpcId;
-			var tcs = new TaskCompletionSource<IResponse>();
+			var tcs = new ETTaskCompletionSource<IResponse>();
 
 			this.requestCallback[rpcId] = (response) =>
 			{
@@ -234,15 +228,10 @@ namespace ETModel
 			cancellationToken.Register(() => this.requestCallback.Remove(rpcId));
 
 			request.RpcId = rpcId;
-			this.Send(0x00, request);
+			this.Send(request);
 			return tcs.Task;
 		}
 
-		public void Send(IMessage message)
-		{
-			this.Send(0x00, message);
-		}
-
 		public void Reply(IResponse message)
 		{
 			if (this.IsDisposed)
@@ -250,18 +239,18 @@ namespace ETModel
 				throw new Exception("session已经被Dispose了");
 			}
 
-			this.Send(0x01, message);
+			this.Send(message);
 		}
 
-		public void Send(byte flag, IMessage message)
+		public void Send(IMessage message)
 		{
 			OpcodeTypeComponent opcodeTypeComponent = this.Network.Entity.GetComponent<OpcodeTypeComponent>();
 			ushort opcode = opcodeTypeComponent.GetOpcode(message.GetType());
 			
-			Send(flag, opcode, message);
+			Send(opcode, message);
 		}
 		
-		public void Send(byte flag, ushort opcode, object message)
+		public void Send(ushort opcode, object message)
 		{
 			if (this.IsDisposed)
 			{
@@ -288,14 +277,8 @@ namespace ETModel
 			this.Network.MessagePacker.SerializeTo(message, stream);
 			stream.Seek(0, SeekOrigin.Begin);
 			
-			this.byteses[0][0] = flag;
-			this.byteses[1].WriteTo(0, opcode);
-			int index = 0;
-			foreach (var bytes in this.byteses)
-			{
-				Array.Copy(bytes, 0, stream.GetBuffer(), index, bytes.Length);
-				index += bytes.Length;
-			}
+			opcodeBytes.WriteTo(0, opcode);
+			Array.Copy(opcodeBytes, 0, stream.GetBuffer(), 0, opcodeBytes.Length);
 
 #if SERVER
 			// 如果是allserver,内部消息不走网络,直接转给session,方便调试时看到整体堆栈

+ 1 - 1
Unity/Assets/Model/Module/Message/SessionCallbackComponent.cs

@@ -5,7 +5,7 @@ namespace ETModel
 {
 	public class SessionCallbackComponent: Component
 	{
-		public Action<Session, byte, ushort, MemoryStream> MessageCallback;
+		public Action<Session, ushort, MemoryStream> MessageCallback;
 		public Action<Session> DisposeCallback;
 
 		public override void Dispose()

+ 1 - 0
Unity/Unity.Model.csproj

@@ -205,6 +205,7 @@
     <Compile Include="Assets\Model\ILBinding\ETModel_Session_Binding.cs" />
     <Compile Include="Assets\Model\ILBinding\ETModel_SessionCallbackComponent_Binding.cs" />
     <Compile Include="Assets\Model\ILBinding\ETModel_SessionComponent_Binding.cs" />
+    <Compile Include="Assets\Model\ILBinding\ETModel_StringHelper_Binding.cs" />
     <Compile Include="Assets\Model\ILBinding\ETModel_Unit_Binding.cs" />
     <Compile Include="Assets\Model\ILBinding\ETModel_UnitComponent_Binding.cs" />
     <Compile Include="Assets\Model\ILBinding\ETModel_UnitFactory_Binding.cs" />

+ 6 - 6
Unity/Unity.sln

@@ -5,10 +5,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Model", "Unity.Model.
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.ThirdParty", "Unity.ThirdParty.csproj", "{E15BADD2-3A26-309A-AB0F-DC5B08044350}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Hotfix", "Unity.Hotfix.csproj", "{1066F652-6A89-D1C4-9881-1A19DF7AB80E}"
-EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Editor", "Unity.Editor.csproj", "{CD311104-1830-B119-81B6-5DBEE2467FFB}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Unity.Hotfix", "Unity.Hotfix.csproj", "{1066F652-6A89-D1C4-9881-1A19DF7AB80E}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -23,14 +23,14 @@ Global
 		{E15BADD2-3A26-309A-AB0F-DC5B08044350}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{E15BADD2-3A26-309A-AB0F-DC5B08044350}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{E15BADD2-3A26-309A-AB0F-DC5B08044350}.Release|Any CPU.Build.0 = Release|Any CPU
-		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Release|Any CPU.Build.0 = Release|Any CPU
 		{CD311104-1830-B119-81B6-5DBEE2467FFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{CD311104-1830-B119-81B6-5DBEE2467FFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{CD311104-1830-B119-81B6-5DBEE2467FFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{CD311104-1830-B119-81B6-5DBEE2467FFB}.Release|Any CPU.Build.0 = Release|Any CPU
+		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{1066F652-6A89-D1C4-9881-1A19DF7AB80E}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE