HeartbeatReplyMessage.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. namespace Microsoft.Xna.Framework.Net
  3. {
  4. /// <summary>
  5. /// Reply message sent in response to a heartbeat, used for RTT calculation.
  6. /// </summary>
  7. public class HeartbeatReplyMessage : INetworkMessage
  8. {
  9. public byte MessageType => 8;
  10. /// <summary>
  11. /// Echo back the request timestamp for RTT calculation.
  12. /// </summary>
  13. public long RequestTimestamp { get; set; }
  14. /// <summary>
  15. /// Reply's own timestamp.
  16. /// </summary>
  17. public long ReplyTimestamp { get; set; }
  18. /// <summary>
  19. /// ID of the gamer sending the reply.
  20. /// </summary>
  21. public string GamerId { get; set; }
  22. public void Serialize(PacketWriter writer)
  23. {
  24. writer.Write(MessageType);
  25. writer.Write(RequestTimestamp);
  26. writer.Write(ReplyTimestamp);
  27. writer.Write(GamerId ?? string.Empty);
  28. }
  29. public void Deserialize(PacketReader reader)
  30. {
  31. // Reader is positioned after the type byte
  32. RequestTimestamp = reader.ReadInt64();
  33. ReplyTimestamp = reader.ReadInt64();
  34. GamerId = reader.ReadString();
  35. }
  36. }
  37. }