sloodle_postcard_instructions.lslpw 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // Sloodle Photo Blog Instructions and Messaging Object
  2. // Gives out instructions for how to use Freemail blogging
  3. // ...and relays messages on success or failure.
  4. //
  5. // Copyright (c) 2007-9 Sloodle
  6. // Released under the GNU GPL
  7. //
  8. // Contributors:
  9. // Edmund Edgar
  10. // Paul Preibisch
  11. //
  12. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  13. string SLOODLE_EOF = "sloodleeof";
  14. string SLOODLE_OBJECT_TYPE = "messager-1.0/photoblogger";
  15. integer SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC = 0;
  16. integer SLOODLE_OBJECT_ACCESS_LEVEL_OWNER = 1;
  17. integer SLOODLE_OBJECT_ACCESS_LEVEL_GROUP = 2;
  18. string sloodleserverroot = "";
  19. string sloodlepwd = "";
  20. integer sloodlecontrollerid = 0;
  21. string sloodleblogaddress = "";
  22. integer isconfigured = FALSE; // Do we have all the configuration data we need?
  23. integer eof = FALSE; // Have we reached the end of the configuration data?
  24. ///// TRANSLATION /////
  25. // Link message channels
  26. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  27. integer SLOODLE_CHANNEL_TRANSLATION_RESPONSE = -1928374652;
  28. // Translation output methods
  29. string SLOODLE_TRANSLATE_LINK = "link"; // No output parameters - simply returns the translation on SLOODLE_TRANSLATION_RESPONSE link message channel
  30. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  31. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  32. string SLOODLE_TRANSLATE_SHOUT = "shout"; // 1 output parameter: chat channel number
  33. string SLOODLE_TRANSLATE_REGION_SAY = "regionsay"; // 1 output parameter: chat channel number
  34. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  35. 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.
  36. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  37. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  38. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  39. // Send a translation request link message
  40. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  41. {
  42. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  43. }
  44. ///// ----------- /////
  45. ///// FUNCTIONS /////
  46. sloodle_debug(string msg)
  47. {
  48. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  49. }
  50. // Configure by receiving a linked message from another script in the object
  51. // Returns TRUE if the object has all the data it needs
  52. integer sloodle_handle_command(string str)
  53. {
  54. list bits = llParseString2List(str,["|"],[]);
  55. integer numbits = llGetListLength(bits);
  56. string name = llList2String(bits,0);
  57. string value1 = "";
  58. string value2 = "";
  59. if (numbits > 1) value1 = llList2String(bits,1);
  60. if (numbits > 2) value2 = llList2String(bits,2);
  61. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  62. else if (name == "set:sloodlepwd") {
  63. // The password may be a single prim password, or a UUID and a password
  64. if (value2 != "") sloodlepwd = value1 + "|" + value2;
  65. else sloodlepwd = value1;
  66. } else if (name == "set:sloodlecontrollerid") sloodlecontrollerid = (integer)value1;
  67. else if (name == "set:sloodleblogaddress") sloodleblogaddress = (string)value1;
  68. else if (name == SLOODLE_EOF) eof = TRUE;
  69. return (sloodleserverroot != "" && sloodlepwd != "" && sloodlecontrollerid > 0);
  70. }
  71. ///// STATES /////
  72. // Default state - waiting for configuration
  73. default
  74. {
  75. state_entry()
  76. {
  77. // Starting again with a new configuration
  78. isconfigured = FALSE;
  79. eof = FALSE;
  80. // Reset our data
  81. sloodleserverroot = "";
  82. sloodlepwd = "";
  83. sloodlecontrollerid = 0;
  84. sloodleblogaddress = "";
  85. }
  86. link_message( integer sender_num, integer num, string str, key id)
  87. {
  88. // Check the channel
  89. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  90. // Split the message into lines
  91. list lines = llParseString2List(str, ["\n"], []);
  92. integer numlines = llGetListLength(lines);
  93. integer i = 0;
  94. for (i=0; i < numlines; i++) {
  95. isconfigured = sloodle_handle_command(llList2String(lines, i));
  96. }
  97. // If we've got all our data AND reached the end of the configuration data, then move on
  98. if (eof == TRUE) {
  99. if (isconfigured == TRUE) {
  100. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");
  101. state ready;
  102. } else {
  103. // Got all configuration but, it's not complete... request reconfiguration
  104. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [], NULL_KEY, "");
  105. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  106. eof = FALSE;
  107. }
  108. }
  109. }
  110. }
  111. touch_start(integer num_detected)
  112. {
  113. // Attempt to request a reconfiguration
  114. if (llDetectedKey(0) == llGetOwner()) {
  115. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:requestconfig", NULL_KEY);
  116. }
  117. }
  118. }
  119. state ready
  120. {
  121. on_rez( integer param)
  122. {
  123. state default;
  124. }
  125. touch_start( integer total_number)
  126. {
  127. // Go through each toucher
  128. integer i = 0;
  129. key id = NULL_KEY;
  130. string touched = "";
  131. for (i=0; i < total_number; i++) {
  132. id = llDetectedKey(i);
  133. string instruction = "Please send a snapshot to "+sloodleblogaddress+".\n";
  134. if (llGetInventoryType( "Photo Blog Instructions") == INVENTORY_NOTECARD) {
  135. llGiveInventory(id, "Photo Blog Instructions");
  136. instruction = instruction + "See the notecard for more details.";
  137. }
  138. llInstantMessage(id, instruction);
  139. }
  140. }
  141. }
  142. // Please leave the following line intact to show where the script lives in Git:
  143. // SLOODLE LSL Script Git Location: mod/messenger-1.0/assets/photoblogger/sloodle_postcard_instructions.lsl