diff --git a/routes/controller.go b/routes/controller.go index fb9aba9..f91aee7 100644 --- a/routes/controller.go +++ b/routes/controller.go @@ -150,7 +150,7 @@ func handleGetAccount(c *gin.Context, req ControllerBody, workerState *worker.St respondWithError(c, NoAccountLeft) return } - workerState.Username = account.Username + workerState.SetUsername(account.Username) host := c.RemoteIP() if loginDelay := config.Config.Worker.LoginDelay; loginDelay > 0 { now := time.Now().Unix() diff --git a/worker/workerState.go b/worker/workerState.go index 94ce147..a9a6b53 100644 --- a/worker/workerState.go +++ b/worker/workerState.go @@ -115,6 +115,12 @@ func (ws *State) Unlock() { ws.mu.Unlock() } +func (ws *State) SetUsername(username string) { + ws.Lock() + defer ws.Unlock() + ws.Username = username +} + func (ws *State) ResetUsername() { ws.Lock() defer ws.Unlock()