752aae2e-77d1-731f-de58-afaf15873cc4_script.lsl 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. /*********************************************
  4. * Copyrght (c) 2009 Paul Preibisch
  5. * Released under the GNU GPL 3.0
  6. * This script can be used in your scripts, but you must include this copyright header as per the GPL Licence
  7. * For more information about GPL 3.0 - see: http://www.gnu.org/copyleft/gpl.html
  8. * This script is part of the SLOODLE Project see http://sloodle.org
  9. *
  10. * httpIn_forwarder.lsl
  11. * Copyright:
  12. * Paul G. Preibisch (Fire Centaur in SL)
  13. * fire@b3dMultiTech.com
  14. *
  15. * Edmund Edgar (Edmund Earp in SL)
  16. * ed@socialminds
  17. *
  18. */
  19. string sloodleserverroot = "";
  20. string sloodlepwd = "";
  21. integer isconfigured=FALSE;
  22. integer eof=FALSE;
  23. integer sloodlecontrollerid = 0;
  24. integer sloodlemoduleid = 0;
  25. key listenHandle;
  26. integer SLOODLE_CHANNEL_OBJECT_CREATOR_REQUEST_CONFIGURATION_VIA_HTTP_IN_URL = -1639270089; //Object creator telling itself it wants to rez an object at a position (specified as key)
  27. string SLOODLE_HTTP_IN_REQUEST_LINKER = "/mod/sloodle/classroom/httpin_config_linker.php";
  28. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  29. // Configure by receiving a linked message from another script in the object
  30. // Returns TRUE if the object has all the data it needs
  31. integer sloodle_handle_command(string str)
  32. {
  33. list bits = llParseString2List(str,["|"],[]);
  34. integer numbits = llGetListLength(bits);
  35. string name = llList2String(bits,0);
  36. string value1 = "";
  37. string value2 = "";
  38. string SLOODLE_EOF="sloodleeof";
  39. if (numbits > 1) value1 = llList2String(bits,1);
  40. if (numbits > 2) value2 = llList2String(bits,2);
  41. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  42. else if (name == "set:sloodlepwd") {
  43. // The password may be a single prim password, or a UUID and a password
  44. if (value2 != "") sloodlepwd = value1 + "|" + value2;
  45. else sloodlepwd = value1;
  46. } else if (name == "set:sloodlecontrollerid") sloodlecontrollerid = (integer)value1;
  47. else if (name == SLOODLE_EOF) eof = TRUE;
  48. return (sloodleserverroot != "" && sloodlepwd != "" && sloodlecontrollerid > 0 );
  49. }
  50. // Link message channels
  51. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  52. // Translation output methods
  53. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  54. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  55. 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.
  56. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  57. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  58. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  59. // Send a translation request link message
  60. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  61. {
  62. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  63. }
  64. key httpchat;
  65. default
  66. {
  67. state_entry()
  68. {
  69. // llOwnerSay("Httpin_forwarder waiting for config");
  70. }
  71. // allow for reconfiguration without resetting
  72. link_message( integer sender_num, integer num, string str, key id)
  73. {
  74. // llOwnerSay("http-in forwarder got mesage"+str);
  75. // Check the channel
  76. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  77. if (str == "do:reset") llResetScript();
  78. // Split the message into lines
  79. list lines = llParseString2List(str, ["\n"], []);
  80. integer numlines = llGetListLength(lines);
  81. integer i = 0;
  82. for (i=0; i < numlines; i++) {
  83. isconfigured = sloodle_handle_command(llList2String(lines, i));
  84. // llOwnerSay("got command "+llList2String(lines,i)+", configured is "+(string)isconfigured);
  85. }
  86. // If we've got all our data AND reached the end of the configuration data, then move on
  87. if (eof == TRUE) {
  88. if (isconfigured == TRUE) {
  89. // The main script should deal with talking about configuration.
  90. // We'll avoid confusing the user by saying it twice, and just hope we both got the same messages.
  91. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");
  92. state ready;
  93. } else {
  94. // Go all configuration but, it's not complete... request reconfiguration
  95. // sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [], NULL_KEY, "");
  96. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  97. eof = FALSE;
  98. }
  99. }
  100. }
  101. }
  102. on_rez(integer start_param) {
  103. llResetScript();
  104. }
  105. }
  106. state ready {
  107. state_entry()
  108. {
  109. // llOwnerSay("Httpin_forwarder ready");
  110. llListen( SLOODLE_CHANNEL_OBJECT_CREATOR_REQUEST_CONFIGURATION_VIA_HTTP_IN_URL, "", NULL_KEY, "" );
  111. }
  112. listen( integer channel, string name, key id, string str){
  113. if (channel != SLOODLE_CHANNEL_OBJECT_CREATOR_REQUEST_CONFIGURATION_VIA_HTTP_IN_URL ) return;
  114. // llOwnerSay("got config request"+str);
  115. if (llGetOwnerKey(id) != llGetOwner()) {
  116. // llOwnerSay("returning: id of getowner is "+(string)llGetOwner()+" but object owner is "+(string)llGetOwnerKey(id));
  117. return;
  118. }
  119. // llOwnerSay("stilll here t"+str);
  120. //send to httpin_config_linker
  121. string body = "sloodlecontrollerid=" + (string)sloodlecontrollerid;
  122. body += "&sloodlepwd=" + sloodlepwd;
  123. body += "&sloodlemoduleid=" + (string)sloodlemoduleid;
  124. body += "&sloodleobjuuid=" + (string)llGetKey();
  125. body += "&childobjectuuid=" + (string)id;
  126. body += "&httpinurl=" + str;
  127. //llOwnerSay("requested config with body "+body);
  128. httpchat = llHTTPRequest(sloodleserverroot + SLOODLE_HTTP_IN_REQUEST_LINKER, [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], body);
  129. }
  130. // allow for reconfiguration without resetting
  131. link_message( integer sender_num, integer num, string str, key id)
  132. {
  133. if (str == "do:reset") llResetScript();
  134. // llOwnerSay(str);
  135. // Check the channel
  136. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  137. // Split the message into lines
  138. list lines = llParseString2List(str, ["\n"], []);
  139. integer numlines = llGetListLength(lines);
  140. integer i = 0;
  141. for (i=0; i < numlines; i++) {
  142. isconfigured = sloodle_handle_command(llList2String(lines, i));
  143. // llOwnerSay("got command "+llList2String(lines,i)+", configured is "+(string)isconfigured);
  144. }
  145. // If we've got all our data AND reached the end of the configuration data, then move on
  146. if (eof == TRUE) {
  147. if (isconfigured == TRUE) {
  148. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");;
  149. } else {
  150. // Go all configuration but, it's not complete... request reconfiguration
  151. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [], NULL_KEY, "");
  152. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  153. eof = FALSE;
  154. }
  155. }
  156. }
  157. }
  158. on_rez(integer start_param) {
  159. llResetScript();
  160. }
  161. }
  162. // Please leave the following line intact to show where the script lives in Git:
  163. // SLOODLE LSL Script Git Location: mod/set-1.0/objects/default/assets/sloodle_httpin_forwarder.lslp