Explorar el Código

增加OpcodeRangeDefine用来定义Opcode范围,使用的序列化方式,Proto2CS也可以使用,防止出错

tanghai hace 4 años
padre
commit
dd4dd50096

+ 2 - 2
Server/Hotfix/Module/Actor/ActorHelper.cs

@@ -19,12 +19,12 @@ namespace ET
             ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), 8);
             ushort opcode = BitConverter.ToUInt16(memoryStream.GetBuffer(), 8);
             Type type = OpcodeTypeComponent.Instance.GetType(opcode);
             Type type = OpcodeTypeComponent.Instance.GetType(opcode);
 
 
-            if (opcode < MessageSerializeHelper.PbMaxOpcode)
+            if (opcode < OpcodeRangeDefine.PbMaxOpcode)
             {
             {
                 return ProtobufHelper.FromBytes(type, memoryStream.GetBuffer(), 10, (int)memoryStream.Length - 10);
                 return ProtobufHelper.FromBytes(type, memoryStream.GetBuffer(), 10, (int)memoryStream.Length - 10);
             }
             }
             
             
-            if (opcode >= MessageSerializeHelper.JsonMinOpcode)
+            if (opcode >= OpcodeRangeDefine.JsonMinOpcode)
             {
             {
                 return JsonHelper.FromJson(type, memoryStream.GetBuffer().ToStr(10, (int)(memoryStream.Length - 10)));
                 return JsonHelper.FromJson(type, memoryStream.GetBuffer().ToStr(10, (int)(memoryStream.Length - 10)));
             }
             }

+ 23 - 23
Server/Model/Generate/Message/InnerOpcode.cs

@@ -2,28 +2,28 @@ namespace ET
 {
 {
 	public static partial class InnerOpcode
 	public static partial class InnerOpcode
 	{
 	{
-		 public const ushort ObjectQueryRequest = 10001;
-		 public const ushort M2M_TrasferUnitResponse = 10002;
-		 public const ushort M2A_Reload = 10003;
-		 public const ushort A2M_Reload = 10004;
-		 public const ushort G2G_LockRequest = 10005;
-		 public const ushort G2G_LockResponse = 10006;
-		 public const ushort G2G_LockReleaseRequest = 10007;
-		 public const ushort G2G_LockReleaseResponse = 10008;
-		 public const ushort ObjectAddRequest = 10009;
-		 public const ushort ObjectAddResponse = 10010;
-		 public const ushort ObjectLockRequest = 10011;
-		 public const ushort ObjectLockResponse = 10012;
-		 public const ushort ObjectUnLockRequest = 10013;
-		 public const ushort ObjectUnLockResponse = 10014;
-		 public const ushort ObjectRemoveRequest = 10015;
-		 public const ushort ObjectRemoveResponse = 10016;
-		 public const ushort ObjectGetRequest = 10017;
-		 public const ushort ObjectGetResponse = 10018;
-		 public const ushort R2G_GetLoginKey = 10019;
-		 public const ushort G2R_GetLoginKey = 10020;
-		 public const ushort G2M_CreateUnit = 10021;
-		 public const ushort M2G_CreateUnit = 10022;
-		 public const ushort G2M_SessionDisconnect = 10023;
+		 public const ushort ObjectQueryRequest = 20002;
+		 public const ushort M2M_TrasferUnitResponse = 20003;
+		 public const ushort M2A_Reload = 20004;
+		 public const ushort A2M_Reload = 20005;
+		 public const ushort G2G_LockRequest = 20006;
+		 public const ushort G2G_LockResponse = 20007;
+		 public const ushort G2G_LockReleaseRequest = 20008;
+		 public const ushort G2G_LockReleaseResponse = 20009;
+		 public const ushort ObjectAddRequest = 20010;
+		 public const ushort ObjectAddResponse = 20011;
+		 public const ushort ObjectLockRequest = 20012;
+		 public const ushort ObjectLockResponse = 20013;
+		 public const ushort ObjectUnLockRequest = 20014;
+		 public const ushort ObjectUnLockResponse = 20015;
+		 public const ushort ObjectRemoveRequest = 20016;
+		 public const ushort ObjectRemoveResponse = 20017;
+		 public const ushort ObjectGetRequest = 20018;
+		 public const ushort ObjectGetResponse = 20019;
+		 public const ushort R2G_GetLoginKey = 20020;
+		 public const ushort G2R_GetLoginKey = 20021;
+		 public const ushort G2M_CreateUnit = 20022;
+		 public const ushort M2G_CreateUnit = 20023;
+		 public const ushort G2M_SessionDisconnect = 20024;
 	}
 	}
 }
 }

