From d5bed1eecf1930401645a960fcc4ba26f5fd9224 Mon Sep 17 00:00:00 2001 From: shoopea Date: Sun, 5 Dec 2021 17:08:12 +0800 Subject: [PATCH] update map eco/stats --- config.go | 4 +--- ttd.go | 14 ++++++++++++++ version.go | 8 ++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/config.go b/config.go index 057eebc..97ce2bb 100644 --- a/config.go +++ b/config.go @@ -4,7 +4,6 @@ import ( _ "embed" "encoding/json" "io/ioutil" - "log" "time" "github.com/tidwall/pretty" @@ -57,6 +56,7 @@ func (c *Config) Init() error { err := json.Unmarshal(cfgSample, &c) c.Clients = make(map[int]*ClientConfig) c.Stats = make(map[uint8]map[string]*Stat) + if err != nil { return err } @@ -80,8 +80,6 @@ func (c *Config) Load(path string) error { return err } - log.Printf("Stats : %d", len(c.Stats)) - return c.Save(path) } diff --git a/ttd.go b/ttd.go index 0af30df..f90846d 100644 --- a/ttd.go +++ b/ttd.go @@ -384,6 +384,13 @@ func (s *ServerTTD) Poll(stop chan struct{}) { sp.Read(buffer[:p.PLength]) logInfoDebug("Server.Poll() : PacketServerCompanyEconomy :\n- CompanyID: %d\n- M: %d\tL: %d\tI: %d\n- Delivered now: %d\tLast: %d\tPrevious: %d\n- Performance last: %d\t Previous: %d\n- Value last: %d\t Previous: %d", sp.CompanyID, sp.Money, sp.Loan, sp.Income, sp.DeliveredCargoThisQuarter, sp.DeliveredCargoLastQuarter, sp.DeliveredCargoPreviousQuarter, sp.PerformanceLastQuarter, sp.PerformancePreviousQuarter, sp.CompanyValueLastQuarter, sp.CompanyValuePreviousQuarter) + if cfg.Stats == nil { + logInfoDebug("Server.Poll() : PacketServerCompanyEconomy : Stats : uninitialized") + cfg.Stats = make(map[uint8]map[string]*Stat) + } else { + logInfoDebug("Server.Poll() : PacketServerCompanyEconomy : Stats : initialized") + } + _, ok := cfg.Stats[sp.CompanyID] if !ok { cfg.Stats[sp.CompanyID] = make(map[string]*Stat) @@ -414,6 +421,13 @@ func (s *ServerTTD) Poll(stop chan struct{}) { sp.Read(buffer[:p.PLength]) logInfoDebug("Server.Poll() : PacketServerCompanyStats :\n- CompanyID: %d\n- Vehicles T: %d\tL: %d\tB: %d\tP: %d\tS: %d\n- Stations T: %d\tL: %d\tB: %d\tP: %d\tS: %d", sp.CompanyID, sp.Trains, sp.Lorries, sp.Busses, sp.Planes, sp.Ships, sp.TrainStations, sp.LorryStations, sp.BusStops, sp.Airports, sp.Harbours) + if cfg.Stats == nil { + logInfoDebug("Server.Poll() : PacketServerCompanyStats : Stats : uninitialized") + cfg.Stats = make(map[uint8]map[string]*Stat) + } else { + logInfoDebug("Server.Poll() : PacketServerCompanyStats : Stats : initialized") + } + _, ok := cfg.Stats[sp.CompanyID] if !ok { cfg.Stats[sp.CompanyID] = make(map[string]*Stat) diff --git a/version.go b/version.go index cb01815..b80368d 100644 --- a/version.go +++ b/version.go @@ -1,6 +1,6 @@ // Code generated by version.sh (@generated) DO NOT EDIT. package main -var githash = "0c9ac03" -var buildstamp = "2021-12-05_08:43:45" -var commits = "226" -var version = "0c9ac03-b226 - 2021-12-05_08:43:45" +var githash = "0fd8999" +var buildstamp = "2021-12-05_09:07:57" +var commits = "227" +var version = "0fd8999-b227 - 2021-12-05_09:07:57"