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/client.go
Thomas van Weert 9edcb83fc4 CHG: refactor
CHG: use concurrent map instead of regular map with lock
DEL: global session control, moved to per server only
DEL: unused command system
2023-02-16 20:04:17 +01:00

80 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)
}
}