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/handlers/user/server.go

63 lines
1.1 KiB
Go
Raw Permalink Normal View History

package user
import (
"github.com/Mindgamesnl/socketio"
"github.com/ParadoxPixel/ThemePark-Websocket/data"
"github.com/ParadoxPixel/ThemePark-Websocket/objects"
"log"
"sync"
)
func serverLogin(so socketio.Socket) {
id := so.GetQuery().Get("id")
if !data.CanServer(id) {
if debug {
log.Println(
"Server with id:",
so.GetQuery().Get("id"),
"already connected",
)
}
_ = so.Close()
return
}
data.AddServer(&objects.Server{
ID: id,
Sessions: make(map[string]socketio.Socket),
Attraction: make(map[string]string),
Socket: so,
Mux: new(sync.RWMutex),
})
if debug {
log.Println(
"Server with id:",
so.GetQuery().Get("id"),
"connected",
)
}
}
func serverQuit(so socketio.Socket) {
session := so.GetQuery().Get("id")
obj := data.RemoveServer(session)
if obj == nil {
return
}
if debug {
log.Println(
"Server with id:",
so.GetQuery().Get("id"),
"disconnected",
)
}
// Disconnect users
for _, user := range obj.Sessions {
_ = user.Emit("close", "SERVER_ERROR")
_ = user.Close()
}
}