sloodle_mod_accesschecker-1.0.lslp 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Access Checker (for Sloodle 0.3)
  4. // Detects users colliding, and makes sure they are registered/enrolled.
  5. //
  6. // Copyright (c) 2007-8 Sloodle
  7. // Released under the GNU GPL
  8. //
  9. // Contributors:
  10. // Edmund Edgar
  11. // Peter R. Bloomfield
  12. //
  13. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  14. string SLOODLE_EOF = "sloodleeof";
  15. string SLOODLE_OBJECT_TYPE = "regbooth-1.0";
  16. integer SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC = 0;
  17. integer SLOODLE_OBJECT_ACCESS_LEVEL_OWNER = 1;
  18. integer SLOODLE_OBJECT_ACCESS_LEVEL_GROUP = 2;
  19. string sloodleserverroot = "";
  20. string sloodlepwd = "";
  21. integer sloodlecontrollerid = 0;
  22. integer sloodleobjectaccessleveluse = 0; // Who can use this object?
  23. integer isconfigured = FALSE; // Do we have all the configuration data we need?
  24. integer eof = FALSE; // Have we reached the end of the configuration data?
  25. list authorised = []; // A list of authorised individuals whom we can ignore
  26. float TIME_PURGE_AUTH = 3600.0; // How often to purge the list of authorised users (to avoid memory overflow)
  27. ///// TRANSLATION /////
  28. // Link message channels
  29. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  30. integer SLOODLE_CHANNEL_TRANSLATION_RESPONSE = -1928374652;
  31. // Translation output methods
  32. string SLOODLE_TRANSLATE_LINK = "link"; // No output parameters - simply returns the translation on SLOODLE_TRANSLATION_RESPONSE link message channel
  33. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  34. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  35. string SLOODLE_TRANSLATE_SHOUT = "shout"; // 1 output parameter: chat channel number
  36. string SLOODLE_TRANSLATE_REGION_SAY = "regionsay"; // 1 output parameter: chat channel number
  37. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  38. string SLOODLE_TRANSLATE_DIALOG = "dialog"; // Recipient avatar should be identified in link message keyval. At least 2 output parameters: first the channel number for the dialog, and then 1 to 12 button label strings.
  39. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  40. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  41. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  42. // Send a translation request link message
  43. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  44. {
  45. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  46. }
  47. ///// ----------- /////
  48. ///// FUNCTIONS /////
  49. sloodle_debug(string msg)
  50. {
  51. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  52. }
  53. // Configure by receiving a linked message from another script in the object
  54. // Returns TRUE if the object has all the data it needs
  55. integer sloodle_handle_command(string str)
  56. {
  57. list bits = llParseString2List(str,["|"],[]);
  58. integer numbits = llGetListLength(bits);
  59. string name = llList2String(bits,0);
  60. string value1 = "";
  61. string value2 = "";
  62. if (numbits > 1) value1 = llList2String(bits,1);
  63. if (numbits > 2) value2 = llList2String(bits,2);
  64. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  65. else if (name == "set:sloodlepwd") {
  66. // The password may be a single prim password, or a UUID and a password
  67. if (value2 != "") sloodlepwd = value1 + "|" + value2;
  68. else sloodlepwd = value1;
  69. } else if (name == "set:sloodlecontrollerid") sloodlecontrollerid = (integer)value1;
  70. else if (name == "set:sloodleobjectaccessleveluse") sloodleobjectaccessleveluse = (integer)value1;
  71. else if (name == SLOODLE_EOF) eof = TRUE;
  72. return (sloodleserverroot != "" && sloodlepwd != "" && sloodlecontrollerid > 0);
  73. }
  74. // Checks if the given agent is permitted to user this object
  75. // Returns TRUE if so, or FALSE if not
  76. integer sloodle_check_access_use(key id)
  77. {
  78. // Check the access mode
  79. if (sloodleobjectaccessleveluse == SLOODLE_OBJECT_ACCESS_LEVEL_GROUP) {
  80. return llSameGroup(id);
  81. } else if (sloodleobjectaccessleveluse == SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC) {
  82. return TRUE;
  83. }
  84. // Assume it's owner mode
  85. return (id == llGetOwner());
  86. }
  87. ///// STATES /////
  88. // Default state - waiting for configuration
  89. default
  90. {
  91. state_entry()
  92. {
  93. // Starting again with a new configuration
  94. isconfigured = FALSE;
  95. eof = FALSE;
  96. // Reset our data
  97. sloodleserverroot = "";
  98. sloodlepwd = "";
  99. sloodlecontrollerid = 0;
  100. sloodleobjectaccessleveluse = 0;
  101. // Detect collisions
  102. llVolumeDetect(TRUE);
  103. }
  104. link_message( integer sender_num, integer num, string str, key id)
  105. {
  106. // Check the channel
  107. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  108. // Split the message into lines
  109. list lines = llParseString2List(str, ["\n"], []);
  110. integer numlines = llGetListLength(lines);
  111. integer i = 0;
  112. for (i = 0; i < numlines; i++) {
  113. isconfigured = sloodle_handle_command(llList2String(lines, i));
  114. }
  115. // If we've got all our data AND reached the end of the configuration data, then move on
  116. if (eof == TRUE) {
  117. if (isconfigured == TRUE) {
  118. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");
  119. state ready;
  120. } else {
  121. // Got all configuration but, it's not complete... request reconfiguration
  122. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [], NULL_KEY, "");
  123. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  124. eof = FALSE;
  125. }
  126. }
  127. }
  128. }
  129. touch_start(integer num_detected)
  130. {
  131. // Attempt to request a reconfiguration
  132. if (llDetectedKey(0) == llGetOwner()) {
  133. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:requestconfig", NULL_KEY);
  134. }
  135. }
  136. }
  137. state ready
  138. {
  139. on_rez( integer param)
  140. {
  141. state default;
  142. }
  143. state_entry()
  144. {
  145. // Reset our list of authorised users, and set a purge timer running
  146. authorised = [];
  147. llSetTimerEvent(0.0);
  148. llSetTimerEvent(TIME_PURGE_AUTH);
  149. // Detect collisions
  150. llVolumeDetect(TRUE);
  151. }
  152. timer()
  153. {
  154. authorised = [];
  155. }
  156. collision_start(integer total_number)
  157. {
  158. // Go through each collider
  159. integer i = 0;
  160. key id = NULL_KEY;
  161. string touched = "";
  162. for (i=0; i < total_number; i++) {
  163. id = llDetectedKey(i);
  164. // Only process avatars
  165. if (id == llGetOwnerKey(id)) {
  166. // Is the user already authorised?
  167. if (llListFindList(authorised, [id]) >= 0) {
  168. // Let them through
  169. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "accessgranted", [llKey2Name(id)], NULL_KEY, "regenrol");
  170. } else {
  171. // Not authorised - check if this user can use the device
  172. if (sloodle_check_access_use(id)) {
  173. // Attempt to register/enrol the user
  174. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:regenrol|" + sloodleserverroot + "|" + (string)sloodlecontrollerid + "|" + sloodlepwd, id);
  175. } else {
  176. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "nopermission:use", [llKey2Name(id)], NULL_KEY, "");
  177. }
  178. }
  179. }
  180. }
  181. }
  182. link_message(integer sender_num, integer num, string sval, key kval)
  183. {
  184. // Check the channel
  185. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  186. // Check the message
  187. if (sval == "confirm:enrol") {
  188. // Avatar is registered and enrolled. Add them to the authorised list.
  189. if (kval != NULL_KEY && llListFindList(authorised, [kval]) < 0) {
  190. authorised += [kval];
  191. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "accessgranted", [llKey2Name(kval)], NULL_KEY, "regenrol");
  192. }
  193. }
  194. }
  195. }
  196. }
  197. // Please leave the following line intact to show where the script lives in Git:
  198. // SLOODLE LSL Script Git Location: mod/accesschecker-1.0/objects/default/assets/sloodle_mod_accesschecker-1.0.lslp