add stats daily
This commit is contained in:
40
ttd.go
40
ttd.go
@@ -224,6 +224,11 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
|
||||
}
|
||||
s.Status.GameDate = gameDate
|
||||
s.Status.UpdateDate = time.Now()
|
||||
px := PacketAdminRCon{
|
||||
Packet: Packet{PType: AdminPacketAdminRCon},
|
||||
Command: "companies",
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
case AdminPacketServerClientJoin:
|
||||
sp := PacketServerClientJoin{
|
||||
Packet: p,
|
||||
@@ -384,23 +389,23 @@ 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 {
|
||||
cfg.Stats = make(map[int]map[string]*Stat)
|
||||
if cfg.StatsMonthly == nil {
|
||||
cfg.StatsMonthly = make(map[int]map[string]*StatMonthly)
|
||||
}
|
||||
|
||||
if cfg.CompanyIsRegistered(sp.CompanyID) {
|
||||
cc := cfg.GetCompanyClient(sp.CompanyID)
|
||||
_, ok := cfg.Stats[cc.UserID]
|
||||
_, ok := cfg.StatsMonthly[cc.UserID]
|
||||
if !ok {
|
||||
cfg.Stats[cc.UserID] = make(map[string]*Stat)
|
||||
cfg.StatsMonthly[cc.UserID] = make(map[string]*StatMonthly)
|
||||
}
|
||||
stats, ok := cfg.Stats[cc.UserID][s.Status.GameDate.Format("20060102")]
|
||||
stats, ok := cfg.StatsMonthly[cc.UserID][s.Status.GameDate.Format("20060102")]
|
||||
if !ok {
|
||||
stats = &Stat{
|
||||
stats = &StatMonthly{
|
||||
CompanyID: sp.CompanyID,
|
||||
Date: s.Status.GameDate,
|
||||
}
|
||||
cfg.Stats[cc.UserID][s.Status.GameDate.Format("20060102")] = stats
|
||||
cfg.StatsMonthly[cc.UserID][s.Status.GameDate.Format("20060102")] = stats
|
||||
}
|
||||
|
||||
stats.Money = int64(sp.Money)
|
||||
@@ -421,23 +426,23 @@ 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 {
|
||||
cfg.Stats = make(map[int]map[string]*Stat)
|
||||
if cfg.StatsMonthly == nil {
|
||||
cfg.StatsMonthly = make(map[int]map[string]*StatMonthly)
|
||||
}
|
||||
|
||||
if cfg.CompanyIsRegistered(sp.CompanyID) {
|
||||
cc := cfg.GetCompanyClient(sp.CompanyID)
|
||||
_, ok := cfg.Stats[cc.UserID]
|
||||
_, ok := cfg.StatsMonthly[cc.UserID]
|
||||
if !ok {
|
||||
cfg.Stats[cc.UserID] = make(map[string]*Stat)
|
||||
cfg.StatsMonthly[cc.UserID] = make(map[string]*StatMonthly)
|
||||
}
|
||||
stats, ok := cfg.Stats[cc.UserID][s.Status.GameDate.Format("20060102")]
|
||||
stats, ok := cfg.StatsMonthly[cc.UserID][s.Status.GameDate.Format("20060102")]
|
||||
if !ok {
|
||||
stats = &Stat{
|
||||
stats = &StatMonthly{
|
||||
CompanyID: sp.CompanyID,
|
||||
Date: s.Status.GameDate,
|
||||
}
|
||||
cfg.Stats[cc.UserID][s.Status.GameDate.Format("20060102")] = stats
|
||||
cfg.StatsMonthly[cc.UserID][s.Status.GameDate.Format("20060102")] = stats
|
||||
}
|
||||
|
||||
stats.Trains = int(sp.Trains)
|
||||
@@ -851,7 +856,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateDate)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateDate")
|
||||
|
||||
px = PacketAdminUpdateFrequency{
|
||||
Packet: Packet{PType: AdminPacketAdminUpdateFrequency},
|
||||
@@ -860,7 +864,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateClientInfo)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateClientInfo")
|
||||
|
||||
px = PacketAdminUpdateFrequency{
|
||||
Packet: Packet{PType: AdminPacketAdminUpdateFrequency},
|
||||
@@ -869,7 +872,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateCompanyInfo)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateCompanyInfo")
|
||||
|
||||
px = PacketAdminUpdateFrequency{
|
||||
Packet: Packet{PType: AdminPacketAdminUpdateFrequency},
|
||||
@@ -878,7 +880,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateCompanyEconomy)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateCompanyEconomy")
|
||||
|
||||
px = PacketAdminUpdateFrequency{
|
||||
Packet: Packet{PType: AdminPacketAdminUpdateFrequency},
|
||||
@@ -887,7 +888,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateCompanyStats)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateCompanyStats")
|
||||
|
||||
px = PacketAdminUpdateFrequency{
|
||||
Packet: Packet{PType: AdminPacketAdminUpdateFrequency},
|
||||
@@ -896,7 +896,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateChat)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateChat")
|
||||
|
||||
px = PacketAdminUpdateFrequency{
|
||||
Packet: Packet{PType: AdminPacketAdminUpdateFrequency},
|
||||
@@ -905,7 +904,6 @@ func (s *ServerTTD) Initialize() {
|
||||
}
|
||||
err = s.Send(px.Bytes())
|
||||
failError(err, "Server.Initialize() : Send(AdminUpdateConsole)")
|
||||
logInfoDebug("Server.Initialize : AdminUpdateConsole")
|
||||
|
||||
s.Status.Initialized = true
|
||||
|
||||
|
||||
Reference in New Issue
Block a user