update stats/eco

This commit is contained in:
shoopea 2021-12-04 17:14:32 +08:00
parent 7e3b0bf414
commit 0a4b2f44fe
3 changed files with 121 additions and 5 deletions

104
packet.go
View File

@ -211,6 +211,36 @@ type PacketServerCompanyRemove struct {
Reason uint8
}
type PacketServerCompanyEconomy struct {
Packet
CompanyID uint8
Money uint64
Loan uint64
Income int64
DeliveredCargoThisQuarter uint16
CompanyValueLastQuarter uint64
PerformanceLastQuarter uint16
DeliveredCargoLastQuarter uint16
CompanyValuePreviousQuarter uint64
PerformancePreviousQuarter uint16
DeliveredCargoPreviousQuarter uint16
}
type PacketServerCompanyStats struct {
Packet
CompanyID uint8
Trains uint16
Lorries uint16
Busses uint16
Planes uint16
Ships uint16
TrainStations uint16
LorryStations uint16
BusStops uint16
Airports uint16
Harbours uint16
}
type PacketServerChat struct {
Packet
ActionID uint8
@ -488,6 +518,80 @@ func (p *PacketServerCompanyRemove) Read(b []byte) {
p.Reason = uint8(c)
}
func (p *PacketServerCompanyEconomy) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)
c, _ := r.ReadByte()
p.CompanyID = uint8(c)
bs := make([]byte, 8)
_, _ = r.Read(bs)
p.Money = binary.LittleEndian.Uint64(bs[0:])
bs = make([]byte, 8)
_, _ = r.Read(bs)
p.Loan = binary.LittleEndian.Uint64(bs[0:])
bs = make([]byte, 8)
_, _ = r.Read(bs)
p.Income = int64(binary.LittleEndian.Uint64(bs[0:]))
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.DeliveredCargoThisQuarter = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 8)
_, _ = r.Read(bs)
p.CompanyValueLastQuarter = binary.LittleEndian.Uint64(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.PerformanceLastQuarter = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.DeliveredCargoLastQuarter = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 8)
_, _ = r.Read(bs)
p.CompanyValuePreviousQuarter = binary.LittleEndian.Uint64(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.PerformancePreviousQuarter = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.DeliveredCargoPreviousQuarter = binary.LittleEndian.Uint16(bs[0:])
}
func (p *PacketServerCompanyStats) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)
c, _ := r.ReadByte()
p.CompanyID = uint8(c)
bs := make([]byte, 2)
_, _ = r.Read(bs)
p.Trains = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.Lorries = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.Busses = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.Planes = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.Ships = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.TrainStations = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.LorryStations = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.BusStops = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.Airports = binary.LittleEndian.Uint16(bs[0:])
bs = make([]byte, 2)
_, _ = r.Read(bs)
p.Harbours = binary.LittleEndian.Uint16(bs[0:])
}
func (p *PacketServerChat) Read(b []byte) {
r := bufio.NewReader(bytes.NewReader(b))
r.Discard(3)

14
ttd.go
View File

@ -172,7 +172,7 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
break
}
n, err = reader.Read(buffer[read:])
failError(err, "Server.Poll() : reader.Read")
logErrorDebug(err, "Server.Poll() : reader.Read")
read += n
//logInfoDebug("Server.Poll() : waiting for packet, read %d bytes.", read)
}
@ -377,6 +377,18 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
logInfoDebug("Server.Poll() : PacketServerCompanyRemove :\n- CompanyID: %d\n- Reason: %d", sp.CompanyID, sp.Reason)
bot.SendChat(cfg.Telegram.ChatID, fmt.Sprintf("Company #%d deleted (%s)", sp.CompanyID, s.Status.Companies[sp.CompanyID].Name))
delete(s.Status.Companies, sp.CompanyID)
case AdminPacketServerCompanyEconomy:
sp := PacketServerCompanyEconomy{
Packet: p,
}
sp.Read(buffer[:p.PLength])
logInfoDebug("Server.Poll() : PacketServerCompanyEconomy :\n- CompanyID: %d", sp.CompanyID)
case AdminPacketServerCompanyStats:
sp := PacketServerCompanyStats{
Packet: p,
}
sp.Read(buffer[:p.PLength])
logInfoDebug("Server.Poll() : PacketServerCompanyStats :\n- CompanyID: %d", sp.CompanyID)
case AdminPacketServerChat:
sp := PacketServerChat{
Packet: p,

View File

@ -1,6 +1,6 @@
// Code generated by version.sh (@generated) DO NOT EDIT.
package main
var githash = "3e4d6c1"
var buildstamp = "2021-12-04_08:38:00"
var commits = "219"
var version = "3e4d6c1-b219 - 2021-12-04_08:38:00"
var githash = "7e3b0bf"
var buildstamp = "2021-12-04_09:14:19"
var commits = "220"
var version = "7e3b0bf-b220 - 2021-12-04_09:14:19"