add daily stats and color
This commit is contained in:
35
ttd.go
35
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<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) {
|
||||
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<ClientID>[0-9]+).*name: '(?P<ClientName>.+)'.*company: (?P<CompanyID>[0-9]+)( )+IP: .*$")
|
||||
if r.MatchString(sp.Output) {
|
||||
|
||||
Reference in New Issue
Block a user