add daily stats and color
This commit is contained in:
parent
15203263e6
commit
0bfa4461ba
@ -41,6 +41,7 @@ type ClientConfig struct {
|
|||||||
TimeLeft time.Duration `json:"time_left"`
|
TimeLeft time.Duration `json:"time_left"`
|
||||||
CompanyID uint8 `json:"company_id`
|
CompanyID uint8 `json:"company_id`
|
||||||
Ready bool `json:"ready"`
|
Ready bool `json:"ready"`
|
||||||
|
Color string `json:"color"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
16
stats.go
16
stats.go
@ -30,11 +30,13 @@ type StatMonthly struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type StatDaily struct {
|
type StatDaily struct {
|
||||||
Money int64
|
CompanyID uint8
|
||||||
Loan int64
|
Date time.Time
|
||||||
Value int64
|
Money int64
|
||||||
Trains int
|
Loan int64
|
||||||
Road int
|
Value int64
|
||||||
Planes int
|
Train int
|
||||||
Ships int
|
Road int
|
||||||
|
Plane int
|
||||||
|
Ship int
|
||||||
}
|
}
|
||||||
|
35
ttd.go
35
ttd.go
@ -25,7 +25,6 @@ type CompanyTTD struct {
|
|||||||
CompanyID uint8
|
CompanyID uint8
|
||||||
CompanyExtlID int64
|
CompanyExtlID int64
|
||||||
Name string
|
Name string
|
||||||
Value int64
|
|
||||||
Protected bool
|
Protected bool
|
||||||
ClientID uint32
|
ClientID uint32
|
||||||
FirstSeen time.Time
|
FirstSeen time.Time
|
||||||
@ -526,15 +525,45 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
|
|||||||
Packet: p,
|
Packet: p,
|
||||||
}
|
}
|
||||||
sp.Read(buffer[:p.PLength])
|
sp.Read(buffer[:p.PLength])
|
||||||
r := regexp.MustCompile("#:(?P<CompanyID>[0-9]+)\\(.*\\) Company Name: '(?P<CompanyName>.+)'.*Value: (?P<CompanyValue>[0-9]+)( )+.*$")
|
r := regexp.MustCompile("#:(?P<CompanyID>[0-9]+)\\((?P<Color>[a-zA-Z]+)\\) Company Name: '(?P<CompanyName>.+)'.*Money: (?P<Money>[0-9]+).*Loan: (?P<Loan>[0-9]*).*Value: (?P<Value>[0-9]+).* \\(T:(?P<Train>[0-9]+), R:(?P<Road>[0-9]+), P:(?P<Plane>[0-9]+), S:(?P<Ship>[0-9]+)\\).*$")
|
||||||
if r.MatchString(sp.Output) {
|
if r.MatchString(sp.Output) {
|
||||||
|
coID := uint8(0)
|
||||||
for _, co := range srv.Status.Companies {
|
for _, co := range srv.Status.Companies {
|
||||||
if co.Name == r.ReplaceAllString(sp.Output, "${CompanyName}") {
|
if co.Name == r.ReplaceAllString(sp.Output, "${CompanyName}") {
|
||||||
co.CompanyExtlID, _ = strconv.ParseInt(r.ReplaceAllString(sp.Output, "${CompanyID}"), 10, 64)
|
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
|
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<ClientID>[0-9]+).*name: '(?P<ClientName>.+)'.*company: (?P<CompanyID>[0-9]+)( )+IP: .*$")
|
r = regexp.MustCompile("Client #(?P<ClientID>[0-9]+).*name: '(?P<ClientName>.+)'.*company: (?P<CompanyID>[0-9]+)( )+IP: .*$")
|
||||||
if r.MatchString(sp.Output) {
|
if r.MatchString(sp.Output) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// Code generated by version.sh (@generated) DO NOT EDIT.
|
// Code generated by version.sh (@generated) DO NOT EDIT.
|
||||||
package main
|
package main
|
||||||
var githash = "7590355"
|
var githash = "1520326"
|
||||||
var buildstamp = "2021-12-10_13:21:22"
|
var buildstamp = "2021-12-11_02:35:54"
|
||||||
var commits = "252"
|
var commits = "253"
|
||||||
var version = "7590355-b252 - 2021-12-10_13:21:22"
|
var version = "1520326-b253 - 2021-12-11_02:35:54"
|
||||||
|
Loading…
Reference in New Issue
Block a user