Thomas van Weert
9edcb83fc4
CHG: use concurrent map instead of regular map with lock DEL: global session control, moved to per server only DEL: unused command system
34 lines
637 B
Go
Executable file
34 lines
637 B
Go
Executable file
package data
|
|
|
|
import (
|
|
"github.com/ParadoxPixel/ThemePark-Websocket/objects"
|
|
"sync"
|
|
)
|
|
|
|
var servers = new(sync.Map)
|
|
|
|
func AddServer(server *objects.Server) {
|
|
servers.LoadOrStore(server.ID, server)
|
|
}
|
|
|
|
func CanServer(server string) bool {
|
|
if server == "" || server == "null" {
|
|
return false
|
|
}
|
|
|
|
if ok, _ := HasServer(server); ok {
|
|
return false
|
|
} else {
|
|
return true
|
|
}
|
|
}
|
|
|
|
func HasServer(publicKey string) (bool, *objects.Server) {
|
|
val, ok := servers.Load(publicKey)
|
|
return ok, val.(*objects.Server)
|
|
}
|
|
|
|
func RemoveServer(session string) *objects.Server {
|
|
val, _ := servers.LoadAndDelete(session)
|
|
return val.(*objects.Server)
|
|
}
|