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 Reliable = true;
/// Packet meta-information: Id of this packet. Set just before sending.
public int Id;
/// 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) {
Id = buffer.ReadInt();
Reliable = buffer.ReadBool();
}
/// Writes packet meta-information to the buffer.
public void WriteMeta(ByteBuffer buffer) {
buffer.Write(Id);
buffer.Write(Reliable);
}
/// 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,
}
}