This commit is contained in:
shoopea 2020-01-02 19:40:45 +08:00
parent 598bc59c3b
commit 722d278a12

40
job.go
View File

@ -344,17 +344,17 @@ func jobPillage(j Job) {
AND omx.user_id = oj.user_id
AND omx.sender_user_id = ` + strconv.Itoa(userID64ChtWrsBot) + `
AND omx.obj_id = ox.id
AND ox.obj_sub_type_id in (` + strconv.Itoa(cacheObjSubType[`msg_pillage_go`]) +
`, ` + strconv.Itoa(cacheObjSubType[`msg_pillage_timeout`]) +
`, ` + strconv.Itoa(cacheObjSubType[`msg_pillage_loss`]) +
`, ` + strconv.Itoa(cacheObjSubType[`msg_pillage_win`]) + `)
AND ox.obj_sub_type_id in (` + strconv.FormatInt(cacheObjSubType[`msg_pillage_go`], 10) +
`, ` + strconv.FormatInt(cacheObjSubType[`msg_pillage_timeout`], 10) +
`, ` + strconv.FormatInt(cacheObjSubType[`msg_pillage_loss`], 10) +
`, ` + strconv.FormatInt(cacheObjSubType[`msg_pillage_win`], 10) + `)
AND op.id = ` + strconv.FormatInt(r.ObjID64, 10) + `
AND omp.obj_id = op.id
AND omx.date between omp.date AND ADDTIME(omp.date, '0 0:3:30.000000')
ORDER BY CASE ox.obj_sub_type_id WHEN ` + strconv.Itoa(cacheObjSubType[`msg_pillage_win`]) + ` THEN 0
WHEN ` + strconv.Itoa(cacheObjSubType[`msg_pillage_loss`]) + ` THEN 1
WHEN ` + strconv.Itoa(cacheObjSubType[`msg_pillage_timeout`]) + ` THEN 2
WHEN ` + strconv.Itoa(cacheObjSubType[`msg_pillage_go`]) + ` THEN 3
ORDER BY CASE ox.obj_sub_type_id WHEN ` + strconv.FormatInt(cacheObjSubType[`msg_pillage_win`], 10) + ` THEN 0
WHEN ` + strconv.FormatInt(cacheObjSubType[`msg_pillage_loss`], 10) + ` THEN 1
WHEN ` + strconv.FormatInt(cacheObjSubType[`msg_pillage_timeout`], 10) + ` THEN 2
WHEN ` + strconv.FormatInt(cacheObjSubType[`msg_pillage_go`], 10) + ` THEN 3
ELSE 4 END ASC
LIMIT 1;`)
@ -367,7 +367,7 @@ func jobPillage(j Job) {
TGCmdQueue <- s
} else if len(ids) == 1 { // we've got a match, job is done whether we prevented the pillage or not
m, err := getObjMsg(ids[0])
logOnError(err, "jobPillage : getMsg(cacheObjSubType[`msg_pillage_go`], cacheObjSubType[`msg_pillage_timeout`])")
logOnError(err, "jobPillage : getMsg(cacheObjSubType[`msg_pillage_go`], cacheObjSubType[`msg_pillage_timeout`], 10)")
if err == nil {
if m.Date.Add(60 * time.Second).After(time.Now().UTC()) {
msgTypeID64, err := getObjSubTypeId(ids[0])
@ -445,12 +445,12 @@ func jobPillage(j Job) {
and omx.user_id = oj.user_id
and omx.sender_user_id = oj.user_id
and omx.obj_id = ox.id
and ox.obj_sub_type_id =` + strconv.Itoa(cacheObjSubType[`msg_go`]) + `
and ox.obj_sub_type_id =` + strconv.FormatInt(cacheObjSubType[`msg_go`], 10) + `
and omx.date between addtime(oj.schedule, '-30') and oj.schedule;`)
if len(ids) > 0 { // we did, so we reschedule the job to check the outcome and wait
m, err := getObjMsg(ids[0])
logOnError(err, "jobPillage : getMsg(cacheObjSubType[`msg_go`])")
logOnError(err, "jobPillage : getMsg(cacheObjSubType[`msg_go`], 10)")
if err == nil {
s := TGCommand{
Type: commandSendMsg,
@ -460,7 +460,7 @@ func jobPillage(j Job) {
TGCmdQueue <- s
}
err = rescheduleJob(j.ID64, j.Trigger, time.Now().Add(30*time.Second).UTC())
logOnError(err, "jobPillage : rescheduleJob(cacheObjSubType[`msg_go`])")
logOnError(err, "jobPillage : rescheduleJob(cacheObjSubType[`msg_go`], 10)")
} else { //no /go in the last 30 sec so we go ahead, send one and reschedule to check again in 25sec
clientSendCWMsg(j.UserID64, "/go")
err = rescheduleJob(j.ID64, j.Trigger, time.Now().Add(30*time.Second).UTC())
@ -719,9 +719,9 @@ func jobGStock(j Job) {
b, _ := json.Marshal(&p)
jobID64, err := createJob(objSubTypeJobGStock, objJobPriority, j.UserID64, 0, time.Unix(maxUnixTimestamp, 0).UTC(), b)
logOnError(err, "jobGStock : createJob")
setJobCallback(jobID64, j.UserID64, cacheObjSubType[`msg_gstock_any_ack`])
setJobCallback(jobID64, j.UserID64, cacheObjSubType[`msg_busy`])
setJobCallback(jobID64, j.UserID64, cacheObjSubType[`msg_battle`])
setJobCallback(jobID64, j.UserID64, cacheObjSubType[`msg_gstock_any_ack`], 10)
setJobCallback(jobID64, j.UserID64, cacheObjSubType[`msg_busy`], 10)
setJobCallback(jobID64, j.UserID64, cacheObjSubType[`msg_battle`], 10)
err = setJobTimeout(jobID64, 1*time.Minute)
logOnError(err, "jobGStock : setJobTimeout")
clientSendCWMsg(j.UserID64, "/g_stock_res")
@ -894,7 +894,7 @@ func jobGDepositForward(j Job) {
//log.Printf("jobGDepositForward : found (%d / %d), expected (%d / %d).\n", cwm.ItemID64, cwm.Quantity, p.ItemID64, p.Quantity)
err = rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
logOnError(err, "jobGDepositForward : rescheduleJob")
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_g_deposit_req`])
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_g_deposit_req`], 10)
}
return
@ -1055,13 +1055,13 @@ func jobVaultItemStatus(j Job) {
FROM obj_msg_vault_v omv
WHERE omv.user_id = x.user_id
AND omv.item_id = x.item_id
AND omv.msg_type_id = ` + strconv.Itoa(cacheObjSubType[`msg_g_deposit_ack`]) + `
AND omv.msg_type_id = ` + strconv.FormatInt(cacheObjSubType[`msg_g_deposit_ack`], 10) + `
AND omv.chat_id = x.chat_id) deposit
,(SELECT COALESCE(SUM(omv.quantity), 0)
FROM obj_msg_vault_v omv
WHERE omv.user_id = x.user_id
AND omv.item_id = x.item_id
AND omv.msg_type_id = ` + strconv.Itoa(cacheObjSubType[`msg_withdraw_rcv`]) + `
AND omv.msg_type_id = ` + strconv.FormatInt(cacheObjSubType[`msg_withdraw_rcv`], 10) + `
AND omv.chat_id = x.chat_id) withdraw
FROM (SELECT DISTINCT
omv.user_id
@ -1167,13 +1167,13 @@ func jobVaultUserStatus(j Job) {
FROM obj_msg_vault_v omv
WHERE omv.user_id = x.user_id
AND omv.item_id = x.item_id
AND omv.msg_type_id = ` + strconv.Itoa(cacheObjSubType[`msg_g_deposit_ack`]) + `
AND omv.msg_type_id = ` + strconv.FormatInt(cacheObjSubType[`msg_g_deposit_ack`], 10) + `
AND omv.chat_id = x.chat_id) deposit
,(SELECT COALESCE(SUM(omv.quantity), 0)
FROM obj_msg_vault_v omv
WHERE omv.user_id = x.user_id
AND omv.item_id = x.item_id
AND omv.msg_type_id = ` + strconv.Itoa(cacheObjSubType[`msg_withdraw_rcv`]) + `
AND omv.msg_type_id = ` + strconv.FormatInt(cacheObjSubType[`msg_withdraw_rcv`], 10) + `
AND omv.chat_id = x.chat_id) withdraw
FROM (SELECT DISTINCT
omv.user_id