implement start/reset
This commit is contained in:
18
ttd.go
18
ttd.go
@@ -54,6 +54,7 @@ type ServerDataTTD struct {
|
||||
LastClientCompute time.Time
|
||||
Conn net.Conn
|
||||
Stop chan struct{}
|
||||
Started bool
|
||||
}
|
||||
|
||||
var updateHeartBeat = 5 * time.Second
|
||||
@@ -591,6 +592,20 @@ func (s *ServerTTD) PruneCompanies() {
|
||||
|
||||
func (s *ServerTTD) ComputeClientTime() {
|
||||
t := time.Now()
|
||||
if !cfg.Game.Started {
|
||||
s.Data.LastClientCompute = t
|
||||
s.Data.Started = false
|
||||
return
|
||||
}
|
||||
if !s.Data.Started {
|
||||
for _, cc := range cfg.Clients {
|
||||
cc.TimeLeft = cfg.Game.StartingAllotment
|
||||
}
|
||||
bot.SendChat(cfg.Telegram.ChatID, "Starting allotment credited.")
|
||||
s.Data.Started = true
|
||||
return
|
||||
}
|
||||
|
||||
daysNow := int(t.Sub(cfg.Game.StartDate).Hours() / 24)
|
||||
daysLast := int(s.Data.LastClientCompute.Sub(cfg.Game.StartDate).Hours() / 24)
|
||||
if daysLast != daysNow {
|
||||
@@ -714,6 +729,9 @@ func (s *ServerTTD) NeedPause() bool {
|
||||
}
|
||||
|
||||
func (s *ServerTTD) NeedPauseReason() string {
|
||||
if !cfg.Game.Started {
|
||||
return "game not started"
|
||||
}
|
||||
if !s.Status.Initialized {
|
||||
return ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user