Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

Commit

Permalink
only disable account if it's not yet disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio1988 committed Sep 13, 2023
1 parent 4c9bc9e commit ffd24a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 4 additions & 4 deletions accounts/accountManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,12 @@ func (a *AccountManager) AccountExists(username string) bool {
func (a *AccountManager) IsValidAccount(username string) (bool, error) {
for x := range a.accounts {
if a.accounts[x].Username == username {
time24hrAgo := time.Now().Add(-24 * time.Hour).Unix()
timeNow := time.Now().Unix()
timeNow := time.Now()
timeNowUnix := timeNow.Unix()
time24hrAgo := timeNow.Add(-24 * time.Hour).Unix()
return !(a.accounts[x].Suspended ||
a.accounts[x].Banned ||
int64(a.accounts[x].WarnExpiration) > timeNow ||
int64(a.accounts[x].WarnExpiration) > timeNowUnix ||
(a.accounts[x].LastDisabled.Valid && a.accounts[x].LastDisabled.Int64 > time24hrAgo)), nil
}
}
Expand Down Expand Up @@ -273,7 +274,6 @@ func (a *AccountManager) MarkDisabled(username string) {

for x := range a.accounts {
if a.accounts[x].Username == username {

a.accounts[x].LastDisabled = null.IntFrom(time.Now().Unix())
}
}
Expand Down
9 changes: 5 additions & 4 deletions routes/raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,11 @@ func Raw(c *gin.Context) {
}
}
if ws.CheckLimitExceeded() {
log.Warnf("[RAW] [%s] Account would exceed soft limits - DISABLED ACCOUNT: [%s]", res.Uuid, res.Username)
accountManager.MarkDisabled(res.Username)
counts := ws.RequestCounts()
log.Infof("[RAW] [%s] [%s] Account limits: %v", res.Uuid, res.Username, counts)
log.Warnf("[RAW] [%s] [%s] Account would exceed soft limits - DISABLED ACCOUNT", res.Uuid, res.Username)
if isValid, _ := accountManager.IsValidAccount(res.Username); isValid {
accountManager.MarkDisabled(res.Username)
}
log.Infof("[RAW] [%s] [%s] Account limits: %v", res.Uuid, res.Username, ws.RequestCounts())
}
}()
}
Expand Down

0 comments on commit ffd24a0

Please sign in to comment.