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

43 lines
713 B
Go
Raw Permalink Normal View History

2022-08-12 19:08:47 +00:00
package data
import (
"github.com/ParadoxPixel/ThemePark-Websocket/objects"
"sync"
)
var servers = new(sync.Map)
2022-08-12 19:08:47 +00:00
func AddServer(server *objects.Server) {
servers.LoadOrStore(server.ID, server)
2022-08-12 19:08:47 +00:00
}
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) {
2023-02-16 20:11:58 +00:00
val, _ := servers.Load(publicKey)
if val == nil {
return false, nil
}
return true, val.(*objects.Server)
2022-08-12 19:08:47 +00:00
}
func RemoveServer(session string) *objects.Server {
val, _ := servers.LoadAndDelete(session)
2023-02-16 20:11:58 +00:00
if val == nil {
return nil
}
return val.(*objects.Server)
}