From f7ef018ae84980f6d787ecd87888022665a88e0f Mon Sep 17 00:00:00 2001 From: shoopea Date: Mon, 13 May 2019 14:12:31 +0800 Subject: [PATCH] test --- def.go | 6 +-- sql.go | 6 ++- workers.go | 125 ++--------------------------------------------------- 3 files changed, 10 insertions(+), 127 deletions(-) diff --git a/def.go b/def.go index 66c9a87..5449d44 100644 --- a/def.go +++ b/def.go @@ -36,9 +36,9 @@ type ChatWarsMessageMiniWar struct { type ChatWarsMessageMiniWarCastle struct { Gardian string `json:"gardian"` Result string `json:"result"` - Gold int32 `json:"gold"` - Stock int32 `json:"stock"` - Points int32 `json:"points"` + Gold int64 `json:"gold"` + Stock int64 `json:"stock"` + Points int64 `json:"points"` } type MessageParsingRule struct { diff --git a/sql.go b/sql.go index 24138d7..3154803 100644 --- a/sql.go +++ b/sql.go @@ -1344,8 +1344,8 @@ func putUnprocessedMsg(m ChatWarsMessage) (int64, error) { return objId, nil } -func getMsg(objId int64) (ChatWarsMessage, error) { - var m ChatWarsMessage +func getMsg(objId int64) (*ChatWarsMessage, error) { + var m *ChatWarsMessage stmt, err := db.Prepare(`SELECT om.msg_id, om.chat_id, om.sender_user_id, om.date, om.text FROM obj_msg om WHERE om.obj_id = ?`) if err != nil { @@ -1353,6 +1353,8 @@ func getMsg(objId int64) (ChatWarsMessage, error) { } defer stmt.Close() + m = new(ChatWarsMessage) + err = stmt.QueryRow(objId).Scan(&m.ID64, &m.ChatID64, &m.SenderUserID64, &m.Date, &m.Text) if err != nil { return m, err diff --git a/workers.go b/workers.go index 69fe905..25f0ee6 100644 --- a/workers.go +++ b/workers.go @@ -99,128 +99,9 @@ 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: - t, err := time.Parse("02/01/06 15:04", r.ReplaceAllString(m.Text, "${Time}")) - logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : objSubTypeMessageMiniWar parsing time : "+r.ReplaceAllString(m.Text, "${Time}")) - cwm := ChatWarsMessageMiniWar{ - Time: t, - Report: make(map[string]*ChatWarsMessageMiniWarCastle), - } - g, err := strconv.Atoi(r.ReplaceAllString(m.Text, "${Gold1}")) - s, err := strconv.Atoi(r.ReplaceAllString(m.Text, "${Stock1}")) - rep := ChatWarsMessageMiniWarCastle{ - Gardian: r.ReplaceAllString(m.Text, "${Gardian1}"), - Result: r.ReplaceAllString(m.Text, "${Result1}"), - Gold: int32(g), - Stock: int32(s), - } - cwm.Report[r.ReplaceAllString(m.Text, "${Loot1}")] = &rep - g, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Gold2}")) - s, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Stock2}")) - rep = ChatWarsMessageMiniWarCastle{ - Gardian: r.ReplaceAllString(m.Text, "${Gardian2}"), - Result: r.ReplaceAllString(m.Text, "${Result2}"), - Gold: int32(g), - Stock: int32(s), - } - cwm.Report[r.ReplaceAllString(m.Text, "${Loot2}")] = &rep - g, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Gold3}")) - s, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Stock3}")) - rep = ChatWarsMessageMiniWarCastle{ - Gardian: r.ReplaceAllString(m.Text, "${Gardian3}"), - Result: r.ReplaceAllString(m.Text, "${Result3}"), - Gold: int32(g), - Stock: int32(s), - } - cwm.Report[r.ReplaceAllString(m.Text, "${Loot3}")] = &rep - g, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Gold4}")) - s, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Stock4}")) - rep = ChatWarsMessageMiniWarCastle{ - Gardian: r.ReplaceAllString(m.Text, "${Gardian4}"), - Result: r.ReplaceAllString(m.Text, "${Result4}"), - Gold: int32(g), - Stock: int32(s), - } - cwm.Report[r.ReplaceAllString(m.Text, "${Loot4}")] = &rep - g, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Gold5}")) - s, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Stock5}")) - rep = ChatWarsMessageMiniWarCastle{ - Gardian: r.ReplaceAllString(m.Text, "${Gardian5}"), - Result: r.ReplaceAllString(m.Text, "${Result5}"), - Gold: int32(g), - Stock: int32(s), - } - cwm.Report[r.ReplaceAllString(m.Text, "${Loot5}")] = &rep - g, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Gold6}")) - s, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Stock6}")) - rep = ChatWarsMessageMiniWarCastle{ - Gardian: r.ReplaceAllString(m.Text, "${Gardian6}"), - Result: r.ReplaceAllString(m.Text, "${Result6}"), - Gold: int32(g), - Stock: int32(s), - } - cwm.Report[r.ReplaceAllString(m.Text, "${Loot6}")] = &rep - g, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Gold7}")) - s, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Stock7}")) - rep = ChatWarsMessageMiniWarCastle{ - Gardian: r.ReplaceAllString(m.Text, "${Gardian7}"), - Result: r.ReplaceAllString(m.Text, "${Result7}"), - Gold: int32(g), - Stock: int32(s), - } - cwm.Report[r.ReplaceAllString(m.Text, "${Loot7}")] = &rep - - p, err := strconv.Atoi(r.ReplaceAllString(m.Text, "${Points1}")) - logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : convert Points1 : "+r.ReplaceAllString(m.Text, "$(Points1)")) - cwm.Report[r.ReplaceAllString(m.Text, "${Score1}")].Points = int32(p) - - p, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Points2}")) - logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : convert Points2 : "+r.ReplaceAllString(m.Text, "$(Points2)")) - cwm.Report[r.ReplaceAllString(m.Text, "${Score2}")].Points = int32(p) - - p, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Points3}")) - logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : convert Points3 : "+r.ReplaceAllString(m.Text, "$(Points3)")) - cwm.Report[r.ReplaceAllString(m.Text, "${Score3}")].Points = int32(p) - - p, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Points4}")) - logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : convert Points4 : "+r.ReplaceAllString(m.Text, "$(Points4)")) - cwm.Report[r.ReplaceAllString(m.Text, "${Score4}")].Points = int32(p) - - p, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Points5}")) - logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : convert Points5 : "+r.ReplaceAllString(m.Text, "$(Points5)")) - cwm.Report[r.ReplaceAllString(m.Text, "${Score5}")].Points = int32(p) - - p, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Points6}")) - logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : convert Points6 : "+r.ReplaceAllString(m.Text, "$(Points6)")) - cwm.Report[r.ReplaceAllString(m.Text, "${Score6}")].Points = int32(p) - - p, err = strconv.Atoi(r.ReplaceAllString(m.Text, "${Points7}")) - logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : convert Points7 : "+r.ReplaceAllString(m.Text, "$(Points7)")) - cwm.Report[r.ReplaceAllString(m.Text, "${Score7}")].Points = int32(p) - - //b, err := json.Marshal(cwm) - /* - if len(r.ReplaceAllString(m.Text, "${Loot1}")) < 6 || len(r.ReplaceAllString(m.Text, "${Loot1}")) > 11 { - log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : NOT MATCHED \nLoot1: %s\n%s\n", r.ReplaceAllString(m.Text, "${Loot1}"), m.Text) - } - */ - //log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : MATCHED!\nLoot1: %s\n%s\n", r.ReplaceAllString(m.Text, "${Loot1}"), m.Text) - if (len(r.ReplaceAllString(m.Text, "${Loot1}")) < 6 || len(r.ReplaceAllString(m.Text, "${Loot1}")) > 11) || - (len(r.ReplaceAllString(m.Text, "${Loot2}")) < 6 || len(r.ReplaceAllString(m.Text, "${Loot2}")) > 11) || - (len(r.ReplaceAllString(m.Text, "${Loot3}")) < 6 || len(r.ReplaceAllString(m.Text, "${Loot3}")) > 11) || - (len(r.ReplaceAllString(m.Text, "${Loot4}")) < 6 || len(r.ReplaceAllString(m.Text, "${Loot4}")) > 11) || - (len(r.ReplaceAllString(m.Text, "${Loot5}")) < 6 || len(r.ReplaceAllString(m.Text, "${Loot5}")) > 11) || - (len(r.ReplaceAllString(m.Text, "${Loot6}")) < 6 || len(r.ReplaceAllString(m.Text, "${Loot6}")) > 11) || - (len(r.ReplaceAllString(m.Text, "${Loot7}")) < 6 || len(r.ReplaceAllString(m.Text, "${Loot7}")) > 11) { - log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : NOT MATCHED \nLoot1: %s\nLoot2: %s\nLoot3: %s\nLoot4: %s\nLoot5: %s\nLoot6: %s\nLoot7: %s\n%s\n", r.ReplaceAllString(m.Text, "${Loot1}"), r.ReplaceAllString(m.Text, "${Loot2}"), r.ReplaceAllString(m.Text, "${Loot3}"), r.ReplaceAllString(m.Text, "${Loot4}"), r.ReplaceAllString(m.Text, "${Loot5}"), r.ReplaceAllString(m.Text, "${Loot6}"), r.ReplaceAllString(m.Text, "${Loot7}"), m.Text) - } else { - //log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : MATCHED! \nLoot1: %s | Result1: %s | Gold1: %s | Stock1: %s\nLoot2: %s | Result2: %s | Gold2: %s | Stock2: %s\nLoot3: %s | Result3: %s | Gold3: %s | Stock3: %s\nLoot4: %s | Result4: %s | Gold4: %s | Stock4: %s\nLoot5: %s | Result5: %s | Gold5: %s | Stock5: %s\nLoot6: %s | Result6: %s | Gold6: %s | Stock6: %s\nLoot7: %s | Result7: %s | Gold7: %s | Stock7: %s\n%s\n", r.ReplaceAllString(m.Text, "${Loot1}"), r.ReplaceAllString(m.Text, "${Result1}"), r.ReplaceAllString(m.Text, "${Gold1}"), r.ReplaceAllString(m.Text, "${Stock1}"), r.ReplaceAllString(m.Text, "${Loot2}"), r.ReplaceAllString(m.Text, "${Result2}"), r.ReplaceAllString(m.Text, "${Gold2}"), r.ReplaceAllString(m.Text, "${Stock2}"), r.ReplaceAllString(m.Text, "${Loot3}"), r.ReplaceAllString(m.Text, "${Result3}"), r.ReplaceAllString(m.Text, "${Gold3}"), r.ReplaceAllString(m.Text, "${Stock3}"), r.ReplaceAllString(m.Text, "${Loot4}"), r.ReplaceAllString(m.Text, "${Result4}"), r.ReplaceAllString(m.Text, "${Gold4}"), r.ReplaceAllString(m.Text, "${Stock4}"), r.ReplaceAllString(m.Text, "${Loot5}"), r.ReplaceAllString(m.Text, "${Result5}"), r.ReplaceAllString(m.Text, "${Gold5}"), r.ReplaceAllString(m.Text, "${Stock5}"), r.ReplaceAllString(m.Text, "${Loot6}"), r.ReplaceAllString(m.Text, "${Result6}"), r.ReplaceAllString(m.Text, "${Gold6}"), r.ReplaceAllString(m.Text, "${Stock6}"), r.ReplaceAllString(m.Text, "${Loot7}"), r.ReplaceAllString(m.Text, "${Result7}"), r.ReplaceAllString(m.Text, "${Gold7}"), r.ReplaceAllString(m.Text, "${Stock7}"), m.Text) - //log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : objSubTypeMessageMiniWar\nScore1 : %s | Points1 : %s\nScore2 : %s | Points2 : %s\nScore3 : %s | Points3 : %s\nScore4 : %s | Points4 : %s\nScore5 : %s | Points5 : %s\nScore6 : %s | Points6 : %s\nScore7 : %s | Points8 : %s\n%s\n%s\n", r.ReplaceAllString(m.Text, "${Score1}"), r.ReplaceAllString(m.Text, "${Points1}"), r.ReplaceAllString(m.Text, "${Score2}"), r.ReplaceAllString(m.Text, "${Points2}"), r.ReplaceAllString(m.Text, "${Score3}"), r.ReplaceAllString(m.Text, "${Points3}"), r.ReplaceAllString(m.Text, "${Score4}"), r.ReplaceAllString(m.Text, "${Points4}"), r.ReplaceAllString(m.Text, "${Score5}"), r.ReplaceAllString(m.Text, "${Points5}"), r.ReplaceAllString(m.Text, "${Score6}"), r.ReplaceAllString(m.Text, "${Points6}"), r.ReplaceAllString(m.Text, "${Score7}"), r.ReplaceAllString(m.Text, "${Points7}"), m.Text, string(b)) - } - /* - if err == nil { - log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : War time : %s (%d)\n", r.ReplaceAllString(m.Text, "${Time}"), objId) - } - */ + cwm, err := parseSubTypeMessageMiniWar(m, r) + b, err := json.Marshal(cwm) + log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : %s\n%s\n", m.Text, string(b)) case objSubTypeMessageAuctionAnnounce: cwm := ChatWarsMessageAuctionAnnounce{