From d09710eb3de881fb365da77b85b9d7191a746a55 Mon Sep 17 00:00:00 2001 From: shoopea Date: Fri, 26 Nov 2021 08:29:09 +0800 Subject: [PATCH] fix client config cleanup --- bot.go | 12 +++++++++--- ttd.go | 11 ----------- version.go | 8 ++++---- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/bot.go b/bot.go index e29720b..20350ec 100644 --- a/bot.go +++ b/bot.go @@ -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" } } diff --git a/ttd.go b/ttd.go index ae0f9f0..72b982d 100644 --- a/ttd.go +++ b/ttd.go @@ -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()) { diff --git a/version.go b/version.go index 97bbd46..7d445f4 100644 --- a/version.go +++ b/version.go @@ -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"