5a427f6d-acd8-8e50-20cd-df42e7b6f11c_script.lsl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Sloodle Scoreboard
  4. //
  5. // Part of the Sloodle project (www.sloodle.org)
  6. //
  7. // Copyright (c) 2011-06 contributors (see below)
  8. // Released under the GNU GPL v3
  9. //
  10. // Contributors:
  11. // Edmund Edgar
  12. // Paul Preibisch
  13. //
  14. integer SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST=-1828374651; // this channel is used to send status codes for translation to the error_messages lsl script
  15. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  16. integer SLOODLE_CHANNEL_AVATAR_DIALOG = 1001;
  17. integer SLOODLE_AWARDS_POINTS_CHANGE_NOTIFICATION= 10601;
  18. integer SLOODLE_CHANNEL_SCOREBOARD_SHARED_MEDIA_SET_ADMIN_URL_CHANNEL= -1639271128; // This is the channel that the scoreboard shouts out its admin URL
  19. integer SLOODLE_CHANNEL_SCOREBOARD_SHARED_MEDIA_CHANGE_ADMIN_URL_CHANNEL= -1639271129; // This is the channel that the scoreboard shouts out its admin URL WHEN It has changed due to a region event (lost its url etc)
  20. integer SLOODLE_SCOREBOARD_CONNECT_HUD= -1639271130; // channel which gets sent a linked message by the connect a hud button when it is touched.
  21. string SLOODLE_EOF = "sloodleeof";
  22. string SLOODLE_OBJECT_TYPE = "chat-1.0";
  23. integer SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC = 0;
  24. integer SLOODLE_OBJECT_ACCESS_LEVEL_OWNER = 1;
  25. integer SLOODLE_OBJECT_ACCESS_LEVEL_GROUP = 2;
  26. string sloodleserverroot = "";
  27. string sloodlepwd = "";
  28. integer sloodlecontrollerid = 0;
  29. integer sloodlemoduleid = 0;
  30. integer sloodlelistentoobjects = 0; // Should this object listen to other objects?
  31. integer sloodleobjectaccessleveluse = 0; // Who can use this object?
  32. integer sloodleobjectaccesslevelctrl = 0; // Who can control this object?
  33. integer sloodleserveraccesslevel = 0; // Who can use the server resource? (Value passed straight back to Moodle)
  34. integer sloodlegroupid = 0;
  35. integer sloodleshowallcontrollers = 0;
  36. integer sloodleroundid = 0;
  37. integer sloodlerefreshtime = 0;
  38. integer isconfigured = FALSE; // Do we have all the configuration data we need?
  39. integer eof = FALSE; // Have we reached the end of the configuration data?
  40. integer lastmessagetimestamp = 0;
  41. integer messagetimestamp = 0;
  42. ///// TRANSLATION /////
  43. // Link message channels
  44. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  45. integer SLOODLE_CHANNEL_TRANSLATION_RESPONSE = -1928374652;
  46. // Translation output methods
  47. string SLOODLE_TRANSLATE_LINK = "link"; // No output parameters - simply returns the translation on SLOODLE_TRANSLATION_RESPONSE link message channel
  48. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  49. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  50. string SLOODLE_TRANSLATE_SHOUT = "shout"; // 1 output parameter: chat channel number
  51. string SLOODLE_TRANSLATE_REGION_SAY = "regionsay"; // 1 output parameter: chat channel number
  52. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  53. 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.
  54. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  55. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  56. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  57. integer MENU_CHANNEL; //random channel used for dialogs
  58. integer listenHandle;
  59. string paramstr;
  60. string view_url;
  61. string admin_url;
  62. // Send a translation request link message
  63. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  64. {
  65. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  66. }
  67. ///// ----------- /////
  68. ///// FUNCTIONS /////
  69. integer randInt(integer n)
  70. {
  71. return (integer)llFrand(n + 1);
  72. }
  73. integer randIntBetween(integer min, integer max)
  74. {
  75. return min + randInt(max - min);
  76. }
  77. sloodle_error_code(string method, key avuuid,integer statuscode)
  78. {
  79. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST, method+"|"+(string)avuuid+"|"+(string)statuscode, NULL_KEY);
  80. }
  81. sloodle_debug(string msg)
  82. {
  83. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  84. }
  85. handle_points_notification(string str) {
  86. string changeduserid;
  87. string newbalance;
  88. list lines = llParseStringKeepNulls(str,["\n"],[]);
  89. integer l;
  90. // llOwnerSay("points notification: "+str);
  91. for(l=0; l<llGetListLength(lines); l++) {
  92. string line = llList2String(lines, l);
  93. list bits = llParseStringKeepNulls(line,["|"],[]);
  94. integer numbits = llGetListLength(bits);
  95. string name = llList2String(bits,0);
  96. string value = "";
  97. if (llGetListLength(bits) > 1) {
  98. value = llList2String(bits,1);
  99. }
  100. if (name == "balance") newbalance = value;
  101. if (name == "userid") changeduserid = value;
  102. if (name == "lastmessagetimestamp") lastmessagetimestamp = (integer)value;
  103. if (name == "messagetimestamp") messagetimestamp = (integer)value;
  104. }
  105. string hash = "#"+changeduserid+"_"+newbalance+"_"+(string)lastmessagetimestamp+"_"+(string)messagetimestamp;
  106. // llOwnerSay("About to update scoreboard for "+newbalance+" for user "+changeduserid);
  107. update_media(hash);
  108. lastmessagetimestamp = messagetimestamp;
  109. }
  110. //update screen
  111. update_media(string hash) {
  112. string url = view_url+hash;
  113. llSetPrimMediaParams( 1, [ PRIM_MEDIA_CURRENT_URL, url,
  114. PRIM_MEDIA_HOME_URL, url,
  115. PRIM_MEDIA_AUTO_ZOOM, TRUE,
  116. PRIM_MEDIA_AUTO_PLAY, TRUE,
  117. PRIM_MEDIA_PERMS_INTERACT,
  118. PRIM_MEDIA_PERM_ANYONE ] );
  119. // setup the control screen
  120. integer media_control;
  121. if ( sloodleobjectaccesslevelctrl == 0 ) media_control = PRIM_MEDIA_PERM_ANYONE;
  122. else if ( sloodleobjectaccesslevelctrl == 2 ) media_control = PRIM_MEDIA_PERM_GROUP;
  123. else media_control = PRIM_MEDIA_PERM_OWNER;
  124. }
  125. // Configure by receiving a linked message from another script in the object
  126. // Returns TRUE if the object has all the data it needs
  127. integer sloodle_handle_command(string str)
  128. {
  129. // llOwnerSay(str);
  130. list bits = llParseString2List(str,["|"],[]);
  131. integer numbits = llGetListLength(bits);
  132. string name = llList2String(bits,0);
  133. string value1 = "";
  134. string value2 = "";
  135. if (numbits > 1) value1 = llList2String(bits,1);
  136. if (numbits > 2) value2 = llList2String(bits,2);
  137. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  138. else if (name == "set:sloodlepwd") {
  139. // The password may be a single prim password, or a UUID and a password
  140. if (value2 != "") sloodlepwd = value1 + "|" + value2;
  141. else sloodlepwd = value1;
  142. } else if (name == "set:sloodlecontrollerid") sloodlecontrollerid = (integer)value1;
  143. else if (name == "set:sloodleobjectaccessleveluse") sloodleobjectaccessleveluse = (integer)value1;
  144. else if (name == "set:sloodleserveraccesslevel") sloodleserveraccesslevel = (integer)value1;
  145. else if (name == "set:sloodleobjectaccesslevelctrl") sloodleobjectaccesslevelctrl = (integer)value1;
  146. else if (name == "set:sloodlerefreshtime") sloodlerefreshtime = (integer)value1;
  147. else if (name == "set:sloodleshowallcontrollers") sloodleshowallcontrollers = (integer)value1;
  148. else if (name == "set:sloodlegroupid") sloodlegroupid = (integer)value1;
  149. else if (name == "set:sloodleroundid") sloodleroundid = (integer)value1;
  150. else if (name == SLOODLE_EOF) eof = TRUE;
  151. return (sloodleserverroot != "" && sloodlepwd != "" && sloodlecontrollerid > 0);
  152. }
  153. // Default state - waiting for configuration
  154. integer face=4;
  155. default
  156. {
  157. on_rez( integer param)
  158. {
  159. llResetScript();
  160. }
  161. state_entry()
  162. {
  163. llClearPrimMedia(face);
  164. // Starting again with a new configuration
  165. isconfigured = FALSE;
  166. eof = FALSE;
  167. // Reset our data
  168. sloodleserverroot = "";
  169. sloodlepwd = "";
  170. sloodlecontrollerid = 0;
  171. sloodlemoduleid = 0;
  172. sloodleobjectaccessleveluse = 0;
  173. sloodleobjectaccesslevelctrl = 0;
  174. sloodlegroupid = 0;
  175. sloodleshowallcontrollers = 0;
  176. sloodleroundid = 0;
  177. sloodlerefreshtime = 0;
  178. }
  179. link_message( integer sender_num, integer num, string str, key id)
  180. {
  181. // Check the channel
  182. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  183. // Split the message into lines
  184. list lines = llParseString2List(str, ["\n"], []);
  185. integer numlines = llGetListLength(lines);
  186. integer i = 0;
  187. for (i=0; i < numlines; i++) {
  188. isconfigured = sloodle_handle_command(llList2String(lines, i));
  189. }
  190. // If we've got all our data AND reached the end of the configuration data, then move on
  191. if (eof == TRUE) {
  192. if (isconfigured == TRUE) {
  193. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");
  194. state ready;
  195. } else {
  196. // Go all configuration but, it's not complete... request reconfiguration
  197. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [], NULL_KEY, "");
  198. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  199. eof = FALSE;
  200. }
  201. }
  202. }
  203. }
  204. touch_start(integer num_detected)
  205. {
  206. // Attempt to request a reconfiguration
  207. if (llDetectedKey(0) == llGetOwner()) {
  208. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:requestconfig", NULL_KEY);
  209. }
  210. }
  211. }
  212. state ready
  213. {
  214. on_rez( integer param)
  215. {
  216. llResetScript();
  217. }
  218. state_entry()
  219. {
  220. llClearPrimMedia(face);
  221. paramstr = "&sloodleobjuuid=" + (string)llGetKey();
  222. view_url= sloodleserverroot+"/mod/sloodle/mod/scoreboard-1.0/shared_media/index.php?" + paramstr;
  223. admin_url = sloodleserverroot+"/mod/sloodle/mod/scoreboard-1.0/shared_media/index.php?" + paramstr + "&mode=admin";
  224. update_media("");
  225. }
  226. state_exit()
  227. {
  228. llSetTimerEvent(0.0);
  229. }
  230. link_message( integer sender_num, integer num, string str, key id)
  231. {
  232. // Check the channel
  233. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  234. // Split the message into lines
  235. list lines = llParseString2List(str, ["\n"], []);
  236. integer numlines = llGetListLength(lines);
  237. integer i = 0;
  238. for (i=0; i < numlines; i++) {
  239. isconfigured = sloodle_handle_command(llList2String(lines, i));
  240. }
  241. } else if (num == SLOODLE_AWARDS_POINTS_CHANGE_NOTIFICATION) { // Awards points change notification
  242. handle_points_notification( str );
  243. }else
  244. if (num == SLOODLE_SCOREBOARD_CONNECT_HUD){
  245. llOwnerSay("Transmitting Scoreboard UUID to Owner's HUD");
  246. llRegionSay(SLOODLE_CHANNEL_SCOREBOARD_SHARED_MEDIA_SET_ADMIN_URL_CHANNEL, (string)admin_url+"|"+(string)id+"|"+(string)llGetKey());
  247. llShout(SLOODLE_CHANNEL_SCOREBOARD_SHARED_MEDIA_SET_ADMIN_URL_CHANNEL,(string)admin_url+"|"+(string)id+"|"+(string)llGetKey());
  248. }
  249. }
  250. }
  251. // Please leave the following line intact to show where the script lives in Git:
  252. // SLOODLE LSL Script Git Location: mod/scoreboard-1.0/objects/default/assets/sloodle_mod_scoreboard.lslp