message.ossl.lslp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. /*
  4. * ossl_message.lslp
  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. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation, either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. * All scripts must maintain this copyrite information, including the contributer information listed
  25. *
  26. * Contributors:
  27. * Paul Preibisch
  28. * Edmund Edgar
  29. *
  30. * DESCRIPTION
  31. *
  32. */
  33. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343; // an arbitrary channel the sloodle scripts will use to talk to each other. Doesn't atter what it is, as long as the same thing is set in the sloodle_slave script.
  34. string sloodleserverroot = "";
  35. integer sloodlecontrollerid = 0;
  36. string sloodlepwd = "";
  37. integer sloodlemoduleid = 0;
  38. integer sloodleobjectaccessleveluse = 0; // Who can use this object?
  39. integer sloodleobjectaccesslevelctrl = 0; // Who can control this object?
  40. integer sloodleserveraccesslevel = 0; // Who can use the server resource? (Value passed straight back to Moodle)
  41. integer isconfigured = FALSE; // Do we have all the configuration data we need?
  42. string SLOODLE_EOF = "sloodleeof";
  43. integer eof = FALSE; // Have we reached the end of the configuration data?
  44. integer SLOODLE_CHANNEL_QUIZ_MASTER_REQUEST= -1639277006;
  45. integer SLOODLE_CHANNEL_USER_TOUCH = -1639277002;//user touched object
  46. integer SLOODLE_CHANNEL_QUIZ_MASTER_RESPONSE= -1639277008;
  47. integer SLOODLE_CHANNEL_QUIZ_LOADING_QUIZ = -1639271109;
  48. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  49. integer SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST=-1828374651;
  50. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  51. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  52. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  53. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  54. 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.
  55. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  56. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  57. integer SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC = 0;
  58. integer SLOODLE_OBJECT_ACCESS_LEVEL_OWNER = 1;
  59. integer SLOODLE_OBJECT_ACCESS_LEVEL_GROUP = 2;
  60. vector RED =<1.00000, 0.00000, 0.00000>;
  61. vector ORANGE=<1.00000, 0.43763, 0.02414>;
  62. vector YELLOW=<1.00000, 1.00000, 0.00000>;
  63. vector GREEN=<0.00000, 1.00000, 0.00000>;
  64. vector BLUE=<0.00000, 0.00000, 1.00000>;
  65. vector BABYBLUE=<0.00000, 1.00000, 1.00000>;
  66. vector PINK=<1.00000, 0.00000, 1.00000>;
  67. vector PURPLE=<0.57338, 0.25486, 1.00000>;
  68. vector BLACK= <0.00000, 0.00000, 0.00000>;
  69. vector WHITE= <1.00000, 1.00000, 1.00000>;
  70. vector AVCLASSBLUE= <0.06274,0.247058,0.35294>;
  71. vector AVCLASSLIGHTBLUG=<0.8549,0.9372,0.9686>;//#daeff7
  72. string region;
  73. vector landing_point;
  74. vector look_at;
  75. string ossl_message;
  76. sloodle_error_code(string method, key avuuid,integer statuscode, string msg){
  77. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST, method+"|"+(string)avuuid+"|"+(string)statuscode+"|"+(string)msg, NULL_KEY);
  78. }
  79. sloodle_debug(string msg){
  80. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  81. }
  82. // Send a translation request link message
  83. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch){
  84. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  85. }
  86. print_message(string message){
  87. string CommandList = ""; // Storage for our drawing commands
  88. integer font_size=42;
  89. vector Extents = osGetDrawStringSize( "vector", message, "Arial", font_size );
  90. CommandList = osSetFontSize( CommandList, font_size ); // Use 10-point text
  91. integer xpos = 512 - ((integer) Extents.x >> 1); // Center the text horizontally
  92. integer ypos = 255 - ((integer) Extents.y >> 1); // and vertically
  93. CommandList = osMovePen( CommandList, xpos, ypos ); // Position the text
  94. CommandList = osDrawText( CommandList, ossl_message ); // Place some text
  95. // Now draw the image
  96. osSetDynamicTextureData( "", "vector", CommandList, "width:1024,height:512", 0 );
  97. }
  98. // Configure by receiving a linked message from another script in the object
  99. // Returns TRUE if the object has all the data it needs
  100. integer sloodle_handle_command(string str){
  101. list bits = llParseString2List(str,["|"],[]);
  102. integer numbits = llGetListLength(bits);
  103. string name = llList2String(bits,0);
  104. string value1 = "";
  105. string value2 = "";
  106. if (numbits > 1) value1 = llList2String(bits,1);
  107. if (numbits > 2) value2 = llList2String(bits,2);
  108. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  109. else if (name == "set:sloodlepwd") {
  110. // The password may be a single prim password, or a UUID and a password
  111. if (value2 != "") {
  112. sloodlepwd = value1 + "|" + value2;
  113. }
  114. else {
  115. sloodlepwd = value1;
  116. }
  117. }
  118. else if (name == "set:ossl_message") {
  119. ossl_message = value1;
  120. debug("ossl_message: "+ossl_message);
  121. print_message(ossl_message);
  122. }
  123. else if (name == "set:sloodlecontrollerid"){
  124. sloodlecontrollerid = (integer)value1;
  125. debug("sloodlecontrollerid: "+(string)sloodlecontrollerid);
  126. }
  127. else if (name == "set:sloodlemoduleid") {
  128. sloodlemoduleid = (integer)value1;
  129. debug("sloodlemoduleid: "+(string)sloodlemoduleid);
  130. }
  131. else if (name == "set:sloodleobjectaccessleveluse") {
  132. sloodleobjectaccessleveluse = (integer)value1;
  133. debug("sloodleobjectaccessleveluse: "+(string)sloodleobjectaccessleveluse);
  134. }
  135. else if (name == "set:sloodleserveraccesslevel") {
  136. sloodleserveraccesslevel = (integer)value1;
  137. debug("sloodleserveraccesslevel: "+(string)sloodleserveraccesslevel);
  138. }
  139. else if (name == SLOODLE_EOF) eof = TRUE;
  140. return (sloodleserverroot != "" && sloodlecontrollerid > 0);
  141. }
  142. debug (string message ){
  143. list params = llGetPrimitiveParams ([PRIM_MATERIAL ]);
  144. if (llList2Integer (params ,0)==PRIM_MATERIAL_FLESH){
  145. llOwnerSay("memory: "+(string)llGetFreeMemory()+" Script name: "+llGetScriptName ()+": " +message );
  146. }
  147. }
  148. default {
  149. on_rez(integer start_param) {
  150. llResetScript();
  151. }
  152. state_entry(){
  153. isconfigured = FALSE;
  154. eof = FALSE;
  155. }
  156. link_message( integer sender_num, integer chan, string str, key user_key){
  157. // Check the channel for configuration messages
  158. if (chan == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  159. // Split the message into lines
  160. list lines = llParseString2List(str, ["\n"], []);
  161. integer numlines = llGetListLength(lines);
  162. integer i = 0;
  163. for (i=0; i < numlines; i++) {
  164. isconfigured = sloodle_handle_command(llList2String(lines, i));
  165. }
  166. // If we've got all our data AND reached the end of the configuration data (eof), then move on
  167. if (eof == TRUE) {
  168. if (isconfigured == TRUE) {
  169. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");
  170. state ready;
  171. } else {
  172. // Go all configuration but, it's not complete... request reconfiguration
  173. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [llGetScriptName()], NULL_KEY, "");
  174. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  175. eof = FALSE;
  176. }
  177. }
  178. }
  179. }
  180. }
  181. state ready{
  182. on_rez(integer start_param) {
  183. llResetScript();
  184. }
  185. state_entry() {
  186. eof == FALSE;
  187. isconfigured=FALSE;
  188. }
  189. link_message( integer sender_num, integer chan, string str, key user_key){
  190. // Check the channel for configuration messages
  191. if (chan == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  192. // Split the message into lines
  193. list lines = llParseString2List(str, ["\n"], []);
  194. integer numlines = llGetListLength(lines);
  195. integer i = 0;
  196. for (i=0; i < numlines; i++) {
  197. isconfigured = sloodle_handle_command(llList2String(lines, i));
  198. }
  199. // If we've got all our data AND reached the end of the configuration data (eof), then move on
  200. if (eof == TRUE) {
  201. if (isconfigured == TRUE) {
  202. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");
  203. } else {
  204. // Go all configuration but, it's not complete... request reconfiguration
  205. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [llGetScriptName()], NULL_KEY, "");
  206. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  207. eof = FALSE;
  208. }
  209. }
  210. }
  211. }
  212. }