-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.lsl
More file actions
99 lines (84 loc) · 3.05 KB
/
Copy pathserver.lsl
File metadata and controls
99 lines (84 loc) · 3.05 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
93
94
95
96
97
98
99
/*
OnTrack by Tracer Prometheus aka Tracert Ping
An experiment in communications between the real world and the virtual one
Notes:
URLs are automatically released and invalidated in certain situations. In the following situations, there is no need to call llReleaseURL. But you will have to request a new one afterwards
When the region is restarted or goes offline
When the script holding the URLs is reset, or recompiled
When the object containing the script is deleted, or taken to inventory
*/
key url_request;
getHandler(list path, list args, string body)
{
llOwnerSay("path: " + llList2CSV(path));
llOwnerSay("args: " + llList2CSV(args));
llOwnerSay("body: " + body);
}
default
{
state_entry()
{
url_request = llRequestURL();
}
touch_start(integer total_number)
{
llResetScript();
}
http_request(key id, string method, string body)
{
if (url_request == id)
{
url_request = "";
if (method == URL_REQUEST_GRANTED)
{
string msg = "NEW URL: " + body;
llOwnerSay(msg);
llMessageLinked(LINK_SET, 0, msg, "");
}
else if (method == URL_REQUEST_DENIED)
{
llOwnerSay("Something went wrong, no url:\n" + body);
}
}
else
{
llOwnerSay("NEW REQUEST: "+llList2CSV([id,method,body]));
list headerList = ["x-script-url",
"x-path-info", "x-query-string",
"x-remote-ip", "user-agent",
"Content-Length","content-length",
"Host","host"];
integer index = -llGetListLength(headerList);
do
{
string header = llList2String(headerList, index);
llOwnerSay(header+": "+llGetHTTPHeader(id, header));
}
while (++index);
// Split up any path information into path segments
list path = llParseString2List(llGetHTTPHeader(id,"x-path-info"),["/"],[]);
// Split up the query args into a usable list
// If you use ?, =, + or & in keys or values then you may need to adjust this.
string query_arg = llGetHTTPHeader(id,"x-query-string");
query_arg = llUnescapeURL(query_arg);
list query_args = llParseString2List(query_arg,["?","=","+","&"],[]);
llOwnerSay("method: "+method);
if (method == "GET")
{
llSetContentType(id, CONTENT_TYPE_TEXT);
llHTTPResponse(id, 200, "OK");
getHandler(path,query_args,body);
}
else if (method == "POST")
{
llSetContentType(id, CONTENT_TYPE_TEXT);
llHTTPResponse(id, 200, "OK");
getHandler(path,query_args,body);
}
else
{
llHTTPResponse(id,405,"Unsupported Method");
}
}
} // http_request
}