sloodle_mod_regbooth-1.0.lslp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Sloodle Registration Booth (for Sloodle 0.3)
  4. // Allows users to touch a panel to do manual registration of their avatar.
  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. ///// TRANSLATION /////
  26. // Link message channels
  27. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  28. integer SLOODLE_CHANNEL_TRANSLATION_RESPONSE = -1928374652;
  29. // Translation output methods
  30. string SLOODLE_TRANSLATE_LINK = "link"; // No output parameters - simply returns the translation on SLOODLE_TRANSLATION_RESPONSE link message channel
  31. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  32. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  33. string SLOODLE_TRANSLATE_SHOUT = "shout"; // 1 output parameter: chat channel number
  34. string SLOODLE_TRANSLATE_REGION_SAY = "regionsay"; // 1 output parameter: chat channel number
  35. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  36. 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.
  37. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  38. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  39. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  40. // Send a translation request link message
  41. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  42. {
  43. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  44. }
  45. ///// ----------- /////
  46. ///// FUNCTIONS /////
  47. sloodle_debug(string msg)
  48. {
  49. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  50. }
  51. // Configure by receiving a linked message from another script in the object
  52. // Returns TRUE if the object has all the data it needs
  53. integer sloodle_handle_command(string str)
  54. {
  55. list bits = llParseString2List(str,["|"],[]);
  56. integer numbits = llGetListLength(bits);
  57. string name = llList2String(bits,0);
  58. string value1 = "";
  59. string value2 = "";
  60. if (numbits > 1) value1 = llList2String(bits,1);
  61. if (numbits > 2) value2 = llList2String(bits,2);
  62. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  63. else if (name == "set:sloodlepwd") {
  64. // The password may be a single prim password, or a UUID and a password
  65. if (value2 != "") sloodlepwd = value1 + "|" + value2;
  66. else sloodlepwd = value1;
  67. } else if (name == "set:sloodlecontrollerid") sloodlecontrollerid = (integer)value1;
  68. else if (name == "set:sloodleobjectaccessleveluse") sloodleobjectaccessleveluse = (integer)value1;
  69. else if (name == SLOODLE_EOF) eof = TRUE;
  70. return (sloodleserverroot != "" && sloodlepwd != "" && sloodlecontrollerid > 0);
  71. }
  72. // Checks if the given agent is permitted to user this object
  73. // Returns TRUE if so, or FALSE if not
  74. integer sloodle_check_access_use(key id)
  75. {
  76. // Check the access mode
  77. if (sloodleobjectaccessleveluse == SLOODLE_OBJECT_ACCESS_LEVEL_GROUP) {
  78. return llSameGroup(id);
  79. } else if (sloodleobjectaccessleveluse == SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC) {
  80. return TRUE;
  81. }
  82. // Assume it's owner mode
  83. return (id == llGetOwner());
  84. }
  85. ///// STATES /////
  86. // Default state - waiting for configuration
  87. default
  88. {
  89. state_entry()
  90. {
  91. // Starting again with a new configuration
  92. isconfigured = FALSE;
  93. eof = FALSE;
  94. // Reset our data
  95. sloodleserverroot = "";
  96. sloodlepwd = "";
  97. sloodlecontrollerid = 0;
  98. sloodleobjectaccessleveluse = 0;
  99. }
  100. link_message( integer sender_num, integer num, string str, key id)
  101. {
  102. // Check the channel
  103. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  104. // Split the message into lines
  105. list lines = llParseString2List(str, ["\n"], []);
  106. integer numlines = llGetListLength(lines);
  107. integer i = 0;
  108. for (i=0; i < numlines; i++) {
  109. isconfigured = sloodle_handle_command(llList2String(lines, i));
  110. }
  111. // If we've got all our data AND reached the end of the configuration data, then move on
  112. if (eof == TRUE) {
  113. if (isconfigured == TRUE) {
  114. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");
  115. state ready;
  116. } else {
  117. // Got all configuration but, it's not complete... request reconfiguration
  118. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [], NULL_KEY, "");
  119. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  120. eof = FALSE;
  121. }
  122. }
  123. }
  124. }
  125. touch_start(integer num_detected)
  126. {
  127. // Attempt to request a reconfiguration
  128. if (llDetectedKey(0) == llGetOwner()) {
  129. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:requestconfig", NULL_KEY);
  130. }
  131. }
  132. }
  133. state ready
  134. {
  135. on_rez( integer param)
  136. {
  137. state default;
  138. }
  139. touch_start( integer total_number)
  140. {
  141. // Go through each toucher
  142. integer i;
  143. key id = NULL_KEY;
  144. string touched = "";
  145. for (i=0; i < total_number; i++) {
  146. id = llDetectedKey(i);
  147. // Check if this user can use the device
  148. if (sloodle_check_access_use(id)) {
  149. // Was it the panel that was touched?
  150. touched = llGetLinkName(llDetectedLinkNumber(i));
  151. if (touched == "panel") llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reg|" + sloodleserverroot + "|" + (string)sloodlecontrollerid + "|" + sloodlepwd, id);
  152. } else {
  153. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "nopermission:use", [llKey2Name(id)], NULL_KEY, "");
  154. }
  155. }
  156. }
  157. }
  158. // Please leave the following line intact to show where the script lives in Git:
  159. // SLOODLE LSL Script Git Location: mod/regbooth-1.0/objects/default/assets/sloodle_mod_regbooth-1.0.lslp