60aec86a-180a-2e02-5689-9c6f43f5db25_script.lsl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Sloodle configuration notecard reader
  4. // Reads a configuration notecard and transmits the data via link messages to other scripts
  5. // If the notecard changes, then it automatically resets.
  6. //
  7. // Part of the Sloodle project (www.sloodle.org)
  8. // Copyright (c) 2007-8 Sloodle
  9. // Released under the GNU GPL v3
  10. //
  11. // Contributors:
  12. // Edmund Edgar
  13. // Peter R. Bloomfield
  14. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  15. string SLOODLE_CONFIG_NOTECARD = "sloodle_config";
  16. string SLOODLE_EOF = "sloodleeof";
  17. key sloodle_notecard_key = NULL_KEY;
  18. integer sloodle_notecard_line = 0;
  19. string COMMENT_PREFIX = "//";
  20. key latestnotecard = NULL_KEY; // The most recently read notecard
  21. string notecarddata = "";
  22. string httpinurl = "";
  23. integer isnotecarddone = 0;
  24. string sloodlepwd = "";
  25. string sloodleserverroot = "";
  26. string sloodlecontrollerid = "";
  27. string SLOODLE_HTTP_IN_REQUEST_LINKER = "/mod/sloodle/classroom/httpin_config_linker.php";
  28. 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)
  29. sloodle_start_reading_notecard()
  30. {
  31. // Do we have a configuratio notecard?
  32. if (llGetInventoryType(SLOODLE_CONFIG_NOTECARD) == INVENTORY_NOTECARD) {
  33. // Start reading it
  34. sloodle_notecard_line = 0;
  35. sloodle_notecard_key = llGetNotecardLine("sloodle_config", 0); // read the first line. The dataserver event will get the next one.
  36. latestnotecard = llGetInventoryKey(SLOODLE_CONFIG_NOTECARD);
  37. } else {
  38. latestnotecard = NULL_KEY;
  39. }
  40. }
  41. register_config_if_ready()
  42. {
  43. if ( (httpinurl == "") || (isnotecarddone == 0) ) {
  44. return;
  45. }
  46. if ( ( sloodleserverroot == "") || (sloodlepwd == "") ) {
  47. return;
  48. }
  49. // llOwnerSay("need to talk to "+sloodleserverroot+" and have them register me and send me my config");
  50. //send to httpin_config_linker
  51. string body = "sloodlecontrollerid=" + (string)sloodlecontrollerid;
  52. body += "&sloodlepwd=" + sloodlepwd;
  53. body += "&sloodleobjuuid=" + (string)llGetKey();
  54. body += "&childobjectuuid=" + (string)llGetKey();
  55. body += "&httpinurl=" + httpinurl;
  56. body += "&sloodleobjname=" + llGetObjectName();
  57. body += notecarddata;
  58. //llOwnerSay("requested config with body "+body);
  59. llHTTPRequest(sloodleserverroot + SLOODLE_HTTP_IN_REQUEST_LINKER, [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], body);
  60. }
  61. default
  62. {
  63. on_rez(integer start_param)
  64. {
  65. llResetScript();
  66. }
  67. state_entry()
  68. {
  69. // Pause for a moment, in case all scripts were reset at the same time
  70. llSleep(0.2);
  71. // Go!
  72. sloodle_start_reading_notecard();
  73. }
  74. dataserver(key requested, string data)
  75. {
  76. if ( requested == sloodle_notecard_key ) // make sure we are getting the data we want
  77. {
  78. sloodle_notecard_key = NULL_KEY;
  79. if ( data != EOF )
  80. {
  81. // If this is a comment line, then do not forward it
  82. string trimmeddata = llStringTrim(data, STRING_TRIM_HEAD);
  83. if (llSubStringIndex(trimmeddata, COMMENT_PREFIX) != 0) {
  84. list bits = llParseString2List(data,["|"],[]);
  85. integer numbits = llGetListLength(bits);
  86. string name = llList2String(bits,0);
  87. string value1 = "";
  88. if (numbits > 1) value1 = llList2String(bits,1);
  89. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  90. else if (name == "set:sloodlepwd") sloodlepwd = value1;
  91. else if (name == "set:sloodlecontrollerid") sloodlecontrollerid = value1;
  92. else notecarddata = notecarddata + "&" + name + "=" + value1;
  93. }
  94. // Advance to the next line
  95. sloodle_notecard_line++;
  96. sloodle_notecard_key = llGetNotecardLine("sloodle_config",sloodle_notecard_line);
  97. } else {
  98. isnotecarddone = 1;
  99. register_config_if_ready();
  100. }
  101. }
  102. }
  103. link_message(integer sender_num, integer num, string str, key id) {
  104. if (num == SLOODLE_CHANNEL_OBJECT_CREATOR_REQUEST_CONFIGURATION_VIA_HTTP_IN_URL) {
  105. httpinurl = str;
  106. register_config_if_ready();
  107. }
  108. }
  109. changed(integer change) {
  110. // If the inventory is changed, and we have a Sloodle config notecard, then use it to re-initialise
  111. if (change & CHANGED_INVENTORY && llGetInventoryType(SLOODLE_CONFIG_NOTECARD) == INVENTORY_NOTECARD) {
  112. // If the current notecard is not the same as the one we read most recently, then reset
  113. if (llGetInventoryKey(SLOODLE_CONFIG_NOTECARD) != latestnotecard) llResetScript();
  114. }
  115. }
  116. }
  117. // Please leave the following line intact to show where the script lives in Git:
  118. // SLOODLE LSL Script Git Location: mod/set-1.0/objects/default/assets/sloodle_notecard_httpin.lslp