sloodle_moodle_screen.lslp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Sloodle Moodle Screen
  4. //
  5. // Part of the Sloodle project (www.sloodle.org)
  6. //
  7. // Copyright (c) 2011-06 contributors (see below)
  8. // Released under the GNU GPL v3
  9. //
  10. // Contributors:
  11. // Edmund Edgar
  12. // Paul Preibisch
  13. //
  14. integer SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST=-1828374651; // this channel is used to send status codes for translation to the error_messages lsl script
  15. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  16. integer SLOODLE_CHANNEL_AVATAR_DIALOG = 1001;
  17. string SLOODLE_EOF = "sloodleeof";
  18. string SLOODLE_OBJECT_TYPE = "moodle-screen-1.0";
  19. integer SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC = 0;
  20. integer SLOODLE_OBJECT_ACCESS_LEVEL_OWNER = 1;
  21. integer SLOODLE_OBJECT_ACCESS_LEVEL_GROUP = 2;
  22. string sloodleserverroot = "";
  23. string sloodlepwd = "";
  24. integer sloodlecontrollerid = 0;
  25. integer sloodlemoduleid = 0;
  26. integer sloodlelistentoobjects = 0; // Should this object listen to other objects?
  27. integer sloodleobjectaccessleveluse = 0; // Who can use this object?
  28. integer sloodleobjectaccesslevelctrl = 0; // Who can control this object?
  29. integer sloodleserveraccesslevel = 0; // Who can use the server resource? (Value passed straight back to Moodle)
  30. integer sloodlegroupid = 0;
  31. integer sloodleshowallcontrollers = 0;
  32. integer sloodleroundid = 0;
  33. integer sloodlerefreshtime = 0;
  34. integer isconfigured = FALSE; // Do we have all the configuration data we need?
  35. integer eof = FALSE; // Have we reached the end of the configuration data?
  36. ///// TRANSLATION /////
  37. // Link message channels
  38. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  39. integer SLOODLE_CHANNEL_TRANSLATION_RESPONSE = -1928374652;
  40. // Translation output methods
  41. string SLOODLE_TRANSLATE_LINK = "link"; // No output parameters - simply returns the translation on SLOODLE_TRANSLATION_RESPONSE link message channel
  42. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  43. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  44. string SLOODLE_TRANSLATE_SHOUT = "shout"; // 1 output parameter: chat channel number
  45. string SLOODLE_TRANSLATE_REGION_SAY = "regionsay"; // 1 output parameter: chat channel number
  46. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  47. 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.
  48. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  49. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  50. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  51. // Send a translation request link message
  52. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  53. {
  54. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  55. }
  56. ///// ----------- /////
  57. ///// FUNCTIONS /////
  58. sloodle_error_code(string method, key avuuid,integer statuscode)
  59. {
  60. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST, method+"|"+(string)avuuid+"|"+(string)statuscode, NULL_KEY);
  61. }
  62. sloodle_debug(string msg)
  63. {
  64. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  65. }
  66. update_media() {
  67. llOwnerSay("media : "+sloodleserverroot);
  68. llSetPrimMediaParams( 4, [ PRIM_MEDIA_CURRENT_URL, sloodleserverroot, PRIM_MEDIA_AUTO_ZOOM, TRUE, PRIM_MEDIA_AUTO_PLAY, TRUE, PRIM_MEDIA_PERMS_INTERACT, PRIM_MEDIA_PERM_GROUP ] );
  69. llSetPrimMediaParams( 4, [ PRIM_MEDIA_HOME_URL, sloodleserverroot, PRIM_MEDIA_AUTO_ZOOM, TRUE, PRIM_MEDIA_AUTO_PLAY, TRUE, PRIM_MEDIA_PERMS_INTERACT, PRIM_MEDIA_PERM_GROUP ] );
  70. }
  71. // Configure by receiving a linked message from another script in the object
  72. // Returns TRUE if the object has all the data it needs
  73. integer sloodle_handle_command(string str)
  74. {
  75. list bits = llParseString2List(str,["|"],[]);
  76. integer numbits = llGetListLength(bits);
  77. string name = llList2String(bits,0);
  78. string value1 = "";
  79. string value2 = "";
  80. if (numbits > 1) value1 = llList2String(bits,1);
  81. if (numbits > 2) value2 = llList2String(bits,2);
  82. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  83. else if (name == "set:sloodlepwd") {
  84. // The password may be a single prim password, or a UUID and a password
  85. if (value2 != "") sloodlepwd = value1 + "|" + value2;
  86. else sloodlepwd = value1;
  87. }
  88. else if (name == SLOODLE_EOF) eof = TRUE;
  89. return (sloodleserverroot != "" && sloodlepwd != "");
  90. }
  91. // Default state - waiting for configuration
  92. default
  93. {
  94. state_entry()
  95. {
  96. llClearPrimMedia(4);
  97. // Starting again with a new configuration
  98. isconfigured = FALSE;
  99. eof = FALSE;
  100. // Reset our data
  101. sloodleserverroot = "";
  102. sloodlepwd = "";
  103. }
  104. link_message( integer sender_num, integer num, string str, key id)
  105. {
  106. // Check the channel
  107. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  108. // Split the message into lines
  109. list lines = llParseString2List(str, ["\n"], []);
  110. integer numlines = llGetListLength(lines);
  111. integer i = 0;
  112. for (i=0; i < numlines; i++) {
  113. isconfigured = sloodle_handle_command(llList2String(lines, i));
  114. }
  115. // If we've got all our data AND reached the end of the configuration data, then move on
  116. if (eof == TRUE) {
  117. if (isconfigured == TRUE) {
  118. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");
  119. state ready;
  120. } else {
  121. // Go all configuration but, it's not complete... request reconfiguration
  122. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [], NULL_KEY, "");
  123. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  124. eof = FALSE;
  125. }
  126. }
  127. }
  128. }
  129. touch_start(integer num_detected)
  130. {
  131. // Attempt to request a reconfiguration
  132. if (llDetectedKey(0) == llGetOwner()) {
  133. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:requestconfig", NULL_KEY);
  134. }
  135. }
  136. }
  137. state ready
  138. {
  139. on_rez( integer param)
  140. {
  141. state default;
  142. }
  143. state_entry()
  144. {
  145. update_media();
  146. }
  147. state_exit()
  148. {
  149. llSetTimerEvent(0.0);
  150. }
  151. }
  152. // Please leave the following line intact to show where the script lives in Git:
  153. // SLOODLE LSL Script Git Location: mod/moodlescreen-1.0/objects/default/assets/sloodle_moodle_screen.lslp