f23e2ae0-711e-5e32-dd5a-991f4e4d6ad8_script.lsl 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Manual avatar registration and enrolment script.
  4. // Will initiate manual (URL-based) avatar registration/enrolment in
  5. // response to link messages.
  6. //
  7. // Part of the Sloodle project (www.sloodle.org).
  8. // Copyright (c) 2008 Sloodle
  9. // Released under the GNU GPL v3
  10. //
  11. // Contributors:
  12. // Peter R. Bloomfield
  13. //
  14. // Can be supplied with 3 link messages for registration only, enrolment only, or both.
  15. // The avatar in question should be identified in the key value for all 3.
  16. // The string value should take on one of the following formats:
  17. //
  18. // <cmd>|<sloodleserverroot>|<sloodlecontrollerid>|<prim_pwd>
  19. // <cmd>|<sloodleserverroot>|<sloodlecontrollerid>|<uuid>|<pwd>
  20. //
  21. // The <cmd> value should be one of the following:
  22. //
  23. // do:reg = registration
  24. // do:enrol = enrolment
  25. // do:regenrol = registration & enrolment
  26. //
  27. ///// DATA /////
  28. integer SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST=-1828374651; // this channel is used to send status codes for translation to the error_messages lsl script
  29. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  30. integer SLOODLE_CHANNEL_AVATAR_DIALOG = 1001;
  31. string SLOODLE_REG_LINKER = "/mod/sloodle/login/regenrol_linker.php";
  32. string SLOODLE_EOF = "sloodleeof";
  33. list httpreqs = []; // Alternating list of HTTP request keys, and their corresponding avatar keys
  34. ///// TRANSLATION /////
  35. // Link message channels
  36. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  37. integer SLOODLE_CHANNEL_TRANSLATION_RESPONSE = -1928374652;
  38. // Translation output methods
  39. string SLOODLE_TRANSLATE_LINK = "link"; // No output parameters - simply returns the translation on SLOODLE_TRANSLATION_RESPONSE link message channel
  40. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  41. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  42. string SLOODLE_TRANSLATE_SHOUT = "shout"; // 1 output parameter: chat channel number
  43. string SLOODLE_TRANSLATE_REGION_SAY = "regionsay"; // 1 output parameter: chat channel number
  44. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  45. 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.
  46. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  47. string SLOODLE_TRANSLATE_LOAD_URL_PARALLEL = "loadurlpar"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  48. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  49. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  50. // Send a translation request link message
  51. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  52. {
  53. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  54. }
  55. ///// ----------- /////
  56. ///// FUNCTIONS /////
  57. /******************************************************************************************************************************
  58. * sloodle_error_code -
  59. * Author: Paul Preibisch
  60. * Description - This function sends a linked message on the SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST channel
  61. * The error_messages script hears this, translates the status code and sends an instant message to the avuuid
  62. * Params: method - SLOODLE_TRANSLATE_SAY, SLOODLE_TRANSLATE_IM etc
  63. * Params: avuuid - this is the avatar UUID to that an instant message with the translated error code will be sent to
  64. * Params: status code - the status code of the error as on our wiki: http://slisweb.sjsu.edu/sl/index.php/Sloodle_status_codes
  65. *******************************************************************************************************************************/
  66. sloodle_error_code(string method, key avuuid,integer statuscode){
  67. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST, method+"|"+(string)avuuid+"|"+(string)statuscode, NULL_KEY);
  68. }
  69. // Send debug info
  70. sloodle_debug(string msg)
  71. {
  72. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  73. }
  74. ///// STATES /////
  75. // Only a single state... no configuration needed
  76. default
  77. {
  78. state_entry()
  79. {
  80. }
  81. link_message(integer sender_num, integer num, string sval, key kval)
  82. {
  83. // Check which channel this message arrived on
  84. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  85. // Make sure we have a key value for an avatar
  86. if (kval == NULL_KEY || kval != llGetOwnerKey(kval)) return;
  87. // Parse the message into fields
  88. list fields = llParseStringKeepNulls(sval, ["|"], []);
  89. integer numfields = llGetListLength(fields);
  90. if (numfields < 4) return;
  91. // Make sure it's an expected command
  92. string cmd = llList2String(fields, 0);
  93. if (cmd != "do:reg" && cmd != "do:enrol" && cmd != "do:regenrol") return;
  94. // Extract the mode from the command
  95. string sloodlemode = llGetSubString(cmd, 3, -1);
  96. // Get all the other fields
  97. string sloodleserverroot = llList2String(fields, 1);
  98. integer sloodlecontrollerid = (integer)llList2String(fields, 2);
  99. string sloodlepwd = llList2String(fields, 3);
  100. // If there is an additional field, then it was an object-specific password
  101. if (numfields > 4) {
  102. sloodlepwd += "|" + llList2String(fields, 4);
  103. }
  104. // Notify the user
  105. sloodle_translation_request(SLOODLE_TRANSLATE_IM, [], "attempting" + sloodlemode, [], kval, "regenrol");
  106. // Send the request
  107. string body = "sloodlecontrollerid=" + (string)sloodlecontrollerid;
  108. body += "&sloodlepwd=" + sloodlepwd;
  109. body += "&sloodleuuid=" + (string)kval;
  110. body += "&sloodleavname=" + llKey2Name(kval);
  111. body += "&sloodlemode=" + sloodlemode;
  112. key newhttp = llHTTPRequest(sloodleserverroot + SLOODLE_REG_LINKER, [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], body);
  113. httpreqs += [newhttp, kval];
  114. }
  115. }
  116. http_response(key id, integer status, list meta, string body)
  117. {
  118. // Ignore unexpected responses
  119. integer pos = llListFindList(httpreqs, [id]);
  120. if (pos < 0) return;
  121. // Grab the avatar key then delete the entries
  122. key av = llList2Key(httpreqs, pos + 1);
  123. httpreqs = llDeleteSubList(httpreqs, pos, pos + 1);
  124. // Check the return code
  125. if (status != 200) {
  126. sloodle_translation_request(SLOODLE_TRANSLATE_IM, [0], "httperror:code", [status], av, "");
  127. return;
  128. }
  129. // Split the response into lines
  130. list lines = llParseStringKeepNulls(body, ["\n"], []);
  131. integer numlines = llGetListLength(lines);
  132. // Fetch the status line
  133. list statusfields = llParseStringKeepNulls(llList2String(lines, 0), ["|"], []);
  134. integer statuscode = (integer)llList2String(statusfields, 0);
  135. // Check for standard status codes
  136. if (statuscode == -321) {
  137. sloodle_translation_request(SLOODLE_TRANSLATE_IM, [0], "enrolfailed:notreg", [statuscode], av, "regenrol");
  138. return;
  139. } else if (statuscode == 301) {
  140. sloodle_translation_request(SLOODLE_TRANSLATE_IM, [0], "alreadyauthenticated", [llKey2Name(av)], av, "regenrol");
  141. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "confirm:reg", av);
  142. return;
  143. } else if (statuscode == 401) {
  144. sloodle_translation_request(SLOODLE_TRANSLATE_IM, [0], "alreadyenrolled", [llKey2Name(av)], av, "regenrol");
  145. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "confirm:enrol", av);
  146. return;
  147. } else if (statuscode <= 0) {
  148. //sloodle_translation_request(SLOODLE_TRANSLATE_IM, [0], "servererror", [statuscode], av, "");
  149. sloodle_error_code(SLOODLE_TRANSLATE_SAY, NULL_KEY,statuscode); //send message to error_message.lsl
  150. return;
  151. }
  152. // We expect at least 2 lines
  153. if (numlines < 2) {
  154. sloodle_translation_request(SLOODLE_TRANSLATE_IM, [0], "badresponseformat", [], av, "");
  155. return;
  156. }
  157. // Grab the URL
  158. string url = llList2String(lines, 1);
  159. sloodle_translation_request(SLOODLE_TRANSLATE_LOAD_URL_PARALLEL, [url], "regenrolurl", [], av, "regenrol");
  160. }
  161. }
  162. // Please leave the following line intact to show where the script lives in Git:
  163. // SLOODLE LSL Script Git Location: mod/regenrolbooth-1.0/objects/default/assets/sloodle_manual_reg_enrol.lslp