From 0a4b2f44fe1feb7140da6379dafa1da88df8b3c3 Mon Sep 17 00:00:00 2001 From: shoopea Date: Sat, 4 Dec 2021 17:14:32 +0800 Subject: [PATCH] update stats/eco --- packet.go | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++ ttd.go | 14 +++++++- version.go | 8 ++--- 3 files changed, 121 insertions(+), 5 deletions(-) diff --git a/packet.go b/packet.go index 6893cd5..5a9031e 100644 --- a/packet.go +++ b/packet.go @@ -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) diff --git a/ttd.go b/ttd.go index 7477918..8d184fc 100644 --- a/ttd.go +++ b/ttd.go @@ -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, diff --git a/version.go b/version.go index ce81bf7..47b267f 100644 --- a/version.go +++ b/version.go @@ -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"