This commit is contained in:
shoopea 2019-05-18 18:33:53 +08:00
parent b310196953
commit 278fb1cab6
4 changed files with 66 additions and 35 deletions

29
def.go
View File

@ -101,7 +101,7 @@ type Job struct {
} }
type JobPayloadPillage struct { type JobPayloadPillage struct {
Date time.Time `json:"date"` ObjID64 int64 `json:"obj_id"`
} }
type JobPayloadTribute struct { type JobPayloadTribute struct {
@ -166,15 +166,17 @@ const (
objSubTypeMessageMe = 310 objSubTypeMessageMe = 310
objSubTypeMessageInventory = 311 objSubTypeMessageInventory = 311
objSubTypeMessagePillageInc = 312 objSubTypeMessagePillageInc = 312
objSubTypeMessageTributeInc = 313 objSubTypeMessagePillageGo = 313
objSubTypeMessagePillageAck = 314 objSubTypeMessagePillageWin = 314
objSubTypeMessageTributeAck = 315 objSubTypeMessagePillageLoss = 315
objSubTypeMessageAuctionAnnounce = 316 objSubTypeMessageTributeInc = 316
objSubTypeMessageAuctionUpdReq = 317 objSubTypeMessageTributeAck = 317
objSubTypeMessageAuctionUpdAck = 318 objSubTypeMessageAuctionAnnounce = 318
objSubTypeMessageTimeAck = 319 objSubTypeMessageAuctionUpdReq = 319
objSubTypeMessageTimeReq = 320 objSubTypeMessageAuctionUpdAck = 320
objSubTypeMessageGo = 321 objSubTypeMessageTimeAck = 321
objSubTypeMessageTimeReq = 322
objSubTypeMessageGo = 323
objSubTypeJobPillage = 601 objSubTypeJobPillage = 601
objSubTypeJobTribute = 602 objSubTypeJobTribute = 602
objSubTypeJobStatus = 603 objSubTypeJobStatus = 603
@ -189,9 +191,10 @@ const (
objSubTypeItemPart = 705 objSubTypeItemPart = 705
objSubTypeItemOther = 706 objSubTypeItemOther = 706
objJobStatusNew = 0 objJobStatusNew = 0
objJonStatusPending = 10 objJobStatusPillageGo = 1
objJobStatusDone = 20 objJonStatusPending = 10
objJobStatusDone = 20
objJobPriority = 1 objJobPriority = 1
objJobPriorityRescanMsg = 2 objJobPriorityRescanMsg = 2

30
job.go
View File

@ -93,16 +93,32 @@ func jobSetDone(j Job) {
} }
func jobPillage(j Job) { func jobPillage(j Job) {
var r JobPayloadPillage /*
var r JobPayloadPillage
err := setJobStart(j.ID64) err := setJobStart(j.ID64)
logOnError(err, "jobPillage : setJobStart") logOnError(err, "jobPillage : setJobStart")
err = json.Unmarshal(j.Payload, &r) err = json.Unmarshal(j.Payload, &r)
logOnError(err, "jobPillage : Unmarshal payload") logOnError(err, "jobPillage : Unmarshal payload")
err = setJobDone(j.ID64) ids := getSQLListID64(` select og.id
logOnError(err, "jobPillage : setJobDone") from obj og
,obj_msg omg
,obj op
,obj_msg omp
,obj_job oj
where omg.obj_id = og.id
and og.obj_sub_type_id = ` + strconv.Itoa(objSubTypeMessageGo) `
and omg.user_id = oj.user_id
and omg.sender_user_id = oj.user_id
and oj.obj_id = ` + strconv.Itoa(j.ID64) `
and omp.obj_id = op.id
and op.id = ` + strconv.Itoa(r.ObjID64) `
and omg.date between omp.date and addtime(omp.date, '0 0:3:0.000000');`
err = setJobStatus(j.ID64, objJobStatusPillageGo, time.Now().Add(5 * time.second))
logOnError(err, "jobPillage : setJobDone")
*/
return return
} }

6
sql.go
View File

@ -310,8 +310,10 @@ func initDB() {
,(` + strconv.Itoa(objSubTypeMessageMe) + `, "me", "Hero short summary", ` + strconv.Itoa(objTypeMessage) + `) ,(` + strconv.Itoa(objSubTypeMessageMe) + `, "me", "Hero short summary", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageInventory) + `, "inv", "Inventory", ` + strconv.Itoa(objTypeMessage) + `) ,(` + strconv.Itoa(objSubTypeMessageInventory) + `, "inv", "Inventory", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessagePillageInc) + `, "pillage_inc", "Pillage incoming", ` + strconv.Itoa(objTypeMessage) + `) ,(` + strconv.Itoa(objSubTypeMessagePillageInc) + `, "pillage_inc", "Pillage incoming", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessagePillageGo) + `, "pillage_go", "Pillage go", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessagePillageWin) + `, "pillage_win", "Pillage win", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessagePillageLoss) + `, "pillage_loss", "Pillage loss", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageTributeInc) + `, "tribute_inc", "Tribute incoming", ` + strconv.Itoa(objTypeMessage) + `) ,(` + strconv.Itoa(objSubTypeMessageTributeInc) + `, "tribute_inc", "Tribute incoming", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessagePillageAck) + `, "pillage_ack", "Pillage acknowledged", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageTributeAck) + `, "tribute_ack", "Tribute acknowledged", ` + strconv.Itoa(objTypeMessage) + `) ,(` + strconv.Itoa(objSubTypeMessageTributeAck) + `, "tribute_ack", "Tribute acknowledged", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageAuctionAnnounce) + `, "auction_announce", "Auction announce", ` + strconv.Itoa(objTypeMessage) + `) ,(` + strconv.Itoa(objSubTypeMessageAuctionAnnounce) + `, "auction_announce", "Auction announce", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageAuctionUpdReq) + `, "auction_upd_req", "Auction update request", ` + strconv.Itoa(objTypeMessage) + `) ,(` + strconv.Itoa(objSubTypeMessageAuctionUpdReq) + `, "auction_upd_req", "Auction update request", ` + strconv.Itoa(objTypeMessage) + `)
@ -1321,6 +1323,8 @@ func resetMsgParsingRules() {
`Battle (?P<Time>[0-9]{2}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2})$") `Battle (?P<Time>[0-9]{2}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2})$")
,(5000, ` + strconv.Itoa(objSubTypeMessagePillageInc) + `, "Pillage Inc", "^You were strolling around on your horse when you noticed (\\[(?P<Guild>[A-Z0-9]{1,3})\\]){0,1}(?P<Attacker>.*) of .{1}(?P<Castle>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)) Castle trying to pillage a local village. To stop him click /go$") ,(5000, ` + strconv.Itoa(objSubTypeMessagePillageInc) + `, "Pillage Inc", "^You were strolling around on your horse when you noticed (\\[(?P<Guild>[A-Z0-9]{1,3})\\]){0,1}(?P<Attacker>.*) of .{1}(?P<Castle>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)) Castle trying to pillage a local village. To stop him click /go$")
,(5000, ` + strconv.Itoa(objSubTypeMessageGo) + `, "Go", "^/go$") ,(5000, ` + strconv.Itoa(objSubTypeMessageGo) + `, "Go", "^/go$")
,(5000, ` + strconv.Itoa(objSubTypeMessagePillageGo) + `,"Pillage Go", "^You lift up your sword and charge at the violator.$")
,(5000, ` + strconv.Itoa(objSubTypeMessagePillageWin) + `,"Pillage Win", "^You successfully defeated (\\[(?P<Guild>[A-Z0-9]{1,3})\\]){0,1}(?P<Attacker>.*). As he was crawling away, you picked up some of the gold he left behind. Received (?P<Gold>[0-9]+) gold and (?P<Exp>[0-9]+) exp.$`)
;`) ;`)
failOnError(err, "resetMsgParsingRules : populate table msg_rules") failOnError(err, "resetMsgParsingRules : populate table msg_rules")
} }

View File

@ -108,24 +108,32 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgPillageInc") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgPillageInc")
err = setObjSubTypeId(objId, objSubTypeMessagePillageInc) err = setObjSubTypeId(objId, objSubTypeMessagePillageInc)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageInc)") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageInc)")
if m.Date.Add(3 * time.Minute).After(time.Now()) { // if m.Date.Add(3 * time.Minute).After(time.Now()) {
p := JobPayloadPillage{ p := JobPayloadPillage{
Date: m.Date, ObjID64: objId,
}
b, _ := json.Marshal(&p)
err = createJob(objSubTypeJobPillage, objJobPriority, m.UserID64, time.Now().Add(time.Duration(25+rand.Intn(35))*time.Second), b)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : createJob(JobPillage)")
s := TGCommand{
Type: commandSendMsg,
Text: fmt.Sprintf("Catching pillage (%s)", m.Date.Format(time.RFC3339)),
ToUserID64: m.UserID64,
}
TGCmdQueue <- s
} }
b, _ := json.Marshal(&p)
err = createJob(objSubTypeJobPillage, objJobPriority, m.UserID64, m.Date.Add(time.Duration(25+rand.Intn(35))*time.Second), b)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : createJob(JobPillage)")
s := TGCommand{
Type: commandSendMsg,
Text: fmt.Sprintf("Catching pillage (%s)", m.Date.Format(time.RFC3339)),
ToUserID64: m.UserID64,
}
TGCmdQueue <- s
// }
case objSubTypeMessageGo: case objSubTypeMessageGo:
err = setObjSubTypeId(objId, objSubTypeMessageGo) err = setObjSubTypeId(objId, objSubTypeMessageGo)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(Go)") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(Go)")
case objSubTypeMessagePillageGo:
err = setObjSubTypeId(objId, objSubTypeMessagePillageGo)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageGo)")
case objSubTypeMessagePillageWin:
err = setObjSubTypeId(objId, objSubTypeMessagePillageWin)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageWin)")
case objSubTypeMessagePillageLoss:
err = setObjSubTypeId(objId, objSubTypeMessagePillageLoss)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageLoss)")
case objSubTypeMessageAuctionAnnounce: case objSubTypeMessageAuctionAnnounce:
cwm := ChatWarsMessageAuctionAnnounce{ cwm := ChatWarsMessageAuctionAnnounce{
ObjID64: objId, ObjID64: objId,