GamerLeavingMessage.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using Microsoft.Xna.Framework.Net;
  2. namespace Microsoft.Xna.Framework.Net
  3. {
  4. /// <summary>
  5. /// Message sent when a gamer explicitly leaves the session (graceful disconnect).
  6. /// This allows immediate notification instead of waiting for heartbeat timeout (9 seconds).
  7. /// </summary>
  8. public class GamerLeavingMessage : INetworkMessage
  9. {
  10. /// <summary>
  11. /// Message type ID for GamerLeavingMessage.
  12. /// </summary>
  13. public byte MessageType => 9;
  14. /// <summary>
  15. /// The unique ID of the gamer who is leaving.
  16. /// </summary>
  17. public string GamerId { get; set; }
  18. /// <summary>
  19. /// Optional reason for leaving (e.g., "User quit", "Application closing").
  20. /// </summary>
  21. public string Reason { get; set; }
  22. /// <summary>
  23. /// Serializes the message to a packet writer.
  24. /// </summary>
  25. public void Serialize(PacketWriter writer)
  26. {
  27. writer.Write(MessageType);
  28. writer.Write(GamerId ?? string.Empty);
  29. writer.Write(Reason ?? string.Empty);
  30. }
  31. /// <summary>
  32. /// Deserializes the message from a packet reader.
  33. /// </summary>
  34. public void Deserialize(PacketReader reader)
  35. {
  36. GamerId = reader.ReadString();
  37. Reason = reader.ReadString();
  38. }
  39. }
  40. }