2 // huffware script: welcomebot visitor list, by fred huffhines
4 // originally based on LSL wiki examples.
5 // how to use this script:
6 // 1) create an object that you want to track visitors to your area.
7 // 2) change the parameters below to reflect your own information.
8 // 3) add the script to your tracker object.
9 // 4) reply to the script's rez email with the following commands:
10 // list: send the current visitor list.
11 // scan: scan the area near the greeter object.
12 // clear: throw out the visitor list. sends a copy before deleting.
14 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
15 // do not use it in objects without fully realizing you are implicitly accepting that license.
19 // how do we reconcile having a config notecard with the giveaway ones?
20 // just name it special?
21 // we want the script not to reset when the parameters change!
22 // it should just reset the notecard stuff and other variables.
23 // no new setup on email and all that stuff!
24 // maintain list of last visit times.
28 // put your e-mail address here.
29 string owner_email = "fred@gruntose.com";
31 // put the GUIDs of your business partners here. the owner is automatically
33 list notification_list = [];
35 // place name used to identify this visitor list.
36 string greeter_name = "eepaw shop welcomebot";
38 // the description of where this is.
39 string welcome_message = "Welcome to the eepaw shop (Eclectic Electric Patterns and Widgets). Please touch the welcomebot for more information.";
41 // you can make the bot listen on a different channel if you like...
42 integer OWNER_CHANNEL = 14;
44 integer MAX_ITEMS_PER_LINE = 4; // how many visitors to show on one line of output.
46 integer EMAIL_RECEPTION_ENABLED = FALSE; // currently not enabled in opensim.
48 integer EMAIL_SENDING_ENABLED = FALSE; // apparently many sims don't allow email sending.
50 integer MAX_VISITORS_TRACKED = 120;
51 // the number of items we keep around in the list of visitors.
53 float pause_when_mail_pending = 2.0; // check for mail this frequently when there's a stack.
54 float pause_no_pending_mail = 42.0; // if no mail had been waiting, we check more slackly.
56 // number of seconds between sending the owner a visitor list.
57 integer auto_list_interval = 43200; // 43200 is every 12 hours.
59 // any variables that need to be modified are above this...
60 ///////////////////////////////////////////////////////////
62 float SENSOR_RANGE = 10.0; // in meters.
64 float SENSOR_RATE = 30.0; // in seconds.
76 integer last_automatic_list_sent; // when we last updated the owner automatically.
78 // sends an email. somewhat a thin wrapper.
79 send_email(string recipient, string subject, string text)
81 if (EMAIL_SENDING_ENABLED) {
82 // some sims do not support email.
83 llEmail(recipient, subject, text);
87 cloaked_owner_alert(string text)
89 // temporarily change the name so emails will come from the expected greeter.
90 string hold_name = llGetObjectName();
91 llSetObjectName(greeter_name);
94 // restore our name back to the original.
95 llSetObjectName(hold_name);
98 cloaked_IM(key who_to_tell, string text)
100 // temporarily change the name so emails will come from the expected greeter.
101 string hold_name = llGetObjectName();
102 llSetObjectName(greeter_name);
104 llInstantMessage(who_to_tell, text);
105 // restore our name back to the original.
106 llSetObjectName(hold_name);
109 // notifies all the people in the list who want to hear about visitors.
110 notify_folks(string text)
112 // temporarily change the name so emails will come from the expected greeter.
113 string hold_name = llGetObjectName();
114 llSetObjectName(greeter_name);
116 list temp_notify = notification_list;
117 temp_notify += [llGetOwner()];
120 for (i = 0; i < llGetListLength(temp_notify); i++) {
121 string current_id = llList2String(temp_notify, i);
122 if ((key)current_id == llGetOwner()) cloaked_owner_alert(text);
123 else cloaked_IM((key)current_id, text);
126 // restore our name back to the original.
127 llSetObjectName(hold_name);
130 // looks for the name provided in a list. the index is returned if
131 // the name is found, otherwise a negative number is returned.
132 integer find_name_in_list(string name, list avlist)
134 integer len = llGetListLength(avlist);
136 for (i = 0; i < len; i++)
138 if (llList2String(avlist, i) == name)
144 // looks for changes in the current locale.
145 check_region(list detected)
147 // we accumulate information about people who have changed state in the variables below.
148 string names_entering = "";
149 string names_leaving = "";
150 integer num_entering = 0;
151 integer num_leaving = 0;
153 // see if we have somebody new.
154 integer len = llGetListLength(detected);
156 for (i = 0; i < len; i++) {
157 string name = llList2String(detected, i);
158 if (find_name_in_list(name, current_list) < 0) {
159 current_list += name;
160 if (num_entering > 0) names_entering += ", ";
161 names_entering += name;
166 // see if somebody left.
167 len = llGetListLength(current_list);
168 for (i = 0; i < len; i++) {
169 string name = llList2String(current_list, i);
170 if (find_name_in_list(name, detected) < 0) {
171 if (num_leaving > 0) names_leaving += ", ";
172 names_leaving += name;
177 // update current list to be current only
178 current_list = detected;
180 // create a message describing the state.
182 if (num_entering > 0) msg = "Arrived: " + names_entering;
183 if (num_leaving > 0) {
184 if (llStringLength(msg) > 0) msg += "\n";
185 msg += "Left: " + names_leaving;
187 if (msg != "") notify_folks(msg);
190 string build_visitor_list()
192 string text = greeter_name + ":\n";
193 integer len = llGetListLength(visitor_list);
195 integer items_per_line = 0;
196 for (i = len - 1; i >= 0; i--) {
197 if (items_per_line != 0) {
200 text += llList2String(visitor_list, i);
202 if (items_per_line >= MAX_ITEMS_PER_LINE) {
207 // handle case for last line.
208 if (items_per_line != 0) text += "\n";
209 text += "Total=" + (string)len;
215 llOwnerSay(build_visitor_list());
220 llOwnerSay(greeter_name + " scan\n" + scan_list);
225 string text = build_visitor_list();
226 send_email(owner_email, greeter_name + " visitor list", text);
231 send_email(owner_email, greeter_name + " scan", scan_list);
241 last_automatic_list_sent = llGetUnixTime();
246 regionName = llGetRegionName();
248 vector rezPos = llGetPos();
249 maxZ = rezPos.z + MAXZ;
250 minZ = rezPos.z - MINZ;
251 string rezInfo = "Key: "+(string)myKey + " @ "+regionName+" "+(string)rezPos+" ("+(string)maxZ+")";
252 notify_folks(rezInfo);
253 send_email(owner_email, greeter_name + " Rez Information", rezInfo);
254 llSetTimerEvent(pause_no_pending_mail);
255 llSensorRepeat( "", "", AGENT, SENSOR_RANGE, TWO_PI, SENSOR_RANGE);
256 // hook up the bot to the radio so it will hear commands.
257 llListen(OWNER_CHANNEL, "", llGetOwner(), "");
258 llOwnerSay("Listening to commands on channel " + (string)OWNER_CHANNEL
259 + " (list, scan, clear)");
262 // performs the requested command.
263 process_command_locally(string msg)
265 if (msg == "list") send_list_in_text();
266 else if (msg == "scan") send_scan_in_text();
267 else if (msg == "clear") {
274 // huffware script: auto-retire, by fred huffhines, version 2.5.
275 // distributed under BSD-like license.
276 // !! keep in mind that this code must be *copied* into another
277 // !! script that you wish to add auto-retirement capability to.
278 // when a script has auto_retire in it, it can be dropped into an
279 // object and the most recent version of the script will destroy
280 // all older versions.
282 // the version numbers are embedded into the script names themselves.
283 // the notation for versions uses a letter 'v', followed by two numbers
284 // in the form "major.minor".
285 // major and minor versions are implicitly considered as a floating point
286 // number that increases with each newer version of the script. thus,
287 // "hazmap v0.1" might be the first script in the "hazmap" script continuum,
288 // and "hazmap v3.2" is a more recent version.
290 // example usage of the auto-retirement script:
293 // auto_retire(); // make sure newest addition is only version of script.
296 // this script is partly based on the self-upgrading scripts from markov brodsky
297 // and jippen faddoul.
300 string self = llGetScriptName(); // the name of this script.
301 list split = compute_basename_and_version(self);
302 if (llGetListLength(split) != 2) return; // nothing to do for this script.
303 string basename = llList2String(split, 0); // script name with no version attached.
304 string version_string = llList2String(split, 1); // the version found.
306 // find any scripts that match the basename. they are variants of this script.
307 for (posn = llGetInventoryNumber(INVENTORY_SCRIPT) - 1; posn >= 0; posn--) {
308 //log_it("invpo=" + (string)posn);
309 string curr_script = llGetInventoryName(INVENTORY_SCRIPT, posn);
310 if ( (curr_script != self) && (llSubStringIndex(curr_script, basename) == 0) ) {
311 // found a basic match at least.
312 list inv_split = compute_basename_and_version(curr_script);
313 if (llGetListLength(inv_split) == 2) {
314 // see if this script is more ancient.
315 string inv_version_string = llList2String(inv_split, 1); // the version found.
316 // must make sure that the retiring script is completely the identical basename;
317 // just matching in the front doesn't make it a relative.
318 if ( (llList2String(inv_split, 0) == basename)
319 && ((float)inv_version_string < (float)version_string) ) {
320 // remove script with same name from inventory that has inferior version.
321 llRemoveInventory(curr_script);
328 // separates the base script name and version number. used by auto_retire.
329 list compute_basename_and_version(string to_chop_up)
331 // minimum script name is 2 characters plus a version.
332 integer space_v_posn;
333 // find the last useful space and 'v' combo.
334 for (space_v_posn = llStringLength(to_chop_up) - 3;
335 (space_v_posn >= 2) && (llGetSubString(to_chop_up, space_v_posn, space_v_posn + 1) != " v");
337 // look for space and v but do nothing else.
338 //log_it("pos=" + (string)space_v_posn);
340 if (space_v_posn < 2) return []; // no space found.
341 //log_it("space v@" + (string)space_v_posn);
342 // now we zoom through the stuff after our beloved v character and find any evil
343 // space characters, which are most likely from SL having found a duplicate item
344 // name and not so helpfully renamed it for us.
346 for (indy = llStringLength(to_chop_up) - 1; indy > space_v_posn; indy--) {
347 //log_it("indy=" + (string)space_v_posn);
348 if (llGetSubString(to_chop_up, indy, indy) == " ") {
349 // found one; zap it. since we're going backwards we don't need to
350 // adjust the loop at all.
351 to_chop_up = llDeleteSubString(to_chop_up, indy, indy);
352 //log_it("saw case of previously redundant item, aieee. flattened: " + to_chop_up);
355 string full_suffix = llGetSubString(to_chop_up, space_v_posn, -1);
356 // ditch the space character for our numerical check.
357 string chop_suffix = llGetSubString(full_suffix, 1, llStringLength(full_suffix) - 1);
358 // strip out a 'v' if there is one.
359 if (llGetSubString(chop_suffix, 0, 0) == "v")
360 chop_suffix = llGetSubString(chop_suffix, 1, llStringLength(chop_suffix) - 1);
361 // if valid floating point number and greater than zero, that works for our version.
362 string basename = to_chop_up; // script name with no version attached.
363 if ((float)chop_suffix > 0.0) {
364 // this is a big success right here.
365 basename = llGetSubString(to_chop_up, 0, -llStringLength(full_suffix) - 1);
366 return [ basename, chop_suffix ];
368 // seems like we found nothing useful.
376 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
377 on_rez(integer parm) { state rerun; }
379 state rerun { state_entry() { state default; } }
385 initialize_greeter();
388 on_rez(integer param) { llResetScript(); }
392 if (EMAIL_RECEPTION_ENABLED) {
393 llGetNextEmail("", ""); // check for email with any subject/sender
395 integer curTime = llGetUnixTime();
396 if (curTime - last_automatic_list_sent < auto_list_interval) return;
397 last_automatic_list_sent = curTime;
398 send_list_in_email();
402 email(string time, string address, string subj, string message, integer num_left)
404 list args = llParseString2List(message, [" "], []);
405 if (llGetListLength(args) < 1) return; // nothing to do.
406 string cmd = llToLower(llList2String(args, 0));
407 //room for a process_command_for_email here.
408 if (cmd == "list") send_list_in_email();
409 else if (cmd == "scan") send_scan_in_email();
410 else if (cmd == "clear") {
411 send_list_in_email();
415 if (num_left == 0) llSetTimerEvent(pause_no_pending_mail); // sleep longer before checking.
416 else llSetTimerEvent(pause_when_mail_pending); // short sleep since others are waiting.
419 listen(integer channel, string name, key id, string msg)
421 if ( (channel != OWNER_CHANNEL) || (id != llGetOwner()) ) return; // not for them.
422 process_command_locally(msg);
425 // when a visitor touches the welcomebot, hand out the first landmark and
426 // first notecard we have stored.
427 touch_start(integer count) {
428 string item_name = llGetInventoryName(INVENTORY_NOTECARD, 0); // first notecard.
430 llGiveInventory(llDetectedKey(0), item_name);
431 item_name = llGetInventoryName(INVENTORY_LANDMARK, 0);
433 llGiveInventory(llDetectedKey(0), item_name);
436 sensor(integer number_detected)
439 vector pos = llGetPos();
440 string textVerbose = "";
441 string textNewVerbose = "";
449 for (outer = 0; outer < number_detected; outer++)
451 vector dpos = llDetectedPos(outer);
452 if (llGetLandOwnerAt(dpos)==llGetLandOwnerAt(llGetPos()))
454 string detected_name = llDetectedName(outer);
455 string detected_key = llDetectedKey(outer);
456 integer info_res = llGetAgentInfo(detected_key);
457 float diff = llVecDist(pos,dpos);
458 integer dist = llRound(diff);
459 string result = detected_name+" ("+detected_key+") " + (string)dist;
460 if(dpos.y>pos.y) result+="N";
461 else if(dpos.y<pos.y) result+="S";
462 if(dpos.x>pos.x) result+="E";
463 else if(dpos.x<pos.x) result+="W";
464 result += (string)((integer)(dpos.z-pos.z));
466 if(info_res & AGENT_SCRIPTED) result += "S";
467 if(info_res & AGENT_FLYING) result += "F";
468 if(info_res & AGENT_AWAY) result += "A";
469 if(info_res & AGENT_IN_AIR) result += "H";
470 if(info_res & AGENT_MOUSELOOK) result += "M";
471 if (llDetectedGroup(outer)) result += "G";
473 if ((dpos.x >= 0 && dpos.x <= 256) &&
474 (dpos.y >= 0 && dpos.y <= 256) &&
475 (dpos.z >= minZ) && (dpos.z <= maxZ))
477 if (llDetectedGroup(outer)) group++;
480 // add to the detected list
481 detected += detected_name;
483 // see if they are on the visitor list
484 if (find_name_in_list(detected_name, visitor_list) < 0) {
485 // make sure we haven't gone beyond our limit.
486 if (llGetListLength(visitor_list) >= MAX_VISITORS_TRACKED) {
487 visitor_list = llDeleteSubList(visitor_list, 0, 0);
489 // add to the visitor list
490 visitor_list += detected_name;
492 // handle any separators to make more readable
495 textNewVerbose += "\n";
499 textNew += detected_name;
500 textNewVerbose += detected_name+" ("+detected_key+") @ "+regionName+" "+(string)dpos;
503 // increment the count of new visitors
505 cloaked_IM(detected_key, welcome_message);
512 textVerbose += result + "\n";
517 // extra verbose logging.
518 // notify_folks(textNew + "\n" + textNewVerbose);
520 scan_list = textVerbose;
522 check_region(detected);