sloodle_mod_regenrolbooth-1.0.lslp 7.5 KB

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