package data import ( "github.com/Mindgamesnl/socketio" "github.com/ParadoxPixel/ThemePark-Websocket/data" "github.com/ParadoxPixel/ThemePark-Websocket/objects" "log" "strings" ) func Load(namespace socketio.Namespace, debug bool) { namespace.OnEvent("data", func(so socketio.Socket, msg string) { clientType := so.GetQuery().Get("type") == "server" var ok bool var server *objects.Server if !clientType { ok, server = data.HasServer(so.GetQuery().Get("control_id")) if !ok { if debug { log.Println( "No server found with id:", so.GetQuery().Get("control_id"), "for client:", so.GetQuery().Get("token"), ) } return } _ = server.Socket.Emit("data", msg) return } ok, server = data.HasServer(so.GetQuery().Get("id")) if !strings.HasPrefix(msg, "{") { args := strings.SplitN(msg, "@", 2) ok, session := server.HasSession(args[0]) if !ok { if debug { log.Println( "Unable to send packet from server:", server.ID, "to client:", args[0], ) } return } _ = session.Emit("data", args[1]) return } }) }