final start/reset touches

This commit is contained in:
shoopea 2021-12-04 13:39:15 +08:00
parent 84579af511
commit acf58c99ef
4 changed files with 17 additions and 19 deletions

14
bot.go
View File

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

View File

@ -45,9 +45,7 @@ func main() {
srv = &ServerTTD{
Config: cfg.Server,
Data: &ServerDataTTD{
Started: cfg.Game.Started,
},
Data: &ServerDataTTD{},
Status: &ServerStatusTTD{},
}
go srv.Start()

10
ttd.go
View File

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

View File

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