+ 2 - 2
Server/Model/Generate/Message/MongoOpcode.cs

@@ -2,7 +2,7 @@ namespace ET
 {
 {
 	public static partial class MongoOpcode
 	public static partial class MongoOpcode
 	{
 	{
-		 public const ushort ObjectQueryResponse = 40001;
-		 public const ushort M2M_TrasferUnitRequest = 40002;
+		 public const ushort ObjectQueryResponse = 30002;
+		 public const ushort M2M_TrasferUnitRequest = 30003;
 	}
 	}
 }
 }

+ 24 - 24
Server/Model/Generate/Message/OuterOpcode.cs

@@ -2,29 +2,29 @@ namespace ET
 {
 {
 	public static partial class OuterOpcode
 	public static partial class OuterOpcode
 	{
 	{
-		 public const ushort C2M_TestRequest = 20001;
-		 public const ushort M2C_TestResponse = 20002;
-		 public const ushort Actor_TransferRequest = 20003;
-		 public const ushort Actor_TransferResponse = 20004;
-		 public const ushort C2G_EnterMap = 20005;
-		 public const ushort G2C_EnterMap = 20006;
-		 public const ushort UnitInfo = 20007;
-		 public const ushort M2C_CreateUnits = 20008;
-		 public const ushort C2M_PathfindingResult = 20009;
-		 public const ushort C2M_Stop = 20010;
-		 public const ushort M2C_PathfindingResult = 20011;
-		 public const ushort M2C_Stop = 20012;
-		 public const ushort C2G_Ping = 20013;
-		 public const ushort G2C_Ping = 20014;
-		 public const ushort G2C_Test = 20015;
-		 public const ushort C2M_Reload = 20016;
-		 public const ushort M2C_Reload = 20017;
-		 public const ushort C2R_Login = 20018;
-		 public const ushort R2C_Login = 20019;
-		 public const ushort C2G_LoginGate = 20020;
-		 public const ushort G2C_LoginGate = 20021;
-		 public const ushort G2C_TestHotfixMessage = 20022;
-		 public const ushort C2M_TestRobotCase = 20023;
-		 public const ushort M2C_TestRobotCase = 20024;
+		 public const ushort C2M_TestRequest = 10002;
+		 public const ushort M2C_TestResponse = 10003;
+		 public const ushort Actor_TransferRequest = 10004;
+		 public const ushort Actor_TransferResponse = 10005;
+		 public const ushort C2G_EnterMap = 10006;
+		 public const ushort G2C_EnterMap = 10007;
+		 public const ushort UnitInfo = 10008;
+		 public const ushort M2C_CreateUnits = 10009;
+		 public const ushort C2M_PathfindingResult = 10010;
+		 public const ushort C2M_Stop = 10011;
+		 public const ushort M2C_PathfindingResult = 10012;
+		 public const ushort M2C_Stop = 10013;
+		 public const ushort C2G_Ping = 10014;
+		 public const ushort G2C_Ping = 10015;
+		 public const ushort G2C_Test = 10016;
+		 public const ushort C2M_Reload = 10017;
+		 public const ushort M2C_Reload = 10018;
+		 public const ushort C2R_Login = 10019;
+		 public const ushort R2C_Login = 10020;
+		 public const ushort C2G_LoginGate = 10021;
+		 public const ushort G2C_LoginGate = 10022;
+		 public const ushort G2C_TestHotfixMessage = 10023;
+		 public const ushort C2M_TestRobotCase = 10024;
+		 public const ushort M2C_TestRobotCase = 10025;
 	}
 	}
 }
 }

+ 4 - 4
Tools/App/Apps/Proto2CS/Proto2CS.cs

