Files
lsl-shell/endpoint.lsl

93 lines
2.7 KiB
Plaintext
Raw Permalink Normal View History

2020-04-12 15:51:44 +02:00
integer connected = 0;
2020-04-12 17:44:17 +02:00
key SECRET_KEY = "29731e5170353a8b235098c43cd2099a4e805c55fb4395890e81f437c17334a9";
2020-04-13 01:43:13 +02:00
list commands = [];
2020-04-12 15:51:44 +02:00
2020-04-13 14:41:15 +02:00
respond(key id, integer status, string key_, string data)
{
llHTTPResponse(id, status, llList2Json(JSON_OBJECT, [key_, data]));
}
broadcast_command(key request_id, string command)
2020-04-13 14:50:09 +02:00
{
2020-04-13 15:05:34 +02:00
// Broadcast the message to other scripts. We expect one script to return
2020-04-13 14:50:09 +02:00
// a link_message in response. We pass the request_id to be able
// to identify the response.
llMessageLinked(LINK_SET, -1, command, request_id);
2020-04-13 14:50:09 +02:00
}
2020-04-12 15:51:44 +02:00
default
{
state_entry()
{
llRequestSecureURL();
llMessageLinked(LINK_SET, -1, "", "get_commands");
2020-04-13 01:43:13 +02:00
}
link_message(integer link, integer num, string msg, key id)
{
if(num == -1 && id == "command_info")
2020-04-13 01:43:13 +02:00
{
commands += llParseString2List(msg, ["|"], []);
}
else if(num == 0)
{
respond(id, 200, "result", msg);
}
else if(num == 1)
2020-04-13 01:43:13 +02:00
{
respond(id, 200, "error", msg);
2020-04-13 01:43:13 +02:00
}
2020-04-12 15:51:44 +02:00
}
changed(integer change)
{
if(change & CHANGED_OWNER || change & CHANGED_REGION || \
change & CHANGED_REGION_START)
llResetScript();
}
2020-04-12 15:51:44 +02:00
http_request(key id, string method, string body)
{
if(method == URL_REQUEST_GRANTED)
{
string url = body;
llOwnerSay(url);
}
else if(method == "POST")
{
2020-04-12 17:44:17 +02:00
llOwnerSay("POST: " + body);
if(llJsonGetValue(body, ["secret_key"]) == SECRET_KEY)
2020-04-12 15:51:44 +02:00
{
2020-04-13 15:10:53 +02:00
string command = llJsonGetValue(body, ["command"]);
if(command == "connect")
2020-04-12 17:44:17 +02:00
{
if(connected == FALSE)
{
respond(id, 200, "uuid", llGetKey());
connected = TRUE;
}
else
{
respond(id, 423, "error", "Session is currently in use");
}
2020-04-12 17:44:17 +02:00
}
2020-04-13 15:10:53 +02:00
else if(command == "disconnect")
2020-04-12 17:44:17 +02:00
{
2020-04-13 14:41:15 +02:00
respond(id, 200, "result", "disconnected");
connected = FALSE;
2020-04-12 17:44:17 +02:00
}
2020-04-13 15:10:53 +02:00
else if(command == "get_commands")
2020-04-13 01:43:13 +02:00
{
2020-04-13 14:41:15 +02:00
respond(id, 200, "available_commands", llList2Json(JSON_OBJECT, \
commands));
2020-04-13 01:43:13 +02:00
}
broadcast_command(id, command);
2020-04-12 15:51:44 +02:00
}
else
{
2020-04-13 14:41:15 +02:00
respond(id, 401, "error", "Invalid secret key");
2020-04-12 15:51:44 +02:00
}
}
}
}