implement start/reset

This commit is contained in:
shoopea
2021-12-04 13:24:45 +08:00
parent 00d4b8667f
commit 84579af511
4 changed files with 141 additions and 70 deletions

18
ttd.go
View File

@@ -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 ""
}