test
This commit is contained in:
parent
bc9beea374
commit
32a6cbc54e
57
packet.go
57
packet.go
@ -43,6 +43,26 @@ const (
|
|||||||
AdminPacketServerRConEnd = 125
|
AdminPacketServerRConEnd = 125
|
||||||
AdminPacketServerPong = 126
|
AdminPacketServerPong = 126
|
||||||
InvalidAdminPacket = 255
|
InvalidAdminPacket = 255
|
||||||
|
|
||||||
|
AdminUpdateDate = 0
|
||||||
|
AdminUpdateClientInfo = 1
|
||||||
|
AdminUpdateCompanyInfo = 2
|
||||||
|
AdminUpdateCompanyEconomy = 3
|
||||||
|
AdminUpdateCompanyStats = 4
|
||||||
|
AdminUpdateChat = 5
|
||||||
|
AdminUpdateConsole = 6
|
||||||
|
AdminUpdateCmdNames = 7
|
||||||
|
AdminUpdateCmdLogging = 8
|
||||||
|
AdminUpdateGamescript = 9
|
||||||
|
AdminUpdateEnd = 10
|
||||||
|
|
||||||
|
AdminFrequencyPoll = 0x01
|
||||||
|
AdminFrequencyDaily = 0x02
|
||||||
|
AdminFrequencyWeekly = 0x04
|
||||||
|
AdminFrequencyMonthly = 0x08
|
||||||
|
AdminFrequencyQuarterly = 0x10
|
||||||
|
AdminFrequencyAnnually = 0x20
|
||||||
|
AdminFrequencyAutomatic = 0x40
|
||||||
)
|
)
|
||||||
|
|
||||||
type Packet struct {
|
type Packet struct {
|
||||||
@ -78,6 +98,12 @@ type PacketAdminServerWelcome struct {
|
|||||||
MapY uint16
|
MapY uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PacketAdminUpdateFrequency struct {
|
||||||
|
Packet
|
||||||
|
UpdateType uint16
|
||||||
|
UpdateFrequency 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)
|
||||||
@ -94,6 +120,17 @@ func (p *PacketAdminJoin) Bytes() []byte {
|
|||||||
return buf.Bytes()
|
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)
|
||||||
|
binary.Write(buf, binary.LittleEndian, p.UpdateFrequency)
|
||||||
|
|
||||||
|
return buf.Bytes()
|
||||||
|
}
|
||||||
|
|
||||||
func (p *PacketAdminServerWelcome) Read(b []byte) {
|
func (p *PacketAdminServerWelcome) Read(b []byte) {
|
||||||
r := bufio.NewReader(bytes.NewReader(b))
|
r := bufio.NewReader(bytes.NewReader(b))
|
||||||
r.Discard(3)
|
r.Discard(3)
|
||||||
@ -134,24 +171,6 @@ func (p *PacketAdminServerProtocol) Read(b []byte) {
|
|||||||
p.FrequenciesAllowed = binary.LittleEndian.Uint16(bs[2:])
|
p.FrequenciesAllowed = binary.LittleEndian.Uint16(bs[2:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func handlePacket(p Packet, b []byte) {
|
func readPacket(p Packet, b []byte) {
|
||||||
switch p.PType {
|
|
||||||
case AdminPacketServerProtocol:
|
|
||||||
logInfoDebug("AdminPacketServerProtocol Raw : %v", b)
|
|
||||||
sp := PacketAdminServerProtocol{
|
|
||||||
Packet: p,
|
|
||||||
}
|
|
||||||
sp.Read(b)
|
|
||||||
logInfoDebug("AdminPacketServerProtocol :\n- ProtocolVersion: %v\n- FurtherData: %v\n- UpdatePacketType: %v\n- FrequenciesAllowed: %b", sp.ProtocolVersion, sp.FurtherData, sp.UpdatePacketType, sp.FrequenciesAllowed)
|
|
||||||
case AdminPacketServerWelcome:
|
|
||||||
logInfoDebug("AdminPacketServerWelcome Raw : %v", b)
|
|
||||||
sp := PacketAdminServerWelcome{
|
|
||||||
Packet: p,
|
|
||||||
}
|
|
||||||
sp.Read(b)
|
|
||||||
logInfoDebug("AdminPacketServerWelcome :\n- ServerName: %v\n- OpenTTDVersion: %v\n- Dedicated: %v\n- MapSeed: %x\n- MapLandscape: %v\n- MapStartDate: %v\n- Size: %v x %v", sp.ServerName, sp.OpenTTDVersion, sp.Dedicated, sp.MapSeed, sp.MapLandscape, sp.MapStartDate, sp.MapX, sp.MapY)
|
|
||||||
default:
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user