xs_home_world.lsl 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. // Version 0.32 12-03-2011
  2. // script by Xundra Snowpaw
  3. // mods by Ferd Frederix
  4. // revisions:
  5. // 10-3-2011 Mod by Ferd to listen to HOME_CHANNEL, not -237918, the original src has no other reference to that channel.
  6. // 11-16-2011 Use latest globals from GLobal Constants
  7. //
  8. // New BSD License: http://www.opensource.org/licenses/bsd-license.php
  9. // Copyright (c) 2010, Xundra Snowpaw
  10. // All rights reserved.
  11. //
  12. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  13. //* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  14. //* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  15. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16. ////////////////////////////////////////////////////////////////////
  17. ///////////////////////////////////////////////
  18. // COPY FROM GLOBAL CONSTANTS FILE LOCATED IN Debug Folder
  19. // INCLUDE THESE IN ALL SCRIPTS //
  20. // XS_pet constants and names
  21. ///// GLOBAL CONSTANTS extracted from original source //////
  22. //
  23. // if you change any of these constants, change it everywhere and in a list in XS_Debug so it can print them
  24. //
  25. // 0.24 is the original Pet Quail
  26. // 0.25 is the modified Pet Quail
  27. // 0.26 is the Robot code, which is generic
  28. float VERSION = 0.26;
  29. integer ENCRYPT = FALSE;
  30. key YOUR_UUID = ""; // if you add a UUID for your avatar here, you can change it later
  31. // and other alts or feruiends can edit and make these pets
  32. // If you leave it blank, only the creator can work on them
  33. string Animal = "Troubot"; // was 'Quail', must be the name of your animal
  34. string Egg = "Nut and Bolt"; // was 'XS Egg', must be the name of your egg
  35. string Crate = "Transport UFO"; // was XS-Cryocrate
  36. string HomeObject = "Home Flag"; // was "XS Home Object
  37. string SECRET_PASSWORD = "moonlet"; // must use one unique to any animal
  38. integer SECRET_NUMBER = 99999; // any number thats a secret
  39. integer MaxAge = 7; // can get prggers in 7 days
  40. integer UNITS_OF_FOOD = 168; // food bowl food
  41. float secs_to_grow = 86400; // grow daily = 86400
  42. // global listeners
  43. integer FOOD_CHANNEL = -999191;
  44. integer ANIMAL_CHANNEL = -999192;
  45. integer EGG_CHANNEL = -999193;
  46. integer HOME_CHANNEL = -999194;
  47. integer BOX_CHANNEL = -999195;
  48. integer ACC_CHANNEL = -999196;
  49. integer UPDATE_CHANNEL = -999197;
  50. integer API_CHANNEL = -999198;
  51. // global prim animation linkmessages on channel 1
  52. // these are the prim animations played for each type of possible animation
  53. string ANI_STAND = "stand"; // default standing animation
  54. string ANI_WALKL = "left"; // triggers Left foot and righrt arm walk animation
  55. string ANI_WALKR = "right"; // triggers Right foot and left arm walk animation
  56. string ANI_SLEEP = "sleep"; // Sleeping
  57. string ANI_WAVE = "wave"; // Calling for sex, needs help with food, etc.
  58. // global link messages to control the animal
  59. integer LINK_AGE_START = 800; // when quail is rezzed and secret_number, is sent by brain to breeder, eater and informatic get booted up
  60. integer LINK_FOOD_CONSUME = 900; // from movement to brain when close to food, brain then consumes a random amount up to 10000
  61. integer LINK_FOODMINUS = 901; // xs_brain receives FOOD_CONSUME, decrement hunger (eat)
  62. integer LINK_HUNGRY = 903; // sent by eater (string)hunger_amount, checks each hour
  63. integer LINK_HAMOUNT = 904; // hunger_amount = (integer)str,m updates the hunger amount in scripts
  64. integer LINK_SET_HOME = 910; // loc ^ dist
  65. integer LINK_MOVER = 911; // tell mover to rest for str seconds
  66. integer LINK_FOODIE_CLR = 920; // clear all food_bowl_keys and contents
  67. integer LINK_FOODIE = 921; // send FOOD_LOCATION coordinates to movement
  68. integer LINK_COLOR1 = 930; // colour1
  69. integer LINK_COLOR2 = 931; // colour2
  70. integer LINK_SEX = 932; // sex
  71. integer LINK_SHINE = 933; // shine
  72. integer LINK_GLOW = 934; // glow
  73. integer LINK_GEN = 935; // generation
  74. integer LINK_RESET_SIZE = 936; // reset size to 1
  75. integer LINK_MAGE = 940; // xs_brain sends, xs_ager consumes, adds str to age, if older than 7 days, will grow the animal
  76. integer LINK_DAYTIME = 941; // xs_ager consumes, starts a timer of 86,400 seconds in xs_ager
  77. integer LINK_GET_AGE = 942; // get age from xs_ager and sent it on channel 943
  78. integer LINK_PUT_AGE = 943; // print age from xs_ager
  79. integer LINK_PACKAGE = 950; // look for a cryo_crate
  80. integer LINK_SEEK_FEMALE = 960; // MALE_BREED_CALL
  81. integer LINK_MALE_BREED_CALL = 961; // triggered by LINK_SEEK_FEMALE
  82. integer LINK_SIGNAL_ELIGIBLE = 962; // sent by female when hears LINK_MALE_BREED_CALL
  83. integer LINK_FEMALE_ELIGIBLE = 963; // sent when it hears in chat FEMALE_ELIGIBLE
  84. integer LINK_CALL_MALE = 964; // if LINK_FEMALE_ELIGIBLE && looking_for_female
  85. integer LINK_MALE_ON_THE_WAY = 965; // triggered by LINK_CALL_MALE
  86. integer LINK_FEMALE_LOCATION = 966; // female location, sends coordinates of a female
  87. integer LINK_RQST_BREED = 967; // sent when close enough to male/female
  88. integer LINK_CALL_MALE_INFO = 968; // sent by xs_breeding, this line of code was in error in v.24 of xs_breeding see line 557 and 636 of xs_brain which make calls and also xs_breeding which receives LINK_MALE_INFO.
  89. integer LINK_MALE_INFO = 969;
  90. integer LINK_LAY_EGG = 970; // llRezObject("XS Egg"
  91. integer LINK_BREED_FAIL = 971; // key = father, failed, timed out
  92. integer LINK_PREGNANT = 972; // chick is preggers
  93. integer LINK_SOUND_ON= 973; // sound is on
  94. integer LINK_SOUND_OFF= 974; // sound is off
  95. integer LINK_SLEEPING = 990; // close eyes
  96. integer LINK_UNSLEEPING = 991; // open eyes
  97. integer LINK_SOUND = 1001; // plays a sound if enabled
  98. integer LINK_SPECIAL = 1010; // xs_special, is str = "Normal", removes script
  99. integer LINK_PREGNANCY_TIME = 5000; // in seconds as str
  100. integer LINK_SLEEP = 7999; // disable sleep by parameter
  101. integer LINK_TIMER = 8000; // scan for food bowl about every 1800 seconds
  102. integer LINK_DIE = 9999; // death
  103. ///////// end global Link constants ////////
  104. ///////////// END OF COPIED CODE ////////////
  105. /////// DON'T CHANGE THE FOLLOWING! (Unless you know what you are doing!)
  106. integer XTEA_DELTA = 0x9E3779B9; // (sqrt(5) - 1) * 2^31
  107. integer xtea_num_rounds = 6;
  108. list xtea_key = [0, 0, 0, 0];
  109. integer hex2int(string hex) {
  110. if(llGetSubString(hex,0,1) == "0x")
  111. return (integer)hex;
  112. if(llGetSubString(hex,0,0) == "x")
  113. return (integer)("0"+hex);
  114. return(integer)("0x"+hex);
  115. }
  116. // Convers any string to a 32 char MD5 string and then to a list of
  117. // 4 * 32 bit integers = 128 bit Key. MD5 ensures always a specific
  118. // 128 bit key is generated for any string passed.
  119. list xtea_key_from_string( string str )
  120. {
  121. str = llMD5String(str,0); // Use Nonce = 0
  122. return [ hex2int(llGetSubString( str, 0, 7)),
  123. hex2int(llGetSubString( str, 8, 15)),
  124. hex2int(llGetSubString( str, 16, 23)),
  125. hex2int(llGetSubString( str, 24, 31))];
  126. }
  127. // Encipher two integers and return the result as a 12-byte string
  128. // containing two base64-encoded integers.
  129. string xtea_encipher( integer v0, integer v1 )
  130. {
  131. integer num_rounds = xtea_num_rounds;
  132. integer sum = 0;
  133. do {
  134. // LSL does not have unsigned integers, so when shifting right we
  135. // have to mask out sign-extension bits.
  136. v0 += (((v1 << 4) ^ ((v1 >> 5) & 0x07FFFFFF)) + v1) ^ (sum + llList2Integer(xtea_key, sum & 3));
  137. sum += XTEA_DELTA;
  138. v1 += (((v0 << 4) ^ ((v0 >> 5) & 0x07FFFFFF)) + v0) ^ (sum + llList2Integer(xtea_key, (sum >> 11) & 3));
  139. } while( num_rounds = ~-num_rounds );
  140. //return only first 6 chars to remove "=="'s and compact encrypted text.
  141. return llGetSubString(llIntegerToBase64(v0),0,5) +
  142. llGetSubString(llIntegerToBase64(v1),0,5);
  143. }
  144. // Decipher two base64-encoded integers and return the FIRST 30 BITS of
  145. // each as one 10-byte base64-encoded string.
  146. string xtea_decipher( integer v0, integer v1 )
  147. {
  148. integer num_rounds = xtea_num_rounds;
  149. integer sum = XTEA_DELTA*xtea_num_rounds;
  150. do {
  151. // LSL does not have unsigned integers, so when shifting right we
  152. // have to mask out sign-extension bits.
  153. v1 -= (((v0 << 4) ^ ((v0 >> 5) & 0x07FFFFFF)) + v0) ^ (sum + llList2Integer(xtea_key, (sum>>11) & 3));
  154. sum -= XTEA_DELTA;
  155. v0 -= (((v1 << 4) ^ ((v1 >> 5) & 0x07FFFFFF)) + v1) ^ (sum + llList2Integer(xtea_key, sum & 3));
  156. } while ( num_rounds = ~-num_rounds );
  157. return llGetSubString(llIntegerToBase64(v0), 0, 4) +
  158. llGetSubString(llIntegerToBase64(v1), 0, 4);
  159. }
  160. // Encrypt a full string using XTEA.
  161. string xtea_encrypt_string( string str )
  162. {
  163. if (! ENCRYPT)
  164. return str;
  165. // encode string
  166. str = llStringToBase64(str);
  167. // remove trailing =s so we can do our own 0 padding
  168. integer i = llSubStringIndex( str, "=" );
  169. if ( i != -1 )
  170. str = llDeleteSubString( str, i, -1 );
  171. // we don't want to process padding, so get length before adding it
  172. integer len = llStringLength(str);
  173. // zero pad
  174. str += "AAAAAAAAAA=";
  175. string result;
  176. i = 0;
  177. do {
  178. // encipher 30 (5*6) bits at a time.
  179. result += xtea_encipher(llBase64ToInteger(llGetSubString(str, i, i + 4) + "A="), llBase64ToInteger(llGetSubString(str, i+5, i + 9) + "A="));
  180. i+=10;
  181. } while ( i < len );
  182. return result;
  183. }
  184. // Decrypt a full string using XTEA
  185. string xtea_decrypt_string( string str ) {
  186. if (! ENCRYPT)
  187. return str;
  188. integer len = llStringLength(str);
  189. integer i=0;
  190. string result;
  191. //llOwnerSay(str);
  192. do {
  193. integer v0;
  194. integer v1;
  195. v0 = llBase64ToInteger(llGetSubString(str, i, i + 5) + "==");
  196. i+= 6;
  197. v1 = llBase64ToInteger(llGetSubString(str, i, i + 5) + "==");
  198. i+= 6;
  199. result += xtea_decipher(v0, v1);
  200. } while ( i < len );
  201. // Replace multiple trailing zeroes with a single one
  202. i = llStringLength(result) - 1;
  203. while ( llGetSubString(result, i - 1, i) == "AA" ){
  204. result = llDeleteSubString(result, i, i);
  205. i--;
  206. }
  207. i = llStringLength(result) - 1;
  208. // while (llGetSubString(result, i, i + 1) == "A" ) {
  209. // i--;
  210. // }
  211. result = llGetSubString(result, 0, i+1);
  212. i = llStringLength(result);
  213. integer mod = i%4; //Depending on encoded length diffrent appends are needed
  214. if(mod == 1) result += "A==";
  215. else if(mod == 2 ) result += "==";
  216. else if(mod == 3) result += "=";
  217. return llBase64ToString(result);
  218. }
  219. string base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  220. //tunables
  221. integer world = TRUE;
  222. talkback()
  223. {
  224. vector pos = llGetPos();
  225. vector size = llGetScale();
  226. llShout(ANIMAL_CHANNEL, xtea_encrypt_string("XSPET^HOME_LOCATION^" + (string)pos + "^" + (string) size.x ) );
  227. }
  228. default
  229. {
  230. state_entry()
  231. {
  232. xtea_key = xtea_key_from_string(SECRET_PASSWORD);
  233. llListen(HOME_CHANNEL, "", "", "XSPET_PING_HOME"); // listen for a pet to say XSPET_PING_HOME - Mod by Ferd to listen to HOME_CHANNEL, not -237918
  234. }
  235. touch_start(integer total_number)
  236. {
  237. if (llDetectedKey(0) == llGetOwner()) {
  238. talkback();
  239. llOwnerSay("Setting Home Location");
  240. }
  241. }
  242. listen(integer channel, string name, key id, string msg)
  243. {
  244. talkback();
  245. }
  246. }