Revert "test"

This reverts commit b98069f4ba.
This commit is contained in:
shoopea 2019-06-28 15:54:54 +08:00
parent c2a12b880e
commit afa8b181ae

View File

@ -62,7 +62,6 @@ func MQGetMsgWorker(id int, msgs chan<- ChatWarsMessage) {
msgs <- x msgs <- x
} }
} }
log.Printf("MQGetMsgWorker[" + strconv.Itoa(id) + "] : Closing queue.\n")
s.Close() s.Close()
} }
@ -92,74 +91,76 @@ func MQKeepAliveWorker() {
log.Printf("MQKeepAliveWorker : Session address : %p.\n", &s) log.Printf("MQKeepAliveWorker : Session address : %p.\n", &s)
log.Printf("MQKeepAliveWorker : Connection address : %p.\n", &s.MQConnection) log.Printf("MQKeepAliveWorker : Connection address : %p.\n", &s.MQConnection)
log.Printf("MQKeepAliveWorker : Channel address : %p.\n", &s.MQChannel) log.Printf("MQKeepAliveWorker : Channel address : %p.\n", &s.MQChannel)
/* q, err := s.MQChannel.QueueDeclare(
q, err := s.MQChannel.QueueDeclare( s.Queue, // name
s.Queue, // name false, // durable
false, // durable false, // delete when unused
false, // delete when unused false, // exclusive
false, // exclusive false, // no-wait
false, // no-wait nil, // arguments
nil, // arguments
) )
m, err := s.MQChannel.Consume( m, err := s.MQChannel.Consume(
q.Name, // queue q.Name, // queue
"", // consumer "", // consumer
true, // auto-ack true, // auto-ack
false, // exclusive false, // exclusive
false, // no-local false, // no-local
false, // no-wait false, // no-wait
nil, // args nil, // args
) )
for d := range m {
log.Printf("MQKeepAliveWorker : Received a message: %s", string(d.Body))
for d := range m { x := MQKeepAlive{}
log.Printf("MQKeepAliveWorker : Received a message: %s", string(d.Body)) err = json.Unmarshal(d.Body, &x)
x := MQKeepAlive{} logOnError(err, "MQKeepAliveWorker : Can't unmarshal.\n"+string(d.Body))
err = json.Unmarshal(d.Body, &x) if err == nil {
logOnError(err, "MQKeepAliveWorker : Can't unmarshal.\n"+string(d.Body)) if x.Date.Add(10 * time.Second).Before(time.Now()) {
if err == nil { // outdated keep-alive coming from client
if x.Date.Add(10 * time.Second).Before(time.Now()) { } else if v, ok := clientsKeepAlive.Load(x.UserID64); ok {
// outdated keep-alive coming from client k := v.(*MQKeepAlive)
} else if v, ok := clientsKeepAlive.Load(x.UserID64); ok { k.Date = x.Date
k := v.(*MQKeepAlive) } else {
k.Date = x.Date cs := MQSession{
} else { User: cfg.Rabbit.User,
cs := MQSession{ Password: cfg.Rabbit.Password,
User: cfg.Rabbit.User, Host: cfg.Rabbit.Host,
Password: cfg.Rabbit.Password, Path: x.Queue,
Host: cfg.Rabbit.Host, SSL: false,
Path: x.Queue, Queue: "msg",
SSL: false, isConnected: false,
Queue: "msg",
isConnected: false,
}
err = cs.Open()
logOnError(err, "MQKeepAliveWorker : Failed to open MQ session")
clientsKeepAlive.Store(x.UserID64, &x)
clientsQueue[x.UserID64] = &cs
c := TGCommand{
Type: commandSendMsg,
ToUserID64: x.UserID64,
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
clientSendCWMsg(x.UserID64, `🏅Me`)
clientSendCWMsg(x.UserID64, `/hero`)
} }
err = cs.Open()
logOnError(err, "MQKeepAliveWorker : Failed to open MQ session")
clientsKeepAlive.Store(x.UserID64, &x)
clientsQueue[x.UserID64] = &cs
c := TGCommand{
Type: commandSendMsg,
ToUserID64: x.UserID64,
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
clientSendCWMsg(x.UserID64, `🏅Me`)
/*
c = TGCommand{
Type: commandSendMsg,
FromUserID64: x.UserID64,
ToChatID64: userID64ChtWrsBot,
Text: `/hero`,
}
MQTGCmdQueue <- c
*/
} }
} }
*/ }
s.Close()
log.Printf("MQKeepAliveWorker : Closing queue.\n")
} }
log.Printf("MQKeepAliveWorker : Closing.") log.Printf("MQKeepAliveWorker : Closing.")