Archived
2
0
This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
neko-custom/server/internal/websocket/state/state.go

89 lines
1.9 KiB
Go
Raw Normal View History

2022-09-14 06:04:43 +12:00
package state
type State struct {
banned map[string]string // IP -> session ID (that banned it)
locked map[string]string // resource name -> session ID (that locked it)
2022-11-04 14:54:05 +13:00
fileTransferEnabled bool // admins can transfer files
fileTransferUnprivEnabled bool // all users can transfer files
fileTransferPath string // path where files are located
2022-09-14 06:04:43 +12:00
}
2022-11-04 14:54:05 +13:00
func New(fileTransferEnabled bool, fileTransferUnprivEnabled bool, fileTransferPath string) *State {
2022-09-14 06:04:43 +12:00
return &State{
banned: make(map[string]string),
locked: make(map[string]string),
2022-11-04 14:54:05 +13:00
fileTransferEnabled: fileTransferEnabled,
fileTransferUnprivEnabled: fileTransferUnprivEnabled,
fileTransferPath: fileTransferPath,
2022-09-14 06:04:43 +12:00
}
}
// Ban
func (s *State) Ban(ip, id string) {
s.banned[ip] = id
}
func (s *State) Unban(ip string) {
delete(s.banned, ip)
}
func (s *State) IsBanned(ip string) bool {
_, ok := s.banned[ip]
return ok
}
func (s *State) GetBanned(ip string) (string, bool) {
id, ok := s.banned[ip]
return id, ok
}
func (s *State) AllBanned() map[string]string {
return s.banned
}
// Lock
func (s *State) Lock(resource, id string) {
s.locked[resource] = id
}
func (s *State) Unlock(resource string) {
delete(s.locked, resource)
}
func (s *State) IsLocked(resource string) bool {
_, ok := s.locked[resource]
return ok
}
func (s *State) GetLocked(resource string) (string, bool) {
id, ok := s.locked[resource]
return id, ok
}
func (s *State) AllLocked() map[string]string {
return s.locked
}
2022-11-04 14:54:05 +13:00
// File Transfer
func (s *State) FileTransferEnabled() bool {
return s.fileTransferEnabled
}
func (s *State) UnprivFileTransferEnabled() bool {
return s.fileTransferUnprivEnabled
}
func (s *State) SetFileTransferState(admin bool, unpriv bool) {
s.fileTransferEnabled = admin
s.fileTransferUnprivEnabled = unpriv
}
2022-11-04 14:54:05 +13:00
func (s *State) FileTransferPath() string {
return s.fileTransferPath
}