@@ -32,16 +32,16 @@ namespace ET
         public static void Proto2CS()
         public static void Proto2CS()
         {
         {
             msgOpcode.Clear();
             msgOpcode.Clear();
-            Proto2CS("ET", "../Proto/InnerMessage.proto", serverMessagePath, "InnerOpcode", 10000);
+            Proto2CS("ET", "../Proto/InnerMessage.proto", serverMessagePath, "InnerOpcode", OpcodeRangeDefine.InnerMinOpcode);
             GenerateOpcode("ET", "InnerOpcode", serverMessagePath);
             GenerateOpcode("ET", "InnerOpcode", serverMessagePath);
             
             
-            Proto2CS("ET", "../Proto/MongoMessage.proto", serverMessagePath, "MongoOpcode", 40000);
+            Proto2CS("ET", "../Proto/MongoMessage.proto", serverMessagePath, "MongoOpcode", OpcodeRangeDefine.MongoMinOpcode);
             GenerateOpcode("ET", "MongoOpcode", serverMessagePath);
             GenerateOpcode("ET", "MongoOpcode", serverMessagePath);
 
 
-            Proto2CS("ET", "../Proto/OuterMessage.proto", serverMessagePath, "OuterOpcode", 20000);
+            Proto2CS("ET", "../Proto/OuterMessage.proto", serverMessagePath, "OuterOpcode", OpcodeRangeDefine.OuterMinOpcode);
             GenerateOpcode("ET", "OuterOpcode", serverMessagePath);
             GenerateOpcode("ET", "OuterOpcode", serverMessagePath);
 
 
-            Proto2CS("ET", "../Proto/OuterMessage.proto", clientMessagePath, "OuterOpcode", 20000);
+            Proto2CS("ET", "../Proto/OuterMessage.proto", clientMessagePath, "OuterOpcode", OpcodeRangeDefine.OuterMinOpcode);
             GenerateOpcode("ET", "OuterOpcode", clientMessagePath);
             GenerateOpcode("ET", "OuterOpcode", clientMessagePath);
         }
         }
 
 

+ 4 - 0
Tools/App/Tools.App.csproj

@@ -44,6 +44,10 @@
         <Compile Include="..\..\Unity\Codes\Model\Module\Config\**\*.cs">
         <Compile Include="..\..\Unity\Codes\Model\Module\Config\**\*.cs">
             <Link>Module\Config\%(RecursiveDir)%(FileName)%(Extension)</Link>
             <Link>Module\Config\%(RecursiveDir)%(FileName)%(Extension)</Link>
         </Compile>
         </Compile>
+
+        <Compile Include="..\..\Unity\Codes\Model\Module\Message\OpcodeRangeDefine.cs">
+            <Link>Module\Message\OpcodeRangeDefine.cs</Link>
+        </Compile>
     </ItemGroup>
     </ItemGroup>
     
     
     <ItemGroup>
     <ItemGroup>

+ 24 - 24
Unity/Codes/Model/Generate/Message/OuterOpcode.cs

@@ -2,29 +2,29 @@ namespace ET
 {
 {
 	public static partial class OuterOpcode
 	public static partial class OuterOpcode
 	{
 	{
-		 public const ushort C2M_TestRequest = 20001;
-		 public const ushort M2C_TestResponse = 20002;
-		 public const ushort Actor_TransferRequest = 20003;
-		 public const ushort Actor_TransferResponse = 20004;
-		 public const ushort C2G_EnterMap = 20005;
-		 public const ushort G2C_EnterMap = 20006;
-		 public const ushort UnitInfo = 20007;
-		 public const ushort M2C_CreateUnits = 20008;
-		 public const ushort C2M_PathfindingResult = 20009;
-		 public const ushort C2M_Stop = 20010;
-		 public const ushort M2C_PathfindingResult = 20011;
-		 public const ushort M2C_Stop = 20012;
-		 public const ushort C2G_Ping = 20013;
-		 public const ushort G2C_Ping = 20014;
-		 public const ushort G2C_Test = 20015;
-		 public const ushort C2M_Reload = 20016;
-		 public const ushort M2C_Reload = 20017;
-		 public const ushort C2R_Login = 20018;
-		 public const ushort R2C_Login = 20019;
-		 public const ushort C2G_LoginGate = 20020;
-		 public const ushort G2C_LoginGate = 20021;
-		 public const ushort G2C_TestHotfixMessage = 20022;
-		 public const ushort C2M_TestRobotCase = 20023;
-		 public const ushort M2C_TestRobotCase = 20024;
+		 public const ushort C2M_TestRequest = 10002;
+		 public const ushort M2C_TestResponse = 10003;
+		 public const ushort Actor_TransferRequest = 10004;
+		 public const ushort Actor_TransferResponse = 10005;
+		 public const ushort C2G_EnterMap = 10006;
+		 public const ushort G2C_EnterMap = 10007;
+		 public const ushort UnitInfo = 10008;
+		 public const ushort M2C_CreateUnits = 10009;
+		 public const ushort C2M_PathfindingResult = 10010;
+		 public const ushort C2M_Stop = 10011;
+		 public const ushort M2C_PathfindingResult = 10012;
+		 public const ushort M2C_Stop = 10013;
+		 public const ushort C2G_Ping = 10014;
+		 public const ushort G2C_Ping = 10015;
+		 public const ushort G2C_Test = 10016;
+		 public const ushort C2M_Reload = 10017;
+		 public const ushort M2C_Reload = 10018;
+		 public const ushort C2R_Login = 10019;
+		 public const ushort R2C_Login = 10020;
+		 public const ushort C2G_LoginGate = 10021;
+		 public const ushort G2C_LoginGate = 10022;
+		 public const ushort G2C_TestHotfixMessage = 10023;
+		 public const ushort C2M_TestRobotCase = 10024;
+		 public const ushort M2C_TestRobotCase = 10025;
 	}
 	}
 }
 }

