From acf58c99eff798cd7093ce43fb0f1ea9fc5be9b3 Mon Sep 17 00:00:00 2001 From: shoopea Date: Sat, 4 Dec 2021 13:39:15 +0800 Subject: [PATCH] final start/reset touches --- bot.go | 14 ++++++++++++-- main.go | 4 +--- ttd.go | 10 ---------- version.go | 8 ++++---- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/bot.go b/bot.go index 1b2cdc3..815cfb7 100644 --- a/bot.go +++ b/bot.go @@ -284,6 +284,12 @@ func botActuallyReset(m *tb.Message) { bot.SendChat(m.Chat.ID, "Request expired.") } else { cfg.Game.Started = false + for _, cc := range cfg.Clients { + cc.Ready = false + cc.CompanyID = 255 + cc.Online = false + cc.TimeLeft = 0 + } bot.SendChat(m.Chat.ID, "Game resetted.") } delete(botActionMap, ref) @@ -350,6 +356,7 @@ func botActuallyStart(m *tb.Message) { cfg.Game.StartDate = time.Now() for _, cc := range cfg.Clients { cc.Ready = true + cc.TimeLeft = cfg.Game.StartingAllotment } bot.SendChat(m.Chat.ID, "Game started !") } @@ -745,6 +752,7 @@ func botRegister(m *tb.Message) { Username: m.Sender.Username, CompanyID: 255, TimeLeft: 0, + Ready: cfg.Game.Started, } cfg.Clients[m.Sender.ID] = cc } else { @@ -809,11 +817,13 @@ func botRegister(m *tb.Message) { if len(coList) == 1 { for id, _ := range coList { cc.CompanyID = id - if cc.TimeLeft == 0 { + if cc.TimeLeft == 0 && cfg.Game.Started { days := int(time.Now().Sub(cfg.Game.StartDate).Hours() / 24) cc.TimeLeft = cfg.Game.StartingAllotment + cfg.Game.DailyAllotment*time.Duration(days) + bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s registered %s (with %s playable)", cc.Username, srv.Status.Companies[cc.CompanyID].Name, cc.TimeLeft.Round(time.Second))) + } else { + bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s registered %s", cc.Username, srv.Status.Companies[cc.CompanyID].Name)) } - bot.SendChat(m.Chat.ID, fmt.Sprintf("@%s registered %s (with %s playable)", cc.Username, srv.Status.Companies[cc.CompanyID].Name, cc.TimeLeft.Round(time.Second))) return } } diff --git a/main.go b/main.go index 8692917..5e4cc20 100644 --- a/main.go +++ b/main.go @@ -45,9 +45,7 @@ func main() { srv = &ServerTTD{ Config: cfg.Server, - Data: &ServerDataTTD{ - Started: cfg.Game.Started, - }, + Data: &ServerDataTTD{}, Status: &ServerStatusTTD{}, } go srv.Start() diff --git a/ttd.go b/ttd.go index a5ff402..fbf7528 100644 --- a/ttd.go +++ b/ttd.go @@ -54,7 +54,6 @@ type ServerDataTTD struct { LastClientCompute time.Time Conn net.Conn Stop chan struct{} - Started bool } var updateHeartBeat = 5 * time.Second @@ -594,15 +593,6 @@ 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 } diff --git a/version.go b/version.go index 4084be0..c7c3570 100644 --- a/version.go +++ b/version.go @@ -1,6 +1,6 @@ // Code generated by version.sh (@generated) DO NOT EDIT. package main -var githash = "00d4b86" -var buildstamp = "2021-12-04_05:24:10" -var commits = "212" -var version = "00d4b86-b212 - 2021-12-04_05:24:10" +var githash = "84579af" +var buildstamp = "2021-12-04_05:35:59" +var commits = "213" +var version = "84579af-b213 - 2021-12-04_05:35:59"