fix client config cleanup

This commit is contained in:
shoopea 2021-11-26 08:29:09 +08:00
parent 07c2ea7adb
commit d09710eb3d
3 changed files with 13 additions and 18 deletions

12
bot.go
View File

@ -204,13 +204,19 @@ func botPlayers(m *tb.Message) {
online := ""
for _, cc := range cfg.Clients {
if cc.Online {
online = online + fmt.Sprintf(" - %s (%s) : %s", cc.Username, cc.TimeLeft, srv.Status.Companies[cc.CompanyID].Name) + "\r\n"
if co, ok := srv.Status.Companies[cc.CompanyID]; ok {
online = online + fmt.Sprintf(" - %s (%s) : %s", cc.Username, cc.TimeLeft, co.Name) + "\r\n"
} else {
online = online + fmt.Sprintf(" - %s (none) : %s", cc.Username, cc.TimeLeft) + "\r\n"
}
}
}
offline := ""
for _, cc := range cfg.Clients {
if _, ok := srv.Status.Companies[cc.CompanyID]; ok && !cc.Online {
offline = offline + fmt.Sprintf(" - %s (%s) : %s", cc.Username, cc.TimeLeft, srv.Status.Companies[cc.CompanyID].Name) + "\r\n"
if co, ok := srv.Status.Companies[cc.CompanyID]; ok && !cc.Online {
offline = offline + fmt.Sprintf(" - %s (%s) : %s", cc.Username, cc.TimeLeft, co.Name) + "\r\n"
} else {
offline = offline + fmt.Sprintf(" - %s (none) : %s", cc.Username, cc.TimeLeft) + "\r\n"
}
}

11
ttd.go
View File

@ -138,7 +138,6 @@ func (s *ServerTTD) HeartBeat(stop chan struct{}) {
s.UpdateDate()
s.UpdateClients()
s.UpdateCompanies()
s.UpdateConfigClients()
s.PruneClients()
s.PruneCompanies()
s.ComputeClientTime()
@ -566,16 +565,6 @@ func (s *ServerTTD) UpdateCompanies() {
s.Status.UpdateCompanies = time.Now()
}
func (s *ServerTTD) UpdateConfigClients() {
for _, cc := range cfg.Clients {
if cc.CompanyID != 255 {
if _, ok := srv.Status.Companies[cc.CompanyID]; !ok {
cc.CompanyID = 255
}
}
}
}
func (s *ServerTTD) PruneClients() {
for cltID, clt := range s.Status.Clients {
if clt.LastSeen.Add(2 * updateHeartBeat).Before(time.Now()) {

View File

@ -1,6 +1,6 @@
// Code generated by version.sh (@generated) DO NOT EDIT.
package main
var githash = "d312644"
var buildstamp = "2021-11-26_00:22:05"
var commits = "205"
var version = "d312644-b205 - 2021-11-26_00:22:05"
var githash = "07c2ea7"
var buildstamp = "2021-11-26_00:28:51"
var commits = "206"
var version = "07c2ea7-b206 - 2021-11-26_00:28:51"