+ 4 - 8
Unity/Codes/Model/Module/Message/MessageSerializeHelper.cs

@@ -5,18 +5,14 @@ namespace ET
 {
 {
     public static class MessageSerializeHelper
     public static class MessageSerializeHelper
     {
     {
-        public const ushort PbMaxOpcode = 40000;
-        
-        public const ushort JsonMinOpcode = 51000;
-        
         public static object DeserializeFrom(ushort opcode, Type type, MemoryStream memoryStream)
         public static object DeserializeFrom(ushort opcode, Type type, MemoryStream memoryStream)
         {
         {
-            if (opcode < PbMaxOpcode)
+            if (opcode < OpcodeRangeDefine.PbMaxOpcode)
             {
             {
                 return ProtobufHelper.FromStream(type, memoryStream);
                 return ProtobufHelper.FromStream(type, memoryStream);
             }
             }
             
             
-            if (opcode >= JsonMinOpcode)
+            if (opcode >= OpcodeRangeDefine.JsonMinOpcode)
             {
             {
                 return JsonHelper.FromJson(type, memoryStream.GetBuffer().ToStr((int)memoryStream.Position, (int)(memoryStream.Length - memoryStream.Position)));
                 return JsonHelper.FromJson(type, memoryStream.GetBuffer().ToStr((int)memoryStream.Position, (int)(memoryStream.Length - memoryStream.Position)));
             }
             }
@@ -29,13 +25,13 @@ namespace ET
 
 
         public static void SerializeTo(ushort opcode, object obj, MemoryStream memoryStream)
         public static void SerializeTo(ushort opcode, object obj, MemoryStream memoryStream)
         {
         {
-            if (opcode < PbMaxOpcode)
+            if (opcode < OpcodeRangeDefine.PbMaxOpcode)
             {
             {
                 ProtobufHelper.ToStream(obj, memoryStream);
                 ProtobufHelper.ToStream(obj, memoryStream);
                 return;
                 return;
             }
             }
 
 
-            if (opcode >= JsonMinOpcode)
+            if (opcode >= OpcodeRangeDefine.JsonMinOpcode)
             {
             {
                 string s = JsonHelper.ToJson(obj);
                 string s = JsonHelper.ToJson(obj);
                 byte[] bytes = s.ToUtf8();
                 byte[] bytes = s.ToUtf8();

+ 2 - 2
Unity/Codes/Model/Module/Message/OpcodeHelper.cs

@@ -22,12 +22,12 @@ namespace ET
 
 
         public static bool IsOuterMessage(ushort opcode)
         public static bool IsOuterMessage(ushort opcode)
         {
         {
-            return opcode >= 20000;
+            return opcode < OpcodeRangeDefine.OuterMaxOpcode;
         }
         }
 
 
         public static bool IsInnerMessage(ushort opcode)
         public static bool IsInnerMessage(ushort opcode)
         {
         {
-            return opcode < 20000;
+            return opcode >= OpcodeRangeDefine.InnerMinOpcode;
         }
         }
 
 
         public static void LogMsg(int zone, ushort opcode, object message)
         public static void LogMsg(int zone, ushort opcode, object message)

+ 26 - 0
Unity/Codes/Model/Module/Message/OpcodeRangeDefine.cs

@@ -0,0 +1,26 @@
+namespace ET
+{
+    public static class OpcodeRangeDefine
+    {
+        // 10001 - 30000 是pb,中间分成两个部分,外网pb跟内网pb
+        public const ushort PbMinOpcode = 10001;
+        
+        public const ushort OuterMinOpcode = 10001;
+        public const ushort OuterMaxOpcode = 20000;
+
+        // 20001-30000 内网pb
+        public const ushort InnerMinOpcode = 20001;
+        
+        public const ushort PbMaxOpcode = 30000;
+        
+        // 30001 - 40000 是bson,bson只用于内网
+        public const ushort MongoMinOpcode = 30001;
+        
+        public const ushort InnerMaxOpcode = 40000;
+        
+        public const ushort JsonMinOpcode = 50000;
+        public const ushort JsonMaxOpcode = 60000;
+        
+        public const ushort MaxOpcode = 60000;
+    }
+}