test obj_tribute

This commit is contained in:
shoopea 2020-02-03 14:18:17 +08:00
parent c1f97e4c85
commit 32a556ef6d
5 changed files with 70 additions and 16 deletions

View File

@ -824,6 +824,11 @@
"name": "Valley", "name": "Valley",
"obj_type": "quest" "obj_type": "quest"
}, },
{
"intl_id": "tribute",
"name": "Tribute",
"obj_type": "tribute"
},
{ {
"intl_id": "test", "intl_id": "test",
"name": "Test", "name": "Test",

View File

@ -51,6 +51,10 @@
"intl_id": "quest", "intl_id": "quest",
"name": "Quest" "name": "Quest"
}, },
{
"intl_id": "tribute",
"name": "Tribute"
},
{ {
"intl_id": "test", "intl_id": "test",
"name": "Test" "name": "Test"

5
msg.go
View File

@ -285,6 +285,11 @@ func parseSubTypeMessageTributesStatsAck(m *ChatWarsMessage, r *regexp.Regexp) (
log.Printf("parseSubTypeMessageTributesStatsAck : Item : %s\n", re.ReplaceAllString(l[0], "${Item}")) log.Printf("parseSubTypeMessageTributesStatsAck : Item : %s\n", re.ReplaceAllString(l[0], "${Item}"))
log.Printf("parseSubTypeMessageTributesStatsAck : Quantity : %s\n", re.ReplaceAllString(l[0], "${Quantity}")) log.Printf("parseSubTypeMessageTributesStatsAck : Quantity : %s\n", re.ReplaceAllString(l[0], "${Quantity}"))
log.Printf("parseSubTypeMessageTributesStatsAck : Exp : %s\n", re.ReplaceAllString(l[0], "${Exp}")) log.Printf("parseSubTypeMessageTributesStatsAck : Exp : %s\n", re.ReplaceAllString(l[0], "${Exp}"))
tribute.Date, err = fromChatWarsDate(re.ReplaceAllString(l[0], "${Date}"))
logOnError(err, "parseSubTypeMessageTributesStatsAck : fromChatWarsDate")
tribute.ItemID64 = getSilentObjItemID(``, re.ReplaceAllString(l[0], "${Item}"))
tribute.Quantity, _ = strconv.ParseInt(r.ReplaceAllString(l[0], "${Quantity}"), 10, 64)
tribute.Exp, _ = strconv.ParseInt(r.ReplaceAllString(l[0], "${Exp}"), 10, 64)
cwm.Tributes = append(cwm.Tributes, tribute) cwm.Tributes = append(cwm.Tributes, tribute)
} }

70
sql.go
View File

@ -296,10 +296,38 @@ func initDB() {
,quantity INT NOT NULL ,quantity INT NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE ,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,FOREIGN KEY (item_id) REFERENCES obj_item(obj_id) ON DELETE CASCADE ,FOREIGN KEY (item_id) REFERENCES obj_item(obj_id) ON DELETE CASCADE
,UNIQUE KEY (obj_id, item_id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`) ) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_gold") failOnError(err, "initDB : create table obj_msg_item")
log.Println("initDB : obj_msg_item created ...") log.Println("initDB : obj_msg_item created ...")
_, err = db.Exec(`CREATE TABLE obj_msg_tribute (
obj_id BIGINT UNSIGNED NOT NULL
,user_id BIGINT UNSIGNED NOT NULL
,item_id BIGINT UNSIGNED NOT NULL
,quantity SMALLINT NOT NULL
,xp SMALLINT NOT NULL
,date DATETIME NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,FOREIGN KEY (user_id) REFERENCES obj_user(obj_id) ON DELETE CASCADE
,FOREIGN KEY (item_id) REFERENCES obj_item(obj_id) ON DELETE CASCADE
,UNIQUE KEY (user_id, date)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_msg_tribute")
log.Println("initDB : obj_msg_tribute created ...")
_, err = db.Exec(`CREATE TABLE obj_tribute (
tg_user_id BIGINT UNSIGNED NOT NULL
,item_id BIGINT UNSIGNED NOT NULL
,quantity INT NOT NULL
,exp INT NOT NULL
,date DATETIME NOT NULL
,FOREIGN KEY (item_id) REFERENCES obj_item(obj_id) ON DELETE CASCADE
,UNIQUE KEY (tg_user_id, item_id, quantity, exp, date)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_tribute")
log.Println("initDB : obj_tribute created ...")
_, err = db.Exec(`CREATE TABLE msg_rules ( _, err = db.Exec(`CREATE TABLE msg_rules (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT
,prio SMALLINT NOT NULL ,prio SMALLINT NOT NULL
@ -313,21 +341,6 @@ func initDB() {
failOnError(err, "initDB : create table msg_rules") failOnError(err, "initDB : create table msg_rules")
log.Println("initDB : msg_rules created ...") log.Println("initDB : msg_rules created ...")
_, err = db.Exec(`CREATE TABLE obj_tribute (
obj_id BIGINT UNSIGNED NOT NULL
,user_id BIGINT UNSIGNED NOT NULL
,item_id BIGINT UNSIGNED NOT NULL
,quantity SMALLINT NOT NULL
,xp SMALLINT NOT NULL
,date DATETIME NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
,FOREIGN KEY (user_id) REFERENCES obj_user(obj_id) ON DELETE CASCADE
,FOREIGN KEY (item_id) REFERENCES obj_item(obj_id) ON DELETE CASCADE
,UNIQUE KEY (user_id, date)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table obj_tribute")
log.Println("initDB : obj_tribute created ...")
_, err = db.Exec(`CREATE TABLE obj_xp ( _, err = db.Exec(`CREATE TABLE obj_xp (
obj_id BIGINT UNSIGNED NOT NULL obj_id BIGINT UNSIGNED NOT NULL
,user_id BIGINT UNSIGNED NOT NULL ,user_id BIGINT UNSIGNED NOT NULL
@ -627,6 +640,31 @@ func insertMsgDuelFight(m *ChatWarsMessageDuelFight) error {
return nil return nil
} }
func insertMsgTributesStats(m *ChatWarsMessageTributesStatsAck) error {
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
if err != nil {
return err
}
if objSubTypeId != cacheObjSubType[`msg`] && objSubTypeId != cacheObjSubType[`msg_tributes_stats_ack`] {
return errors.New("Message type mismatch")
}
stmt, err := db.Prepare(`INSERT INTO obj_tribute (tg_user_id, item_id, quantity, exp, date)
VALUES (?, ?, ?, ?, ?);`)
logOnError(err, "insertMsgTributesStats : Prepare")
if err != nil {
return err
}
defer stmt.Close()
for _, t := range m.Tributes {
_, err = stmt.Exec(m.Msg.TGUserID64, t.ItemID64, t.Quantity, t.Exp, t.Date)
logOnError(err, "insertMsgTributesStats Exec")
}
return nil
}
func insertMsgAuctionAnnounce(m *ChatWarsMessageAuctionAnnounce) error { func insertMsgAuctionAnnounce(m *ChatWarsMessageAuctionAnnounce) error {
objSubTypeId, err := getObjSubTypeId(m.ObjID64) objSubTypeId, err := getObjSubTypeId(m.ObjID64)
if err != nil { if err != nil {

View File

@ -518,6 +518,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
case cacheObjSubType[`msg_tributes_stats_ack`]: case cacheObjSubType[`msg_tributes_stats_ack`]:
_, err := parseSubTypeMessageTributesStatsAck(m, rule.re) _, err := parseSubTypeMessageTributesStatsAck(m, rule.re)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_tributes_stats_ack`]") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_tributes_stats_ack`]")
err = insertMsgTributesStats(cwm)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgTributesStats")
default: default:
//log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID64, objId, m.Text) //log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID64, objId, m.Text)
} }