update client
This commit is contained in:
parent
41d7e2a78f
commit
de3e06de2c
@ -95,7 +95,7 @@ func getLockedRandomClient() (*ChirpClient, error) {
|
|||||||
func setClientBusy(userID64 int64, from time.Time, duration time.Duration) error {
|
func setClientBusy(userID64 int64, from time.Time, duration time.Duration) error {
|
||||||
if clt, ok := getLockedClient(userID64, false); ok {
|
if clt, ok := getLockedClient(userID64, false); ok {
|
||||||
if from.UTC().Add(duration).After(time.Now().UTC()) {
|
if from.UTC().Add(duration).After(time.Now().UTC()) {
|
||||||
clt.CWIdle = false
|
clt.GameIdle = false
|
||||||
clt.CWBusyUntil = from.UTC().Add(duration)
|
clt.CWBusyUntil = from.UTC().Add(duration)
|
||||||
log.Printf("setClientBusy[%s] : set for %s.\n", clt.Login, duration.String())
|
log.Printf("setClientBusy[%s] : set for %s.\n", clt.Login, duration.String())
|
||||||
} else {
|
} else {
|
||||||
@ -112,7 +112,7 @@ func setClientIdle(userID64 int64, from time.Time) error {
|
|||||||
if clt, ok := getLockedClient(userID64, false); ok {
|
if clt, ok := getLockedClient(userID64, false); ok {
|
||||||
if from.UTC().After(clt.CWLastUpdate.UTC()) {
|
if from.UTC().After(clt.CWLastUpdate.UTC()) {
|
||||||
clt.CWBusyUntil = from
|
clt.CWBusyUntil = from
|
||||||
clt.CWIdle = true
|
clt.GameIdle = true
|
||||||
clt.CWLastUpdate = from
|
clt.CWLastUpdate = from
|
||||||
log.Printf("setClientIdle[%s] : updated.\n", clt.Login)
|
log.Printf("setClientIdle[%s] : updated.\n", clt.Login)
|
||||||
} else {
|
} else {
|
||||||
@ -129,7 +129,7 @@ func getLockedIdleClient() (*ChirpClient, error) {
|
|||||||
muxClients.RLock()
|
muxClients.RLock()
|
||||||
ids := make([]int64, 0)
|
ids := make([]int64, 0)
|
||||||
for _, c := range clients {
|
for _, c := range clients {
|
||||||
if c.CWIdle {
|
if c.GameIdle {
|
||||||
ids = append(ids, c.TGUserID64)
|
ids = append(ids, c.TGUserID64)
|
||||||
fmt.Printf("getLockedIdleClient : appending %s (%d).\n", c.Login, c.TGUserID64)
|
fmt.Printf("getLockedIdleClient : appending %s (%d).\n", c.Login, c.TGUserID64)
|
||||||
}
|
}
|
||||||
@ -244,7 +244,7 @@ func clientMsgMeAck(m *ChatWarsMessageMeAck) {
|
|||||||
clientSendCWMsg(m.Msg.TGUserID64, "/g_roles")
|
clientSendCWMsg(m.Msg.TGUserID64, "/g_roles")
|
||||||
}
|
}
|
||||||
if m.State == `🛌Rest` {
|
if m.State == `🛌Rest` {
|
||||||
clt.CWIdle = true
|
clt.GameIdle = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
22
cron.go
22
cron.go
@ -14,11 +14,12 @@ import (
|
|||||||
|
|
||||||
func startCron() *cron.Cron {
|
func startCron() *cron.Cron {
|
||||||
c := cron.New(cron.WithLocation(time.UTC))
|
c := cron.New(cron.WithLocation(time.UTC))
|
||||||
c.AddFunc("15 7,15,23 * * *", cronSendWarReport)
|
|
||||||
c.AddFunc("58 6,14,22 * * *", cronSetDef)
|
c.AddFunc("58 6,14,22 * * *", cronSetDef)
|
||||||
c.AddFunc("02 1,3,5,9,11,13,17,19,21 * * *", cronGetHammerTime)
|
c.AddFunc("02 1,3,5,9,11,13,17,19,21 * * *", cronGetHammerTime)
|
||||||
c.AddFunc("10 7,15,23 * * *", cronGetHammerTime)
|
c.AddFunc("12 7,15,23 * * *", cronGetHammerTime)
|
||||||
c.AddFunc("13 3,7,11,15,19,23 * * *", cronTribute)
|
c.AddFunc("13 3,7,11,15,19,23 * * *", cronTribute)
|
||||||
|
c.AddFunc("14 7,15,23 * * *", cronCheckVaultLimit)
|
||||||
|
c.AddFunc("15 7,15,23 * * *", cronSendWarReport)
|
||||||
c.AddFunc("@every 1m", cronSaveClients)
|
c.AddFunc("@every 1m", cronSaveClients)
|
||||||
c.Start()
|
c.Start()
|
||||||
return c
|
return c
|
||||||
@ -118,3 +119,20 @@ func cronSaveClients() {
|
|||||||
logOnError(err, "cronSaveClients : Rename")
|
logOnError(err, "cronSaveClients : Rename")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cronCheckVaultLimit() {
|
||||||
|
clt, err := getLockedRandomClient()
|
||||||
|
logOnError(err, "cronGetHammerTime : getLockedRandomClient")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
clt.Mux.Unlock()
|
||||||
|
|
||||||
|
p := JobPayloadCheckVaultLimit{
|
||||||
|
Status: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
b, _ := json.Marshal(p)
|
||||||
|
t := time.Now().UTC().Add(1 * time.Second)
|
||||||
|
_, err = createJob(cacheObjSubType[`job_check_vault_limit`], objJobPriority, clt.TGUserID64, 0, t, b)
|
||||||
|
}
|
||||||
|
@ -734,6 +734,11 @@
|
|||||||
"name": "Craft all items summary job",
|
"name": "Craft all items summary job",
|
||||||
"obj_type": "job"
|
"obj_type": "job"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"intl_id": "job_check_vault_limit",
|
||||||
|
"name": "Check vault resource limit",
|
||||||
|
"obj_type": "job"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"intl_id": "item_res",
|
"intl_id": "item_res",
|
||||||
"name": "Resource",
|
"name": "Resource",
|
||||||
|
@ -1093,7 +1093,7 @@
|
|||||||
],
|
],
|
||||||
"craft": {
|
"craft": {
|
||||||
"cmd": "/brew_62",
|
"cmd": "/brew_62",
|
||||||
"mana": 10,
|
"mana": 15,
|
||||||
"items": [
|
"items": [
|
||||||
{
|
{
|
||||||
"code": "44",
|
"code": "44",
|
||||||
|
8
def.go
8
def.go
@ -85,7 +85,8 @@ type ChirpClient struct {
|
|||||||
CWClass string `json:"class"`
|
CWClass string `json:"class"`
|
||||||
CWBusyUntil time.Time `json:"busy_until"`
|
CWBusyUntil time.Time `json:"busy_until"`
|
||||||
CWLastUpdate time.Time `json:"last_update"`
|
CWLastUpdate time.Time `json:"last_update"`
|
||||||
CWIdle bool `json:"idle"`
|
GameIdle bool `json:"game_idle"`
|
||||||
|
BotIdle bool `json:"bot_idle"`
|
||||||
Mux sync.Mutex `json:"-"`
|
Mux sync.Mutex `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,6 +507,11 @@ type JobPayloadCraftAll struct {
|
|||||||
VaultJobID64 int64 `json:"vault_job_id"`
|
VaultJobID64 int64 `json:"vault_job_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type JobPayloadCheckVaultLimit struct {
|
||||||
|
Status int64 `json:"status"`
|
||||||
|
VaultJobID64 int64 `json:"vault_job_id"`
|
||||||
|
}
|
||||||
|
|
||||||
type JobPayloadGetVault struct {
|
type JobPayloadGetVault struct {
|
||||||
Status int64 `json:"status"`
|
Status int64 `json:"status"`
|
||||||
JobCallbackID64 int64 `json:"job_callback_id"`
|
JobCallbackID64 int64 `json:"job_callback_id"`
|
||||||
|
48
job.go
48
job.go
@ -2098,6 +2098,54 @@ func jobCraftAll(j Job) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func jobCheckVaultLimit(j Job) {
|
||||||
|
var (
|
||||||
|
p JobPayloadCheckVaultLimit
|
||||||
|
p2 JobPayloadGetVault
|
||||||
|
b []byte
|
||||||
|
)
|
||||||
|
|
||||||
|
err := setJobStart(j.ID64)
|
||||||
|
logOnError(err, "jobCheckVaultLimit : setJobStart")
|
||||||
|
|
||||||
|
err = json.Unmarshal(j.Payload, &p)
|
||||||
|
logOnError(err, "jobCheckVaultLimit : Unmarshal payload")
|
||||||
|
|
||||||
|
if p.Status == 0 {
|
||||||
|
p2.JobCallbackID64 = j.ID64
|
||||||
|
p2.ItemTypeList = make([]int64, 0)
|
||||||
|
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_res`])
|
||||||
|
p2.ItemTypeList = append(p2.ItemTypeList, cacheObjSubType[`item_alch`])
|
||||||
|
|
||||||
|
b, err = json.Marshal(p2)
|
||||||
|
logOnError(err, "jobCheckVaultLimit : Marshal(p2)")
|
||||||
|
|
||||||
|
jobID64, err := createJob(cacheObjSubType[`job_get_vault`], objJobPriority, j.UserID64, 0, time.Now().UTC(), b)
|
||||||
|
|
||||||
|
p.Status = 1
|
||||||
|
p.VaultJobID64 = jobID64
|
||||||
|
|
||||||
|
b, err = json.Marshal(p)
|
||||||
|
logOnError(err, "jobCheckVaultLimit : Marshal(p)")
|
||||||
|
|
||||||
|
err = setJobPayloadJSON(j.ID64, p)
|
||||||
|
logOnError(err, "jobCheckVaultLimit : setJobPayloadJSON(p)")
|
||||||
|
|
||||||
|
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
b = getJobPayload(p.VaultJobID64)
|
||||||
|
err = json.Unmarshal(b, &p2)
|
||||||
|
logOnError(err, "jobCheckVaultLimit : Unmarshal(p2)")
|
||||||
|
|
||||||
|
err = setJobDone(j.ID64)
|
||||||
|
logOnError(err, "jobCheckVaultLimit : setJobDone")
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func jobGetVault(j Job) {
|
func jobGetVault(j Job) {
|
||||||
var (
|
var (
|
||||||
p JobPayloadGetVault
|
p JobPayloadGetVault
|
||||||
|
@ -614,6 +614,8 @@ func JobWorker(id int, jobs <-chan Job) {
|
|||||||
jobCraftItem(j)
|
jobCraftItem(j)
|
||||||
case cacheObjSubType[`job_craft_all`]:
|
case cacheObjSubType[`job_craft_all`]:
|
||||||
jobCraftAll(j)
|
jobCraftAll(j)
|
||||||
|
case cacheObjSubType[`job_check_vault_limit`]:
|
||||||
|
jobCheckVaultLimit(j)
|
||||||
default:
|
default:
|
||||||
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64)
|
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user