This commit is contained in:
shoopea 2020-06-14 23:31:26 +02:00
parent 8486ef37ac
commit b4cb5f20d5

View File

@ -56,23 +56,71 @@ type PacketAdminJoin struct {
AppVersion string AppVersion string
} }
type PacketAdminServerProtocol struct {
Packet
ProtocolVersion uint8
FurtherData bool
UpdatePacketType uint16
FrequenciesAllowed uint16
}
type PacketAdminServerWelcome struct {
Packet
ServerName string
OpenTTDVersion string
Dedicated bool
MapName string
MapSeed uint32
MapLandscape uint8
MapStartDate uint32
MapX uint16
MapY uint16
}
func (p *PacketAdminJoin) Bytes() []byte { func (p *PacketAdminJoin) Bytes() []byte {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
p.PLength = uint16(len(p.Password) + len(p.AppName) + len(p.AppVersion) + 6) p.PLength = uint16(len(p.Password) + len(p.AppName) + len(p.AppVersion) + 6)
binary.Write(buf, binary.LittleEndian, p.PLength) binary.Write(buf, binary.LittleEndian, p.PLength)
logInfoDebug("len : %d", buf.Len())
binary.Write(buf, binary.LittleEndian, p.PType) binary.Write(buf, binary.LittleEndian, p.PType)
logInfoDebug("len : %d", buf.Len())
buf.WriteString(p.Password) buf.WriteString(p.Password)
buf.WriteByte(0) buf.WriteByte(0)
logInfoDebug("len : %d", buf.Len())
buf.WriteString(p.AppName) buf.WriteString(p.AppName)
buf.WriteByte(0) buf.WriteByte(0)
logInfoDebug("len : %d", buf.Len())
buf.WriteString(p.AppVersion) buf.WriteString(p.AppVersion)
buf.WriteByte(0) buf.WriteByte(0)
logInfoDebug("len : %d", buf.Len())
return buf.Bytes() return buf.Bytes()
} }
func (p *AdminPacketServerWelcome) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
p.ServerName, _ = r.ReadString(0)
p.OpenTTDVersion, _ = r.ReadString(0)
c, _ := r.ReadByte()
p.Dedicated = bool(c)
p.MapName, _ = r.ReadString(0)
bs := make([]byte, 13)
_, _ = r.Read(bs)
p.MapSeed = binary.LittleEndian.Uint32(bs[0:])
p.MapLandscape = uint8(bs[4:1])
p.MapStartDate = binary.LittleEndian.Uint32(bs[5:])
p.MapX = binary.LittleEndian.Uint16(bs[9:])
p.MapY = binary.LittleEndian.Uint16(bs[11:])
}
func handlePacket(p Packet, b []byte) {
switch p.PType {
case AdminPacketServerProtocol:
case AdminPacketServerWelcome:
sp := PacketAdminServerWelcome{
PLength: p.PLength,
PType: p.PType,
}
sp.Read(b)
logInfoDebug("AdminPacketServerWelcome : %v", sp)
default:
}
}