This commit is contained in:
shoopea 2019-06-10 12:03:47 +08:00
parent 072056a5c0
commit 8935240d68
4 changed files with 65 additions and 3 deletions

26
job.go
View File

@ -359,6 +359,32 @@ func jobPillage(j Job) {
return
}
func jobMsgRefresh(j Job) {
var p JobPayloadMsgRefresh
err := setJobStart(j.ID64)
logOnError(err, "jobMsgRefresh : setJobStart")
err = json.Unmarshal(j.Payload, &p)
logOnError(err, "jobMsgRefresh : Unmarshal payload")
m, err := getObjMsg(p.ObjID64)
logOnError(err, "jobMsgRefresh : getObjMsg")
err = delObj(p.ObjID64)
logOnError(err, "jobMsgRefresh : delObj")
c := TGCommand{
Type: commandRefreshMsg,
FromChatID64: m.ChatID64,
FromMsgID64: m.ID64,
}
MQTGCmdQueue <- c
err = setJobDone(j.ID64)
logOnError(err, "joMsgClient : setJobDone")
return
}
func jobMsgClient(j Job) {
var p JobPayloadMsgClient
err := setJobStart(j.ID64)

33
obj.go
View File

@ -156,6 +156,39 @@ func loadObjMsg() error {
return nil
}
func delObj(objId int64) error {
objSubTypeId, err := getObjSubTypeId(objId)
if err != nil {
return err
}
if objSubTypeId != objSubTypeMessageAuctionAnnounce {
return errors.New("Can only delete objSubTypeMessageAuctionAnnounce.")
}
stmt, err := db.Prepare(`DELETE FROM obj o WHERE o.id = ?`)
if err != nil {
return err
}
defer stmt.Close()
res, err := stmt.Exec(objId)
if err != nil {
return err
}
count, err := res.RowsAffected()
if err != nil {
return err
}
log.Printf("delObj : %d RowsAffected.\n", count)
cacheObjMsg.Delete(objId)
return nil
}
func addObjCastle(logo string, name string) (int64, error) {
tx, err := db.Begin()
logOnError(err, "addObjCastle : start transaction")

View File

@ -124,6 +124,7 @@ func resetMsgParsingRules() {
`.Level: (?P<Level>[0-9]+)\\n` +
`.Atk: (?P<Atk>[0-9]+) .Def: (?P<Def>[0-9]+)\\n` +
`.Exp: (?P<ExpNow>[0-9]+)/(?P<ExpLvl>[0-9]+)\\n` +
`(.Hp: (?P<HPNow>[0-9]+)/(?P<HPMax>[0-9]+).*\\n){0,1}` +
`.Stamina: (?P<StaminaNow>[0-9]+)/(?P<StaminaMax>[0-9]+).*\\n` +
`(.(?P<Gold>(-){0,1}[0-9]+)){0,1}( .(?P<Pogs>[0-9]+)){0,1}( .(?P<Gems>[0-9]+)){0,1}\\n\\n` +
`(.*?)(🎽Equipment \\+(?P<AtkGear>[0-9]+).\\+(?P<DefGear>[0-9]+).){0,1}\\n` +

View File

@ -233,6 +233,8 @@ func JobWorker(id int, jobs <-chan Job) {
jobPillage(j)
case objSubTypeJobMsgClient:
jobMsgClient(j)
case objSubTypeJobMsgRefresh:
jobMsgRefresh(j)
default:
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID)
}
@ -305,10 +307,10 @@ func MQTGCmdWorker(id int, cmds <-chan TGCommand) {
logOnError(err, "MQTGCmdWorker["+strconv.Itoa(id)+"] : Marshal(c)")
log.Printf("MQTGCmdWorker["+strconv.Itoa(id)+"] : new command.\n%s\n", string(j))
err = clientsQueue[c.FromUserID64].Channel.Publish(
"", // exchange
"", // exchange
clientsQueue[c.FromUserID64].Queue.Name, // routing key
false, // mandatory
false, // immediate
false, // mandatory
false, // immediate
amqp.Publishing{
ContentType: "application/json",
Body: []byte(j),