fix client revamping

This commit is contained in:
shoopea 2019-07-31 15:43:17 +08:00
parent c71bd20e5a
commit c0cae8c491

View File

@ -159,19 +159,18 @@ func MQKeepAliveWorker() {
x := MQKeepAlive{} x := MQKeepAlive{}
err = json.Unmarshal(d.Body, &x) err = json.Unmarshal(d.Body, &x)
logOnError(err, "MQKeepAliveWorker : Can't unmarshal.\n"+string(d.Body)) logOnError(err, "MQKeepAliveWorker : Can't unmarshal.\n"+string(d.Body))
log.Printf("MQKeepAliveWorker : Received message :\n%s", string(d.Body))
if err == nil { if err == nil {
log.Printf("MQKeepAliveWorker : Received message from %s (%d).\n", x.Nickname, x.TGUserID64) //log.Printf("MQKeepAliveWorker : Received message from %s (%d).\n", x.Nickname, x.TGUserID64)
if x.Date.Add(10 * time.Second).Before(time.Now()) { if x.Date.Add(10 * time.Second).Before(time.Now()) {
// outdated keep-alive coming from client // outdated keep-alive coming from client
} else if clt, ok := getLockedClient(x.TGUserID64, true); ok { } else if clt, ok := getLockedClient(x.TGUserID64, true); ok {
clt.HeartBeat = x.Date clt.HeartBeat = x.Date
if clt.Active { if clt.Active {
log.Printf("MQKeepAliveWorker : Client %s (%d) already active.\n", clt.Login, clt.TGUserID64) //log.Printf("MQKeepAliveWorker : Client %s (%d) already active.\n", clt.Login, clt.TGUserID64)
clt.Mux.Unlock() clt.Mux.Unlock()
} else { } else {
clt.Login = x.Nickname clt.Login = x.Nickname
log.Printf("MQKeepAliveWorker : Connecting to %s (%d).\n", clt.Login, clt.TGUserID64) //log.Printf("MQKeepAliveWorker : Connecting to %s (%d).\n", clt.Login, clt.TGUserID64)
clt.MQ.User = cfg.Rabbit.User clt.MQ.User = cfg.Rabbit.User
clt.MQ.Password = cfg.Rabbit.Password clt.MQ.Password = cfg.Rabbit.Password
clt.MQ.Host = cfg.Rabbit.Host clt.MQ.Host = cfg.Rabbit.Host
@ -202,26 +201,34 @@ func MQKeepAliveWorker() {
clt.MQ.Connection.Close() clt.MQ.Connection.Close()
} else { } else {
clt.Active = true clt.Active = true
log.Printf("MQKeepAliveWorker : Connected to %s.\n", x.Nickname) //log.Printf("MQKeepAliveWorker : Connected to %s.\n", x.Nickname)
} }
} }
} }
clt.Mux.Unlock() clt.Mux.Unlock()
if clt.Active {
c := TGCommand{
Type: commandSendMsg,
ToUserID64: x.TGUserID64,
Text: "Your client is connected.",
}
TGCmdQueue <- c
c = TGCommand{
Type: commandSendMsg,
ToUserID64: cfg.Bot.Admin,
Text: fmt.Sprintf("Client `%s` is connected.", x.Nickname),
}
TGCmdQueue <- c
c := TGCommand{ clientSendCWMsg(x.TGUserID64, `🏅Me`)
Type: commandSendMsg, } else {
ToUserID64: x.TGUserID64, c = TGCommand{
Text: "Your client is connected.", Type: commandSendMsg,
ToUserID64: cfg.Bot.Admin,
Text: fmt.Sprintf("Cannot connect to client `%s`.", x.Nickname),
}
TGCmdQueue <- c
} }
TGCmdQueue <- c
c = TGCommand{
Type: commandSendMsg,
ToUserID64: cfg.Bot.Admin,
Text: fmt.Sprintf("Client `%s` is connected.", x.Nickname),
}
TGCmdQueue <- c
clientSendCWMsg(x.TGUserID64, `🏅Me`)
} }
} }
} }
@ -596,9 +603,9 @@ func MQTidyKeepAliveWorker() {
TGCmdQueue <- cmd TGCmdQueue <- cmd
clt.Active = false clt.Active = false
} else if clt.Active { } else if clt.Active {
log.Printf("MQTidyKeepAliveWorker : Client %s is active.\n", clt.Login) //log.Printf("MQTidyKeepAliveWorker : Client %s is active.\n", clt.Login)
} else { } else {
log.Printf("MQTidyKeepAliveWorker : Client %s is inactive.\n", clt.Login) //log.Printf("MQTidyKeepAliveWorker : Client %s is inactive.\n", clt.Login)
} }
clt.Mux.Unlock() clt.Mux.Unlock()
} }