53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
namespace Passer.RoboidControl {
|
|
|
|
/// <summary>
|
|
/// A participant messages notifies other participants of its presence
|
|
/// </summary>
|
|
/// When received by another participant, it can be followed by a NetworkIdMsg
|
|
/// to announce that participant to this client such that it can join privately
|
|
public class ParticipantMsg : IMessage {
|
|
/// <summary>
|
|
/// The message ID
|
|
/// </summary>
|
|
public const byte Id = 0xA0;
|
|
/// <summary>
|
|
/// The length of the message
|
|
/// </summary>
|
|
public const byte length = 2;
|
|
/// <summary>
|
|
/// The network ID known by the participant
|
|
/// </summary>
|
|
public byte networkId;
|
|
|
|
/// <summary>
|
|
/// Create a new message for sending
|
|
/// </summary>
|
|
/// <param name="networkId">The network ID known by the participant</param>
|
|
public ParticipantMsg(byte networkId) {
|
|
this.networkId = networkId;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create a message for receiving
|
|
/// </summary>
|
|
/// <param name="buffer">The byte array to parse</param>
|
|
public ParticipantMsg(byte[] buffer) {
|
|
this.networkId = buffer[1];
|
|
}
|
|
|
|
/// <summary>
|
|
/// Serialize the message into a byte array
|
|
/// </summary>
|
|
/// <param name="buffer">The buffer to serialize into</param>
|
|
/// <returns>The length of the message in the buffer</returns>
|
|
public override byte Serialize(ref byte[] buffer) {
|
|
if (buffer.Length < ParticipantMsg.length)
|
|
return 0;
|
|
|
|
byte ix = 0;
|
|
buffer[ix++] = ParticipantMsg.Id;
|
|
buffer[ix++] = networkId;
|
|
return ParticipantMsg.length;
|
|
}
|
|
}
|
|
} |