ae055863-e73f-ac50-2ba2-c15ad63b58f8_script.lsl 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. /*
  4. * Part of the Sloodle project (www.sloodle.org)
  5. *
  6. * Copyright (c) 2011-06 contributors (see below)
  7. * Released under the GNU GPL v3
  8. * -------------------------------------------
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. * All scripts must maintain this copyrite information, including the contributer information listed
  24. *
  25. * Contributors:
  26. * Paul Preibisch
  27. *
  28. * DESCRIPTION
  29. * Contributors:
  30. * Edmund Edgar
  31. * Paul Preibisch
  32. */
  33. integer FACE = 4;
  34. integer counter=0;
  35. integer SLOODLE_CHANNEL_SET_SET_BROWSER_URL_OWNER = -1639270121; // set the open browser button to url, accessible to owner
  36. integer SLOODLE_CHANNEL_SET_SET_BROWSER_URL_GROUP = -1639270122; // set the open browser button to url, accessible to group
  37. integer SLOODLE_CHANNEL_SET_SET_BROWSER_URL_ANYONE = -1639270124; // set the open browser button to url, accessible to anyone
  38. integer active_num;
  39. string url;
  40. string nourlmessage; // If we can't provide a URL, use this message instead, which should be passed to the translation script.
  41. string sloodleserverroot = "";
  42. integer sloodlecontrollerid = 0;
  43. string sloodlepwd = "";
  44. integer sloodlemoduleid = 0;
  45. integer sloodleobjectaccessleveluse = 0; // Who can use this object?
  46. integer sloodleobjectaccesslevelctrl = 0; // Who can control this object?
  47. integer sloodleserveraccesslevel = 0; // Who can use the server resource? (Value passed straight back to Moodle)
  48. integer isconfigured = FALSE; // Do we have all the configuration data we need?
  49. integer eof = FALSE; // Have we reached the end of the configuration data?
  50. string SLOODLE_EOF = "sloodleeof";
  51. // Link message channels
  52. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  53. // Translation output methods
  54. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  55. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  56. 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.
  57. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  58. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  59. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  60. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  61. // Send a translation request link message
  62. // NB This has been changed to LINK_SET from the normal LINK_THIS
  63. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  64. {
  65. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  66. }
  67. integer sloodle_handle_command(string str){
  68. list bits = llParseString2List(str,["|"],[]);
  69. integer numbits = llGetListLength(bits);
  70. string name = llList2String(bits,0);
  71. string value1 = "";
  72. string value2 = "";
  73. if (numbits > 1) value1 = llList2String(bits,1);
  74. if (numbits > 2) value2 = llList2String(bits,2);
  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 != "") {
  79. sloodlepwd = value1 + "|" + value2;
  80. }
  81. else {
  82. sloodlepwd = value1;
  83. }
  84. }
  85. else if (name == "set:sloodlecontrollerid") sloodlecontrollerid = (integer)value1;
  86. else if (name == "set:sloodlemoduleid") sloodlemoduleid = (integer)value1;
  87. else if (name == "set:sloodleobjectaccessleveluse") sloodleobjectaccessleveluse = (integer)value1;
  88. else if (name == "set:sloodleserveraccesslevel") sloodleserveraccesslevel = (integer)value1;
  89. else if (name == SLOODLE_EOF) eof = TRUE;
  90. return (sloodleserverroot != "" && sloodlepwd != "" && sloodlecontrollerid > 0 && sloodlemoduleid > 0);
  91. }
  92. open_in_browser(key toucher)
  93. {
  94. if (nourlmessage != "") {
  95. if (toucher == llGetOwner()) {
  96. sloodle_translation_request(SLOODLE_TRANSLATE_OWNER_SAY, [0], nourlmessage, [llKey2Name(toucher)], NULL_KEY, "");
  97. } else {
  98. sloodle_translation_request(SLOODLE_TRANSLATE_IM, [0], nourlmessage, [llKey2Name(toucher)], NULL_KEY, "");
  99. }
  100. return;
  101. }
  102. llTriggerSound("click", 1.0);
  103. //sloodle_translation_request(SLOODLE_TRANSLATE_IM, [0], nourlmessage, [llKey2Name(toucher)], NULL_KEY, "");
  104. if (toucher == llGetOwner()) {
  105. sloodle_translation_request(SLOODLE_TRANSLATE_OWNER_SAY, [0], "openrezzerurl", [url], NULL_KEY, "");
  106. sloodle_translation_request(SLOODLE_TRANSLATE_LOAD_URL, [url], "openrezzerurl", [], toucher, "");
  107. } else {
  108. sloodle_translation_request(SLOODLE_TRANSLATE_IM, [0], "openrezzerurl", [url], NULL_KEY, "");
  109. sloodle_translation_request(SLOODLE_TRANSLATE_LOAD_URL, [url], "openrezzerurl", [], toucher, "");
  110. }
  111. /*
  112. if (toucher == llGetOwner()) {
  113. llOwnerSay("Open the rezzer in your browser"+"\n"+url);
  114. } else {
  115. llInstantMessage(toucher,"Open the rezzer screen in your browser\n"+url);
  116. }
  117. */
  118. }
  119. default {
  120. on_rez(integer start_param) {
  121. llResetScript();
  122. }
  123. link_message( integer sender_num, integer num, string str, key id ) {
  124. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  125. if (str=="do:reconfigure"||str=="do:reset"){
  126. llResetScript();
  127. return;
  128. }
  129. // Split the message into lines
  130. string config = str;
  131. list lines = llParseString2List(str, ["\n"], []);
  132. integer numlines = llGetListLength(lines);
  133. integer i = 0;
  134. for (i=0; i < numlines; i++) {
  135. isconfigured = sloodle_handle_command(llList2String(lines, i));
  136. }
  137. // If we've got all our data AND reached the end of the configuration data (eof), then move on
  138. if (eof == TRUE) {
  139. if (isconfigured == TRUE) {
  140. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");
  141. state load;
  142. } else {
  143. // Go all configuration but, it's not complete... request reconfiguration
  144. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [llGetScriptName()], NULL_KEY, "");
  145. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  146. eof = FALSE;
  147. }
  148. }
  149. } else if ( ( num == SLOODLE_CHANNEL_SET_SET_BROWSER_URL_OWNER ) || ( num == SLOODLE_CHANNEL_SET_SET_BROWSER_URL_GROUP ) || ( num == SLOODLE_CHANNEL_SET_SET_BROWSER_URL_ANYONE) ) {
  150. active_num = num;
  151. if (str == "") {
  152. url = "";
  153. nourlmessage = "";
  154. return;
  155. }
  156. // if we can't provide a URL, we can set a message to say what to say instead.
  157. //nourlmessage|usedescriptioninstead
  158. if (llGetSubString(str, 0, 12) == "nourlmessage|") {
  159. url = "";
  160. nourlmessage = llGetSubString(str,13,-1);
  161. return;
  162. }
  163. url = str;
  164. nourlmessage = "";
  165. }
  166. }
  167. touch_start(integer d){
  168. if ( (url == "") && (nourlmessage == "") ) {
  169. return;
  170. }
  171. integer j;
  172. for (j=0;j<d;j++){
  173. key toucher = llDetectedKey(j);
  174. if (active_num == SLOODLE_CHANNEL_SET_SET_BROWSER_URL_ANYONE) {
  175. open_in_browser(toucher);
  176. } else if ( toucher == llGetOwner() ) {
  177. open_in_browser(toucher);
  178. } else if ( (active_num == SLOODLE_CHANNEL_SET_SET_BROWSER_URL_GROUP) && llSameGroup(toucher) ) {
  179. open_in_browser(toucher);
  180. } else {
  181. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "nopermission:use", [llKey2Name(toucher)], NULL_KEY, "");
  182. }
  183. }
  184. }//TOUCH
  185. }//default
  186. // Please leave the following line intact to show where the script lives in Git:
  187. // SLOODLE LSL Script Git Location: mod/set-1.0/objects/default/assets/sloodle_open_in_browser.lslp