-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrimScript.lsl
142 lines (123 loc) · 4.05 KB
/
PrimScript.lsl
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
string url;
key urlRequestId;
key selfCheckRequestId;
key requestBoxID; // just to check if we're getting the result we've asked for; all scripts in the same object get the same replies
key requestChatID;
integer listenHandle;
request_url()
{
llReleaseURL(url);
url = "";
urlRequestId = llRequestURL();
}
throw_exception(string inputString)
{
key owner = llGetOwner();
llInstantMessage(owner, inputString);
// yeah, bad way to handle exceptions by restarting.
// However this is just a demo script...
llResetScript();
}
default
{
on_rez(integer start_param)
{
llResetScript();
}
changed(integer change)
{
if (change & (CHANGED_OWNER | CHANGED_INVENTORY))
{
llReleaseURL(url);
url = "";
llResetScript();
}
if (change & (CHANGED_REGION | CHANGED_REGION_START | CHANGED_TELEPORT))
request_url();
}
state_entry()
{
listenHandle = llListen(0, "", NULL_KEY, "");
request_url();
}
listen(integer channel, string name, key id, string message)
{
string txt =
"param1=" + "chat" +
"¶m2=" + (string) channel +
"¶m3=" + name +
"¶m4=" + (string) id +
"¶m5=" + message;
string params = llDumpList2String(llParseString2List(txt, [" "], []), "%20");
llSetColor(<0, 1, 1>, ALL_SIDES);
requestChatID = llHTTPRequest(
"http://66.25.85.79/index.php",
[HTTP_METHOD, "POST",
HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
params);
}
http_request(key id, string method, string body)
{
integer responseStatus = 400;
string responseBody = "Unsupported method";
if (method == URL_REQUEST_DENIED)
throw_exception("The following error occurred while attempting to get a free URL for this device:\n \n" + body);
else if (method == URL_REQUEST_GRANTED)
{
url = body;
string txt =
"param1=" + "box" +
"¶m2=" + url +
"¶m3=" + (string) llGetKey();
string params = llDumpList2String(llParseString2List(txt, [" "], []), "%20");
llSetColor(<0, 1, 0>, ALL_SIDES);
requestBoxID = llHTTPRequest(
"http://66.25.85.79/index.php",
[HTTP_METHOD, "POST",
HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
params);
// check every 5 mins for dropped URL
llSetTimerEvent(300.0);
}
else if (method == "GET")
{
responseStatus = 200;
responseBody = "Hello world!";
}
// else if (method == "POST") ...;
// else if (method == "PUT") ...;
// else if (method == "DELETE") { responseStatus = 403; responseBody = "forbidden"; }
llHTTPResponse(id, responseStatus, responseBody);
}
http_response(key id, integer status, list metaData, string body)
{
if (id == selfCheckRequestId)
{
// If you're not usually doing this,
// now is a good time to get used to doing it!
selfCheckRequestId = NULL_KEY;
if (status != 200)
request_url();
}
else if (id == requestBoxID)
{
llSetColor(<1, 0, 0>, ALL_SIDES);
llWhisper(0, "Web server said: " + body);
}
else if (id == requestChatID)
{
if (body == "chat received")
llSetColor(<0, 0, 1>, ALL_SIDES);
}
else if (id == NULL_KEY)
throw_exception("Too many HTTP requests too fast!");
}
timer()
{
selfCheckRequestId = llHTTPRequest(url,
[HTTP_METHOD, "GET",
HTTP_VERBOSE_THROTTLE, FALSE,
HTTP_BODY_MAXLENGTH, 16384],
"");
}
}