diff --git a/def.go b/def.go index 756a726..992e15f 100644 --- a/def.go +++ b/def.go @@ -1,16 +1,8 @@ package main -type Packet struct { - PLength uint16 - PType uint8 -} - -type PacketAdminJoin struct { - Packet - Password string - AppName string - AppVersion string -} +import ( + "bytes" +) const ( AdminPacketAdminJoin uint8 = 0 @@ -50,3 +42,22 @@ const ( AdminPacketServerPong InvalidAdminPacket = 0xFF ) + +type Packet struct { + PLength uint16 + PType uint8 +} + +type PacketAdminJoin struct { + Packet + Password string + AppName string + AppVersion string +} + +func (p *PacketAdminJoin) Bytes() []byte { + buf := new(bytes.Buffer) + p.PLength = binary.Size(p) + _ = binary.Write(buf, binary.LittleEndian, p) + return buf.Bytes() +}