94 lines
4.3 KiB
Go
94 lines
4.3 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"regexp"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageReportAck, error) {
|
|
cwm := ChatWarsMessageReportAck{}
|
|
log.Printf("parseSubTypeMessageReport : War report identified\n")
|
|
log.Printf("parseSubTypeMessageReport : Castle : %s\n", r.ReplaceAllString(m.Text, "${Castle}"))
|
|
log.Printf("parseSubTypeMessageReport : Guild : %s\n", r.ReplaceAllString(m.Text, "${Guild}"))
|
|
log.Printf("parseSubTypeMessageReport : User : %s\n", r.ReplaceAllString(m.Text, "${User}"))
|
|
log.Printf("parseSubTypeMessageReport : Attack : %s\n", r.ReplaceAllString(m.Text, "${Attack}"))
|
|
log.Printf("parseSubTypeMessageReport : AttackMod : %s\n", r.ReplaceAllString(m.Text, "${AttackMod}"))
|
|
log.Printf("parseSubTypeMessageReport : Defense : %s\n", r.ReplaceAllString(m.Text, "${Defense}"))
|
|
log.Printf("parseSubTypeMessageReport : Level : %s\n", r.ReplaceAllString(m.Text, "${Level}"))
|
|
log.Printf("parseSubTypeMessageReport : Exp : %s\n", r.ReplaceAllString(m.Text, "${Exp}"))
|
|
log.Printf("parseSubTypeMessageReport : Gold : %s\n", r.ReplaceAllString(m.Text, "${Gold}"))
|
|
log.Printf("parseSubTypeMessageReport : Stock : %s\n", r.ReplaceAllString(m.Text, "${Stock}"))
|
|
log.Printf("parseSubTypeMessageReport : Stamina : %s\n", r.ReplaceAllString(m.Text, "${Stamina}"))
|
|
log.Printf("parseSubTypeMessageReport : Crit : %s\n", r.ReplaceAllString(m.Text, "${Crit}"))
|
|
|
|
return &cwm, nil
|
|
}
|
|
|
|
func parseSubTypeMessageDuelFight(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageDuelFight, error) {
|
|
cwm := ChatWarsMessageDuelFight{}
|
|
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
|
|
}
|
|
|
|
func parseSubTypeMessageMiniWar(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMiniWar, error) {
|
|
t, err := time.Parse("02/01/06 15:04", r.ReplaceAllString(m.Text, "${Time}"))
|
|
logOnError(err, "parseSubTypeMessageMiniWar : parsing time : "+r.ReplaceAllString(m.Text, "${Time}"))
|
|
cwm := ChatWarsMessageMiniWar{
|
|
Time: t,
|
|
Report: make(map[string]*ChatWarsMessageMiniWarCastle),
|
|
}
|
|
for i := 1; i <= 7; i++ {
|
|
loot := fmt.Sprintf("${Loot%d}", i)
|
|
gardian := fmt.Sprintf("${Gardian%d}", i)
|
|
result := fmt.Sprintf("${Result%d}", i)
|
|
gold := fmt.Sprintf("${Gold%d}", i)
|
|
stock := fmt.Sprintf("${Stock%d}", i)
|
|
rep := ChatWarsMessageMiniWarCastle{
|
|
Gardian: r.ReplaceAllString(m.Text, gardian),
|
|
Result: r.ReplaceAllString(m.Text, result),
|
|
}
|
|
rep.Gold, err = strconv.ParseInt(r.ReplaceAllString(m.Text, gold), 10, 64)
|
|
rep.Stock, err = strconv.ParseInt(r.ReplaceAllString(m.Text, stock), 10, 64)
|
|
cwm.Report[r.ReplaceAllString(m.Text, loot)] = &rep
|
|
}
|
|
for i := 1; i <= 7; i++ {
|
|
score := fmt.Sprintf("${Score%d}", i)
|
|
points := fmt.Sprintf("${Points%d}", i)
|
|
cwm.Report[r.ReplaceAllString(m.Text, score)].Points, err = strconv.ParseInt(r.ReplaceAllString(m.Text, points), 10, 64)
|
|
}
|
|
|
|
return &cwm, err
|
|
}
|
|
|
|
func parseSubTypeMessagePillageInc(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessagePillageInc, error) {
|
|
cwm := ChatWarsMessagePillageInc{}
|
|
cwm.Attacker = r.ReplaceAllString(m.Text, "${Attacker}")
|
|
cwm.Castle = r.ReplaceAllString(m.Text, "${Castle}")
|
|
cwm.Guild = r.ReplaceAllString(m.Text, "${Guild}")
|
|
|
|
return &cwm, nil
|
|
}
|