This commit is contained in:
shoopea 2019-06-06 13:52:22 +08:00
parent f7120953f3
commit 05a8dd4fe8
5 changed files with 56 additions and 39 deletions

24
def.go
View File

@ -128,16 +128,20 @@ type ChatWarsMessageDuelFight struct {
} }
type ChatWarsMessageAuctionAnnounce struct { type ChatWarsMessageAuctionAnnounce struct {
ObjID64 int64 `json:"obj_id"` ObjID64 int64 `json:"obj_id"`
LotID int32 `json:"lot_id"` LotID int32 `json:"lot_id"`
Item string `json:"item"` ItemID64 int64 `json:"item_id"`
Cond string `json:"cond"` Cond string `json:"cond"`
Quality string `json:"quality"` Quality string `json:"quality"`
Seller string `json:"seller"` SellerID64 int64 `json:"seller_id"`
Buyer string `json:"buyer"` SellerGuildID64 int64 `json:"seller_guild_id"`
Price int32 `json:"price"` SellerCastleID64 int64 `json:"seller_castle_id"`
Status string `json:"status"` BuyerID64 int64 `json:"buyer_id"`
End time.Time `json:"end"` BuyerGuildID64 int64 `json:"buyer_guild_id"`
BuyerCastleID64 int64 `json:"buyer_castle_id"`
Price int32 `json:"price"`
Status string `json:"status"`
End time.Time `json:"end"`
} }
type ChatWarsMessagePillageInc struct { type ChatWarsMessagePillageInc struct {

21
msg.go
View File

@ -30,6 +30,27 @@ func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWa
return &cwm, nil return &cwm, nil
} }
func parseSubTypeMessageAuctionAnnounce(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageAuctionAnnounce, error) {
cwm := ChatWarsMessageAuctionAnnounce{}
l, _ := strconv.ParseInt(r.ReplaceAllString(m.Text, "${Lot}"), 10, 32)
cwm.LotID = int32(l)
cwm.ItemID64 = getObjItemID(r.ReplaceAllString(m.Text, "${Item}"))
cwm.Cond = r.ReplaceAllString(m.Text, "${Cond}")
cwm.Quality = r.ReplaceAllString(m.Text, "${Quality}")
cwm.SellerUserID64 = getObjUserID(r.ReplaceAllString(m.Text, "${SellerUser}"))
cwm.SellerGuildID64 = getObjUserID(r.ReplaceAllString(m.Text, "${SellerGuild}"))
cwm.SellerCastleID64 = getObjUserID(r.ReplaceAllString(m.Text, "${SellerCastle}"))
cwm.BuyerUserID64 = getObjUserID(r.ReplaceAllString(m.Text, "${BuyerUser}"))
cwm.BuyerGuildID64 = getObjUserID(r.ReplaceAllString(m.Text, "${BuyerGuild}"))
cwm.BuyerCastleID64 = getObjUserID(r.ReplaceAllString(m.Text, "${BuyerCastle}"))
p, _ := strconv.ParseInt(r.ReplaceAllString(m.Text, "${Price}"), 10, 32)
cwm.Price = int32(p)
cwm.Status = r.ReplaceAllString(m.Text, "${Status}")
cwm.End, _ = fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}"))
return cwm, nil
}
func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageStock, error) { func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageStock, error) {
cwm := ChatWarsMessageStock{} cwm := ChatWarsMessageStock{}
items := []ChatWarsItems{} items := []ChatWarsItems{}

View File

@ -10,7 +10,7 @@ func resetMsgParsingRules() {
_, err = db.Exec(`INSERT INTO msg_rules (prio, msg_type_id, descn, rule) _, err = db.Exec(`INSERT INTO msg_rules (prio, msg_type_id, descn, rule)
VALUES (5000, ` + strconv.Itoa(objSubTypeMessageReportAck) + `, "Player war report", "^(?P<Castle>[🐉🦅🐺🦈🦌🥔🌑])(\\[(?P<Guild>[A-Z0-9]{1,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}$") VALUES (5000, ` + strconv.Itoa(objSubTypeMessageReportAck) + `, "Player war report", "^(?P<Castle>[🐉🦅🐺🦈🦌🥔🌑])(\\[(?P<Guild>[A-Z0-9]{1,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(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<SellerCastle>[🐉🦅🐺🦈🦌🥔🌑])( ){0,1})(\\[(?P<SellerGuild>[A-Z0-9]{1,3})\\]){0,1}(?P<SellerUser>.*)\\nCurrent price: (?P<Price>[0-9]+) pouch\\(es\\)\\nBuyer: (?P<BuyerCastle>[🐉🦅🐺🦈🦌🥔🌑])( ){0,1})(\\[(?P<BuyerGuild>[A-Z0-9]{1,3})\\]){0,1}(?P<BuyerUser>.*)\\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(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` + `,(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<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` +

30
sql.go
View File

@ -167,16 +167,20 @@ func initDB() {
log.Println("initDB : obj_war_report created ...") log.Println("initDB : obj_war_report created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_auction_announce ( _, err = db.Exec(`CREATE TABLE obj_msg_auction_announce (
obj_id BIGINT UNSIGNED NOT NULL obj_id BIGINT UNSIGNED NOT NULL
,lot_id BIGINT UNSIGNED NOT NULL ,lot_id BIGINT UNSIGNED NOT NULL
,item VARCHAR(80) ,item VARCHAR(80)
,cond VARCHAR(32) ,cond VARCHAR(32)
,quality VARCHAR(32) ,quality VARCHAR(32)
,seller VARCHAR(32) ,seller_castle_id BIGINT UNSIGNED
,buyer VARCHAR(32) ,seller_guild_id BIGINT UNSIGNED
,price SMALLINT NOT NULL ,seller_id BIGINT UNSIGNED
,status VARCHAR(32) ,buyer_castle_id BIGINT UNSIGNED
,end DATETIME NOT NULL ,buyer_guild_id BIGINT UNSIGNED
,buyer_id BIGINT UNSIGNED
,price SMALLINT NOT NULL
,status VARCHAR(32)
,end DATETIME NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE ,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,KEY (lot_id) ,KEY (lot_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`) ) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
@ -517,14 +521,14 @@ func insertMsgAuctionAnnounce(m *ChatWarsMessageAuctionAnnounce) error {
return errors.New("Message type mismatch") return errors.New("Message type mismatch")
} }
stmt, err := db.Prepare(`INSERT INTO obj_msg_auction_announce (obj_id, lot_id, item, cond, quality, seller, buyer, price, status, end) stmt, err := db.Prepare(`INSERT INTO obj_msg_auction_announce (obj_id, lot_id, item, cond, quality, seller_id, seller_guild_id, seller_castle_id, buyer_id, buyer_guild_id, buyer_castle_id, price, status, end)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`)
if err != nil { if err != nil {
return err return err
} }
defer stmt.Close() defer stmt.Close()
_, err = stmt.Exec(m.ObjID64, m.LotID, m.Item, m.Cond, m.Quality, m.Seller, m.Buyer, m.Price, m.Status, m.End) _, err = stmt.Exec(m.ObjID64, m.LotID, m.Item, m.Cond, m.Quality, m.SellerUserID64, m.SellerGuildID64, m.SellerCastleID64, m.BuyerUserID64, m.BuyerGuildID64, m.BuyerCastleID64, m.Price, m.Status, m.End)
if err != nil { if err != nil {
return err return err
} }

View File

@ -169,7 +169,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageDuelFight.") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageDuelFight.")
cwm.ObjID64 = objId cwm.ObjID64 = objId
err = insertMsgDuelFight(cwm) err = insertMsgDuelFight(cwm)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgAuctionAnnounce") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgDuelFight")
case objSubTypeMessageUnionWar: case objSubTypeMessageUnionWar:
_, err := parseSubTypeMessageUnionWar(m, r) _, err := parseSubTypeMessageUnionWar(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageUnionWar.") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageUnionWar.")
@ -179,20 +179,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
cwm.Msg = m cwm.Msg = m
clientMsgGRolesAck(cwm) clientMsgGRolesAck(cwm)
case objSubTypeMessageAuctionAnnounce: case objSubTypeMessageAuctionAnnounce:
cwm := ChatWarsMessageAuctionAnnounce{ cwm, err := parseSubTypeMessageAuctionAnnounce(m, r)
ObjID64: objId, logOonError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageAuctionAnnounce.")
}
l, _ := strconv.ParseInt(r.ReplaceAllString(m.Text, "${Lot}"), 10, 32)
cwm.LotID = int32(l)
cwm.Item = r.ReplaceAllString(m.Text, "${Item}")
cwm.Cond = r.ReplaceAllString(m.Text, "${Cond}")
cwm.Quality = r.ReplaceAllString(m.Text, "${Quality}")
cwm.Seller = r.ReplaceAllString(m.Text, "${Seller}")
cwm.Buyer = r.ReplaceAllString(m.Text, "${Buyer}")
p, _ := strconv.ParseInt(r.ReplaceAllString(m.Text, "${Price}"), 10, 32)
cwm.Price = int32(p)
cwm.Status = r.ReplaceAllString(m.Text, "${Status}")
cwm.End, _ = fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}"))
err = insertMsgAuctionAnnounce(&cwm) err = insertMsgAuctionAnnounce(&cwm)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgAuctionAnnounce") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgAuctionAnnounce")
case objSubTypeMessageTimeAck: case objSubTypeMessageTimeAck: