aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/onefang's leash holder and 1ring support.lsl
blob: b7b34ee2abc098c861c1d2ec9c0640f4e068d51e (plain)
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

integer mychannel = -8888;
integer particle_chan = -270510;
string listenfor;
string response;
string detach;

key masterid;
key handle;
key them = NULL_KEY;
string URL = "";
key RequestID;

default
{
    state_entry()
    {
        masterid = llGetOwner();
        handle = llGetKey();
        listenfor = (string)masterid + "handle";
        response = (string)masterid + "handle ok";
        detach = (string)masterid + "handle detached";
        llListen(mychannel, "", NULL_KEY, listenfor);
        llSay(mychannel, response);
    }

    attach(key id)
    {
        if (NULL_KEY == id)
            llSay(mychannel, detach);
    }

    listen(integer channel, string name, key id, string message)
    {
        llSay(mychannel, response);
        llSay(particle_chan, handle + "#" + masterid);
        if (NULL_KEY == them)
            them = llGetOwnerKey(id);
    }

    dataserver(key id, string data)
    {
        list input = llParseStringKeepNulls(data, ["|"], []);
        string domain = llList2String(input, 0);
        if ("URL" == domain)
        {
            list l = llGetObjectDetails(id, [OBJECT_OWNER]);
            URL = llList2String(input, 1);
llOwnerSay(llKey2Name(id) + ", owned by " + llKey2Name(llList2Key(l, 0)) + ", tells me their new URL is " + URL);
        }
    }
 
    http_response(key id, integer status, list metaData, string body)
    {
        if (id == RequestID)
        {
            RequestID = NULL_KEY;
            if (status != 200)
                llOwnerSay("HTTP error code " + status + "\n" + body);
        }
        else if (id == NULL_KEY)
            llOwnerSay("Too many HTTP requests too fast!");
    }

    on_rez(integer param)
    {
        llResetScript();
    }

    touch_start(integer total_number)
    {
        llSay(particle_chan, handle + "#" + masterid);
    }

    changed(integer change)
    {
        if ("" != URL)
        {
            string message = llGetRegionName() + "|" + (string) llGetPos();

//            llSleep(1.0);
            if (NULL_KEY != them)
            {
                if (change & CHANGED_REGION)
                {
                    RequestID = llHTTPRequest(URL, 
                            [HTTP_METHOD, "POST", HTTP_VERBOSE_THROTTLE, FALSE, HTTP_BODY_MAXLENGTH, 16384],
                            llEscapeURL("REGION|" + message));
                    llOwnerSay("Changed region to " + llGetRegionName() + " - " + (string)llGetPos()
                            + "\n  Requesting that " + osKey2Name(them) + " join me.");
                }
                else if (change & CHANGED_TELEPORT)
                {
                    RequestID = llHTTPRequest(URL,
                            [HTTP_METHOD, "POST", HTTP_VERBOSE_THROTTLE, FALSE, HTTP_BODY_MAXLENGTH, 16384],
                                llEscapeURL("TELEPORT|" + message));
                    llOwnerSay("Teleported to " + llGetRegionName() + " - " + (string)llGetPos()
                            + "\n  Requesting that " + osKey2Name(them) + " join me.");
                }
            }
        }
    }
}