-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathendpoint.lsl
More file actions
92 lines (86 loc) · 2.65 KB
/
Copy pathendpoint.lsl
File metadata and controls
92 lines (86 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
integer connected = 0;
key SECRET_KEY = "29731e5170353a8b235098c43cd2099a4e805c55fb4395890e81f437c17334a9";
list commands = [];
respond(key id, integer status, string key_, string data)
{
llHTTPResponse(id, status, llList2Json(JSON_OBJECT, [key_, data]));
}
broadcast_command(key request_id, string command)
{
// Broadcast the message to other scripts. We expect one script to return
// a link_message in response. We pass the request_id to be able
// to identify the response.
llMessageLinked(LINK_SET, -1, command, request_id);
}
default
{
state_entry()
{
llRequestSecureURL();
llMessageLinked(LINK_SET, -1, "", "get_commands");
}
link_message(integer link, integer num, string msg, key id)
{
if(num == -1 && id == "command_info")
{
commands += llParseString2List(msg, ["|"], []);
}
else if(num == 0)
{
respond(id, 200, "result", msg);
}
else if(num == 1)
{
respond(id, 200, "error", msg);
}
}
changed(integer change)
{
if(change & CHANGED_OWNER || change & CHANGED_REGION || \
change & CHANGED_REGION_START)
llResetScript();
}
http_request(key id, string method, string body)
{
if(method == URL_REQUEST_GRANTED)
{
string url = body;
llOwnerSay(url);
}
else if(method == "POST")
{
llOwnerSay("POST: " + body);
if(llJsonGetValue(body, ["secret_key"]) == SECRET_KEY)
{
string command = llJsonGetValue(body, ["command"]);
if(command == "connect")
{
if(connected == FALSE)
{
respond(id, 200, "uuid", llGetKey());
connected = TRUE;
}
else
{
respond(id, 423, "error", "Session is currently in use");
}
}
else if(command == "disconnect")
{
respond(id, 200, "result", "disconnected");
connected = FALSE;
}
else if(command == "get_commands")
{
respond(id, 200, "available_commands", llList2Json(JSON_OBJECT, \
commands));
}
broadcast_command(id, command);
}
else
{
respond(id, 401, "error", "Invalid secret key");
}
}
}
}