add client extl id and fix setpasswd

This commit is contained in:
shoopea 2021-11-10 14:43:55 +08:00
parent bcc20d3402
commit b43caf02a9
3 changed files with 16 additions and 7 deletions

2
bot.go
View File

@ -210,7 +210,7 @@ func botPasswd(m *tb.Message) {
err := bot.bot.Delete(m) err := bot.bot.Delete(m)
logErrorDebug(err, "botPasswd : Delete") logErrorDebug(err, "botPasswd : Delete")
srv.SetPasswd(co.CompanyID, cc.Passwd) srv.SetPasswd(co.CompanyExtlID, cc.Passwd)
bot.SendUser(int64(m.Sender.ID), fmt.Sprintf("Passwd set to \"%s\"", cc.Passwd)) bot.SendUser(int64(m.Sender.ID), fmt.Sprintf("Passwd set to \"%s\"", cc.Passwd))

13
ttd.go
View File

@ -447,7 +447,7 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
Packet: p, Packet: p,
} }
sp.Read(buffer[:p.PLength]) sp.Read(buffer[:p.PLength])
r := regexp.MustCompile("#:(?P<CompanyID>[0-9]+)\\(.*\\) Company Name: '(?P<CompanyName>.+)'.*Value: (?P<CompanyValue>[0-9]+)( )+.*") r := regexp.MustCompile("#:(?P<CompanyID>[0-9]+)\\(.*\\) Company Name: '(?P<CompanyName>.+)'.*Value: (?P<CompanyValue>[0-9]+)( )+.*$")
if r.MatchString(sp.Output) { if r.MatchString(sp.Output) {
for _, co := range srv.Status.Companies { for _, co := range srv.Status.Companies {
if co.Name == r.ReplaceAllString(sp.Output, "${CompanyName}") { if co.Name == r.ReplaceAllString(sp.Output, "${CompanyName}") {
@ -457,6 +457,15 @@ func (s *ServerTTD) Poll(stop chan struct{}) {
} }
} }
} }
r = regexp.MustCompile("Client #(?P<ClientID>[0-9]+).*name: '(?P<ClientName>.+)'.*company: (?P<CompanyID>[0-9]+)( )+IP: .*$")
if r.MatchString(sp.Output) {
for _, c := range srv.Status.Clients {
if c.Name == r.ReplaceAllString(sp.Output, "${ClientName}") {
c.ClientExtlID, _ = strconv.ParseInt(r.ReplaceAllString(sp.Output, "${ClientID}"), 10, 64)
break
}
}
}
logInfoDebug("Server.Poll() : AdminPacketServerRCon :\n- ColorID: %d\n- Output: %s", sp.ColorID, sp.Output) logInfoDebug("Server.Poll() : AdminPacketServerRCon :\n- ColorID: %d\n- Output: %s", sp.ColorID, sp.Output)
case AdminPacketServerRConEnd: case AdminPacketServerRConEnd:
@ -778,7 +787,7 @@ func (s *ServerTTD) Initialize() {
s.UpdateClients() s.UpdateClients()
} }
func (s *ServerTTD) SetPasswd(id uint8, passwd string) { func (s *ServerTTD) SetPasswd(id int64, passwd string) {
px := PacketAdminRCon{ px := PacketAdminRCon{
Packet: Packet{PType: AdminPacketAdminRCon}, Packet: Packet{PType: AdminPacketAdminRCon},
Command: fmt.Sprintf("company_pw %d %s", id, passwd), Command: fmt.Sprintf("company_pw %d %s", id, passwd),

View File

@ -1,6 +1,6 @@
// Code generated by version.sh (@generated) DO NOT EDIT. // Code generated by version.sh (@generated) DO NOT EDIT.
package main package main
var githash = "6e092ea" var githash = "bcc20d3"
var buildstamp = "2021-11-10_06:35:44" var buildstamp = "2021-11-10_06:41:59"
var commits = "183" var commits = "184"
var version = "6e092ea-b183 - 2021-11-10_06:35:44" var version = "bcc20d3-b184 - 2021-11-10_06:41:59"