Przeglądaj źródła

1.用Task.CompletedTask消除编译警告
2.分离消息头的标签,放到消息定义文件中,方便以后做消息添加工具,一键生成

tanghai 8 lat temu
rodzic
commit
5d2945dab9

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

@@ -9,7 +9,7 @@ namespace Hotfix
 		protected override async Task Run(Unit unit, Actor_Test message)
 		{
 			Log.Debug(message.Info);
-
+			await Task.CompletedTask;
 			unit.GetComponent<UnitGateComponent>().GetActorProxy().Send(message);
 		}
 	}

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

@@ -9,6 +9,7 @@ namespace Hotfix
 	{
 		protected override async Task Run(Unit unit, Actor_TestRequest message, Action<Actor_TestResponse> reply)
 		{
+			await Task.CompletedTask;
 			reply(new Actor_TestResponse() {response = "response actor rpc"});
 		}
 	}

+ 0 - 41
Server/Model/Base/Message/AActorMessage.cs

@@ -1,41 +0,0 @@
-using MongoDB.Bson.Serialization.Attributes;
-using ProtoBuf;
-
-namespace Model
-{
-	[ProtoContract]
-	[BsonKnownTypes(typeof(Actor_Test))]
-	[BsonKnownTypes(typeof(AFrameMessage))]
-	[BsonKnownTypes(typeof(Actor_CreateUnits))]
-	[BsonKnownTypes(typeof(FrameMessage))]
-	[ProtoInclude(10000, typeof(FrameMessage))]
-	[ProtoInclude(10001, typeof(AFrameMessage))]
-	[ProtoInclude(10002, typeof(Actor_CreateUnits))]
-	public abstract class AActorMessage : AMessage
-	{
-	}
-
-	[BsonKnownTypes(typeof(Actor_TestRequest))]
-	[BsonKnownTypes(typeof(Actor_TransferRequest))]
-	public abstract class AActorRequest : ARequest
-	{
-	}
-
-	[BsonKnownTypes(typeof(Actor_TestResponse))]
-	[BsonKnownTypes(typeof(Actor_TransferResponse))]
-	public abstract class AActorResponse : AResponse
-	{
-	}
-
-	/// <summary>
-	/// 帧消息,继承这个类的消息会经过服务端转发
-	/// </summary>
-	[ProtoContract]
-	[ProtoInclude(30000, typeof(Frame_ClickMap))]
-	[BsonKnownTypes(typeof(Frame_ClickMap))]
-	public abstract class AFrameMessage : AActorMessage
-	{
-		[ProtoMember(1)]
-		public long Id;
-	}
-}

Plik diff jest za duży
+ 0 - 0
Server/Model/Entity/Message/InnerMessage.cs


+ 1 - 0
Server/Model/Server.Model.csproj

@@ -17,6 +17,7 @@
   </PropertyGroup>
 
   <ItemGroup>
+    <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\AActorMessage.cs" Link="Base\Message\AActorMessage.cs" />
     <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\AMessage.cs" Link="Base\Message\AMessage.cs" />
     <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\AppType.cs" Link="Message\AppType.cs" />
     <Compile Include="..\..\Unity\Assets\Scripts\Base\Message\IMessageDispatcher.cs" Link="Message\IMessageDispatcher.cs" />

+ 8 - 11
Unity/Assets/Scripts/Base/Message/AActorMessage.cs

@@ -1,28 +1,25 @@
-using MongoDB.Bson.Serialization.Attributes;
-using ProtoBuf;
+using ProtoBuf;
 
