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

46 lines
No EOL
905 B
Go
Executable file

package objects
import (
"github.com/Mindgamesnl/socketio"
"sync"
)
type Server struct {
Socket socketio.Socket
ID string
Sessions map[string]socketio.Socket
Attraction map[string]string
mux sync.RWMutex
}
func (serv *Server) CanAttraction(attraction string) bool {
serv.mux.RLock()
defer serv.mux.RUnlock()
_,b := serv.Attraction[attraction]
return !b
}
func (serv *Server) AddSession(session, attraction string, io socketio.Socket) {
serv.mux.Lock()
serv.Sessions[session] = io
serv.Attraction[attraction] = session
serv.mux.Unlock()
}
func (serv *Server) HasSession(session string) (bool, socketio.Socket) {
serv.mux.RLock()
defer serv.mux.RUnlock()
io, b := serv.Sessions[session]
return b, io
}
func (serv *Server) RemoveSession(session, attraction string) {
serv.mux.Lock()
delete(serv.Sessions, session)
delete(serv.Attraction, attraction)
serv.mux.Unlock()
}