xs_home.lsl 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. // :CATEGORY:XS Pet
  2. // :NAME:XS Pet Quail Modified
  3. // :AUTHOR:Xundra Snowpaw, Ferd Frederix
  4. // :CREATED:2013-09-06
  5. // :EDITED:2013-09-18 15:39:10
  6. // :ID:987
  7. // :NUM:1428
  8. // :REV:1
  9. // :WORLD:Second Life, Opensim
  10. // :DESCRIPTION:
  11. // Modified Pet Quail
  12. // :CODE:
  13. // Version .24 10-3-2011
  14. // script by Xundra Snowpaw
  15. // mods by Ferd Frederix
  16. //
  17. // New BSD License: http://www.opensource.org/licenses/bsd-license.php
  18. // Copyright (c) 2010, Xundra Snowpaw
  19. // All rights reserved.
  20. //
  21. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  22. //* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  23. //* 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.
  24. // 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.
  25. ////////////////////////////////////////////////////////////////////
  26. // revisions:
  27. // 10-3-2011 Mod by Ferd to listen to HOME_CHANNEL, not -237918, the original src has no other reference to that channel.
  28. // change these in all scripts to match
  29. string SECRET_PASSWORD = "top secret";
  30. integer ANIMAL_CHANNEL = -999192;
  31. integer HOME_CHANNEL = -999194;
  32. // DON'T CHANGE THE FOLLOWING! (Unless you know what you are doing!)
  33. integer XTEA_DELTA = 0x9E3779B9; // (sqrt(5) - 1) * 2^31
  34. integer xtea_num_rounds = 6;
  35. list xtea_key = [0, 0, 0, 0];
  36. integer hex2int(string hex) {
  37. if(llGetSubString(hex,0,1) == "0x")
  38. return (integer)hex;
  39. if(llGetSubString(hex,0,0) == "x")
  40. return (integer)("0"+hex);
  41. return(integer)("0x"+hex);
  42. }
  43. // Convers any string to a 32 char MD5 string and then to a list of
  44. // 4 * 32 bit integers = 128 bit Key. MD5 ensures always a specific
  45. // 128 bit key is generated for any string passed.
  46. list xtea_key_from_string( string str )
  47. {
  48. str = llMD5String(str,0); // Use Nonce = 0
  49. return [ hex2int(llGetSubString( str, 0, 7)),
  50. hex2int(llGetSubString( str, 8, 15)),
  51. hex2int(llGetSubString( str, 16, 23)),
  52. hex2int(llGetSubString( str, 24, 31))];
  53. }
  54. // Encipher two integers and return the result as a 12-byte string
  55. // containing two base64-encoded integers.
  56. string xtea_encipher( integer v0, integer v1 )
  57. {
  58. integer num_rounds = xtea_num_rounds;
  59. integer sum = 0;
  60. do {
  61. // LSL does not have unsigned integers, so when shifting right we
  62. // have to mask out sign-extension bits.
  63. v0 += (((v1 << 4) ^ ((v1 >> 5) & 0x07FFFFFF)) + v1) ^ (sum + llList2Integer(xtea_key, sum & 3));
  64. sum += XTEA_DELTA;
  65. v1 += (((v0 << 4) ^ ((v0 >> 5) & 0x07FFFFFF)) + v0) ^ (sum + llList2Integer(xtea_key, (sum >> 11) & 3));
  66. } while( num_rounds = ~-num_rounds );
  67. //return only first 6 chars to remove "=="'s and compact encrypted text.
  68. return llGetSubString(llIntegerToBase64(v0),0,5) +
  69. llGetSubString(llIntegerToBase64(v1),0,5);
  70. }
  71. // Decipher two base64-encoded integers and return the FIRST 30 BITS of
  72. // each as one 10-byte base64-encoded string.
  73. string xtea_decipher( integer v0, integer v1 )
  74. {
  75. integer num_rounds = xtea_num_rounds;
  76. integer sum = XTEA_DELTA*xtea_num_rounds;
  77. do {
  78. // LSL does not have unsigned integers, so when shifting right we
  79. // have to mask out sign-extension bits.
  80. v1 -= (((v0 << 4) ^ ((v0 >> 5) & 0x07FFFFFF)) + v0) ^ (sum + llList2Integer(xtea_key, (sum>>11) & 3));
  81. sum -= XTEA_DELTA;
  82. v0 -= (((v1 << 4) ^ ((v1 >> 5) & 0x07FFFFFF)) + v1) ^ (sum + llList2Integer(xtea_key, sum & 3));
  83. } while ( num_rounds = ~-num_rounds );
  84. return llGetSubString(llIntegerToBase64(v0), 0, 4) +
  85. llGetSubString(llIntegerToBase64(v1), 0, 4);
  86. }
  87. // Encrypt a full string using XTEA.
  88. string xtea_encrypt_string( string str )
  89. {
  90. // encode string
  91. str = llStringToBase64(str);
  92. // remove trailing =s so we can do our own 0 padding
  93. integer i = llSubStringIndex( str, "=" );
  94. if ( i != -1 )
  95. str = llDeleteSubString( str, i, -1 );
  96. // we don't want to process padding, so get length before adding it
  97. integer len = llStringLength(str);
  98. // zero pad
  99. str += "AAAAAAAAAA=";
  100. string result;
  101. i = 0;
  102. do {
  103. // encipher 30 (5*6) bits at a time.
  104. result += xtea_encipher(llBase64ToInteger(llGetSubString(str, i, i + 4) + "A="), llBase64ToInteger(llGetSubString(str, i+5, i + 9) + "A="));
  105. i+=10;
  106. } while ( i < len );
  107. return result;
  108. }
  109. // Decrypt a full string using XTEA
  110. string xtea_decrypt_string( string str ) {
  111. integer len = llStringLength(str);
  112. integer i=0;
  113. string result;
  114. //llOwnerSay(str);
  115. do {
  116. integer v0;
  117. integer v1;
  118. v0 = llBase64ToInteger(llGetSubString(str, i, i + 5) + "==");
  119. i+= 6;
  120. v1 = llBase64ToInteger(llGetSubString(str, i, i + 5) + "==");
  121. i+= 6;
  122. result += xtea_decipher(v0, v1);
  123. } while ( i < len );
  124. // Replace multiple trailing zeroes with a single one
  125. i = llStringLength(result) - 1;
  126. while ( llGetSubString(result, i - 1, i) == "AA" ){
  127. result = llDeleteSubString(result, i, i);
  128. i--;
  129. }
  130. i = llStringLength(result) - 1;
  131. // while (llGetSubString(result, i, i + 1) == "A" ) {
  132. // i--;
  133. // }
  134. result = llGetSubString(result, 0, i+1);
  135. i = llStringLength(result);
  136. integer mod = i%4; //Depending on encoded length diffrent appends are needed
  137. if(mod == 1) result += "A==";
  138. else if(mod == 2 ) result += "==";
  139. else if(mod == 3) result += "=";
  140. return llBase64ToString(result);
  141. }
  142. string base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  143. default
  144. {
  145. state_entry()
  146. {
  147. xtea_key = xtea_key_from_string(SECRET_PASSWORD);
  148. 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
  149. }
  150. touch_start(integer total_number)
  151. {
  152. if (llDetectedKey(0) == llGetOwner()) {
  153. vector size = llGetScale();
  154. vector pos = llGetPos();
  155. pos.z = pos.z - size.z / 2;
  156. llSay(ANIMAL_CHANNEL, xtea_encrypt_string("XSPET^HOME_LOCATION^" + (string)pos + "^" + llGetObjectDesc()));
  157. }
  158. llOwnerSay("Setting Home Location");
  159. }
  160. listen(integer channel, string name, key id, string msg)
  161. {
  162. vector size = llGetScale();
  163. vector pos = llGetPos();
  164. pos.z = pos.z - size.z / 2;
  165. llSay(ANIMAL_CHANNEL, xtea_encrypt_string("XSPET^HOME_LOCATION^" + (string)pos + "^" + llGetObjectDesc()));
  166. }
  167. }