+// 不要在这个文件加[ProtoInclude]跟[BsonKnowType]标签,加到InnerMessage.cs或者OuterMessage.cs里面去
 namespace Model
 {
 	[ProtoContract]
-	[ProtoInclude(10000, typeof(FrameMessage))]
-	[ProtoInclude(10001, typeof(AFrameMessage))]
-	[ProtoInclude(10002, typeof(Actor_CreateUnits))]
-	public abstract class AActorMessage : AMessage
+	public abstract partial class AActorMessage : AMessage
 	{
 	}
 
-	public abstract class AActorRequest : ARequest
+	[ProtoContract]
+	public abstract partial class AActorRequest : ARequest
 	{
 	}
 
-	public abstract class AActorResponse : AResponse
+	[ProtoContract]
+	public abstract partial class AActorResponse : AResponse
 	{
 	}
 
 	[ProtoContract]
-	[ProtoInclude(30000, typeof(Frame_ClickMap))]
-	[BsonKnownTypes(typeof(Frame_ClickMap))]
-	public abstract class AFrameMessage : AActorMessage
+	public abstract partial class AFrameMessage : AActorMessage
 	{
 		[ProtoMember(1)]
 		public long Id;

+ 5 - 14
Unity/Assets/Scripts/Base/Message/AMessage.cs

@@ -1,12 +1,11 @@
 using MongoDB.Bson.Serialization.Attributes;
 using ProtoBuf;
 
+// 不要在这个文件加[ProtoInclude]跟[BsonKnowType]标签,加到InnerMessage.cs或者OuterMessage.cs里面去
 namespace Model
 {
-	[BsonKnownTypes(typeof(ARequest))]
-	[BsonKnownTypes(typeof(AResponse))]
-	[BsonKnownTypes(typeof(AActorMessage))]
-	public abstract class AMessage
+	[ProtoContract]
+	public abstract partial class AMessage
 	{
 		public override string ToString()
 		{
@@ -15,11 +14,7 @@ namespace Model
 	}
 
 	[ProtoContract]
-	[ProtoInclude(10000, typeof(C2R_Login))]
-	[ProtoInclude(10001, typeof(C2G_LoginGate))]
-	[ProtoInclude(10002, typeof(C2G_EnterMap))]
-	[BsonKnownTypes(typeof(AActorRequest))]
-	public abstract class ARequest : AMessage
+	public abstract partial class ARequest : AMessage
 	{
 		[ProtoMember(1000)]
 		[BsonIgnoreIfDefault]
@@ -30,11 +25,7 @@ namespace Model
 	/// 服务端回的RPC消息需要继承这个抽象类
 	/// </summary>
 	[ProtoContract]
-	[ProtoInclude(10000, typeof(R2C_Login))]
-	[ProtoInclude(10001, typeof(G2C_LoginGate))]
-	[ProtoInclude(10002, typeof(G2C_EnterMap))]
-	[BsonKnownTypes(typeof(AActorResponse))]
-	public abstract class AResponse : AMessage
+	public abstract partial class AResponse : AMessage
 	{
 		[ProtoMember(1000)]
 		public uint RpcId;

+ 63 - 57
Unity/Assets/Scripts/Entity/Message/Opcode.cs

@@ -1,72 +1,78 @@
 namespace Model
 {
-	// 1000开始
+	// 客户端 100 - 999, 服务端内部1000以上
 	public enum Opcode: ushort
 	{
-		FrameMessage = 1000,
-		C2R_Login = 1001,
-		R2C_Login = 1002,
-		R2C_ServerLog = 1003,
-		C2G_LoginGate = 1004,
-		G2C_LoginGate = 1005,
-		C2G_EnterMap = 1006,
-		G2C_EnterMap = 1007,
-		C2M_Reload = 1008,
-		M2C_Reload = 1009,
-		C2R_Ping = 1010,
-		R2C_Ping = 1011,
+		ARequest = 1,
+		AResponse = 2,
+		AActorMessage = 3,
+		AActorRequest = 4,
+		AActorResponse = 5,
+		ActorRequest = 6,
+		ActorResponse = 7,
+		ActorRpcRequest = 8,
+		ActorRpcResponse = 9,
+		AFrameMessage = 10,
 
-		Actor_Test = 2001,
-		Actor_TestRequest = 2002,
-		Actor_TestResponse = 2003,
-		Actor_TransferRequest = 2004,
-		Actor_TransferResponse = 2005,
-		Frame_ClickMap = 2006,
-		Actor_CreateUnits = 2007,
+		FrameMessage = 100,
+		C2R_Login,
+		R2C_Login,
+		R2C_ServerLog,
+		C2G_LoginGate,
+		G2C_LoginGate,
+		C2G_EnterMap,
+		G2C_EnterMap,
+		C2M_Reload,
+		M2C_Reload,
+		C2R_Ping,
+		R2C_Ping,
 
+		Actor_Test,
+		Actor_TestRequest,
+		Actor_TestResponse,
+		Actor_TransferRequest,
+		Actor_TransferResponse,
+		Frame_ClickMap,
+		Actor_CreateUnits,
 
-		// server inner opcode
-		ActorRequest = 1,
-		ActorResponse = 2,
-		ActorRpcRequest = 3,
-		ActorRpcResponse = 4,
-		G2G_LockRequest = 10,
-		G2G_LockResponse = 11,
-		G2G_LockReleaseRequest = 12,
-		G2G_LockReleaseResponse = 13,
+		// 服务端Opcode, 从1000开始
+		G2G_LockRequest = 1000,
+		G2G_LockResponse,
+		G2G_LockReleaseRequest,
+		G2G_LockReleaseResponse,
 
-		M2A_Reload = 20,
-		A2M_Reload = 21,
+		M2A_Reload,
+		A2M_Reload,
 
-		DBSaveRequest = 26,
-		DBSaveResponse = 27,
-		DBQueryRequest = 28,
-		DBQueryResponse = 29,
-		DBSaveBatchResponse = 37,
-		DBSaveBatchRequest = 38,
-		DBQueryBatchRequest = 61,
-		DBQueryBatchResponse = 62,
-		DBQueryJsonRequest = 65,
-		DBQueryJsonResponse = 66,
+		DBSaveRequest,
+		DBSaveResponse,
+		DBQueryRequest,
+		DBQueryResponse,
+		DBSaveBatchResponse,
+		DBSaveBatchRequest,
+		DBQueryBatchRequest,
+		DBQueryBatchResponse,
+		DBQueryJsonRequest,
+		DBQueryJsonResponse,
 
-		ObjectAddRequest = 70,
-		ObjectAddResponse = 71,
-		ObjectRemoveRequest = 72,
-		ObjectRemoveResponse = 73,
-		ObjectLockRequest = 74,
-		ObjectLockResponse = 75,
-		ObjectUnLockRequest = 76,
-		ObjectUnLockResponse = 77,
-		ObjectGetRequest = 78,
-		ObjectGetResponse = 79,
+		ObjectAddRequest,
+		ObjectAddResponse,
+		ObjectRemoveRequest,
+		ObjectRemoveResponse,
+		ObjectLockRequest,
+		ObjectLockResponse,
+		ObjectUnLockRequest,
+		ObjectUnLockResponse,
+		ObjectGetRequest,
+		ObjectGetResponse,
 
-		R2G_GetLoginKey = 101,
-		G2R_GetLoginKey = 102,
+		R2G_GetLoginKey,
+		G2R_GetLoginKey,
 
-		G2M_CreateUnit = 103,
-		M2G_CreateUnit = 104,
+		G2M_CreateUnit,
+		M2G_CreateUnit,
 
-		M2M_TrasferUnitRequest = 105,
-		M2M_TrasferUnitResponse = 106,
+		M2M_TrasferUnitRequest,
+		M2M_TrasferUnitResponse,
 	}
 }

+ 54 - 0
Unity/Assets/Scripts/Entity/Message/OuterMessage.cs

@@ -1,8 +1,62 @@
 using System.Collections.Generic;
+using MongoDB.Bson.Serialization.Attributes;
 using ProtoBuf;
 
 namespace Model
 {
+	[BsonKnownTypes(typeof(AActorMessage))]
+	public abstract partial class AMessage
+	{
+	}
+
+	[BsonKnownTypes(typeof(AActorRequest))]
+	[ProtoInclude((int)Opcode.C2R_Login, typeof(C2R_Login))]
+	[ProtoInclude((int)Opcode.C2G_LoginGate, typeof(C2G_LoginGate))]
+	[ProtoInclude((int)Opcode.C2G_EnterMap, typeof(C2G_EnterMap))]
+	public abstract partial class ARequest : AMessage
+	{
+	}
+
+	[BsonKnownTypes(typeof(AActorResponse))]
+	[ProtoInclude((int)Opcode.R2C_Login, typeof(R2C_Login))]
+	[ProtoInclude((int)Opcode.G2C_LoginGate, typeof(G2C_LoginGate))]
+	[ProtoInclude((int)Opcode.G2C_EnterMap, typeof(G2C_EnterMap))]
+	public abstract partial class AResponse : AMessage
+	{
+	}
+
+	[BsonKnownTypes(typeof(Actor_Test))]
+	[BsonKnownTypes(typeof(AFrameMessage))]
+	[BsonKnownTypes(typeof(Actor_CreateUnits))]
+	[BsonKnownTypes(typeof(FrameMessage))]
+	[ProtoInclude((int)Opcode.FrameMessage, typeof(FrameMessage))]
+	[ProtoInclude((int)Opcode.AFrameMessage, typeof(AFrameMessage))]
+	[ProtoInclude((int)Opcode.Actor_CreateUnits, typeof(Actor_CreateUnits))]
+	public abstract partial class AActorMessage : AMessage
+	{
+	}
+
+	[BsonKnownTypes(typeof(Actor_TestRequest))]
+	[BsonKnownTypes(typeof(Actor_TransferRequest))]
+	public abstract partial class AActorRequest : ARequest
+	{
+	}
+
+	[BsonKnownTypes(typeof(Actor_TestResponse))]
+	[BsonKnownTypes(typeof(Actor_TransferResponse))]
+	public abstract partial class AActorResponse : AResponse
+	{
+	}
+
+	/// <summary>
+	/// 帧消息,继承这个类的消息会经过服务端转发
+	/// </summary>
+	[ProtoInclude((int)Opcode.Frame_ClickMap, typeof(Frame_ClickMap))]
+	[BsonKnownTypes(typeof(Frame_ClickMap))]
+	public abstract partial class AFrameMessage : AActorMessage
+	{
+	}
+
 	[ProtoContract]
 	[Message(Opcode.C2R_Login)]
 	public class C2R_Login: ARequest

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików