test
This commit is contained in:
parent
a98057e5fb
commit
bbd11001b2
11
def.go
11
def.go
@ -46,6 +46,16 @@ type ChatWarsMessageReportAck struct {
|
||||
|
||||
type ChatWarsMessageDuelFight struct {
|
||||
ObjID64 int64 `json:"obj_id"`
|
||||
WinCastleID int64 `json:"win_castle"`
|
||||
WinGuild `json:"win_guild"`
|
||||
WinUser `json:"win_user"`
|
||||
WinLife `json:"win_life"`
|
||||
LossCastleID `json:"loss_castle"`
|
||||
LossGuild string `json:"loss_guild"`
|
||||
LossUser string `json:"loss_user"`
|
||||
LossLife int64 `json:"loss_life"`
|
||||
Exp int64 `json:"exp"`
|
||||
Weapon string `json:"weapon"`
|
||||
}
|
||||
|
||||
type ChatWarsMessageAuctionAnnounce struct {
|
||||
@ -196,6 +206,7 @@ const (
|
||||
objSubTypeMessageBuyReq = 336 // /wtb_xx (done)
|
||||
objSubTypeMessageSellReq = 337 // /wts_xx (done)
|
||||
objSubTypeMessageOrderbookReq = 338 // /t_xx (done)
|
||||
objSubTypeMessageOrderbookAck = 339 // orderbook summary (not done)
|
||||
objSubTypeJobPillage = 601
|
||||
objSubTypeJobTribute = 602
|
||||
objSubTypeJobStatus = 603
|
||||
|
36
msg.go
36
msg.go
@ -29,22 +29,26 @@ func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWa
|
||||
|
||||
func parseSubTypeMessageDuelFight(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageDuelFight, error) {
|
||||
cwm := ChatWarsMessageDuelFight{}
|
||||
log.Printf("parseSubTypeMessageDuelFight : Duel fight identified\n")
|
||||
log.Printf("parseSubTypeMessageDuelFight : Castle1 : %s\n", r.ReplaceAllString(m.Text, "${Castle1}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : Guild1 : %s\n", r.ReplaceAllString(m.Text, "${Guild1}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : Duelist1 : %s\n", r.ReplaceAllString(m.Text, "${Duelist1}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : Life1 : %s\n", r.ReplaceAllString(m.Text, "${Life1}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : Castle2 : %s\n", r.ReplaceAllString(m.Text, "${Castle2}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : Guild2 : %s\n", r.ReplaceAllString(m.Text, "${Guild2}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : Duelist2 : %s\n", r.ReplaceAllString(m.Text, "${Duelist2}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : Life2 : %s\n", r.ReplaceAllString(m.Text, "${Life2}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : WinCastle : %s\n", r.ReplaceAllString(m.Text, "${WinCastle}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : WinGuild : %s\n", r.ReplaceAllString(m.Text, "${WinGuild}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : WinDuelist : %s\n", r.ReplaceAllString(m.Text, "${WinDuelist}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : LossCastle : %s\n", r.ReplaceAllString(m.Text, "${LossCastle}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : LossGuild : %s\n", r.ReplaceAllString(m.Text, "${LossGuild}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : LossDuelist : %s\n", r.ReplaceAllString(m.Text, "${LossDuelist}"))
|
||||
log.Printf("parseSubTypeMessageDuelFight : Weapon : %s\n", r.ReplaceAllString(m.Text, "${Weapon}"))
|
||||
if r.ReplaceAllString(m.Text, "${Duelist1}") == r.ReplaceAllString(m.Text, "${WinDuelist}") {
|
||||
cwm.WinCastle = r.ReplaceAllString(m.Text, "${Castle1}")
|
||||
cwm.WinGuild = r.ReplaceAllString(m.Text, "${Guild1}")
|
||||
cwm.WinUser = r.ReplaceAllString(m.Text, "${Duelist1}")
|
||||
cwm.WinLife, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Life1}"), 10, 64)
|
||||
cwm.LossCastle = r.ReplaceAllString(m.Text, "${Castle2}")
|
||||
cwm.LossGuild = r.ReplaceAllString(m.Text, "${Guild2}")
|
||||
cwm.LossUser = r.ReplaceAllString(m.Text, "${Duelist2}")
|
||||
cwm.LossLife, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Life2}"), 10, 64)
|
||||
} else {
|
||||
cwm.LossCastle = r.ReplaceAllString(m.Text, "${Castle1}")
|
||||
cwm.LossGuild = r.ReplaceAllString(m.Text, "${Guild1}")
|
||||
cwm.LossUser = r.ReplaceAllString(m.Text, "${Duelist1}")
|
||||
cwm.LossLife, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Life1}"), 10, 64)
|
||||
cwm.WinCastle = r.ReplaceAllString(m.Text, "${Castle2}")
|
||||
cwm.WinGuild = r.ReplaceAllString(m.Text, "${Guild2}")
|
||||
cwm.WinUser = r.ReplaceAllString(m.Text, "${Duelist2}")
|
||||
cwm.WinLife, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Life2}"), 10, 64)
|
||||
}
|
||||
cwm.Weapon = r.ReplaceAllString(m.Text, "${Weapon}")
|
||||
|
||||
return &cwm, nil
|
||||
}
|
||||
|
80
sql.go
80
sql.go
@ -213,7 +213,26 @@ func initDB() {
|
||||
,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 ...")
|
||||
log.Println("initDB : obj_msg_mini_war_castle created ...")
|
||||
|
||||
_, err = db.Exec(`CREATE TABLE obj_msg_duel_fight (
|
||||
obj_id BIGINT UNSIGNED NOT NULL
|
||||
,win_castle_id SMALLINT UNSIGNED NOT NULL
|
||||
,win_guild VARCHAR(3)
|
||||
,win_user VARCHAR(32)
|
||||
,win_life SMALLINT NOT NULL
|
||||
,loss_castle_id SMALLINT UNSIGNED NOT NULL
|
||||
,loss_guild VARCHAR(3)
|
||||
,loss_user VARCHAR(32)
|
||||
,loss_life SMALLINT NOT NULL
|
||||
,exp INT UNSIGNED NOT NULL
|
||||
,weapon VARCHAR(80)
|
||||
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
|
||||
,FOREIGN KEY (win_castle_id) REFERENCES code_obj_castle(id) ON DELETE CASCADE
|
||||
,FOREIGN KEY (loss_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_duel_fight")
|
||||
log.Println("initDB : obj_msg_duel_fight created ...")
|
||||
|
||||
_, err = db.Exec(`CREATE TABLE obj_msg_auction_upd_req (
|
||||
obj_id BIGINT UNSIGNED NOT NULL
|
||||
@ -1463,6 +1482,30 @@ func insertMsgReport(objId int64, war_date int32, atk int32, def int32, exp int3
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertMsgDuelFight(m *ChatWarsMessageDuelFight) error {
|
||||
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if objSubTypeId != objSubTypeMessageUnknown && objSubTypeId != objSubTypeMessageDuelFight {
|
||||
return errors.New("Message type mismatch")
|
||||
}
|
||||
|
||||
stmt, err := db.Prepare(`INSERT INTO obj_msg_duel_fight (obj_id, win_castle_id, win_guild, win_user, win_life, loss_castle_id, loss_guild, loss_user, loss_life, weapon)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
_, err = stmt.Exec(m.ObjID64, CastleID(m.WinCastle), m.WinGuild, m.WinUser, m.WinLife, CastleID(m.LossCastle), m.LossGuild, m.LossUser, m.LossLife, m.Weapon)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func insertMsgAuctionAnnounce(m *ChatWarsMessageAuctionAnnounce) error {
|
||||
objSubTypeId, err := getObjSubTypeId(m.ObjID64)
|
||||
if err != nil {
|
||||
@ -1516,22 +1559,7 @@ func insertMsgMiniWar(m *ChatWarsMessageMiniWar) error {
|
||||
defer stmt2.Close()
|
||||
|
||||
for c, r := range m.Report {
|
||||
switch c {
|
||||
case "Deerhorn":
|
||||
_, err = stmt2.Exec(m.ObjID64, castleDeer, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
|
||||
case "Dragonscale":
|
||||
_, err = stmt2.Exec(m.ObjID64, castleDragon, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
|
||||
case "Highnest":
|
||||
_, err = stmt2.Exec(m.ObjID64, castleHighnest, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
|
||||
case "Moonlight":
|
||||
_, err = stmt2.Exec(m.ObjID64, castleMoon, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
|
||||
case "Potato":
|
||||
_, err = stmt2.Exec(m.ObjID64, castlePotato, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
|
||||
case "Sharkteeth":
|
||||
_, err = stmt2.Exec(m.ObjID64, castleShark, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
|
||||
case "Wolfpack":
|
||||
_, err = stmt2.Exec(m.ObjID64, castleWolf, r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
|
||||
}
|
||||
_, err = stmt2.Exec(m.ObjID64, CastleID(c), r.Gardian, r.Result, r.Gold, r.Stock, r.Points)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -1556,22 +1584,8 @@ func insertMsgPillageInc(m *ChatWarsMessagePillageInc) error {
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
switch m.Castle {
|
||||
case "Deerhorn":
|
||||
_, err = stmt.Exec(m.ObjID64, m.Attacker, m.Guild, castleDeer)
|
||||
case "Dragonscale":
|
||||
_, err = stmt.Exec(m.ObjID64, m.Attacker, m.Guild, castleDragon)
|
||||
case "Highnest":
|
||||
_, err = stmt.Exec(m.ObjID64, m.Attacker, m.Guild, castleHighnest)
|
||||
case "Moonlight":
|
||||
_, err = stmt.Exec(m.ObjID64, m.Attacker, m.Guild, castleMoon)
|
||||
case "Potato":
|
||||
_, err = stmt.Exec(m.ObjID64, m.Attacker, m.Guild, castlePotato)
|
||||
case "Sharkteeth":
|
||||
_, err = stmt.Exec(m.ObjID64, m.Attacker, m.Guild, castleShark)
|
||||
case "Wolfpack":
|
||||
_, err = stmt.Exec(m.ObjID64, m.Attacker, m.Guild, castleWolf)
|
||||
}
|
||||
_, err = stmt.Exec(m.ObjID64, m.Attacker, m.Guild, CastleID(m.Castle))
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
36
utils.go
36
utils.go
@ -36,6 +36,42 @@ func Max(a int, b int) int {
|
||||
}
|
||||
}
|
||||
|
||||
func CastleID(c string) int {
|
||||
switch c {
|
||||
case "Deerhorn":
|
||||
return castleDeer
|
||||
case "Dragonscale":
|
||||
return castleDragon
|
||||
case "Highnest":
|
||||
return castleHighnest
|
||||
case "Moonlight":
|
||||
return castleMoon
|
||||
case "Potato":
|
||||
return castlePotato
|
||||
case "Sharkteeth":
|
||||
return castleShark
|
||||
case "Wolfpack":
|
||||
return castleWolf
|
||||
case "🐺":
|
||||
return castleDeer
|
||||
case "🐉":
|
||||
return castleDragon
|
||||
case "🦅":
|
||||
return castleHighnest
|
||||
case "🌑":
|
||||
return castleMoon
|
||||
case "🥔":
|
||||
return castlePotato
|
||||
case "🦈":
|
||||
return castleShark
|
||||
case "🐺":
|
||||
return castleWolf
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func fromChatWarsDate(d string) (t time.Time, err error) {
|
||||
r := regexp.MustCompile(`(?P<Day>[0-9]{2}) (?P<Month>(Wintar|Hornung|Lenzin|Ōstar|Winni|Brāh|Hewi|Aran|Witu|Wīndume|Herbist|Hailag)) (?P<Year>[0-9]{4})( (?P<Hour>[0-9]{2}):(?P<Minute>[0-9]{2})){0,1}`)
|
||||
if r.FindStringSubmatch(d) != nil {
|
||||
|
@ -165,6 +165,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
cwm, err := parseSubTypeMessageDuelFight(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageDuelFight.")
|
||||
cwm.ObjID64 = objId
|
||||
err = insertMsgDuelFight(&cwm)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgAuctionAnnounce")
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageDuelFight)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(DuelFight)")
|
||||
case objSubTypeMessageGoQuest:
|
||||
|
Loading…
Reference in New Issue
Block a user