fix references

This commit is contained in:
shoopea 2019-07-31 16:57:45 +08:00
parent 306648c830
commit cd8e1e40f1
6 changed files with 26 additions and 26 deletions

View File

@ -50,7 +50,7 @@ func clientRefreshCWMsg(userID64 int64, chatID64 int64, msgID64 int64) {
} }
func clientMsgMeAck(m *ChatWarsMessageMeAck) { func clientMsgMeAck(m *ChatWarsMessageMeAck) {
if clt, ok := getLockedClient(m.Msg.UserID64, false); ok { if clt, ok := getLockedClient(m.Msg.TGUserID64, false); ok {
if clt.Active { if clt.Active {
if clt.CWLastUpdate.Before(m.Msg.Date) { if clt.CWLastUpdate.Before(m.Msg.Date) {
clt.CWGuildID64 = m.GuildID64 clt.CWGuildID64 = m.GuildID64
@ -58,7 +58,7 @@ func clientMsgMeAck(m *ChatWarsMessageMeAck) {
clt.CWState = m.State clt.CWState = m.State
clt.CWLastUpdate = m.Msg.Date clt.CWLastUpdate = m.Msg.Date
if getObjGuildID(``) != m.GuildID64 && strings.Compare(clt.CWRole, ``) == 0 { if getObjGuildID(``) != m.GuildID64 && strings.Compare(clt.CWRole, ``) == 0 {
clientSendCWMsg(m.Msg.UserID64, "/g_roles") clientSendCWMsg(m.Msg.TGUserID64, "/g_roles")
} }
} }
} }
@ -67,7 +67,7 @@ func clientMsgMeAck(m *ChatWarsMessageMeAck) {
} }
func clientMsgGoQuestAck(m *ChatWarsMessageGoQuestAck) { func clientMsgGoQuestAck(m *ChatWarsMessageGoQuestAck) {
if clt, ok := getLockedClient(m.Msg.UserID64, false); ok { if clt, ok := getLockedClient(m.Msg.TGUserID64, false); ok {
if clt.Active { if clt.Active {
if clt.CWLastUpdate.Before(m.Msg.Date) { if clt.CWLastUpdate.Before(m.Msg.Date) {
clt.CWLastUpdate = m.Msg.Date clt.CWLastUpdate = m.Msg.Date
@ -79,7 +79,7 @@ func clientMsgGoQuestAck(m *ChatWarsMessageGoQuestAck) {
} }
func clientMsgGRolesAck(m *ChatWarsMessageGRolesAck) { func clientMsgGRolesAck(m *ChatWarsMessageGRolesAck) {
if clt, ok := getLockedClient(m.Msg.UserID64, false); ok { if clt, ok := getLockedClient(m.Msg.TGUserID64, false); ok {
if clt.Active { if clt.Active {
if clt.CWLastUpdate.Before(m.Msg.Date) { if clt.CWLastUpdate.Before(m.Msg.Date) {
if m.CommanderID64 == clt.CWUserID64 { if m.CommanderID64 == clt.CWUserID64 {

14
def.go
View File

@ -109,13 +109,13 @@ type ChatWarsMessageReportAck struct {
} }
type ChatWarsMessageMeAck struct { type ChatWarsMessageMeAck struct {
Msg *ChatWarsMessage `json:"msg"` Msg *ChatWarsMessage `json:"msg"`
UserID64 int64 `json:"user_id"` CWUserID64 int64 `json:"user_id"`
GuildID64 int64 `json:"guild_id"` CWGuildID64 int64 `json:"guild_id"`
State string `json:"state"` State string `json:"state"`
Level int64 `json:"level"` Level int64 `json:"level"`
ExpNow int64 `json:"exp_now"` ExpNow int64 `json:"exp_now"`
ExpLvl int64 `json:"exp_lvl"` ExpLvl int64 `json:"exp_lvl"`
} }
type ChatWarsMessageGRolesAck struct { type ChatWarsMessageGRolesAck struct {

2
job.go
View File

@ -430,7 +430,7 @@ func jobMsgRefresh(j Job) {
err = delObj(p.ObjID64) err = delObj(p.ObjID64)
logOnError(err, "jobMsgRefresh : delObj") logOnError(err, "jobMsgRefresh : delObj")
clientRefreshCWMsg(m.UserID64, m.ChatID64, m.ID64) clientRefreshCWMsg(m.TGUserID64, m.ChatID64, m.ID64)
err = setJobDone(j.ID64) err = setJobDone(j.ID64)
logOnError(err, "joMsgClient : setJobDone") logOnError(err, "joMsgClient : setJobDone")

6
msg.go
View File

@ -75,9 +75,9 @@ func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMe
var i int64 var i int64
cwm := ChatWarsMessageMeAck{ cwm := ChatWarsMessageMeAck{
UserID64: getObjUserID(r.ReplaceAllString(m.Text, "${Player}")), CWUserID64: getObjUserID(r.ReplaceAllString(m.Text, "${Player}")),
GuildID64: getObjGuildID(r.ReplaceAllString(m.Text, "${Guild}")), CWGuildID64: getObjGuildID(r.ReplaceAllString(m.Text, "${Guild}")),
State: r.ReplaceAllString(m.Text, "${State}"), State: r.ReplaceAllString(m.Text, "${State}"),
} }
i, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${ExpNow}"), 10, 64) i, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${ExpNow}"), 10, 64)
cwm.ExpNow = i cwm.ExpNow = i

10
obj.go
View File

@ -76,7 +76,7 @@ func objAddName(objID64 int64, name string) error {
return err return err
} }
func addObjMsg(msgID64 int64, msgChatID64 int64, msgUserID64 int64, msgSenderUserID64 int64, msgDate time.Time, msgText string) (int64, error) { func addObjMsg(msgID64 int64, msgChatID64 int64, msgTGUserID64 int64, msgTGSenderUserID64 int64, msgDate time.Time, msgText string) (int64, error) {
tx, err := db.Begin() tx, err := db.Begin()
logOnError(err, "addObjMsg : start transaction") logOnError(err, "addObjMsg : start transaction")
if err != nil { if err != nil {
@ -107,7 +107,7 @@ func addObjMsg(msgID64 int64, msgChatID64 int64, msgUserID64 int64, msgSenderUse
} }
defer stmt.Close() defer stmt.Close()
_, err = stmt.Exec(objId, msgID64, msgChatID64, msgUserID64, msgSenderUserID64, msgDate, msgText) _, err = stmt.Exec(objId, msgID64, msgChatID64, msgTGUserID64, msgTGSenderUserID64, msgDate, msgText)
if err != nil { if err != nil {
err2 := tx.Rollback() err2 := tx.Rollback()
logOnError(err2, "addObjMsg : rollback exec insert obj_msg") logOnError(err2, "addObjMsg : rollback exec insert obj_msg")
@ -121,8 +121,8 @@ func addObjMsg(msgID64 int64, msgChatID64 int64, msgUserID64 int64, msgSenderUse
m := new(ChatWarsMessage) m := new(ChatWarsMessage)
m.ObjID64 = objId m.ObjID64 = objId
m.UserID64 = msgUserID64 m.TGUserID64 = msgTGUserID64
m.SenderUserID64 = msgSenderUserID64 m.SenderUserID64 = msgTGSenderUserID64
m.Date = msgDate m.Date = msgDate
m.ID64 = msgID64 m.ID64 = msgID64
m.ChatID64 = msgChatID64 m.ChatID64 = msgChatID64
@ -148,7 +148,7 @@ func getObjMsg(objId int64) (*ChatWarsMessage, error) {
m = new(ChatWarsMessage) m = new(ChatWarsMessage)
err = stmt.QueryRow(objId).Scan(&m.ID64, &m.ChatID64, &m.UserID64, &m.SenderUserID64, &m.Date, &m.Text) err = stmt.QueryRow(objId).Scan(&m.ID64, &m.ChatID64, &m.TGUserID64, &m.TGSenderUserID64, &m.Date, &m.Text)
if err != nil { if err != nil {
return m, err return m, err
} }

View File

@ -309,7 +309,7 @@ func MQTGCmdWorker(id int, cmds <-chan TGCommand) {
func SQLCWMsgWorker(id int, msgs <-chan ChatWarsMessage, objIds chan<- int64) { func SQLCWMsgWorker(id int, msgs <-chan ChatWarsMessage, objIds chan<- int64) {
//log.Printf("SQLCWMsgWorker[" + strconv.Itoa(id) + "] : Starting.") //log.Printf("SQLCWMsgWorker[" + strconv.Itoa(id) + "] : Starting.")
for m := range msgs { for m := range msgs {
objId, err := addObjMsg(m.ID64, m.ChatID64, m.UserID64, m.SenderUserID64, m.Date, m.Text) objId, err := addObjMsg(m.ID64, m.ChatID64, m.TGUserID64, m.TGSenderUserID64, m.Date, m.Text)
logOnError(err, "SQLCWMsgWorker["+strconv.Itoa(id)+"] : Inserting message.") logOnError(err, "SQLCWMsgWorker["+strconv.Itoa(id)+"] : Inserting message.")
if err == nil && objId != 0 { if err == nil && objId != 0 {
// log.Printf("SQLCWMsgWorker["+strconv.Itoa(id)+"] : Message inserted (%d).\n", objId) // log.Printf("SQLCWMsgWorker["+strconv.Itoa(id)+"] : Message inserted (%d).\n", objId)
@ -394,14 +394,14 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
s := TGCommand{ s := TGCommand{
Type: commandSendMsg, Type: commandSendMsg,
Text: fmt.Sprintf("Catching pillage (%s)", m.Date.Format(time.RFC3339)), Text: fmt.Sprintf("Catching pillage (%s)", m.Date.Format(time.RFC3339)),
ToUserID64: m.UserID64, ToUserID64: m.TGUserID64,
} }
TGCmdQueue <- s TGCmdQueue <- s
p := JobPayloadPillage{ p := JobPayloadPillage{
ObjID64: objId, ObjID64: objId,
} }
b, _ := json.Marshal(&p) b, _ := json.Marshal(&p)
_, err = createJob(objSubTypeJobPillage, objJobPriority, m.UserID64, m.Date.Add(time.Duration(25+rand.Intn(35))*time.Second), b) _, err = createJob(objSubTypeJobPillage, objJobPriority, m.TGUserID64, m.Date.Add(time.Duration(25+rand.Intn(35))*time.Second), b)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : createJob(JobPillage)") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : createJob(JobPillage)")
} }
case objSubTypeMessageMeAck: case objSubTypeMessageMeAck:
@ -409,13 +409,13 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.")
cwm.Msg = m cwm.Msg = m
clientMsgMeAck(cwm) clientMsgMeAck(cwm)
_, err = addObjXP(cwm.UserID64, cwm.ExpNow, cwm.ExpLvl, cwm.Level, m.Date) _, err = addObjXP(cwm.CWUserID64, cwm.ExpNow, cwm.ExpLvl, cwm.Level, m.Date)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : addObjXP(MeAck)") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : addObjXP(MeAck)")
case objSubTypeMessageGoQuestAck: case objSubTypeMessageGoQuestAck:
cwm, err := parseSubTypeMessageGoQuestAck(m, r) cwm, err := parseSubTypeMessageGoQuestAck(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageGoQuestAck.") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageGoQuestAck.")
cwm.Msg = m cwm.Msg = m
uid, err := clientGetCWUserID64(m.UserID64) uid, err := clientGetCWUserID64(m.TGUserID64)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Retrieving UserID64.") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Retrieving UserID64.")
if err != nil { if err != nil {
err = setObjSubTypeId(objId, objSubTypeMessageUnknown) err = setObjSubTypeId(objId, objSubTypeMessageUnknown)
@ -448,7 +448,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
ObjID64: m.ObjID64, ObjID64: m.ObjID64,
} }
b, _ := json.Marshal(&p) b, _ := json.Marshal(&p)
_, err = createJob(objSubTypeJobMsgRefresh, objJobPriority, m.UserID64, cwm.End.Add(5*time.Minute).UTC(), b) _, err = createJob(objSubTypeJobMsgRefresh, objJobPriority, m.TGUserID64, cwm.End.Add(5*time.Minute).UTC(), b)
} }
case objSubTypeMessageTimeAck: case objSubTypeMessageTimeAck:
_, err := fromChatWarsDate(r.ReplaceAllString(m.Text, "${Day}") + " " + r.ReplaceAllString(m.Text, "${Month}") + " " + r.ReplaceAllString(m.Text, "${Year}") + " " + r.ReplaceAllString(m.Text, "${Hour}") + ":" + r.ReplaceAllString(m.Text, "${Minute}")) _, err := fromChatWarsDate(r.ReplaceAllString(m.Text, "${Day}") + " " + r.ReplaceAllString(m.Text, "${Month}") + " " + r.ReplaceAllString(m.Text, "${Year}") + " " + r.ReplaceAllString(m.Text, "${Hour}") + ":" + r.ReplaceAllString(m.Text, "${Minute}"))