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/server_manager.go
2022-08-12 21:08:47 +02:00

54 lines
No EOL
906 B
Go
Executable file

package data
import (
"github.com/ParadoxPixel/ThemePark-Websocket/objects"
"sync"
)
var serverMux sync.RWMutex
var servers = make(map[string]*objects.Server)
func AddServer(server *objects.Server) {
serverMux.Lock()
if _,ok := servers[server.ID]; !ok {
servers[server.ID] = server
}
serverMux.Unlock()
}
func CanServer(server string) bool {
if server == "" || server == "null" {
return false
}
if ok, _ := HasServer(server); ok {
return false
} else {
return true
}
}
func GetServer(server string) *objects.Server {
serverMux.Lock()
val,ok := servers[server]
serverMux.Unlock()
if ok {
return val
} else {
return nil
}
}
func HasServer(publicKey string) (bool, *objects.Server) {
serverMux.Lock()
val,ok := servers[publicKey]
serverMux.Unlock()
return ok, val
}
func RemoveServer(session string) {
serverMux.Lock()
delete(servers, session)
serverMux.Unlock()
}