test ref encoding

This commit is contained in:
shoopea 2020-01-15 18:17:38 +08:00
parent 08e73139bb
commit 812690a973
5 changed files with 66 additions and 12 deletions

View File

@ -55,24 +55,24 @@ func getLockedRandomClient() (*ChirpClient, error) {
}
func setClientBusy(userID64 int64, from time.Time, duration time.Duration) error {
if from.UTC().Add(duration).After(time.Now().UTC()) {
if clt, ok := getLockedClient(userID64, false); ok {
if from.UTC().Add(duration).After(time.Now().UTC()) {
clt.CWIdle = false
clt.CWBusyUntil = from.UTC().Add(duration)
clt.Mux.Unlock()
log.Printf("setClientBusy[%s] : set for %s.\n", clt.Login, duration.String())
} else {
log.Printf("setClientBusy[%s] : not updated.\n", clt.Login)
}
clt.Mux.Unlock()
return nil
} else {
return errors.New("Client not found.")
}
}
return nil
}
func setClientIdle(userID64 int64, from time.Time) error {
if clt, ok := getLockedClient(userID64, false); ok {
if from.UTC().After(clt.CWLastUpdate.UTC()) {
fmt.Printf("setClientIdle : updated.\n")
clt.CWBusyUntil = from
clt.CWIdle = true
clt.CWLastUpdate = from

View File

@ -46,9 +46,7 @@ func cronTribute() {
muxClients.RLock()
for _, c := range clients {
if c.Active {
log.Printf("cronTribute : class %s (%s)\n", c.CWClass, c.Login)
if c.CWClass == `Knight` {
log.Printf("cronTribute : sending tribute\n", c.CWClass, c.Login)
clientSendCWMsgDelay(c.TGUserID64, `/tributes`, 0)
}
}

View File

@ -24,6 +24,16 @@
"name": "Guild deposit chat",
"obj_type": "msg"
},
{
"intl_id": "msg_guild_gwithdraw_req",
"name": "Guild withdraw conf req",
"obj_type": "msg"
},
{
"intl_id": "msg_guild_gwithdraw_ack",
"name": "Guild withdraw conf ack",
"obj_type": "msg"
},
{
"intl_id": "msg_war",
"name": "War report",

30
job.go
View File

@ -4,6 +4,8 @@ import (
"archive/zip"
"bytes"
"compress/zlib"
"crypto/sha256"
"encoding/binary"
"encoding/json"
"errors"
"fmt"
@ -15,6 +17,7 @@ import (
"strings"
"time"
"github.com/lytics/base62"
tb "gopkg.in/tucnak/telebot.v2"
)
@ -1556,10 +1559,33 @@ func jobGWithdraw(j Job) {
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(j.UserID64, `/g_stock_other`)
} else {
_, err := getLockedRoleClient(`commander`)
/*
c, err := getLockedRoleClient(`commander`)
logOnError(err, "jobGWithdraw: getLockedRoleClient(commander)")
if err == nil {
c.Mux.Unlock()
}
*/
b, _ := json.Marshal(p)
log.Printf("jobGWithdraw[%d] : got all the info\n%s\n", j.ID64, string(b))
id, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, userID64, 0, time.Unix(maxUnixTimestamp, 0).UTC(), b)
sha256 := sha256.Sum256([]byte(s))
sha128 := sha256[:aes.BlockSize]
c, err := aes.NewCipher(sha128)
in := make([]byte, 0)
buf := make([]byte, 8)
binary.LittleEndian.PutUint64(buf, uint64(id))
in = append(in, buf)
binary.LittleEndian.PutUint64(buf, uint64(j.UserID64))
in = append(in, buf)
out := make([]byte, len(in))
c.Encrypt(out, in)
ref := base62.StdEncoding.EncodeToString(out)
log.Printf("jobGWithdraw[%d] : got all the info for ref %s\n", j.ID64, string(ref))
}
err = setJobDone(j.ID64)

View File

@ -19,6 +19,26 @@ func resetMsgParsingRules() error {
err = json.Unmarshal(b, &rules)
r := MessageParsingRule{
Priority: 9999,
Description: "Withdrawal request",
Rule: "^To validate (@[A-Za-z0-9]*) withdrawal of\n([0-9]+ x .*\n)+(Click /withdraw_[a-zA-Z0-9]{22})$",
MsgTypeID64: cacheObjSubType[`msg_guild_gwithdraw_req`],
ChatID64: cfg.Bot.Mainchat,
SenderUserID64: 0,
}
rules2 = append(rules2, r)
r := MessageParsingRule{
Priority: 9999,
Description: "Withdrawal acknowledgment",
Rule: "^/withdraw_[a-zA-Z0-9]{22}$",
MsgTypeID64: cacheObjSubType[`msg_guild_gwithdraw_ack`],
ChatID64: cfg.Bot.Mainchat,
SenderUserID64: 0,
}
rules2 = append(rules2, r)
r := MessageParsingRule{
Priority: 1,
Description: "Default Main chat",