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