Initial commit
This commit is contained in:
commit
570f501a76
16 changed files with 639 additions and 0 deletions
22
objects/config.go
Executable file
22
objects/config.go
Executable file
|
@ -0,0 +1,22 @@
|
|||
package objects
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
type Configuration struct {
|
||||
Address string `json:"address"`
|
||||
Debug bool `json:"debug"`
|
||||
}
|
||||
|
||||
func LoadConfiguration(file string) (Configuration, error) {
|
||||
bytes, err := ioutil.ReadFile(file)
|
||||
if err != nil {
|
||||
return Configuration{}, err
|
||||
}
|
||||
|
||||
var config Configuration
|
||||
err = json.Unmarshal(bytes, &config)
|
||||
return config, err
|
||||
}
|
46
objects/server.go
Executable file
46
objects/server.go
Executable file
|
@ -0,0 +1,46 @@
|
|||
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()
|
||||
}
|
8
objects/session.go
Executable file
8
objects/session.go
Executable file
|
@ -0,0 +1,8 @@
|
|||
package objects
|
||||
|
||||
type Session struct {
|
||||
Token string `json:"token"`
|
||||
UUID string `json:"uuid"`
|
||||
ID string `json:"id"`
|
||||
Attraction string `json:"attraction"`
|
||||
}
|
Reference in a new issue