81 lines
2 KiB
Go
81 lines
2 KiB
Go
|
package user
|
||
|
|
||
|
import (
|
||
|
"github.com/Mindgamesnl/socketio"
|
||
|
"github.com/ParadoxPixel/ThemePark-Websocket/data"
|
||
|
"log"
|
||
|
)
|
||
|
|
||
|
func clientLogin(so socketio.Socket) {
|
||
|
ok, server := data.HasServer(so.GetQuery().Get("control_id"))
|
||
|
if !ok {
|
||
|
if debug {
|
||
|
log.Println(
|
||
|
"No server with id:",
|
||
|
so.GetQuery().Get("control_id"),
|
||
|
"for token:",
|
||
|
so.GetQuery().Get("token"),
|
||
|
)
|
||
|
}
|
||
|
_ = so.Emit("close", "SERVER_ERROR")
|
||
|
_ = so.Close()
|
||
|
return
|
||
|
}
|
||
|
|
||
|
b := server.AddSession(so.GetQuery().Get("token"), so.GetQuery().Get("attraction"), so)
|
||
|
if !b {
|
||
|
if debug {
|
||
|
log.Println(
|
||
|
"Server with id:",
|
||
|
so.GetQuery().Get("control_id"),
|
||
|
"already has operator for attraction:",
|
||
|
so.GetQuery().Get("attraction"),
|
||
|
)
|
||
|
}
|
||
|
_ = so.Emit("close", "AUTHENTICATION_ERROR")
|
||
|
_ = so.Close()
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if debug {
|
||
|
log.Println(
|
||
|
"Client connected to id:",
|
||
|
so.GetQuery().Get("control_id"),
|
||
|
"with token:",
|
||
|
so.GetQuery().Get("token"),
|
||
|
"to attraction:",
|
||
|
so.GetQuery().Get("attraction"),
|
||
|
)
|
||
|
}
|
||
|
|
||
|
err := server.Socket.Emit("data", "{\"channel\":\"SERVER_IN_REGISTER_CLIENT\",\"data\":{\"payload\":{\"uuid\":\""+so.GetQuery().Get("uuid")+"\",\"token\":\""+so.GetQuery().Get("token")+"\",\"attraction_id\":\""+so.GetQuery().Get("attraction")+"\"},\"type\":\"ClientConnectPayload\"}}")
|
||
|
if err != nil && debug {
|
||
|
log.Println(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func clientQuit(so socketio.Socket) {
|
||
|
session := so.GetQuery().Get("token")
|
||
|
ok, server := data.HasServer(so.GetQuery().Get("control_id"))
|
||
|
if !ok {
|
||
|
return
|
||
|
}
|
||
|
|
||
|
if debug {
|
||
|
log.Println(
|
||
|
"Client disconnected to id:",
|
||
|
so.GetQuery().Get("control_id"),
|
||
|
"with token:",
|
||
|
so.GetQuery().Get("token"),
|
||
|
"to attraction:",
|
||
|
so.GetQuery().Get("attraction"),
|
||
|
)
|
||
|
}
|
||
|
|
||
|
server.RemoveSession(session, so.GetQuery().Get("attraction"))
|
||
|
err := server.Socket.Emit("data", "{\"channel\":\"SERVER_IN_UNREGISTER_CLIENT\",\"data\":{\"payload\":{\"uuid\":\""+so.GetQuery().Get("uuid")+"\"},\"type\":\"ClientDisconnectPayload\"}}")
|
||
|
if err != nil && debug {
|
||
|
log.Println(err)
|
||
|
}
|
||
|
}
|