This commit is contained in:
shoopea 2019-05-30 13:49:11 +08:00
parent 9a30a6cdaf
commit 108b905a8b
5 changed files with 62 additions and 34 deletions

View File

@ -15,26 +15,27 @@ func clientSendCWMsg(userID64 int64, s string) {
MQTGCmdQueue <- c
}
func clientMsgMe(userID64 int64, guildID64 int64, state string, timestamp time.Time) {
if _, ok := clientsQueue[userID64]; ok {
if c, ok := clientsCW[userID64]; ok {
if c.LastUpdate.Before(timestamp) {
c.GuildID64 = guildID64
c.State = state
c.LastUpdate = timestamp
if cacheObjGuild[``].ObjID64 != guildID64 && strings.Compare(c.Role, ``) == 0 {
func clientMsgMe(m ChatWarsMessageMeAck) {
if _, ok := clientsQueue[m.UserID64]; ok {
t, err := getObjMsgDate(m.ObjID64)
if c, ok := clientsCW[m.UserID64]; ok {
if c.LastUpdate.Before(t) {
c.GuildID64 = m.GuildID64
c.State = m.State
c.LastUpdate = t
if cacheObjGuild[``].ObjID64 != m.GuildID64 && strings.Compare(c.Role, ``) == 0 {
clientSendCWMsg(userID64, "/g_roles")
}
}
} else {
c := ChatWarsClient{
GuildID64: guildID64,
GuildID64: m.GuildID64,
State: state,
LastUpdate: timestamp,
LastUpdate: t,
}
clientsCW[userID64] = &c
if cacheObjGuild[``].ObjID64 != guildID64 {
clientSendCWMsg(userID64, "/g_roles")
clientsCW[m.UserID64] = &c
if cacheObjGuild[``].ObjID64 != m.GuildID64 {
clientSendCWMsg(m.UserID64, "/g_roles")
}
}

5
def.go
View File

@ -72,7 +72,10 @@ type ChatWarsMessageReportAck struct {
}
type ChatWarsMessageMeAck struct {
ObjID64 int64 `json:"obj_id"`
ObjID64 int64 `json:"obj_id"`
UserID64 int64 `json:"user_id"`
GuildID64 int64 `json:"guild_id"`
State string `json:"state"`
}
type ChatWarsMessageGoQuestAck struct {

38
msg.go
View File

@ -10,29 +10,32 @@ import (
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}"))
/*
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 parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMeAck, error) {
cwm := ChatWarsMessageMeAck{}
cwm := ChatWarsMessageMeAck{
UserID64: getObjUserID(r.ReplaceAllString(m.Text, "${Player}")),
GuildID64: getObjGuildID(r.ReplaceAllString(m.Text, "${Guild}")),
State: r.ReplaceAllString(m.Text, "${State}"),
}
/*
log.Printf("parseSubTypeMessageReport : Me report identified\n")
log.Printf("parseSubTypeMessageReport : Player : %s\n", r.ReplaceAllString(m.Text, "${Player}"))
log.Printf("parseSubTypeMessageReport : Guild : %s\n", r.ReplaceAllString(m.Text, "${Guild}"))
log.Printf("parseSubTypeMessageReport : Class : %s\n", r.ReplaceAllString(m.Text, "${Class}"))
log.Printf("parseSubTypeMessageReport : Castle : %s\n", r.ReplaceAllString(m.Text, "${Castle}"))
log.Printf("parseSubTypeMessageReport : Level : %s\n", r.ReplaceAllString(m.Text, "${Level}"))
@ -49,7 +52,6 @@ func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMe
log.Printf("parseSubTypeMessageReport : DefGear : %s\n", r.ReplaceAllString(m.Text, "${DefGear}"))
log.Printf("parseSubTypeMessageReport : BagUsed : %s\n", r.ReplaceAllString(m.Text, "${BagUsed}"))
log.Printf("parseSubTypeMessageReport : BagDispo : %s\n", r.ReplaceAllString(m.Text, "${BagDispo}"))
log.Printf("parseSubTypeMessageReport : State : %s\n", r.ReplaceAllString(m.Text, "${State}"))
*/
return &cwm, nil
}

21
obj.go
View File

@ -375,3 +375,24 @@ func loadObjUser() error {
return nil
}
func getObjMsgDate(objID64 int64) (time.Time, error) {
var t time.Time
rows, err := db.Query(`SELECT om.date FROM obj_msg om WHERE om.obj_id = ?;`, objID64)
logOnError(err, "getObjMsgDate : select")
if err != nil {
return time.Now(), nil
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(&t)
logOnError(err, "getObjMsgDate : row")
if err != nil {
return time.Now(), nil
}
}
return t, nil
}

View File

@ -144,6 +144,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
cwm, err := parseSubTypeMessageMeAck(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.")
cwm.ObjID64 = objId
clientMsgMe(cwm)
err = setObjSubTypeId(objId, objSubTypeMessageMeAck)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MeAck)")
case objSubTypeMessageGoQuestAck:
@ -421,13 +422,13 @@ func MQKeepAliveWorker() {
c := TGCommand{
Type: commandSendMsg,
ToUserID64: x.UserID64,
Text: "You are connected.",
Text: "Your client is connected.",
}
TGCmdQueue <- c
c = TGCommand{
Type: commandSendMsg,
ToUserID64: cfg.Bot.Admin,
Text: fmt.Sprintf("%s is connected.", x.Nickname),
Text: fmt.Sprintf("Client `%s` is connected.", x.Nickname),
}
TGCmdQueue <- c