2 // huffware script: viewscreen blitter, by fred huffhines.
4 // listens for web addresses to show and puts them on the screen of this prim.
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.
10 // important switches...
12 integer IS_OPENSIM = TRUE;
13 // selects the major mode of operation for the viewscreen.
15 integer DEBUGGING = TRUE;
16 // if this is set to true, more diagnostic info is printed than normal.
18 // global constants...
20 // API for the viewscreen blitter library...
22 integer VIEWSCREEN_BLITTER_HUFFWARE_ID = 10027;
23 // unique ID for the viewscreen services.
24 string HUFFWARE_PARM_SEPARATOR = "{~~~}";
25 // this pattern is an uncommon thing to see in text, so we use it to separate
26 // our commands in link messages.
27 string HUFFWARE_ITEM_SEPARATOR = "{|||}";
28 // used to separate lists of items from each other when stored inside a parameter.
29 // this allows lists to be passed as single string parameters if needed.
30 integer REPLY_DISTANCE = 100008; // offset added to service's huffware id in reply IDs.
32 string SHOW_URL_COMMAND = "#shurl";
33 // requests the viewscreen to show a particular URL as its texture.
34 string RESET_VIEWSCREEN_COMMAND = "#shrz";
35 // resets the viewscreen script to the default state.
36 string SHOW_TEXTURE_COMMAND = "#shtex";
37 // displays a texture on the prim. the first parameter is the texture key or name.
40 // configurable constants...
42 handle_view_request(string command, string parms)
44 if (command == SHOW_URL_COMMAND) {
45 // the parms is just the URL to display.
47 string to_show = "url is: ";
49 for (i = 0; i < llStringLength(parms); i += 512) {
50 // show the string a chunk at a time or we will be censored by chat limits.
51 integer end = i + 511;
52 if (i >= llStringLength(parms) - 1) i = llStringLength(parms) - 1;
53 to_show += llGetSubString(parms, i, end);
59 // second life implementation...
60 llParcelMediaCommandList( [ PARCEL_MEDIA_COMMAND_STOP,
61 PARCEL_MEDIA_COMMAND_TYPE, "text/html",
62 PARCEL_MEDIA_COMMAND_URL, parms ] );
63 // we separate out the looping player call since we can't rely on the new media
64 // setting being ready within the same media call.
65 llParcelMediaCommandList( [ PARCEL_MEDIA_COMMAND_PLAY, PARCEL_MEDIA_COMMAND_LOOP ] );
67 // opensim implementation...
68 string extra_parms = "";
69 //bgcolor:white,alpha:false,width:1024,height:768,
70 string url_texture_key = osSetDynamicTextureURL("", "image", parms, extra_parms, 5000);
71 //string url_texture_key ="";
73 //llSay(0, "dyn texture is " + url_texture_key);
74 if (url_texture_key != "") {
75 llSetTexture(url_texture_key, ALL_SIDES);
78 } else if (command == RESET_VIEWSCREEN_COMMAND) {
80 } else if (command == SHOW_TEXTURE_COMMAND) {
81 llSetLinkTexture(LINK_THIS, parms, ALL_SIDES);
89 // huffware script: auto-retire, by fred huffhines, version 2.5.
90 // distributed under BSD-like license.
91 // !! keep in mind that this code must be *copied* into another
92 // !! script that you wish to add auto-retirement capability to.
93 // when a script has auto_retire in it, it can be dropped into an
94 // object and the most recent version of the script will destroy
95 // all older versions.
97 // the version numbers are embedded into the script names themselves.
98 // the notation for versions uses a letter 'v', followed by two numbers
99 // in the form "major.minor".
100 // major and minor versions are implicitly considered as a floating point
101 // number that increases with each newer version of the script. thus,
102 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
103 // and "hazmap v3.2" is a more recent version.
105 // example usage of the auto-retirement script:
108 // auto_retire(); // make sure newest addition is only version of script.
111 // this script is partly based on the self-upgrading scripts from markov brodsky
112 // and jippen faddoul.
115 string self = llGetScriptName(); // the name of this script.
116 list split = compute_basename_and_version(self);
117 if (llGetListLength(split) != 2) return; // nothing to do for this script.
118 string basename = llList2String(split, 0); // script name with no version attached.
119 string version_string = llList2String(split, 1); // the version found.
121 // find any scripts that match the basename. they are variants of this script.
122 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
123 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
124 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
125 // found a basic match at least.
126 list inv_split = compute_basename_and_version(curr_script);
127 if (llGetListLength(inv_split) == 2) {
128 // see if this script is more ancient.
129 string inv_version_string = llList2String(inv_split, 1); // the version found.
130 // must make sure that the retiring script is completely the identical basename;
131 // just matching in the front doesn't make it a relative.
132 if ( (llList2String(inv_split, 0) == basename)
133 && ((float)inv_version_string < (float)version_string) ) {
134 // remove script with same name from inventory that has inferior version.
135 llRemoveInventory(curr_script);
142 // separates the base script name and version number. used by auto_retire.
143 list compute_basename_and_version(string to_chop_up)
145 // minimum script name is 2 characters plus a version.
146 integer space_v_posn;
147 // find the last useful space and 'v' combo.
148 for (space_v_posn = llStringLength(to_chop_up) - 3;
149 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
151 // look for space and v but do nothing else.
153 if (space_v_posn < 2) return []; // no space found.
154 // now we zoom through the stuff after our beloved v character and find any evil
155 // space characters, which are most likely from SL having found a duplicate item
156 // name and not so helpfully renamed it for us.
158 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
159 if (llGetSubString(to_chop_up, indy, indy) == " ") {
160 // found one; zap it. since we're going backwards we don't need to
161 // adjust the loop at all.
162 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
165 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
166 // ditch the space character for our numerical check.
167 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
168 // strip out a 'v' if there is one.
169 if (llGetSubString(chop_suffix, 0, 0) == "v")
170 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
171 // if valid floating point number and greater than zero, that works for our version.
172 string basename = to_chop_up; // script name with no version attached.
173 if ((float)chop_suffix > 0.0) {
174 // this is a big success right here.
175 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
176 return [ basename, chop_suffix ];
178 // seems like we found nothing useful.
189 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
190 on_rez(integer parm) { state rerun; }
192 state rerun { state_entry() { state default; } }
198 llParcelMediaCommandList( [ PARCEL_MEDIA_COMMAND_STOP ] );
201 link_message(integer linknum, integer num, string cmd, key parms) {
202 if (num != VIEWSCREEN_BLITTER_HUFFWARE_ID) return; // not for us.
203 handle_view_request(cmd, parms);