normalized perms on all files, to avoid relying on any stored executable bits in...
[feisty_meow.git] / huffware / huffotronic_scripts / html_onna_prim_v1.6.txt
1 
2 // huffware script: html onna prim, by fred huffhines.
3 //
4 // sets the land's media to a web site.
5 //
6 //   this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
7 //   do not use it in objects without fully realizing you are implicitly accepting that license.
8 //
9
10 integer initted = FALSE;
11
12 //////////////
13 // huffware script: auto-retire, by fred huffhines, version 1.9.
14 // distributed under BSD-like license.
15 //   partly based on the self-upgrading scripts from markov brodsky and jippen faddoul.
16 // the function auto_retire() should be added *inside* a version numbered script that
17 // you wish to give the capability of self-upgrading.
18 //   this script supports a notation for versions embedded in script names where a 'v'
19 // is followed by a number in the form "major.minor", e.g. "grunkle script by ted v8.2".
20 // when the containing script is dropped into an object with a different version, the
21 // most recent version eats any existing ones.
22 //   keep in mind that this code must be *copied* into your script you wish to add
23 // auto-retirement capability to.
24 //
25 // example usage of the auto-retirement script:
26 //
27 // default {
28 //    state_entry() {
29 //        auto_retire();  // make sure newest addition is only version of script.
30 //    }
31 // }
32 auto_retire() {
33     string self = llGetScriptName();  // the name of this script.
34     list split = compute_basename_and_version(self);
35     if (llGetListLength(split) != 2) return;  // nothing to do for this script.
36     string basename = llList2String(split, 0);  // script name with no version attached.
37     string version_string = llList2String(split, 1);  // the version found.
38     integer posn;
39     // find any scripts that match the basename.  they are variants of this script.
40     for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
41         string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
42         if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
43             // found a basic match at least.
44             list inv_split = compute_basename_and_version(curr_script);
45             if (llGetListLength(inv_split) == 2) {
46                 // see if this script is more ancient.
47                 string inv_version_string = llList2String(inv_split, 1);  // the version found.
48                 if ((float)inv_version_string < (float)version_string) {
49                     // remove script with same name from inventory that has inferior version.
50                     llRemoveInventory(curr_script);
51                 }
52             }
53         }
54     }
55 }
56 //
57 // separates the base script name and version number.  used by auto_retire.
58 list compute_basename_and_version(string to_chop_up)
59 {
60     if (llSubStringIndex(to_chop_up, " ") < 0) return [];  // no space found, not a valid name to work on.
61         
62     string basename = to_chop_up;  // script name with no version attached.
63     
64     integer posn;
65     // minimum script name is 2 characters plus version.
66     for (posn = llStringLength(to_chop_up) - 1;
67         (posn >= 2) && (llGetSubString(to_chop_up, posn, posn) != " ");
68         posn--) {
69         // find the space.  do nothing else.
70     }
71     if (posn < 2) return [];  // no space found.
72     string full_suffix = llGetSubString(to_chop_up, posn, -1);
73     // ditch the space character for our numerical check.
74     string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
75     // strip out a 'v' if there is one.
76     if (llGetSubString(chop_suffix, 0, 0) == "v")
77         chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
78     // if valid floating point number and greater than zero, that works for our version.
79     if ((float)chop_suffix > 0.0) {
80         // this is a big success right here.
81         basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
82         return [ basename, chop_suffix ];
83     }
84     // seems like we found nothing useful.
85     return [];
86 }
87 //
88 //////////////
89
90 default
91 {
92     state_entry() { if (llSubStringIndex(llGetObjectName(),  "huffotronic") < 0) state real_default; }
93     on_rez(integer parm) { state rerun; }
94 }
95 state rerun { state_entry() { state default; } }
96
97 state real_default
98 {
99     state_entry()
100     {
101         auto_retire();
102
103     }
104     
105     on_rez(integer parm) {
106         llResetScript();
107     }
108     
109     touch_start(integer count) {
110         if ( llParcelMediaQuery([PARCEL_MEDIA_COMMAND_TEXTURE]) == [] ) {
111             llSay(0, "Lacking permission to set/query parcel media. This object has to be owned by/deeded to the land owner.");
112             return;
113         }
114         if (!initted) {
115             string texture_name = llGetInventoryName(INVENTORY_TEXTURE, 0);
116             // sets the media texture to the first texture found in our inventory.
117             llParcelMediaCommandList( [
118                 PARCEL_MEDIA_COMMAND_URL, "http://gruntose.com",
119                 PARCEL_MEDIA_COMMAND_TYPE, "text/html",
120                 PARCEL_MEDIA_COMMAND_TEXTURE, llGetInventoryKey(texture_name),
121                 PARCEL_MEDIA_COMMAND_PLAY ] );
122             llSetTexture(texture_name, ALL_SIDES);
123             initted = TRUE;
124         }
125         
126         // zap it again.
127         llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_STOP]);
128         llParcelMediaCommandList([PARCEL_MEDIA_COMMAND_PLAY]);
129     }
130 }
131