This commit is contained in:
shoopea 2020-06-15 15:05:00 +02:00
parent 7e0cefb4e8
commit de751ce5b2

View File

@ -77,7 +77,12 @@ type PacketAdminJoin struct {
AppVersion string
}
type PacketAdminServerProtocol struct {
type PacketAdminRCon struct {
Packet
Command string
}
type PacketServerProtocol struct {
Packet
ProtocolVersion uint8
FurtherData bool
@ -85,7 +90,7 @@ type PacketAdminServerProtocol struct {
FrequenciesAllowed uint16
}
type PacketAdminServerWelcome struct {
type PacketServerWelcome struct {
Packet
ServerName string
OpenTTDVersion string
@ -104,22 +109,22 @@ type PacketAdminUpdateFrequency struct {
UpdateFrequency uint16
}
type PacketAdminServerDate struct {
type PacketServerDate struct {
Packet
Date uint32
}
type PacketAdminServerClientJoin struct {
type PacketServerClientJoin struct {
Packet
ClientID uint32
}
type PacketAdminServerClientQuit struct {
type PacketServerClientQuit struct {
Packet
ClientID uint32
}
type PacketAdminServerClientInfo struct {
type PacketServerClientInfo struct {
Packet
ClientID uint32
Address string
@ -129,13 +134,13 @@ type PacketAdminServerClientInfo struct {
CompanyID uint8
}
type PacketAdminServerClientError struct {
type PacketServerClientError struct {
Packet
ClientID uint32
ErrorID uint8
}
type PacketAdminServerChat struct {
type PacketServerChat struct {
Packet
ActionID uint8
DestinationID uint8
@ -144,12 +149,18 @@ type PacketAdminServerChat struct {
Amount uint64
}
type PacketAdminServerConsole struct {
type PacketServerConsole struct {
Packet
Origin string
Text string
}
type PacketServerRCon struct {
Packet
ColorID uint16
Output string
}
func (p *PacketAdminJoin) Bytes() []byte {
buf := new(bytes.Buffer)
p.PLength = uint16(len(p.Password) + len(p.AppName) + len(p.AppVersion) + 6)
@ -166,9 +177,22 @@ func (p *PacketAdminJoin) Bytes() []byte {
return buf.Bytes()
}
func (p *PacketAdminRCon) Bytes() []byte {
buf := new(bytes.Buffer)
p.PLength = uint16(len(p.Command) + 4)
binary.Write(buf, binary.LittleEndian, p.PLength)
binary.Write(buf, binary.LittleEndian, p.PType)
buf.WriteString(p.Command)
buf.WriteByte(0)
return buf.Bytes()
}
func (p *PacketAdminUpdateFrequency) Bytes() []byte {
buf := new(bytes.Buffer)
p.PLength = 7
binary.Write(buf, binary.LittleEndian, p.PLength)
binary.Write(buf, binary.LittleEndian, p.PType)
binary.Write(buf, binary.LittleEndian, p.UpdateType)
@ -177,7 +201,7 @@ func (p *PacketAdminUpdateFrequency) Bytes() []byte {
return buf.Bytes()
}
func (p *PacketAdminServerWelcome) Read(b []byte) {
func (p *PacketServerWelcome) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)
p.ServerName, _ = r.ReadString(0)
@ -200,7 +224,7 @@ func (p *PacketAdminServerWelcome) Read(b []byte) {
p.MapY = binary.LittleEndian.Uint16(bs[11:])
}
func (p *PacketAdminServerProtocol) Read(b []byte) {
func (p *PacketServerProtocol) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)
c, _ := r.ReadByte()
@ -217,7 +241,7 @@ func (p *PacketAdminServerProtocol) Read(b []byte) {
p.FrequenciesAllowed = binary.LittleEndian.Uint16(bs[2:])
}
func (p *PacketAdminServerDate) Read(b []byte) {
func (p *PacketServerDate) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)
bs := make([]byte, 4)
@ -226,7 +250,7 @@ func (p *PacketAdminServerDate) Read(b []byte) {
}
func (p *PacketAdminServerClientJoin) Read(b []byte) {
func (p *PacketServerClientJoin) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)
bs := make([]byte, 4)
@ -234,7 +258,7 @@ func (p *PacketAdminServerClientJoin) Read(b []byte) {
p.ClientID = binary.LittleEndian.Uint32(bs[0:])
}
func (p *PacketAdminServerClientInfo) Read(b []byte) {
func (p *PacketServerClientInfo) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)
bs := make([]byte, 4)
@ -251,7 +275,7 @@ func (p *PacketAdminServerClientInfo) Read(b []byte) {
p.CompanyID = uint8(c)
}
func (p *PacketAdminServerClientError) Read(b []byte) {
func (p *PacketServerClientError) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)
bs := make([]byte, 4)
@ -261,7 +285,7 @@ func (p *PacketAdminServerClientError) Read(b []byte) {
p.ErrorID = uint8(c)
}
func (p *PacketAdminServerClientQuit) Read(b []byte) {
func (p *PacketServerClientQuit) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)
bs := make([]byte, 4)
@ -269,7 +293,7 @@ func (p *PacketAdminServerClientQuit) Read(b []byte) {
p.ClientID = binary.LittleEndian.Uint32(bs[0:])
}
func (p *PacketAdminServerChat) Read(b []byte) {
func (p *PacketServerChat) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)
c, _ := r.ReadByte()
@ -285,9 +309,18 @@ func (p *PacketAdminServerChat) Read(b []byte) {
p.Amount = binary.LittleEndian.Uint64(bs[0:])
}
func (p *PacketAdminServerConsole) Read(b []byte) {
func (p *PacketServerConsole) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)
p.Origin, _ = r.ReadString(0)
p.Text, _ = r.ReadString(0)
}
func (p *PacketServerRCon) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)
bs := make([]byte, 2)
_, _ = r.Read(bs)
p.ColorID = binary.LittleEndian.Uint16(bs[0:])
p.Output, _ = r.ReadString(0)
}