gottdad/def.go
2020-06-14 17:31:47 +02:00

71 lines
1.5 KiB
Go

package main
import (
"bytes"
"encoding/binary"
)
const (
AdminPacketAdminJoin uint8 = 0
AdminPacketAdminQuit
AdminPacketAdminUpdateFrequency
AdminPacketAdminPoll
AdminPacketAdminChat
AdminPacketAdminRCon
AdminPacketAdminGamescript
AdminPacketAdminPing
AdminPacketServerFull = 100
AdminPacketServerBanned
AdminPacketServerError
AdminPacketServerProtocol
AdminPacketServerWelcome
AdminPacketServerNewgame
AdminPacketServerShutdown
AdminPacketServerDate
AdminPacketServerClientJoin
AdminPacketServerClientInfo
AdminPacketServerClientUpdate
AdminPacketServerClientQuit
AdminPacketServerClientError
AdminPacketServerCompanyNew
AdminPacketServerCompanyInfo
AdminPacketServerCompanyUpdate
AdminPacketServerCompanyRemove
AdminPacketServerCompanyEconomy
AdminPacketServerCompanyStats
AdminPacketServerChat
AdminPacketServerRCon
AdminPacketServerConsole
AdminPacketServerCmdNames
AdminPacketServerCmdLogging
AdminPacketServerGamescript
AdminPacketServerRConEnd
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 = uint16(len(p.Password) + len(p.AppName) + len(p.AppVersion) + 3)
binary.Write(buf, binary.LittleEndian, p.PLength)
binary.Write(buf, binary.LittleEndian, p.PType)
buf.WriteString(p.Password)
buf.WriteString(p.AppName)
buf.WriteString(p.AppVersion)
return buf.Bytes()
}