ustream_screen.lslp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // UStream Viewer
  4. //
  5. // Copyright (c) 2012 contributors (see below)
  6. //
  7. // Contributors:
  8. // Edmund Edgar
  9. // Paul Preibisch
  10. //
  11. integer SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST=-1828374651; // this channel is used to send status codes for translation to the error_messages lsl script
  12. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  13. integer SLOODLE_CHANNEL_AVATAR_DIALOG = 1001;
  14. string SLOODLE_EOF = "sloodleeof";
  15. string SLOODLE_OBJECT_TYPE = "ustreamviewer-1.0";
  16. integer SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC = 0;
  17. integer SLOODLE_OBJECT_ACCESS_LEVEL_OWNER = 1;
  18. integer SLOODLE_OBJECT_ACCESS_LEVEL_GROUP = 2;
  19. string sloodleserverroot = "";
  20. string sloodlepwd = "";
  21. integer sloodlecontrollerid = 0;
  22. integer sloodlemoduleid = 0;
  23. string sloodleustreamchannel = "";
  24. integer isconfigured = FALSE; // Do we have all the configuration data we need?
  25. integer eof = FALSE; // Have we reached the end of the configuration data?
  26. integer lastmessagetimestamp = 0;
  27. integer messagetimestamp = 0;
  28. ///// TRANSLATION /////
  29. // Link message channels
  30. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  31. integer SLOODLE_CHANNEL_TRANSLATION_RESPONSE = -1928374652;
  32. integer SLOODLE_CHANNEL_OPEN_IN_BROWSER= -1639277000;
  33. // Translation output methods
  34. string SLOODLE_TRANSLATE_LINK = "link"; // No output parameters - simply returns the translation on SLOODLE_TRANSLATION_RESPONSE link message channel
  35. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  36. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  37. string SLOODLE_TRANSLATE_SHOUT = "shout"; // 1 output parameter: chat channel number
  38. string SLOODLE_TRANSLATE_REGION_SAY = "regionsay"; // 1 output parameter: chat channel number
  39. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  40. 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.
  41. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  42. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  43. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  44. integer MENU_CHANNEL; //random channel used for dialogs
  45. integer listenHandle;
  46. string paramstr;
  47. string view_url;
  48. string admin_url;
  49. integer MEDIA_FACE=3;
  50. // Send a translation request link message
  51. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  52. {
  53. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  54. }
  55. ///// ----------- /////
  56. ///// FUNCTIONS /////
  57. integer randInt(integer n)
  58. {
  59. return (integer)llFrand(n + 1);
  60. }
  61. integer randIntBetween(integer min, integer max)
  62. {
  63. return min + randInt(max - min);
  64. }
  65. sloodle_error_code(string method, key avuuid,integer statuscode)
  66. {
  67. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST, method+"|"+(string)avuuid+"|"+(string)statuscode, NULL_KEY);
  68. }
  69. sloodle_debug(string msg)
  70. {
  71. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  72. }
  73. //update screen
  74. update_media(string hash) {
  75. string url = view_url+hash;
  76. llSetPrimMediaParams( MEDIA_FACE, [ PRIM_MEDIA_CURRENT_URL, url,
  77. PRIM_MEDIA_HOME_URL, url,
  78. PRIM_MEDIA_FIRST_CLICK_INTERACT, TRUE,
  79. PRIM_MEDIA_AUTO_ZOOM, TRUE,
  80. PRIM_MEDIA_AUTO_PLAY, TRUE,
  81. PRIM_MEDIA_PERMS_INTERACT, PRIM_MEDIA_PERM_ANYONE,
  82. PRIM_MEDIA_PERMS_CONTROL, PRIM_MEDIA_PERM_NONE
  83. ] );
  84. }
  85. // Configure by receiving a linked message from another script in the object
  86. // Returns TRUE if the object has all the data it needs
  87. integer sloodle_handle_command(string str)
  88. {
  89. // llOwnerSay(str);
  90. list bits = llParseString2List(str,["|"],[]);
  91. integer numbits = llGetListLength(bits);
  92. string name = llList2String(bits,0);
  93. string value1 = "";
  94. string value2 = "";
  95. if (numbits > 1) value1 = llList2String(bits,1);
  96. if (numbits > 2) value2 = llList2String(bits,2);
  97. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  98. else if (name == "set:sloodlepwd") {
  99. // The password may be a single prim password, or a UUID and a password
  100. if (value2 != "") sloodlepwd = value1 + "|" + value2;
  101. else sloodlepwd = value1;
  102. }
  103. else if (name == "set:sloodleustreamchannel") sloodleustreamchannel = (string)value1;
  104. else if (name == SLOODLE_EOF) eof = TRUE;
  105. return (sloodleserverroot != "" && sloodlepwd != "");
  106. }
  107. // Default state - waiting for configuration
  108. default
  109. {
  110. on_rez( integer param)
  111. {
  112. llResetScript();
  113. }
  114. state_entry()
  115. {
  116. llClearPrimMedia(MEDIA_FACE);
  117. // Starting again with a new configuration
  118. isconfigured = FALSE;
  119. eof = FALSE;
  120. // Reset our data
  121. sloodleserverroot = "";
  122. sloodlepwd = "";
  123. sloodlecontrollerid = 0;
  124. sloodlemoduleid = 0;
  125. sloodleustreamchannel = "";
  126. }
  127. link_message( integer sender_num, integer num, string str, key id)
  128. {
  129. // Check the channel
  130. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  131. // Split the message into lines
  132. list lines = llParseString2List(str, ["\n"], []);
  133. integer numlines = llGetListLength(lines);
  134. integer i = 0;
  135. for (i=0; i < numlines; i++) {
  136. isconfigured = sloodle_handle_command(llList2String(lines, i));
  137. }
  138. // If we've got all our data AND reached the end of the configuration data, then move on
  139. if (eof == TRUE) {
  140. if (isconfigured == TRUE) {
  141. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");
  142. state ready;
  143. } else {
  144. // Go all configuration but, it's not complete... request reconfiguration
  145. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [], NULL_KEY, "");
  146. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  147. eof = FALSE;
  148. }
  149. }
  150. }
  151. }
  152. touch_start(integer num_detected)
  153. {
  154. // Attempt to request a reconfiguration
  155. if (llDetectedKey(0) == llGetOwner()) {
  156. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:requestconfig", NULL_KEY);
  157. }
  158. }
  159. }
  160. state ready
  161. {
  162. on_rez( integer param)
  163. {
  164. llResetScript();
  165. }
  166. state_entry()
  167. {
  168. llClearPrimMedia(MEDIA_FACE);
  169. paramstr = "&sloodleobjuuid=" + (string)llGetKey();
  170. paramstr = paramstr + "&ts="+(string)llGetUnixTime();
  171. view_url= sloodleserverroot+"/mod/sloodle/mod/ustreamviewer-1.0/shared_media/index.php?" + paramstr;
  172. update_media("");
  173. }
  174. state_exit()
  175. {
  176. llSetTimerEvent(0.0);
  177. }
  178. link_message( integer sender_num, integer num, string str, key id)
  179. {
  180. // Check the channel
  181. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  182. // Split the message into lines
  183. list lines = llParseString2List(str, ["\n"], []);
  184. integer numlines = llGetListLength(lines);
  185. integer i = 0;
  186. for (i=0; i < numlines; i++) {
  187. isconfigured = sloodle_handle_command(llList2String(lines, i));
  188. }
  189. } else if (num == SLOODLE_CHANNEL_OPEN_IN_BROWSER) {
  190. if (sloodleustreamchannel == "") {
  191. llSay(0, "The ustream channel to display on this viewer hasn't been set yet.");
  192. } else {
  193. llSay(0, "To view this screen in your browser, go to:\n"+"http://www.ustream.tv/channel/"+sloodleustreamchannel);
  194. }
  195. }
  196. }
  197. }
  198. // Please leave the following line intact to show where the script lives in Git:
  199. // SLOODLE LSL Script Git Location: mod/ustreamviewer-1.0/objects/default/assets/ustream_screen.lslp