diff --git a/config.go b/config.go index 90ee5a1..a05f09d 100644 --- a/config.go +++ b/config.go @@ -41,6 +41,7 @@ type ClientConfig struct { TimeLeft time.Duration `json:"time_left"` CompanyID uint8 `json:"company_id` Ready bool `json:"ready"` + Color string `json:"color"` } type Config struct { diff --git a/stats.go b/stats.go index b877f1a..c8ebe40 100644 --- a/stats.go +++ b/stats.go @@ -30,11 +30,13 @@ type StatMonthly struct { } type StatDaily struct { - Money int64 - Loan int64 - Value int64 - Trains int - Road int - Planes int - Ships int + CompanyID uint8 + Date time.Time + Money int64 + Loan int64 + Value int64 + Train int + Road int + Plane int + Ship int } diff --git a/ttd.go b/ttd.go index f4b5343..14c8750 100644 --- a/ttd.go +++ b/ttd.go @@ -25,7 +25,6 @@ type CompanyTTD struct { CompanyID uint8 CompanyExtlID int64 Name string - Value int64 Protected bool ClientID uint32 FirstSeen time.Time @@ -526,15 +525,45 @@ func (s *ServerTTD) Poll(stop chan struct{}) { Packet: p, } sp.Read(buffer[:p.PLength]) - r := regexp.MustCompile("#:(?P[0-9]+)\\(.*\\) Company Name: '(?P.+)'.*Value: (?P[0-9]+)( )+.*$") + r := regexp.MustCompile("#:(?P[0-9]+)\\((?P[a-zA-Z]+)\\) Company Name: '(?P.+)'.*Money: (?P[0-9]+).*Loan: (?P[0-9]*).*Value: (?P[0-9]+).* \\(T:(?P[0-9]+), R:(?P[0-9]+), P:(?P[0-9]+), S:(?P[0-9]+)\\).*$") if r.MatchString(sp.Output) { + coID := uint8(0) for _, co := range srv.Status.Companies { if co.Name == r.ReplaceAllString(sp.Output, "${CompanyName}") { co.CompanyExtlID, _ = strconv.ParseInt(r.ReplaceAllString(sp.Output, "${CompanyID}"), 10, 64) - co.Value, _ = strconv.ParseInt(r.ReplaceAllString(sp.Output, "${CompanyValue}"), 10, 64) + coID = co.CompanyID break } } + + if cfg.StatsDaily == nil { + cfg.StatsDaily = make(map[int]map[string]*StatDaily) + } + + if cfg.CompanyIsRegistered(coID) { + cc := cfg.GetCompanyClient(coID) + cc.Color = r.ReplaceAllString(sp.Output, "${Color}") + _, ok := cfg.StatsDaily[cc.UserID] + if !ok { + cfg.StatsDaily[cc.UserID] = make(map[string]*StatDaily) + } + stats, ok := cfg.StatsDaily[cc.UserID][s.Status.GameDate.Format("20060102")] + if !ok { + stats = &StatDaily{ + CompanyID: coID, + Date: s.Status.GameDate, + } + cfg.StatsDaily[cc.UserID][s.Status.GameDate.Format("20060102")] = stats + } + + stats.Money, _ = strconv.ParseInt(r.ReplaceAllString(sp.Output, "${Money}"), 10, 64) + stats.Loan, _ = strconv.ParseInt(r.ReplaceAllString(sp.Output, "${Loan}"), 10, 64) + stats.Value, _ = strconv.ParseInt(r.ReplaceAllString(sp.Output, "${Value}"), 10, 64) + stats.Train, _ = strconv.Atoi(r.ReplaceAllString(sp.Output, "${Train}")) + stats.Road, _ = strconv.Atoi(r.ReplaceAllString(sp.Output, "${Road}")) + stats.Plane, _ = strconv.Atoi(r.ReplaceAllString(sp.Output, "${Plane}")) + stats.Ship, _ = strconv.Atoi(r.ReplaceAllString(sp.Output, "${Ship}")) + } } r = regexp.MustCompile("Client #(?P[0-9]+).*name: '(?P.+)'.*company: (?P[0-9]+)( )+IP: .*$") if r.MatchString(sp.Output) { diff --git a/version.go b/version.go index 291197d..be93055 100644 --- a/version.go +++ b/version.go @@ -1,6 +1,6 @@ // Code generated by version.sh (@generated) DO NOT EDIT. package main -var githash = "7590355" -var buildstamp = "2021-12-10_13:21:22" -var commits = "252" -var version = "7590355-b252 - 2021-12-10_13:21:22" +var githash = "1520326" +var buildstamp = "2021-12-11_02:35:54" +var commits = "253" +var version = "1520326-b253 - 2021-12-11_02:35:54"