45 lines
779 B
Go
45 lines
779 B
Go
|
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()
|
||
|
}
|