This commit is contained in:
shoopea 2019-05-14 10:28:26 +08:00
parent 62b56a6130
commit 9f14c3fb48
3 changed files with 117 additions and 40 deletions

9
def.go
View File

@ -29,6 +29,7 @@ type ChatWarsMessageAuctionAnnounce struct {
}
type ChatWarsMessageMiniWar struct {
ObjID64 int64 `json:"obj_id"`
Report map[string]*ChatWarsMessageMiniWarCastle `json:"castle"`
Time time.Time `json:"time"`
}
@ -99,6 +100,14 @@ const (
objTypeJob = 6
objTypeItem = 7
castleDeer = 1
castleDragon = 2
castleHighnest = 3
castleMoon = 4
castlePotato = 5
castleShark = 6
castleWolf = 7
objSubTypeMessageUnknown = 301
objSubTypeMessageWar = 302
objSubTypeMessageMiniWar = 303

134
sql.go
View File

@ -101,6 +101,15 @@ func initDB() {
failOnError(err, "initDB : create table obj_guild")
log.Println("initDB : obj_guild created ...")
_, err = db.Exec(`CREATE TABLE code_obj_castle (
id SMALLINT UNSIGNED NOT NULL
,user_id VARCHAR(32) NOT NULL
,intl_id VARCHAR(32) NOT NULL
,name VARCHAR(80) NOT NULL
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_castle")
log.Println("initDB : obj_guild created ...")
_, err = db.Exec(`CREATE TABLE obj_war (
obj_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT
,start_time DATETIME NOT NULL
@ -168,6 +177,30 @@ func initDB() {
failOnError(err, "initDB : create table obj_msg_auction_announce")
log.Println("initDB : obj_msg_auction_announce created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_mini_war (
obj_id BIGINT UNSIGNED NOT NULL
,date DATETIME NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,UNIQUE KEY (date)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg_mini_war")
log.Println("initDB : obj_msg_mini_war created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_mini_war_castle (
obj_id BIGINT UNSIGNED NOT NULL
,castle_id SMALLINT UNSIGNED NOT NULL
,gardian TINYINT NOT NULL
,result VARCHAR(8)
,gold SMALLINT NOT NULL
,stock SMALLINT NOT NULL
,points SMALLINT NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,FOREIGN KEY (castle_id) REFERENCES code_obj_castle(id) ON DELETE CASCADE
,UNIQUE KEY (obj_id, castle_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg_mini_war_castle")
log.Println("initDB : obj_msg_auction_announce created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_auction_upd_req (
obj_id BIGINT UNSIGNED NOT NULL
,lot_id BIGINT UNSIGNED NOT NULL
@ -238,6 +271,18 @@ func initDB() {
failOnError(err, "initDB : populate table code_obj_type")
log.Println("initDB : code_obj_type populated ...")
_, err = db.Exec(`INSERT INTO code_obj_castle (id, intl_id, user_id, name)
VALUES (` + strconv.Itoa(castleDeer) + `, "deer", "🦌", "Deerhorn")
,(` + strconv.Itoa(castleDragon) + `, "dragon", "🐉", "Dragonscale")
,(` + strconv.Itoa(castleHighnest) + `, "highnest", "🦅", "Highnest")
,(` + strconv.Itoa(castleMoon) + `, "moon", "🌑", "Moonlight")
,(` + strconv.Itoa(castlePotato) + `, "potato", "🥔", "Potato")
,(` + strconv.Itoa(castleShark) + `, "shark", "🦈", "Sharkteeth")
,(` + strconv.Itoa(castleWolf) + `, "wolf", "🐺", "Wolfpack")
;`)
failOnError(err, "initDB : populate table code_obj_castle")
log.Println("initDB : code_obj_castle populated ...")
_, err = db.Exec(`INSERT INTO code_obj_sub_type (id, intl_id, name, obj_type_id)
VALUES (` + strconv.Itoa(objSubTypeMessageUnknown) + `, "unknown", "Unknown", ` + strconv.Itoa(objTypeMessage) + `)
,(` + strconv.Itoa(objSubTypeMessageWar) + `, "war", "War report", ` + strconv.Itoa(objTypeMessage) + `)
@ -1240,40 +1285,8 @@ func resetMsgParsingRules() {
_, err = db.Exec(`INSERT INTO msg_rules (prio, msg_type_id, descn, rule)
VALUES (5000, ` + strconv.Itoa(objSubTypeMessageReport) + `, "Player war report", "^(?P<Castle>[🐉🦅🐺🦈🦌🥔🌑])(\\[(?P<Guild>[A-Z]{3})\\]){0,1}(?P<User>([A-Za-z0-9 ]*)) ⚔:(?P<Attack>[0-9]+)(?P<AttackMod>\\((-|\\+)[0-9]+\\)){0,1} 🛡:(?P<Defense>[0-9]+) Lvl: (?P<Level>[0-9]+)\\nYour result on the battlefield:\\n(🔥Exp: (?P<Exp>[0-9]+)\\n){0,1}(💰Gold: (?P<Gold>\\-{0,1}[0-9]+)\\n){0,1}(📦Stock: (?P<Stock>\\-{0,1}[0-9]+)){0,1}(\\n(?P<Stamina>(🔋Stamina restored))){0,1}(\\n(?P<Crit>(⚡Critical strike))){0,1}$")
,(5000, ` + strconv.Itoa(objSubTypeMessageAuctionAnnounce) + `, "Auction annouce", "^Lot #(?P<Lot>[0-9]+) : (?P<Item>.*)\\n(Quality: (?P<Quality>.*)\\n){0,1}(Condition: (?P<Cond>.*)\\n){0,1}Seller: (?P<Seller>.*)\\nCurrent price: (?P<Price>[0-9]+) pouch\\(es\\)\\nBuyer: (?P<Buyer>.*)\\nEnd At: (?P<End>.*)\\nStatus: (?P<Status>.*)(\\n)*(?s:.*)")
,(5000, ` + strconv.Itoa(objSubTypeMessageTimeAck) + `, "Time", "^In Chat Wars world now\\n(?P<Time>.*)\\n(?P<Hour>[0-9]{2}):(?P<Minute>[0-9]{2})\\n(?P<Day>[0-9]{2}) (?P<Month>.+) (?P<Year>[0-9]{4})\\n(?s:.*)$")` + /*
,(5000, ` + strconv.Itoa(objSubTypeMessageMiniWar) + `, "Mini War", "^Battle results:\\n` +
`(?P<Gardian1>🔱){0,1}(?P<CastleLoot1>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<CastleResult1>(🛡|🛡👌|⚔️|⚔️ ⚡️))( (?P<CastleGold1>(\\-|\\+)[0-9]+)💰){0,1}( (?P<CastleStock1>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?P<CastleLoot2>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<CastleResult2>(🛡|🛡👌|⚔️|⚔️ ⚡️))( (?P<CastleGold2>(\\-|\\+)[0-9]+)💰){0,1}( (?P<CastleStock2>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?P<CastleLoot3>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<CastleResult3>(🛡|🛡👌|⚔️|⚔️ ⚡️))( (?P<CastleGold3>(\\-|\\+)[0-9]+)💰){0,1}( (?P<CastleStock3>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?P<CastleLoot4>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<CastleResult4>(🛡|🛡👌|⚔️|⚔️ ⚡️))( (?P<CastleGold4>(\\-|\\+)[0-9]+)💰){0,1}( (?P<CastleStock4>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?P<CastleLoot5>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<CastleResult5>(🛡|🛡👌|⚔️|⚔️ ⚡️))( (?P<CastleGold5>(\\-|\\+)[0-9]+)💰){0,1}( (?P<CastleStock5>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?P<CastleLoot6>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<CastleResult6>(🛡|🛡👌|⚔️|⚔️ ⚡️))( (?P<CastleGold6>(\\-|\\+)[0-9]+)💰){0,1}( (?P<CastleStock6>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?P<CastleLoot7>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<CastleResult7>(🛡|🛡👌|⚔️|⚔️ ⚡️))( (?P<CastleGold7>(\\-|\\+)[0-9]+)💰){0,1}( (?P<CastleStock7>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`\\n🏆Scores:\\n` +
`(?P<CastleScore1>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Score1>\\+[0-9]+)\\n` +
`(?P<CastleScore2>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Score2>\\+[0-9]+)\\n` +
`(?P<CastleScore3>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Score3>\\+[0-9]+)\\n` +
`(?P<CastleScore4>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Score4>\\+[0-9]+)\\n` +
`(?P<CastleScore5>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Score5>\\+[0-9]+)\\n` +
`(?P<CastleScore6>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Score6>\\+[0-9]+)\\n` +
`(?P<CastleScore7>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Score7>\\+[0-9]+)\\n` +
`\\n` +
`Battle (?P<Time>[0-9]{2}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2})$")` + /*
,(4000, ` + strconv.Itoa(objSubTypeMessageMiniWar) + `, "Mini War", "^Battle results:\\n` +
`(?P<Gardian1>🔱){0,1}(?P<Loot1>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Result1>[ 🛡👌⚡️⚔️]*)[ ]*((?P<Gold1>(\\-|\\+)[0-9]+)💰){0,1}[ ]*((?P<Stock1>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?P<Gardian2>🔱){0,1}(?P<Loot2>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Result2>[ 🛡👌⚡️⚔️]*)[ ]*((?P<Gold2>(\\-|\\+)[0-9]+)💰){0,1}[ ]*((?P<Stock2>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?P<Gardian3>🔱){0,1}(?P<Loot3>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Result3>[ 🛡👌⚡️⚔️]*)[ ]*((?P<Gold3>(\\-|\\+)[0-9]+)💰){0,1}[ ]*((?P<Stock3>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?P<Gardian4>🔱){0,1}(?P<Loot4>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Result4>[ 🛡👌⚡️⚔️]*)[ ]*((?P<Gold4>(\\-|\\+)[0-9]+)💰){0,1}[ ]*((?P<Stock4>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?P<Gardian5>🔱){0,1}(?P<Loot5>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Result5>[ 🛡👌⚡️⚔️]*)[ ]*((?P<Gold5>(\\-|\\+)[0-9]+)💰){0,1}[ ]*((?P<Stock5>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?P<Gardian6>🔱){0,1}(?P<Loot6>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Result6>[ 🛡👌⚡️⚔️]*)[ ]*((?P<Gold6>(\\-|\\+)[0-9]+)💰){0,1}[ ]*((?P<Stock6>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?P<Gardian7>🔱){0,1}(?P<Loot7>(🌑Moonlight|🐺Wolfpack|🦌Deerhorn|🐉Dragonscale|🦈Sharkteeth|🥔Potato|🦅Highnest)): (?P<Result7>[ 🛡👌⚡️⚔️]*)[ ]*((?P<Gold7>(\\-|\\+)[0-9]+)💰){0,1}[ ]*((?P<Stock7>(\\-|\\+)[0-9]+)📦){0,1}\\n` +
`(?s:.*)` +
`Battle (?P<Time>[0-9]{2}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2})$")
,(4000, ` + strconv.Itoa(objSubTypeMessageMiniWar) + `, "Mini War", "^Battle results:\\n` +
`(?P<Gardian1>🔱){0,1}.*(?P<Loot1>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)): (?P<Result1>[.^\x{1F4B0}\x{1F4E6}]*)[ ]*((?P<Gold1>(\\-|\\+)[0-9]+)\x{1F4B0}){0,1}[ ]*((?P<Stock1>(\\-|\\+)[0-9]+)\x{1F4E6}){0,1}\\n` +
`(?s:.*)` +
`Battle (?P<Time>[0-9]{2}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2})$")*/`
,(4000, ` + strconv.Itoa(objSubTypeMessageMiniWar) + `, "Mini War", "^Battle results:\\n` +
,(5000, ` + strconv.Itoa(objSubTypeMessageTimeAck) + `, "Time", "^In Chat Wars world now\\n(?P<Time>.*)\\n(?P<Hour>[0-9]{2}):(?P<Minute>[0-9]{2})\\n(?P<Day>[0-9]{2}) (?P<Month>.+) (?P<Year>[0-9]{4})\\n(?s:.*)$")` +
`,(5000, ` + strconv.Itoa(objSubTypeMessageMiniWar) + `, "Mini War", "^⛳Battle results:\\n` +
`(?P<Gardian1>🔱){0,1}.*(?P<Loot1>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)):(?P<Result1>[^\\x{1F4B0}\\x{1F4E6}]*)((?P<Gold1>(\\-|\\+)[0-9]+)\\x{1F4B0}){0,1}[ ]*((?P<Stock1>(\\-|\\+)[0-9]+)\\x{1F4E6}){0,1}\\n` +
`(?P<Gardian2>🔱){0,1}.*(?P<Loot2>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)):(?P<Result2>[^\\x{1F4B0}\\x{1F4E6}]*)((?P<Gold2>(\\-|\\+)[0-9]+)\\x{1F4B0}){0,1}[ ]*((?P<Stock2>(\\-|\\+)[0-9]+)\\x{1F4E6}){0,1}\\n` +
`(?P<Gardian3>🔱){0,1}.*(?P<Loot3>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)):(?P<Result3>[^\\x{1F4B0}\\x{1F4E6}]*)((?P<Gold3>(\\-|\\+)[0-9]+)\\x{1F4B0}){0,1}[ ]*((?P<Stock3>(\\-|\\+)[0-9]+)\\x{1F4E6}){0,1}\\n` +
@ -1450,6 +1463,59 @@ func insertMsgAuctionAnnounce(m *ChatWarsMessageAuctionAnnounce) error {
return nil
}
func insertMsgMiniWar(m *ChatWarsMessageMiniWar) error {
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
if err != nil {
return err
}
if objSubTypeId != objSubTypeMessageUnknown && objSubTypeId != objSubTypeMessageMiniWar {
return errors.New("Message type mismatch")
}
stmt1, err := db.Prepare(`INSERT INTO obj_msg_mini_war (obj_id, date)
VALUES (?, ?);`)
if err != nil {
return err
}
defer stmt1.Close()
_, err = stmt.Exec(m.ObjID64, m.Time)
if err != nil {
return err
}
stmt2, err := db.Prepare(`INSERT INTO obj_msg_mini_war_report (obj_id, castle_id, gardian, result, gold, stock, points)
VALUES (?, ?, ?, ?, ?, ?, ?);`)
if err != nil {
return err
}
defer stmt2.Close()
for c, r := range m.Report {
switch c {
case "Deerhorn":
_, err = stmt.Exec(m.ObjID64, castleDeer, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
case "Dragonscale":
_, err = stmt.Exec(m.ObjID64, castleDragon, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
case "Highnest":
_, err = stmt.Exec(m.ObjID64, castleHighnest, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
case "Moonlight":
_, err = stmt.Exec(m.ObjID64, castleMoon, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
case "Potato":
_, err = stmt.Exec(m.ObjID64, castlePotato, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
case "Sharkteeth":
_, err = stmt.Exec(m.ObjID64, castleshark, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
case "Wolfpack":
_, err = stmt.Exec(m.ObjID64, castleWolf, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
}
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

@ -101,9 +101,11 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
case objSubTypeMessageMiniWar:
cwm, err := parseSubTypeMessageMiniWar(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMiniWar.")
b, err := json.Marshal(cwm)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Marshalling objSubTypeMessageMiniWar.")
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : %s\n%s\n", m.Text, string(b))
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 objSubTypeMessageAuctionAnnounce:
cwm := ChatWarsMessageAuctionAnnounce{
@ -121,7 +123,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
cwm.Status = r.ReplaceAllString(m.Text, "${Status}")
cwm.End, _ = fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}"))
err = insertMsgAuctionAnnounce(&cwm)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : AuctionAnnounce")
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgAuctionAnnounce")
err = setObjSubTypeId(objId, objSubTypeMessageAuctionAnnounce)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(AuctionAnnounce)")
case objSubTypeMessageTimeAck: