This commit is contained in:
shoopea 2019-05-15 18:02:17 +08:00
parent 33aa4ea6dc
commit 912690e66d
4 changed files with 76 additions and 1 deletions

7
def.go
View File

@ -38,6 +38,13 @@ type ChatWarsMessageAuctionAnnounce struct {
End time.Time `json:"end"`
}
type ChatWarsMessagePillageInc struct {
ObjID64 int64 `json:"obj_id"`
Attacker string `json:"attacker"`
Guild string `json:"guild"`
Castle string `json:"castle"`
}
type ChatWarsMessageMiniWar struct {
ObjID64 int64 `json:"obj_id"`
Report map[string]*ChatWarsMessageMiniWarCastle `json:"castle"`

9
msg.go
View File

@ -36,3 +36,12 @@ func parseSubTypeMessageMiniWar(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWars
return &cwm, err
}
func parseSubTypeMessagePillageInc(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessagePillageInc, error) {
cwm := ChatWarsMessagePillageInc{}
cwm.Attacker = r.ReplaceAllString(m.Text, "${Attacker}")
cwm.Castle = r.ReplaceAllString(m.Text, "${Castle}")
cwm.Guild = r.ReplaceAllString(m.Text, "${Guild}")
return &cwm, nil
}

52
sql.go
View File

@ -134,6 +134,17 @@ func initDB() {
failOnError(err, "initDB : create table obj_msg")
log.Println("initDB : obj_msg created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_pillage_inc (
obj_id BIGINT UNSIGNED NOT NULL
,attacker VARCHAR(32)
,guild VARCHAR(32)
,castle_id SMALLINT UNSIGNED NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,FOREIGN KEY (castle_id) REFERENCES code_obj_castle(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg_report")
log.Println("initDB : obj_msg_report created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_report (
obj_id BIGINT UNSIGNED NOT NULL
,war_id BIGINT UNSIGNED NOT NULL
@ -1305,7 +1316,7 @@ func resetMsgParsingRules() {
`.*(?P<Score7>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)): (?P<Points7>\\+([0-9]+|NaN))\\n` +
`(?s:.*)` +
`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<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-Z]{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$")` +
`;`)
failOnError(err, "resetMsgParsingRules : populate table msg_rules")
}
@ -1519,6 +1530,45 @@ func insertMsgMiniWar(m *ChatWarsMessageMiniWar) error {
return nil
}
func insertMsgPillageInc(m *ChatWarsMessagePillageInc) error {
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
if err != nil {
return err
}
if objSubTypeId != objSubTypeMessageUnknown && objSubTypeId != objSubTypeMessagePillageInc {
return errors.New("Message type mismatch")
}
stmt, err := db.Prepare(`INSERT INTO obj_msg_pillage_inc (obj_id, attacker, guild, castle_id)
VALUES (?, ?, ?, ?);`)
if err != nil {
return err
}
defer stmt.Close()
switch m.Castle {
case "Deerhorn":
_, err = stmt.Exec(m.ObjID64, m.Attacker, castleDeer)
case "Dragonscale":
_, err = stmt.Exec(m.ObjID64, m.Attacker, castleDragon)
case "Highnest":
_, err = stmt.Exec(m.ObjID64, m.Attacker, castleHighnest)
case "Moonlight":
_, err = stmt.Exec(m.ObjID64, m.Attacker, castleMoon)
case "Potato":
_, err = stmt.Exec(m.ObjID64, m.Attacker, castlePotato)
case "Sharkteeth":
_, err = stmt.Exec(m.ObjID64, m.Attacker, castleShark)
case "Wolfpack":
_, err = stmt.Exec(m.ObjID64, m.Attacker, castleWolf)
}
if err != nil {
return err
}
return nil
}
func createJob(job_type_id int32, priority int32, schedule time.Time, payload []byte) error {
stmt, err := db.Prepare(`INSERT INTO obj (obj_type_id, obj_sub_type_id)
VALUES (? , ?);`)

View File

@ -99,14 +99,23 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Stamina : %s (%d)\n", r.ReplaceAllString(m.Text, "${Stamina}"), objId)
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Crit : %s (%d)\n", r.ReplaceAllString(m.Text, "${Crit}"), objId)
case objSubTypeMessageMiniWar:
cwm, err := parseSubTypeMessageMiniWar(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMiniWar.")
cwm.ObjID64 = objId
err = insertMsgMiniWar(cwm)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgMiniWar")
err = setObjSubTypeId(objId, objSubTypeMessageMiniWar)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MiniWar)")
case objSubTypeMessagePillageInc:
/*
cwm, err := parseSubTypeMessagePillageInc(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMiniWar.")
cwm.ObjID64 = objId
err = insertMsgPillageInc(cwm)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgMiniWar")
*/
err = setObjSubTypeId(objId, objSubTypeMessagePillageInc)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageInc)")
case objSubTypeMessageAuctionAnnounce: