mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-08 07:37:52 +08:00
更改目录结构
This commit is contained in:
45
server/sessdata/limit_client.go
Normal file
45
server/sessdata/limit_client.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package sessdata
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/bjdgyc/anylink/base"
|
||||
)
|
||||
|
||||
const limitAllKey = "__ALL__"
|
||||
|
||||
var (
|
||||
limitClient = map[string]int{limitAllKey: 0}
|
||||
limitMux = sync.Mutex{}
|
||||
)
|
||||
|
||||
func LimitClient(user string, close bool) bool {
|
||||
limitMux.Lock()
|
||||
defer limitMux.Unlock()
|
||||
|
||||
_all := limitClient[limitAllKey]
|
||||
c, ok := limitClient[user]
|
||||
if !ok { // 不存在用户
|
||||
limitClient[user] = 0
|
||||
}
|
||||
|
||||
if close {
|
||||
limitClient[user] = c - 1
|
||||
limitClient[limitAllKey] = _all - 1
|
||||
return true
|
||||
}
|
||||
|
||||
// 全局判断
|
||||
if _all >= base.Cfg.MaxClient {
|
||||
return false
|
||||
}
|
||||
|
||||
// 超出同一个用户限制
|
||||
if c >= base.Cfg.MaxUserClient {
|
||||
return false
|
||||
}
|
||||
|
||||
limitClient[user] = c + 1
|
||||
limitClient[limitAllKey] = _all + 1
|
||||
return true
|
||||
}
|
Reference in New Issue
Block a user