AMessage.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using MongoDB.Bson.Serialization.Attributes;
  2. using ProtoBuf;
  3. namespace Model
  4. {
  5. [BsonKnownTypes(typeof(ARequest))]
  6. [BsonKnownTypes(typeof(AResponse))]
  7. [BsonKnownTypes(typeof(AActorMessage))]
  8. public abstract class AMessage
  9. {
  10. public override string ToString()
  11. {
  12. return MongoHelper.ToJson(this);
  13. }
  14. }
  15. [ProtoContract]
  16. [ProtoInclude(10000, typeof(C2R_Login))]
  17. [ProtoInclude(10001, typeof(C2G_LoginGate))]
  18. [ProtoInclude(10002, typeof(C2G_EnterMap))]
  19. [BsonKnownTypes(typeof(AActorRequest))]
  20. public abstract class ARequest : AMessage
  21. {
  22. [ProtoMember(1000)]
  23. [BsonIgnoreIfDefault]
  24. public uint RpcId;
  25. }
  26. /// <summary>
  27. /// 服务端回的RPC消息需要继承这个抽象类
  28. /// </summary>
  29. [ProtoContract]
  30. [ProtoInclude(10000, typeof(R2C_Login))]
  31. [ProtoInclude(10001, typeof(G2C_LoginGate))]
  32. [ProtoInclude(10002, typeof(G2C_EnterMap))]
  33. [BsonKnownTypes(typeof(AActorResponse))]
  34. public abstract class AResponse : AMessage
  35. {
  36. [ProtoMember(1000)]
  37. public uint RpcId;
  38. [ProtoMember(1001)]
  39. public int Error = 0;
  40. [ProtoMember(1002)]
  41. public string Message = "";
  42. }
  43. }