using Microsoft.Xna.Framework.Net;
using System;
namespace Microsoft.Xna.Framework.Net
{
///
/// Message broadcast by host to synchronize session state transitions across all clients.
/// Ensures all players see the same state (Lobby → Playing → Ended) at the same time.
///
public class SessionStateMessage : INetworkMessage
{
///
/// Message type ID for SessionStateMessage.
///
public byte MessageType => 10;
///
/// The new session state.
///
public NetworkSessionState NewState { get; set; }
///
/// UTC timestamp when the state change occurred (milliseconds since Unix epoch).
///
public long Timestamp { get; set; }
///
/// Optional reason for the state change (e.g., "Host started game", "Game completed").
///
public string Reason { get; set; }
///
/// Serializes the message to a packet writer.
///
public void Serialize(PacketWriter writer)
{
writer.Write(MessageType);
writer.Write((byte)NewState);
writer.Write(Timestamp);
writer.Write(Reason ?? string.Empty);
}
///
/// Deserializes the message from a packet reader.
///
public void Deserialize(PacketReader reader)
{
NewState = (NetworkSessionState)reader.ReadByte();
Timestamp = reader.ReadInt64();
Reason = reader.ReadString();
}
}
}