2 // huffware script: tester for inventory exchanger, by fred huffhines.
4 // makes sure that the inventory exchanger is working, although this currently
5 // needs some manual inspection to be sure that the items are properly exchanged
6 // with the child prims.
8 // this script is licensed by the GPL v3 which is documented at: http://www.gnu.org/licenses/gpl.html
9 // do not use it in objects without fully realizing you are implicitly accepting that license.
12 // requires inventory exchanger version 2.0 or better.
14 // do not redefine these constants.
15 integer INVENTORY_EXCHANGER_HUFFWARE_ID = 10021;
16 // the unique id within the huffware system for the jaunt script to
17 // accept commands on. this is used in llMessageLinked as the num parameter.
18 string HUFFWARE_PARM_SEPARATOR = "{~~~}";
19 // this pattern is an uncommon thing to see in text, so we use it to separate
20 // our commands in link messages.
21 //string HUFFWARE_ITEM_SEPARATOR = "{|||}";
22 // used to separate lists of items from each other when stored inside a parameter.
23 // this allows lists to be passed as single string parameters if needed.
24 integer REPLY_DISTANCE = 100008; // offset added to service's huffware id in reply IDs.
25 // commands available via the library:
26 string REGISTER_ASSETS_COMMAND = "#regis#";
27 // makes the root prim's inventory exchanger track a set of items which each participating
28 // child prim should have. this command is only available to the root prim; child prims
29 // cannot register any assets but instead can get updates on the assets. the parameter
30 // required is a list of asset definitions, wrapped by the huffware item separator. each
31 // asset definition is in turn a two part list wrapped with the asset field separator.
32 string ASSET_FIELD_SEPARATOR = "&&"; // separates the type from the name in our list.
33 string WILDCARD_INVENTORY_NAME = "ALL";
34 // this keyword can be used to register all of the inventory items available of the
35 // specified type. this should be passed as the inventory item name in the second half of
36 // an asset definition list.
37 string WHACK_INVENTORY_SIGNAL = "DEL*";
38 // ensures that the child prim doesn't maintain *any* of the inventory of the type specified.
39 string AVAILABLE_ASSETS_EVENT = "#gotz#";
40 // the root prim publishes this event to list out what items it has available. the child
41 // prims need to ask for anything that they're currently missing. the included parameters
42 // are in the same format as the register assets command, but no wildcards will be present;
43 // all asset names will be fully expanded.
44 string REQUEST_UPDATES = "#nupd#";
45 // used by the child prim to request an updated version of an asset or assets. the parameters
46 // should follow the register assets command.
47 string FINISHED_UPDATING = "#donq#";
48 // a signal sent from the root prim to the child prim when the root has finished updating
49 // the assets requested. this lets the child know that it can clean out any outdated versions
50 // of items which got an update. there are no parameters to this, because the child prim
51 // should have at most one update outstanding at a time.
54 // looks for an inventory item with the same prefix as the "basename_to_seek".
55 integer find_basename_in_inventory(string basename_to_seek, integer inv_type)
57 integer num_inv = llGetInventoryNumber(inv_type);
58 if (num_inv == 0) return -1; // nothing there!
60 for (indy = 0; indy < num_inv; indy++) {
61 if (is_prefix(llGetInventoryName(inv_type, indy), basename_to_seek))
64 return -2; // failed to find it.
67 // returns the name of the inventory exchange script, if one is present. we don't worry
68 // about there being more than one present; that's a different script's problem rather
69 // than one from the inventory exchanger.
70 string get_exchangers_name()
72 integer found = find_basename_in_inventory("inventory exchanger", INVENTORY_SCRIPT);
76 return llGetInventoryName(INVENTORY_SCRIPT, found);
79 // tell the root prim's inventory exchanger what to monitor.
80 post_exchangeable_assets()
82 llMessageLinked(LINK_THIS, INVENTORY_EXCHANGER_HUFFWARE_ID, REGISTER_ASSETS_COMMAND,
84 (string)INVENTORY_LANDMARK + ASSET_FIELD_SEPARATOR + "ALL",
85 (string)INVENTORY_SOUND + ASSET_FIELD_SEPARATOR + "ALL",
86 (string)INVENTORY_SCRIPT + ASSET_FIELD_SEPARATOR + get_exchangers_name(),
87 (string)INVENTORY_TEXTURE + ASSET_FIELD_SEPARATOR + "ALL"
94 integer debug_num = 0;
95 // a debugging output method. can be disabled entirely in one place.
99 // tell this to the owner.
100 llOwnerSay(llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
101 // say this on an unusual channel for chat if it's not intended for general public.
102 // llSay(108, llGetScriptName() + "[" + (string)debug_num + "] " + to_say);
103 // say this on open chat that anyone can hear. we take off the bling for this one.
107 // joins a list of parameters using the parameter sentinel for the library.
108 string wrap_parameters(list to_flatten)
109 { return llDumpList2String(to_flatten, HUFFWARE_PARM_SEPARATOR); }
111 // returns the index of the first occurrence of "pattern" inside
112 // the "full_string". if it is not found, then a negative number is returned.
113 integer find_substring(string full_string, string pattern)
114 { return llSubStringIndex(llToLower(full_string), llToLower(pattern)); }
116 // returns TRUE if the "prefix" string is the first part of "compare_with".
117 integer is_prefix(string compare_with, string prefix)
118 { return find_substring(compare_with, prefix) == 0; }
124 state_entry() { if (llSubStringIndex(llGetObjectName(), "huffotronic") < 0) state real_default; }
125 on_rez(integer parm) { state rerun; }
127 state rerun { state_entry() { state default; } }
132 llSetTimerEvent(14); // pretty fast update cycle will push the exchange events.
133 post_exchangeable_assets();
136 // this tester has no link message responsibilities. once it tells the root prim's
137 // inventory exchanger what to do, that's all it needs to say.
138 // link_message(integer link_num, integer service, string cmd, key parms) {}
141 // repost all the assets we care about. this ensures that we're up to date if the
142 // inventory changes.
143 post_exchangeable_assets();