namespace NeonTea.Quakeball.TeaNet.Packets {
/// A packet for sending stuff over to connections.
public abstract class Packet {
/// Packet meta-information: Is this packet reliable. Set just before sending.
public bool PacketIsReliable = true;
/// Packet meta-information: Id of this packet. Set just before sending.
public int PacketId;
/// Size of this packet in bytes. Only available after the packet has been Read (when received) or Written (when sent).
public int Size;
/// Write any relevant information about this packet into the buffer.
public abstract void Write(ByteBuffer buffer);
/// Read and assign any relevant information about this packet from the buffer.
public abstract void Read(ByteBuffer buffer);
/// Reads packet meta-information from the buffer.
public void ReadMeta(ByteBuffer buffer) {
PacketIsReliable = buffer.ReadBool();
}
/// Writes packet meta-information to the buffer.
public void WriteMeta(ByteBuffer buffer) {
buffer.Write(PacketIsReliable);
}
/// Make a shallow copy for this packet, copying any primitives but retaining any references to instances.
public Packet ShallowCopy() {
return (Packet)this.MemberwiseClone();
}
}
/// Defines something as writeable/readable by the buffer. Useful for creating abstractions within packets.
public interface Serializable {
void Write(ByteBuffer buffer);
void Read(ByteBuffer buffer);
}
public enum PacketStage {
Establishing = 0,
Rejected = 1,
Closed = 2,
Ready = 3,
}
public enum ClosingReason {
Unknown = 0,
IncorrectVersion = 1,
Timeout = 2,
Manual = 3,
}
}