sloodle_mod_touchable-1.0.lslp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Sloodle WebIntercom (for Sloodle 0.4)
  4. // Links in-world SL (text) chat with a Moodle chatroom
  5. // Part of the Sloodle project (www.sloodle.org)
  6. //
  7. // Copyright (c) 2006-8 Sloodle
  8. // Released under the GNU GPL
  9. //
  10. // Contributors:
  11. // Paul Andrews
  12. // Daniel Livingstone
  13. // Jeremy Kemp
  14. // Edmund Edgar
  15. // Peter R. Bloomfield
  16. //
  17. integer SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST=-1828374651; // this channel is used to send status codes for translation to the error_messages lsl script
  18. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  19. integer SLOODLE_CHANNEL_AVATAR_DIALOG = 1001;
  20. string SLOODLE_INTERACTION_LINKER = "/mod/sloodle/mod/interaction-1.0/linker.php";
  21. string SLOODLE_EOF = "sloodleeof";
  22. integer SLOODLE_OBJECT_INTERACTION= -1639271132; //channel interaction objects speak on
  23. integer SLOODLE_OBJECT_REGISTER_INTERACTION= -1639271133; //channel objects send interactions to the mod_interaction-1.0 script on to be forwarded to server
  24. string SLOODLE_OBJECT_TYPE = "chat-1.0";
  25. integer SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC = 0;
  26. integer SLOODLE_OBJECT_ACCESS_LEVEL_OWNER = 1;
  27. integer SLOODLE_OBJECT_ACCESS_LEVEL_GROUP = 2;
  28. string sloodleserverroot = "";
  29. string sloodlepwd = "";
  30. integer sloodlecontrollerid = 0;
  31. integer sloodlemoduleid = 0;
  32. integer sloodlelistentoobjects = 0; // Should this object listen to other objects?
  33. integer sloodleobjectaccessleveluse = 0; // Who can use this object?
  34. integer sloodleobjectaccesslevelctrl = 0; // Who can control this object?
  35. integer sloodleserveraccesslevel = 0; // Who can use the server resource? (Value passed straight back to Moodle)
  36. integer sloodleautodeactivate = 1; // Should the WebIntercom auto-deactivate when not in use?
  37. integer isconfigured = FALSE; // Do we have all the configuration data we need?
  38. integer eof = FALSE; // Have we reached the end of the configuration data?
  39. ///// TRANSLATION /////
  40. // Link message channels
  41. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  42. integer SLOODLE_CHANNEL_TRANSLATION_RESPONSE = -1928374652;
  43. // Translation output methods
  44. string SLOODLE_TRANSLATE_LINK = "link"; // No output parameters - simply returns the translation on SLOODLE_TRANSLATION_RESPONSE link message channel
  45. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  46. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  47. string SLOODLE_TRANSLATE_SHOUT = "shout"; // 1 output parameter: chat channel number
  48. string SLOODLE_TRANSLATE_REGION_SAY = "regionsay"; // 1 output parameter: chat channel number
  49. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  50. 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.
  51. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  52. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  53. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  54. key httprequest = NULL_KEY;
  55. key avuuid = NULL_KEY;
  56. // Send a translation request link message
  57. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  58. {
  59. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  60. }
  61. ///// ----------- /////
  62. ///// FUNCTIONS /////
  63. /******************************************************************************************************************************
  64. * sloodle_error_code -
  65. * Author: Paul Preibisch
  66. * Description - This function sends a linked message on the SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST channel
  67. * The error_messages script hears this, translates the status code and sends an instant message to the avuuid
  68. * Params: method - SLOODLE_TRANSLATE_SAY, SLOODLE_TRANSLATE_IM etc
  69. * Params: avuuid - this is the avatar UUID to that an instant message with the translated error code will be sent to
  70. * Params: status code - the status code of the error as on our wiki: http://slisweb.sjsu.edu/sl/index.php/Sloodle_status_codes
  71. *******************************************************************************************************************************/
  72. sloodle_error_code(string method, key avuuid,integer statuscode, string msg){
  73. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST, method+"|"+(string)avuuid+"|"+(string)statuscode+"|"+(string)msg, NULL_KEY);
  74. }
  75. sloodle_debug(string msg)
  76. {
  77. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  78. }
  79. // Configure by receiving a linked message from another script in the object
  80. // Returns TRUE if the object has all the data it needs
  81. integer sloodle_handle_command(string str)
  82. {
  83. list bits = llParseString2List(str,["|"],[]);
  84. integer numbits = llGetListLength(bits);
  85. string name = llList2String(bits,0);
  86. string value1 = "";
  87. string value2 = "";
  88. if (numbits > 1) value1 = llList2String(bits,1);
  89. if (numbits > 2) value2 = llList2String(bits,2);
  90. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  91. else if (name == "set:sloodlepwd") {
  92. // The password may be a single prim password, or a UUID and a password
  93. if (value2 != "") sloodlepwd = value1 + "|" + value2;
  94. else sloodlepwd = value1;
  95. } else if (name == "set:sloodlecontrollerid") sloodlecontrollerid = (integer)value1;
  96. else if (name == "set:sloodlemoduleid") sloodlemoduleid = (integer)value1;
  97. else if (name == "set:sloodlelistentoobjects") sloodlelistentoobjects = (integer)value1;
  98. else if (name == "set:sloodleobjectaccessleveluse") sloodleobjectaccessleveluse = (integer)value1;
  99. else if (name == "set:sloodleobjectaccesslevelctrl") sloodleobjectaccesslevelctrl = (integer)value1;
  100. else if (name == "set:sloodleserveraccesslevel") sloodleserveraccesslevel = (integer)value1;
  101. else if (name == "set:sloodleautodeactivate") sloodleautodeactivate = (integer)value1;
  102. else if (name == SLOODLE_EOF) eof = TRUE;
  103. return (sloodleserverroot != "" && sloodlepwd != "" && sloodlecontrollerid > 0);
  104. }
  105. // Checks if the given agent is permitted to control this object
  106. // Returns TRUE if so, or FALSE if not
  107. integer sloodle_check_access_ctrl(key id)
  108. {
  109. // Check the access mode
  110. if (sloodleobjectaccesslevelctrl == SLOODLE_OBJECT_ACCESS_LEVEL_GROUP) {
  111. return llSameGroup(id);
  112. } else if (sloodleobjectaccesslevelctrl == SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC) {
  113. return TRUE;
  114. }
  115. // Assume it's owner mode
  116. return (id == llGetOwner());
  117. }
  118. // Checks if the given agent is permitted to user this object
  119. // Returns TRUE if so, or FALSE if not
  120. integer sloodle_check_access_use(key id)
  121. {
  122. // Check the access mode
  123. if (sloodleobjectaccessleveluse == SLOODLE_OBJECT_ACCESS_LEVEL_GROUP) {
  124. return llSameGroup(id);
  125. } else if (sloodleobjectaccessleveluse == SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC) {
  126. return TRUE;
  127. }
  128. // Assume it's owner mode
  129. return (id == llGetOwner());
  130. }
  131. // Start recording the specified agent
  132. register_interaction(key id,string task)
  133. {
  134. // Inform the Moodle chatroom
  135. string body = "sloodlecontrollerid=" + (string)sloodlecontrollerid;
  136. body += "&sloodlepwd=" + sloodlepwd;
  137. body += "&sloodlemoduleid=" + (string)sloodlemoduleid;
  138. body += "&sloodleuuid=" + (string)id;
  139. body += "&sloodleobjuuid=" + (string)llGetKey();
  140. body += "&sloodleavname=" + llEscapeURL(llKey2Name(id));
  141. body += "&task=" + llEscapeURL(task);
  142. httprequest = llHTTPRequest(sloodleserverroot + SLOODLE_INTERACTION_LINKER, [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], body);
  143. // llOwnerSay("sending httprequest: "+sloodleserverroot + SLOODLE_INTERACTION_LINKER+ "?"+body);
  144. }
  145. // Default state - waiting for configuration
  146. default
  147. {
  148. state_entry()
  149. {
  150. // Set the texture on the sides to indicate we're deactivated
  151. llSetText("", <0.0,0.0,0.0>, 0.0);
  152. isconfigured = FALSE;
  153. eof = FALSE;
  154. // Reset our data
  155. sloodleserverroot = "";
  156. sloodlepwd = "";
  157. sloodlecontrollerid = 0;
  158. sloodlemoduleid = 0;
  159. sloodlelistentoobjects = 0;
  160. sloodleobjectaccessleveluse = 0;
  161. sloodleobjectaccesslevelctrl = 0;
  162. sloodleserveraccesslevel = 0;
  163. }
  164. link_message( integer sender_num, integer num, string str, key id)
  165. {
  166. // Check the channel
  167. // llOwnerSay(str);
  168. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  169. // Split the message into lines
  170. list lines = llParseString2List(str, ["\n"], []);
  171. integer numlines = llGetListLength(lines);
  172. integer i = 0;
  173. for (i=0; i < numlines; i++) {
  174. isconfigured = sloodle_handle_command(llList2String(lines, i));
  175. }
  176. // If we've got all our data AND reached the end of the configuration data, then move on
  177. if (eof == TRUE) {
  178. if (isconfigured == TRUE) {
  179. state ready;
  180. } else {
  181. // Go all configuration but, it's not complete... request reconfiguration
  182. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [], NULL_KEY, "");
  183. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  184. eof = FALSE;
  185. }
  186. }
  187. }
  188. }
  189. }
  190. state ready {
  191. on_rez(integer start_param) {
  192. llResetScript();
  193. }
  194. link_message(integer sender_num, integer num, string str, key id) {
  195. if (num==SLOODLE_OBJECT_REGISTER_INTERACTION){
  196. register_interaction(id,str);
  197. }
  198. }
  199. state_entry() {
  200. llOwnerSay("ready");
  201. }
  202. http_response(key id, integer status, list meta, string body)
  203. {
  204. // Is this the expected data?
  205. if (id != httprequest) return;
  206. httprequest = NULL_KEY;
  207. // Make sure the request worked
  208. llMessageLinked(LINK_SET, SLOODLE_OBJECT_INTERACTION, body, NULL_KEY);
  209. if (status != 200) {
  210. sloodle_debug("Failed HTTP response. Status: " + (string)status);
  211. sloodle_error_code(SLOODLE_TRANSLATE_SAY, avuuid,status,""); //send message to error_message.lsl
  212. return;
  213. }
  214. // Make sure there is a body to the request
  215. if (llStringLength(body) == 0) return;
  216. // Split the data up into lines
  217. list lines = llParseStringKeepNulls(body, ["\n"], []);
  218. integer numlines = llGetListLength(lines);
  219. // Extract all the status fields
  220. list statusfields = llParseStringKeepNulls( llList2String(lines,0), ["|"], [] );
  221. // Get the statuscode
  222. integer statuscode = llList2Integer(statusfields,0);
  223. // Was it an error code?
  224. if (statuscode <= 0) {
  225. string msg;
  226. if (numlines > 1) {
  227. msg = llList2String(lines, 1);
  228. }
  229. sloodle_debug(msg);
  230. //Sloodle 2.0 Change - output custom errorcode to other scripts
  231. sloodle_error_code(SLOODLE_TRANSLATE_IM, avuuid,statuscode, msg); //send message to error_message.lsl
  232. return;
  233. }
  234. }
  235. }
  236. // Please leave the following line intact to show where the script lives in Git:
  237. // SLOODLE LSL Script Git Location: mod/interaction-1.0/objects/touchobject/assets/sloodle_mod_touchable-1.0.lslp