test
This commit is contained in:
parent
9a30a6cdaf
commit
108b905a8b
27
client.go
27
client.go
@ -15,26 +15,27 @@ func clientSendCWMsg(userID64 int64, s string) {
|
|||||||
MQTGCmdQueue <- c
|
MQTGCmdQueue <- c
|
||||||
}
|
}
|
||||||
|
|
||||||
func clientMsgMe(userID64 int64, guildID64 int64, state string, timestamp time.Time) {
|
func clientMsgMe(m ChatWarsMessageMeAck) {
|
||||||
if _, ok := clientsQueue[userID64]; ok {
|
if _, ok := clientsQueue[m.UserID64]; ok {
|
||||||
if c, ok := clientsCW[userID64]; ok {
|
t, err := getObjMsgDate(m.ObjID64)
|
||||||
if c.LastUpdate.Before(timestamp) {
|
if c, ok := clientsCW[m.UserID64]; ok {
|
||||||
c.GuildID64 = guildID64
|
if c.LastUpdate.Before(t) {
|
||||||
c.State = state
|
c.GuildID64 = m.GuildID64
|
||||||
c.LastUpdate = timestamp
|
c.State = m.State
|
||||||
if cacheObjGuild[``].ObjID64 != guildID64 && strings.Compare(c.Role, ``) == 0 {
|
c.LastUpdate = t
|
||||||
|
if cacheObjGuild[``].ObjID64 != m.GuildID64 && strings.Compare(c.Role, ``) == 0 {
|
||||||
clientSendCWMsg(userID64, "/g_roles")
|
clientSendCWMsg(userID64, "/g_roles")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
c := ChatWarsClient{
|
c := ChatWarsClient{
|
||||||
GuildID64: guildID64,
|
GuildID64: m.GuildID64,
|
||||||
State: state,
|
State: state,
|
||||||
LastUpdate: timestamp,
|
LastUpdate: t,
|
||||||
}
|
}
|
||||||
clientsCW[userID64] = &c
|
clientsCW[m.UserID64] = &c
|
||||||
if cacheObjGuild[``].ObjID64 != guildID64 {
|
if cacheObjGuild[``].ObjID64 != m.GuildID64 {
|
||||||
clientSendCWMsg(userID64, "/g_roles")
|
clientSendCWMsg(m.UserID64, "/g_roles")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
3
def.go
3
def.go
@ -73,6 +73,9 @@ type ChatWarsMessageReportAck struct {
|
|||||||
|
|
||||||
type ChatWarsMessageMeAck 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 {
|
type ChatWarsMessageGoQuestAck struct {
|
||||||
|
12
msg.go
12
msg.go
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageReportAck, error) {
|
func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageReportAck, error) {
|
||||||
cwm := ChatWarsMessageReportAck{}
|
cwm := ChatWarsMessageReportAck{}
|
||||||
|
/*
|
||||||
log.Printf("parseSubTypeMessageReport : War report identified\n")
|
log.Printf("parseSubTypeMessageReport : War report identified\n")
|
||||||
log.Printf("parseSubTypeMessageReport : Castle : %s\n", r.ReplaceAllString(m.Text, "${Castle}"))
|
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 : Guild : %s\n", r.ReplaceAllString(m.Text, "${Guild}"))
|
||||||
@ -23,16 +24,18 @@ func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWa
|
|||||||
log.Printf("parseSubTypeMessageReport : Stock : %s\n", r.ReplaceAllString(m.Text, "${Stock}"))
|
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 : Stamina : %s\n", r.ReplaceAllString(m.Text, "${Stamina}"))
|
||||||
log.Printf("parseSubTypeMessageReport : Crit : %s\n", r.ReplaceAllString(m.Text, "${Crit}"))
|
log.Printf("parseSubTypeMessageReport : Crit : %s\n", r.ReplaceAllString(m.Text, "${Crit}"))
|
||||||
|
*/
|
||||||
return &cwm, nil
|
return &cwm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMeAck, error) {
|
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 : 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 : Class : %s\n", r.ReplaceAllString(m.Text, "${Class}"))
|
||||||
log.Printf("parseSubTypeMessageReport : Castle : %s\n", r.ReplaceAllString(m.Text, "${Castle}"))
|
log.Printf("parseSubTypeMessageReport : Castle : %s\n", r.ReplaceAllString(m.Text, "${Castle}"))
|
||||||
log.Printf("parseSubTypeMessageReport : Level : %s\n", r.ReplaceAllString(m.Text, "${Level}"))
|
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 : DefGear : %s\n", r.ReplaceAllString(m.Text, "${DefGear}"))
|
||||||
log.Printf("parseSubTypeMessageReport : BagUsed : %s\n", r.ReplaceAllString(m.Text, "${BagUsed}"))
|
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 : BagDispo : %s\n", r.ReplaceAllString(m.Text, "${BagDispo}"))
|
||||||
log.Printf("parseSubTypeMessageReport : State : %s\n", r.ReplaceAllString(m.Text, "${State}"))
|
|
||||||
*/
|
*/
|
||||||
return &cwm, nil
|
return &cwm, nil
|
||||||
}
|
}
|
||||||
|
21
obj.go
21
obj.go
@ -375,3 +375,24 @@ func loadObjUser() error {
|
|||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
@ -144,6 +144,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
|||||||
cwm, err := parseSubTypeMessageMeAck(m, r)
|
cwm, err := parseSubTypeMessageMeAck(m, r)
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.")
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.")
|
||||||
cwm.ObjID64 = objId
|
cwm.ObjID64 = objId
|
||||||
|
clientMsgMe(cwm)
|
||||||
err = setObjSubTypeId(objId, objSubTypeMessageMeAck)
|
err = setObjSubTypeId(objId, objSubTypeMessageMeAck)
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MeAck)")
|
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MeAck)")
|
||||||
case objSubTypeMessageGoQuestAck:
|
case objSubTypeMessageGoQuestAck:
|
||||||
@ -421,13 +422,13 @@ func MQKeepAliveWorker() {
|
|||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandSendMsg,
|
Type: commandSendMsg,
|
||||||
ToUserID64: x.UserID64,
|
ToUserID64: x.UserID64,
|
||||||
Text: "You are connected.",
|
Text: "Your client is connected.",
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
c = TGCommand{
|
c = TGCommand{
|
||||||
Type: commandSendMsg,
|
Type: commandSendMsg,
|
||||||
ToUserID64: cfg.Bot.Admin,
|
ToUserID64: cfg.Bot.Admin,
|
||||||
Text: fmt.Sprintf("%s is connected.", x.Nickname),
|
Text: fmt.Sprintf("Client `%s` is connected.", x.Nickname),
|
||||||
}
|
}
|
||||||
TGCmdQueue <- c
|
TGCmdQueue <- c
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user