3
0
Fork 0
This repository has been archived on 2024-11-14. You can view files and clone it, but cannot push or open issues or pull requests.
ThemeParkPlus-Socket/data/session_manager.go

45 lines
779 B
Go
Raw Normal View History

2022-08-12 19:08:47 +00:00
package data
import (
"github.com/ParadoxPixel/ThemePark-Websocket/objects"
"sync"
)
var sessionMux sync.RWMutex
var sessions = make(map[string]*objects.Session)
func AddSession(session *objects.Session) {
sessionMux.Lock()
sessions[session.Token] = session
sessionMux.Unlock()
}
func GetSession(session string) *objects.Session {
sessionMux.Lock()
val := sessions[session]
sessionMux.Unlock()
return val
}
func HasSession(session string) bool {
sessionMux.Lock()
_,ok := sessions[session]
sessionMux.Unlock()
return ok
}
func CanSession(session string) bool {
if session == "" || session == "null" {
return false
}
return !HasSession(session)
}
func RemoveSession(session string) {
sessionMux.Lock()
delete(sessions, session)
sessionMux.Unlock()
}