2 // huffware script: zen mondo's mailbox, modified by fred huffhines.
4 // original attributions are below.
6 // my changes are licensed via:
7 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
8 // do not use it in objects without fully realizing you are implicitly accepting that license.
11 //////////////////////////////////////
12 // ZenMondo's Mailbox by ZenMondo Wormser
14 // Displays Online Status, as well as accepting
15 // notecard "mail" to be be delivered to owner.
17 // Cleans Up after itself, deletes non-notecards.
22 // This script is given for free, and may NOT be
23 // resold or used in a commercial product.
24 // You may copy and distribute this script for free.
25 // When you redistribute or copy this script, you must
26 // do so with FULL PERMS (modify, copy, and transfer),
27 // and leave this notice intact.
29 // You are free to modify this code, but any derivitive
30 // scripts must not be used in a commercial product or
31 // or sold, and must contain this license.
33 // This script is provided free for learning
34 // purposes, take it apart, break it, fix it,
35 // learn something. If you come up with something
38 // Questions about codepoetry (scripting) can always be addressed
39 // to me, ZenMondo Wormser.
41 /////////////////////////////////////////
51 // huffware script: auto-retire, by fred huffhines, version 2.5.
52 // distributed under BSD-like license.
53 // !! keep in mind that this code must be *copied* into another
54 // !! script that you wish to add auto-retirement capability to.
55 // when a script has auto_retire in it, it can be dropped into an
56 // object and the most recent version of the script will destroy
57 // all older versions.
59 // the version numbers are embedded into the script names themselves.
60 // the notation for versions uses a letter 'v', followed by two numbers
61 // in the form "major.minor".
62 // major and minor versions are implicitly considered as a floating point
63 // number that increases with each newer version of the script. thus,
64 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
65 // and "hazmap v3.2" is a more recent version.
67 // example usage of the auto-retirement script:
70 // auto_retire(); // make sure newest addition is only version of script.
73 // this script is partly based on the self-upgrading scripts from markov brodsky
74 // and jippen faddoul.
77 string self = llGetScriptName(); // the name of this script.
78 list split = compute_basename_and_version(self);
79 if (llGetListLength(split) != 2) return; // nothing to do for this script.
80 string basename = llList2String(split, 0); // script name with no version attached.
81 string version_string = llList2String(split, 1); // the version found.
83 // find any scripts that match the basename. they are variants of this script.
84 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
85 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
86 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
87 // found a basic match at least.
88 list inv_split = compute_basename_and_version(curr_script);
89 if (llGetListLength(inv_split) == 2) {
90 // see if this script is more ancient.
91 string inv_version_string = llList2String(inv_split, 1); // the version found.
92 // must make sure that the retiring script is completely the identical basename;
93 // just matching in the front doesn't make it a relative.
94 if ( (llList2String(inv_split, 0) == basename)
95 && ((float)inv_version_string < (float)version_string) ) {
96 // remove script with same name from inventory that has inferior version.
97 llRemoveInventory(curr_script);
104 // separates the base script name and version number. used by auto_retire.
105 list compute_basename_and_version(string to_chop_up)
107 // minimum script name is 2 characters plus a version.
108 integer space_v_posn;
109 // find the last useful space and 'v' combo.
110 for (space_v_posn = llStringLength(to_chop_up) - 3;
111 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
113 // look for space and v but do nothing else.
115 if (space_v_posn < 2) return []; // no space found.
116 // now we zoom through the stuff after our beloved v character and find any evil
117 // space characters, which are most likely from SL having found a duplicate item
118 // name and not so helpfully renamed it for us.
120 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
121 if (llGetSubString(to_chop_up, indy, indy) == " ") {
122 // found one; zap it. since we're going backwards we don't need to
123 // adjust the loop at all.
124 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
127 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
128 // ditch the space character for our numerical check.
129 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
130 // strip out a 'v' if there is one.
131 if (llGetSubString(chop_suffix, 0, 0) == "v")
132 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
133 // if valid floating point number and greater than zero, that works for our version.
134 string basename = to_chop_up; // script name with no version attached.
135 if ((float)chop_suffix > 0.0) {
136 // this is a big success right here.
137 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
138 return [ basename, chop_suffix ];
140 // seems like we found nothing useful.
148 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
149 on_rez(integer parm) { state rerun; }
151 state rerun { state_entry() { state default; } }
158 llAllowInventoryDrop(TRUE);
159 name_query = llRequestAgentData(llGetOwner(), DATA_NAME);
160 llSetText("Setting Up, Ready in one minute.", <0,1,1>, 1.0);
168 online_query = llRequestAgentData(llGetOwner(),DATA_ONLINE);
171 dataserver(key queryid, string data)
174 if(queryid == name_query)
177 //llSay(0, data + " " + user_name);
180 if(queryid == online_query)
182 integer online = (integer) data;
186 llSetText(user_name + " is ONLINE\nDrop a NoteCard into me\nto Send " + user_name + " a message.", <0,1,0>, 1.0);
192 llSetText(user_name + " is OFFLINE\nDrop a NoteCard into me\nto Send " + user_name + " a message.", <1,0,0>, 1.0);
199 changed(integer mask)
201 if(mask & (CHANGED_ALLOWED_DROP | CHANGED_INVENTORY))
203 integer num_notes = llGetInventoryNumber(INVENTORY_NOTECARD);
207 string note_name = llGetInventoryName(INVENTORY_NOTECARD, 0);
209 llSay(0, "Sending Notecard, '" + note_name +"' please stand by.");
211 llGiveInventory(llGetOwner(), note_name);
213 llInstantMessage(llGetOwner(), "A NoteCard has been sent to you: " + note_name);
214 llSay(0, "The Notecard, " + note_name + " has been sent. Thank you.");
217 llRemoveInventory(note_name);
219 num_notes = llGetInventoryNumber(INVENTORY_NOTECARD);
221 while(num_notes > 0) // They dropped more than one notecard. Clean it up
223 note_name = llGetInventoryName(INVENTORY_NOTECARD, 0);
225 llSay(0, "Deleting " + note_name + ". It was not submitted. Try Dropping one note at a time.");
227 llRemoveInventory(note_name);
229 num_notes = llGetInventoryNumber(INVENTORY_NOTECARD);
235 else //Not a Notecard
237 //find out what was dropped and remove it.
241 integer num_inv = llGetInventoryNumber(INVENTORY_ALL); // Should be 2
243 while(counter < num_inv)
245 inventory += [llGetInventoryName(INVENTORY_ALL, counter)];
249 // WHat we expect to find
250 list this_script = [llGetScriptName()];
252 //Delete this script (which belong in the inventory) from the list
253 integer index = llListFindList(inventory, this_script);
254 inventory = llDeleteSubList(inventory, index, index);
257 index = llGetListLength(inventory);
260 //Just in case they snuck in more than one inventory item
263 llSay(0, "That was not a notecard. Removing " + llList2String(inventory, 0));
264 llRemoveInventory(llList2String(inventory, 0));
265 inventory = llDeleteSubList(inventory, 0, 0);
266 index = llGetListLength(inventory);
272 on_rez(integer start_param)