2023-06-08 10:46:33 -04:00
|
|
|
package hy
|
|
|
|
|
|
|
|
import (
|
2023-06-09 00:36:49 -04:00
|
|
|
"encoding/base64"
|
2023-06-08 10:46:33 -04:00
|
|
|
"errors"
|
2023-07-27 21:13:11 -04:00
|
|
|
|
2023-06-18 22:31:42 -04:00
|
|
|
"github.com/Yuzuki616/V2bX/api/panel"
|
2023-06-08 10:46:33 -04:00
|
|
|
"github.com/Yuzuki616/V2bX/core"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (h *Hy) AddUsers(p *core.AddUsersParams) (int, error) {
|
|
|
|
s, ok := h.servers.Load(p.Tag)
|
|
|
|
if !ok {
|
|
|
|
return 0, errors.New("the node not have")
|
|
|
|
}
|
|
|
|
u := &s.(*Server).users
|
|
|
|
for i := range p.UserInfo {
|
|
|
|
u.Store(p.UserInfo[i].Uuid, struct{}{})
|
|
|
|
}
|
|
|
|
return len(p.UserInfo), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Hy) GetUserTraffic(tag, uuid string, reset bool) (up int64, down int64) {
|
2023-06-09 00:36:49 -04:00
|
|
|
v, _ := h.servers.Load(tag)
|
|
|
|
s := v.(*Server)
|
|
|
|
auth := base64.StdEncoding.EncodeToString([]byte(uuid))
|
2023-07-27 21:13:11 -04:00
|
|
|
up = s.counter.GetCounter(auth).UpCounter.Load()
|
|
|
|
down = s.counter.GetCounter(auth).DownCounter.Load()
|
2023-06-08 10:46:33 -04:00
|
|
|
if reset {
|
2023-06-18 20:30:10 -04:00
|
|
|
s.counter.Reset(auth)
|
2023-06-08 10:46:33 -04:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-06-18 22:31:42 -04:00
|
|
|
func (h *Hy) DelUsers(users []panel.UserInfo, tag string) error {
|
2023-06-08 10:46:33 -04:00
|
|
|
v, e := h.servers.Load(tag)
|
|
|
|
if !e {
|
|
|
|
return errors.New("the node is not have")
|
|
|
|
}
|
|
|
|
s := v.(*Server)
|
|
|
|
for i := range users {
|
2023-06-18 22:31:42 -04:00
|
|
|
s.users.Delete(users[i].Uuid)
|
|
|
|
s.counter.Delete(base64.StdEncoding.EncodeToString([]byte(users[i].Uuid)))
|
2023-06-08 10:46:33 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|