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{}
err = json.Unmarshal(d.Body, &x)
logOnError(err, "MQKeepAliveWorker : Can't unmarshal.\n"+string(d.Body))
log.Printf("MQKeepAliveWorker : Received message :\n%s", string(d.Body))
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()) {
// outdated keep-alive coming from client
} else if clt, ok := getLockedClient(x.TGUserID64, true); ok {
clt.HeartBeat = x.Date
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()
} else {
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.Password = cfg.Rabbit.Password
clt.MQ.Host = cfg.Rabbit.Host
@ -202,26 +201,34 @@ func MQKeepAliveWorker() {
clt.MQ.Connection.Close()
} else {
clt.Active = true
log.Printf("MQKeepAliveWorker : Connected to %s.\n", x.Nickname)
//log.Printf("MQKeepAliveWorker : Connected to %s.\n", x.Nickname)
}
}
}
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{
Type: commandSendMsg,
ToUserID64: x.TGUserID64,
Text: "Your client is connected.",
clientSendCWMsg(x.TGUserID64, `🏅Me`)
} else {
c = TGCommand{
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
clt.Active = false
} 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 {
log.Printf("MQTidyKeepAliveWorker : Client %s is inactive.\n", clt.Login)
//log.Printf("MQTidyKeepAliveWorker : Client %s is inactive.\n", clt.Login)
}
clt.Mux.Unlock()
}