From e185eff5780ef5aaec67ca0156b9ef26de6a4c6c Mon Sep 17 00:00:00 2001 From: shoopea Date: Wed, 10 Nov 2021 13:41:37 +0800 Subject: [PATCH] update --- bot.go | 35 +++++++++++++++++++++++++---------- ttd.go | 10 ++++++++++ version.go | 8 ++++---- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/bot.go b/bot.go index fe892e2..43bda76 100644 --- a/bot.go +++ b/bot.go @@ -188,17 +188,32 @@ func botPasswd(m *tb.Message) { bot.SendChat(m.Chat.ID, "User not registered.") return } - r := regexp.MustCompile("^\\/passwd( )+(?P[^ ]+)$") - if r.MatchString(m.Text) { - // we have a parameter - passwd := r.ReplaceAllString(m.Text, "${Passwd}") - cc.Passwd = passwd - bot.SendUser(int64(m.Sender.ID), fmt.Sprintf("Passwd set to \"%s\"", passwd)) - err := bot.bot.Delete(m) - logErrorDebug(err, "botPasswd : Delete") - } else { - bot.SendChat(m.Chat.ID, "No passwd provided") + if cc.CompanyID == 255 { + bot.SendChat(m.Chat.ID, "No company registered.") + return } + co, ok := srv.Status.Companies[cc.CompanyID] + if !ok { + bot.SendChat(m.Chat.ID, "Registered company doesn't exist.") + cc.CompanyID = 255 + return + } + + r := regexp.MustCompile("^\\/passwd( )+(?P[^ ]+)$") + if !r.MatchString(m.Text) { + bot.SendChat(m.Chat.ID, "No passwd provided") + return + } + // we have a parameter + cc.Passwd = r.ReplaceAllString(m.Text, "${Passwd}") + + err := bot.bot.Delete(m) + logErrorDebug(err, "botPasswd : Delete") + + srv.SetPasswd(co.CompanyID, cc.Passwd) + + bot.SendUser(int64(m.Sender.ID), fmt.Sprintf("Passwd set to \"%s\"", cc.Passwd)) + return } diff --git a/ttd.go b/ttd.go index 35a1e64..4f8f996 100644 --- a/ttd.go +++ b/ttd.go @@ -735,3 +735,13 @@ func (s *ServerTTD) Initialize() { s.UpdateCompanies() s.UpdateClients() } + +func (s *ServerTTD) SetPasswd(id uint8, passwd string) { + px := PacketAdminRCon{ + Packet: Packet{PType: AdminPacketAdminRCon}, + Command: fmt.Sprintf("company_pw %d %s", id, passwd), + } + err := s.Send(px.Bytes()) + logErrorDebug(err, "Server.SetPasswd() : Send(AdminPacketAdminRCon)") + return +} diff --git a/version.go b/version.go index 4aa0c99..ef8dd9e 100644 --- a/version.go +++ b/version.go @@ -1,6 +1,6 @@ // Code generated by version.sh (@generated) DO NOT EDIT. package main -var githash = "8d58018" -var buildstamp = "2021-11-10_04:56:39" -var commits = "177" -var version = "8d58018-b177 - 2021-11-10_04:56:39" +var githash = "4772cd7" +var buildstamp = "2021-11-10_05:41:24" +var commits = "179" +var version = "4772cd7-b179 - 2021-11-10_05:41:24"