sloodle_mod_enrolbooth-1.0.lslp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Sloodle Registration Booth (for Sloodle 1.0)
  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. // Paul Preibisch
  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. vector RED = <0.77278,0.04391,0.00000>;//RED
  46. vector ORANGE = <0.87130,0.41303,0.00000>;//orange
  47. vector YELLOW = <0.82192,0.86066,0.00000>;//YELLOW
  48. vector GREEN = <0.12616,0.77712,0.00000>;//GREEN
  49. vector BLUE = <0.00000,0.05804,0.98688>;//BLUE
  50. vector PINK = <0.83635,0.00000,0.88019>;//INDIGO
  51. vector PURPLE = <0.39257,0.00000,0.71612>;//PURPLE
  52. vector WHITE = <1.000,1.000,1.000>;//WHITE
  53. vector BLACK = <0.000,0.000,0.000>;//BLACK
  54. ///// ----------- /////
  55. ///// FUNCTIONS /////
  56. integer SETTEXT_CHANNEL= 981000; //channel used for hover text
  57. sloodle_debug(string msg)
  58. {
  59. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  60. }
  61. // Configure by receiving a linked message from another script in the object
  62. // Returns TRUE if the object has all the data it needs
  63. integer sloodle_handle_command(string str)
  64. {
  65. list bits = llParseString2List(str,["|"],[]);
  66. integer numbits = llGetListLength(bits);
  67. string name = llList2String(bits,0);
  68. string value1 = "";
  69. string value2 = "";
  70. if (numbits > 1) value1 = llList2String(bits,1);
  71. if (numbits > 2) value2 = llList2String(bits,2);
  72. if (name=="set:sloodlecoursename_full") {
  73. llMessageLinked(LINK_SET, SETTEXT_CHANNEL,"TEXT::"+value1+"|COLOR::"+(string)PINK+"|BLINK::"+(string)FALSE+"|TIMER::0", NULL_KEY);
  74. }
  75. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  76. else if (name == "set:sloodlepwd") {
  77. // The password may be a single prim password, or a UUID and a password
  78. if (value2 != "") sloodlepwd = value1 + "|" + value2;
  79. else sloodlepwd = value1;
  80. } else if (name == "set:sloodlecontrollerid") sloodlecontrollerid = (integer)value1;
  81. else if (name == "set:sloodleobjectaccessleveluse") sloodleobjectaccessleveluse = (integer)value1;
  82. else if (name == SLOODLE_EOF) eof = TRUE;
  83. return (sloodleserverroot != "" && sloodlepwd != "" && sloodlecontrollerid > 0);
  84. }
  85. // Checks if the given agent is permitted to user this object
  86. // Returns TRUE if so, or FALSE if not
  87. integer sloodle_check_access_use(key id)
  88. {
  89. // Check the access mode
  90. if (sloodleobjectaccessleveluse == SLOODLE_OBJECT_ACCESS_LEVEL_GROUP) {
  91. return llSameGroup(id);
  92. } else if (sloodleobjectaccessleveluse == SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC) {
  93. return TRUE;
  94. }
  95. // Assume it's owner mode
  96. return (id == llGetOwner());
  97. }
  98. ///// STATES /////
  99. // Default state - waiting for configuration
  100. default
  101. {
  102. state_entry()
  103. {
  104. // Starting again with a new configuration
  105. isconfigured = FALSE;
  106. eof = FALSE;
  107. // Reset our data
  108. sloodleserverroot = "";
  109. sloodlepwd = "";
  110. sloodlecontrollerid = 0;
  111. sloodleobjectaccessleveluse = 0;
  112. }
  113. link_message( integer sender_num, integer num, string str, key id)
  114. {
  115. // Check the channel
  116. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  117. // Split the message into lines
  118. list lines = llParseString2List(str, ["\n"], []);
  119. integer numlines = llGetListLength(lines);
  120. integer i = 0;
  121. for (i=0; i < numlines; i++) {
  122. isconfigured = sloodle_handle_command(llList2String(lines, i));
  123. }
  124. // If we've got all our data AND reached the end of the configuration data, then move on
  125. if (eof == TRUE) {
  126. if (isconfigured == TRUE) {
  127. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");
  128. state ready;
  129. } else {
  130. // Got all configuration but, it's not complete... request reconfiguration
  131. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [], NULL_KEY, "");
  132. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  133. eof = FALSE;
  134. }
  135. }
  136. }
  137. }
  138. touch_start(integer num_detected)
  139. {
  140. // Attempt to request a reconfiguration
  141. if (llDetectedKey(0) == llGetOwner()) {
  142. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:requestconfig", NULL_KEY);
  143. }
  144. }
  145. }
  146. state ready
  147. {
  148. state_entry()
  149. {
  150. llSetText("",RED,1);
  151. }
  152. on_rez( integer param)
  153. {
  154. state default;
  155. }
  156. touch_start( integer total_number)
  157. {
  158. // Go through each toucher
  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. // Check if this user can use the device
  165. if (sloodle_check_access_use(id)) {
  166. // Was it the panel that was touched?
  167. touched = llGetLinkName(llDetectedLinkNumber(i));
  168. if (touched == "panel") llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:regenrol|" + sloodleserverroot + "|" + (string)sloodlecontrollerid + "|" + sloodlepwd, id);
  169. } else {
  170. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "nopermission:use", [llKey2Name(id)], NULL_KEY, "");
  171. }
  172. }
  173. }
  174. }
  175. // Please leave the following line intact to show where the script lives in Git:
  176. // SLOODLE LSL Script Git Location: mod/enrolbooth-1.0/objects/default/assets/sloodle_mod_enrolbooth-1.0.lslp