d00ab5d2-6ac9-b66a-e2f0-e4c4ac2cedcc_script.lsl 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. /*********************************************
  4. * Copyrght (c) 2012 various contributors (see below)
  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. * sloodle_rez_status_confirmer.lsl
  11. * Copyright:
  12. * Paul G. Preibisch (Fire Centaur in SL)
  13. * fire@avatarclassroom.com
  14. *
  15. * Edmund Edgar (Edmund Earp in SL)
  16. * ed@avatarclassroom.com
  17. *
  18. * This script handles reporting to the server if objects that it rezzed are no longer there.
  19. */
  20. string sloodleserverroot = "";
  21. string sloodlepwd = "";
  22. integer isconfigured=FALSE;
  23. integer eof=FALSE;
  24. integer sloodlecontrollerid = 0;
  25. integer sloodlemoduleid = 0;
  26. string SLOODLE_CONFIRM_ACTIVE_OBJECTS_LINKER = "/mod/sloodle/classroom/confirm_active_objects.php";
  27. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  28. key requesthttp = NULL_KEY;
  29. key reporthttp = NULL_KEY;
  30. // Configure by receiving a linked message from another script in the object
  31. // Returns TRUE if the object has all the data it needs
  32. integer sloodle_handle_command(string str)
  33. {
  34. list bits = llParseString2List(str,["|"],[]);
  35. integer numbits = llGetListLength(bits);
  36. string name = llList2String(bits,0);
  37. string value1 = "";
  38. string value2 = "";
  39. string SLOODLE_EOF="sloodleeof";
  40. if (numbits > 1) value1 = llList2String(bits,1);
  41. if (numbits > 2) value2 = llList2String(bits,2);
  42. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  43. else if (name == "set:sloodlepwd") {
  44. // The password may be a single prim password, or a UUID and a password
  45. if (value2 != "") sloodlepwd = value1 + "|" + value2;
  46. else sloodlepwd = value1;
  47. } else if (name == "set:sloodlecontrollerid") sloodlecontrollerid = (integer)value1;
  48. else if (name == SLOODLE_EOF) eof = TRUE;
  49. return (sloodleserverroot != "" && sloodlepwd != "" && sloodlecontrollerid > 0 );
  50. }
  51. default
  52. {
  53. state_entry()
  54. {
  55. // llOwnerSay("waiting for config");
  56. }
  57. // allow for reconfiguration without resetting
  58. link_message( integer sender_num, integer num, string str, key id)
  59. {
  60. // llOwnerSay("http-in forwarder got mesage"+str);
  61. // Check the channel
  62. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  63. // Split the message into lines
  64. list lines = llParseString2List(str, ["\n"], []);
  65. integer numlines = llGetListLength(lines);
  66. integer i = 0;
  67. if (str == "do:reset") llResetScript();
  68. for (i=0; i < numlines; i++) {
  69. isconfigured = sloodle_handle_command(llList2String(lines, i));
  70. // llOwnerSay("got command "+llList2String(lines,i)+", configured is "+(string)isconfigured);
  71. }
  72. // If we've got all our data AND reached the end of the configuration data, then move on
  73. if (eof == TRUE) {
  74. if (isconfigured == TRUE) {
  75. state ready;
  76. } else {
  77. // Go all configuration but, it's not complete... request reconfiguration
  78. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  79. eof = FALSE;
  80. }
  81. }
  82. }
  83. }
  84. on_rez(integer start_param) {
  85. llResetScript();
  86. }
  87. changed(integer change) {
  88. if (change & CHANGED_REGION_START) {
  89. llResetScript();
  90. }
  91. }
  92. }
  93. state ready {
  94. state_entry()
  95. {
  96. // llOwnerSay("config rez status confirmer ready");
  97. llSetTimerEvent(10);
  98. }
  99. http_response(key request_id, integer status, list metadata, string body) {
  100. if (request_id != requesthttp) {
  101. return;
  102. }
  103. // Split the data up into lines
  104. list lines = llParseStringKeepNulls(body, ["\n"], []);
  105. integer numlines = llGetListLength(lines);
  106. // Extract all the status fields
  107. list statusfields = llParseStringKeepNulls( llList2String(lines,0), ["|"], [] );
  108. // Get the statuscode
  109. integer statuscode = llList2Integer(statusfields,0);
  110. if (statuscode < 0) {
  111. llResetScript();
  112. }
  113. float refreshseconds = 60;
  114. // llOwnerSay(body);
  115. if (llGetListLength(statusfields) >= 12) {
  116. if (llList2Float(statusfields,12) > 0) {
  117. refreshseconds = llList2Float(statusfields,12);
  118. }
  119. }
  120. string replybody = "sloodlecontrollerid=" + (string)sloodlecontrollerid;
  121. replybody += "&sloodlepwd=" + sloodlepwd;
  122. replybody += "&sloodlemoduleid=" + (string)sloodlemoduleid;
  123. replybody += "&sloodleobjuuid=" + (string)llGetKey();
  124. replybody += "&sloodlecmd=reportdisappeared";
  125. replybody += "&sloodlemissinguuids=";
  126. integer i;
  127. integer has_missing = 0;
  128. for (i=1; i<numlines; i++) {
  129. string uuidstr = llList2String( lines, i );
  130. if (llGetListLength( llGetObjectDetails( (key)uuidstr, [OBJECT_NAME]) ) == 0) {
  131. has_missing = 1;
  132. replybody += uuidstr + "|";
  133. }
  134. }
  135. reporthttp = llHTTPRequest(sloodleserverroot + SLOODLE_CONFIRM_ACTIVE_OBJECTS_LINKER, [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], replybody );
  136. // llOwnerSay("requestiong " +sloodleserverroot + SLOODLE_CONFIRM_ACTIVE_OBJECTS_LINKER + replybody);
  137. llSetTimerEvent(refreshseconds);
  138. }
  139. timer() {
  140. // Ask if there's anything we need
  141. string body = "sloodlecontrollerid=" + (string)sloodlecontrollerid;
  142. body += "&sloodlepwd=" + sloodlepwd;
  143. body += "&sloodlemoduleid=" + (string)sloodlemoduleid;
  144. body += "&sloodleobjuuid=" + (string)llGetKey();
  145. body += "&sloodlecmd=requestconfirmable";
  146. requesthttp = llHTTPRequest(sloodleserverroot + SLOODLE_CONFIRM_ACTIVE_OBJECTS_LINKER, [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], body);
  147. // llOwnerSay("on timer requestiong " +sloodleserverroot + SLOODLE_CONFIRM_ACTIVE_OBJECTS_LINKER + body);
  148. llSetTimerEvent(30); // In case the request fails
  149. }
  150. // allow for reconfiguration without resetting
  151. link_message( integer sender_num, integer num, string str, key id)
  152. {
  153. // llOwnerSay(str);
  154. // Check the channel
  155. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  156. if (str == "do:reset") llResetScript();
  157. // Split the message into lines
  158. list lines = llParseString2List(str, ["\n"], []);
  159. integer numlines = llGetListLength(lines);
  160. integer i = 0;
  161. for (i=0; i < numlines; i++) {
  162. isconfigured = sloodle_handle_command(llList2String(lines, i));
  163. // llOwnerSay("got command "+llList2String(lines,i)+", configured is "+(string)isconfigured);
  164. }
  165. }
  166. }
  167. on_rez(integer start_param) {
  168. llResetScript();
  169. }
  170. changed(integer change) {
  171. if (change & CHANGED_REGION_START) {
  172. llResetScript();
  173. }
  174. }
  175. }
  176. // Please leave the following line intact to show where the script lives in Git:
  177. // SLOODLE LSL Script Git Location: mod/set-1.0/objects/default/assets/sloodle_rez_status_confirmer.lslp