<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Script Academy &#187; Sample Scripts</title>
	<atom:link href="http://www.scriptacademy.org/archives/category/sample-scripts/feed" rel="self" type="application/rss+xml" />
	<link>http://www.scriptacademy.org</link>
	<description>'Cos we're all noobs at something</description>
	<lastBuildDate>Mon, 09 Aug 2010 21:22:06 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Group Name Grabber</title>
		<link>http://www.scriptacademy.org/archives/9</link>
		<comments>http://www.scriptacademy.org/archives/9#comments</comments>
		<pubDate>Sun, 15 Jun 2008 19:31:21 +0000</pubDate>
		<dc:creator>Hippyjim Starbrook</dc:creator>
				<category><![CDATA[Sample Scripts]]></category>

		<guid isPermaLink="false">http://www.scriptacademy.org/?p=9</guid>
		<description><![CDATA[Our first webservice is now live! This service is free for any group member to use. If you use it, please post a comment here so we can see some of the great ideas you come up with!]]></description>
			<content:encoded><![CDATA[<p>Our first webservice is now live! This service is free for any group member to use. If you use it, please post a comment here so we can see some of the great ideas you come up with!</p>
<p>Instructions and code after the break.<br />
<span id="more-9"></span></p>
<p><strong>How to use it:</strong></p>
<p>If you pass it a valid group key, it will return the group name, as found in SL search. If the group is not listed &#8211; either because it is not set to show in search, or the group key isn&#8217;t right, it returns an X.</p>
<p>The URL to check the name is:</p>
<p>http:/groupname.scriptacedemy.org/MY_GROUP_KEY &#8211; where &#8220;MY_GROUP_KEY&#8221; is the SL UUID of the group.</p>
<p>Here is an example script to show how it could be used:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.scriptacademy.org/wp-content/plugins/wp-codebox/wp-codebox.php?p=9&amp;download=groupNameGrabber.lsl">groupNameGrabber.lsl</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p91"><td class="line_numbers"><pre>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
</pre></td><td class="code" id="p9code1"><pre class="lsl" style="font-family:monospace;">// Group Name Grabber
//
// By Hippyjim Starbrook
&nbsp;
// A key variable to keep track of our web requests
key httpid;
&nbsp;
default
{
&nbsp;
    // On touch, start the request
    touch_start(integer total_number)
    {
        // Get a list containing my group details
        list details = llGetObjectDetails(llGetKey(), [OBJECT_GROUP]);
&nbsp;
        // Grab the key as a string from that list
        string groupkey = llList2String(details, 0);
&nbsp;
        // Make the web request including the group key as part of the url
        httpid = llHTTPRequest(&quot;http://groupname.scriptacademy.org/&quot; + groupkey, [HTTP_METHOD, &quot;GET&quot;], &quot;&quot;);
    }
&nbsp;
&nbsp;
    // When the web replies, say the result
    http_response(key id, integer status, list data, string body)
    {
&nbsp;
        // check the web replied ok, and that we made the request properly
        if (status == 200 &amp;&amp; id == httpid)
        {
            // if the web replied with an X, say it's a private group
            if (body == &quot;X&quot;)
            {
                llSay(0, &quot;I'm in a private group&quot;);
            }
            // if not, say the group name
            else
            {
                llSay(0, &quot;I'm in &quot; + body);
            }
        }
    }
}</pre></td></tr></table></div>

<p>The PHP on the server side is:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left2">Download <a href="http://www.scriptacademy.org/wp-content/plugins/wp-codebox/wp-codebox.php?p=9&amp;download=groupNameGrabber.php">groupNameGrabber.php</a></span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p92"><td class="line_numbers"><pre>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
</pre></td><td class="code" id="p9code2"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">/*
*
*  Group Name Grabber PHP script - By Hippyjim Starbrook
*
*  usage:
*
*  send a GET request with ?ky= the group key to get the name of a group with the given key
*  if the request is malformed, or the key doesn't exist, returns X
*
*/</span>
&nbsp;
<span style="color: #000088;">$groupKey</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;ky&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// create a new cURL resource</span>
<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// set URL and other appropriate options</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;http://world.secondlife.com/group/&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$groupKey</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_HEADER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// grab URL and pass it to the browser</span>
<span style="color: #000088;">$dump</span> <span style="color: #339933;">=</span> curl_e xec<span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// note the space in &quot;curl_e xec&quot; must be removed for it to work - only added here due to a limit in the blog software</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// close cURL resource, and free up system resources</span>
<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// remove all HTML tags from the result, except the &lt;h1&gt; tags (which will surround our group name)</span>
<span style="color: #000088;">$dump</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dump</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&lt;h1&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// if the reply doesn't include the phrase &quot;The specified key does not exist&quot; take the page apart</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dump</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;The specified key does not exist&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// find the position of the phrase &quot;Group:&quot; in the page, as that shows the start of our group name</span>
	<span style="color: #000088;">$groupPos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dump</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Group:&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span> <span style="color: #cc66cc;">6</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// find the closing &lt;/h1&gt; tag immediately after &quot;Group:&quot; as that signifies the end of our group name</span>
	<span style="color: #000088;">$endPos</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dump</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&lt;/h1&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$groupPos</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// our group name is the string in between these two points</span>
	<span style="color: #000088;">$groupName</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$dump</span><span style="color: #339933;">,</span> <span style="color: #000088;">$groupPos</span><span style="color: #339933;">,</span> <span style="color: #000088;">$endPos</span><span style="color: #339933;">-</span><span style="color: #000088;">$groupPos</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// output the group name</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$groupName</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">// otherwise output an X</span>
<span style="color: #b1b100;">else</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;X&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.scriptacademy.org/archives/9/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

