sloodle_mod_primdrop-1.0.lslp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Sloodle PrimDrop (for Sloodle 0.3)
  4. // Allows students to submit SL objects as Moodle assignments.
  5. // Part of the Sloodle project (www.sloodle.org)
  6. //
  7. // Copyright (c) 2007-8 Sloodle
  8. // Released under the GNU GPL
  9. //
  10. // Contributors:
  11. // Jeremy Kemp
  12. // Peter R. Bloomfield
  13. // Paul Preibisch (Fire Centaur in SL)
  14. /// DATA ///
  15. // Sloodle constants
  16. integer SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST=-1828374651; // this channel is used to send status codes for translation to the error_messages lsl script
  17. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  18. integer SLOODLE_CHANNEL_AVATAR_DIALOG = 1001;
  19. string SLOODLE_PRIMDROP_LINKER = "/mod/sloodle/mod/primdrop-1.0/linker.php";
  20. string SLOODLE_ASSIGNMENT_VIEW = "/mod/assignment/view.php";
  21. string SLOODLE_EOF = "sloodleeof";
  22. integer SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC = 0;
  23. integer SLOODLE_OBJECT_ACCESS_LEVEL_OWNER = 1;
  24. integer SLOODLE_OBJECT_ACCESS_LEVEL_GROUP = 2;
  25. string SLOODLE_OBJECT_TYPE = "primdrop-1.0";
  26. integer SLOODLE_CHANNEL_PRIMDROP_INVENTORY = -1639270071;
  27. string PRIMDROP_RECEIVE_DROP = "do:receivedrop"; // Instructs the object to receive a drop
  28. string PRIMDROP_CANCEL_DROP = "do:canceldrop"; // Cancel drop receiving
  29. string PRIMDROP_FINISHED_DROP = "set:droppedobject"; // The drop has finished (object name passed as parameter after pipe character)
  30. // Configuration settings
  31. string sloodleserverroot = "";
  32. string sloodlepwd = "";
  33. integer sloodlecontrollerid = 0;
  34. integer sloodlemoduleid = 0;
  35. integer sloodleobjectaccessleveluse = 0; // Who can use this object?
  36. integer sloodleobjectaccesslevelctrl = 0; // Who can control this object?
  37. integer sloodleserveraccesslevel = 0; // Who can use the server resource? (Value passed straight back to Moodle)
  38. // Configuration status
  39. integer isconfigured = FALSE; // Do we have all the configuration data we need?
  40. integer eof = FALSE; // Have we reached the end of the configuration data?
  41. // This defines who is currently dropping or rezzing an item
  42. key current_user = NULL_KEY;
  43. // These lists are used when determining what inventory has been added
  44. list old_inventory = [];
  45. list new_inventory = [];
  46. // The name of the object which is being submitted
  47. string submit_obj = "";
  48. // HTTP request keys
  49. key httpcheck = NULL_KEY; // Request used to check the assignment
  50. key httpsubmit = NULL_KEY; // Request used to submit objects
  51. // Assignment information
  52. string assignmentname = "";
  53. string assignmentsummary = "";
  54. // Alternating list of keys, timestamps and page numbers, indicating who activated a dialog and when
  55. list cmddialog = [];
  56. // Menu button labels
  57. string MENU_BUTTON_CANCEL = "0";
  58. string MENU_BUTTON_SUMMARY = "1";
  59. string MENU_BUTTON_SUBMIT = "2";
  60. string MENU_BUTTON_ONLINE = "3";
  61. string MENU_BUTTON_TAKE_ALL = "4";
  62. // List of button labels ('cos otherwise the compiler runs out of memory!)
  63. //list teacherbuttons = [MENU_BUTTON_SUBMIT, MENU_BUTTON_ONLINE, MENU_BUTTON_TAKE_ALL,MENU_BUTTON_CANCEL, MENU_BUTTON_SUMMARY];
  64. // OpenSim chokes on this
  65. list teacherbuttons = ["3", "2", "4", "0", "1"];
  66. //list userbuttons = [MENU_BUTTON_SUMMARY, MENU_BUTTON_SUBMIT,MENU_BUTTON_ONLINE,MENU_BUTTON_CANCEL];
  67. list userbuttons = ["1", "2", "3", "0"];
  68. // The relative position at which items will be rezzed
  69. vector rez_pos = <0.0, 2.0, 1.0>;
  70. ///// TRANSLATION /////
  71. // Link message channels
  72. integer SLOODLE_CHANNEL_TRANSLATION_REQUEST = -1928374651;
  73. // Translation output methods
  74. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  75. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  76. 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.
  77. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  78. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  79. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  80. // Send a translation request link message
  81. sloodle_translation_request(string output_method, list output_params, string string_name, list string_params, key keyval, string batch)
  82. {
  83. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_TRANSLATION_REQUEST, output_method + "|" + llList2CSV(output_params) + "|" + string_name + "|" + llList2CSV(string_params) + "|" + batch, keyval);
  84. }
  85. ///// ----------- /////
  86. /// FUNCTIONS ///
  87. /******************************************************************************************************************************
  88. * sloodle_error_code -
  89. * Author: Paul Preibisch
  90. * Description - This function sends a linked message on the SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST channel
  91. * The error_messages script hears this, translates the status code and sends an instant message to the avuuid
  92. * Params: method - SLOODLE_TRANSLATE_SAY, SLOODLE_TRANSLATE_IM etc
  93. * Params: avuuid - this is the avatar UUID to that an instant message with the translated error code will be sent to
  94. * Params: status code - the status code of the error as on our wiki: http://slisweb.sjsu.edu/sl/index.php/Sloodle_status_codes
  95. *******************************************************************************************************************************/
  96. sloodle_error_code(string method, key avuuid,integer statuscode){
  97. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST, method+"|"+(string)avuuid+"|"+(string)statuscode, NULL_KEY);
  98. }
  99. sloodle_debug(string msg)
  100. {
  101. llMessageLinked(LINK_THIS, DEBUG_CHANNEL, msg, NULL_KEY);
  102. }
  103. sloodle_reset()
  104. {
  105. llSetText("", <0.0,0.0,0.0>, 0.0);
  106. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reset", NULL_KEY);
  107. llResetScript();
  108. }
  109. // Configure by receiving a linked message from another script in the object
  110. // Returns TRUE if the object has all the data it needs
  111. integer sloodle_handle_command(string str)
  112. {
  113. list bits = llParseString2List(str,["|"],[]);
  114. integer numbits = llGetListLength(bits);
  115. string name = llList2String(bits,0);
  116. string value1 = "";
  117. string value2 = "";
  118. if (numbits > 1) value1 = llList2String(bits,1);
  119. if (numbits > 2) value2 = llList2String(bits,2);
  120. if (name == "set:sloodleserverroot") sloodleserverroot = value1;
  121. else if (name == "set:sloodlepwd") {
  122. // The password may be a single prim password, or a UUID and a password
  123. if (value2 != "") sloodlepwd = value1 + "|" + value2;
  124. else sloodlepwd = value1;
  125. } else if (name == "set:sloodlecontrollerid") sloodlecontrollerid = (integer)value1;
  126. else if (name == "set:sloodlemoduleid") sloodlemoduleid = (integer)value1;
  127. else if (name == "set:sloodleobjectaccessleveluse") sloodleobjectaccessleveluse = (integer)value1;
  128. else if (name == "set:sloodleobjectaccesslevelctrl") sloodleobjectaccesslevelctrl = (integer)value1;
  129. else if (name == "set:sloodleserveraccesslevel") sloodleserveraccesslevel = (integer)value1;
  130. else if (name == SLOODLE_EOF) eof = TRUE;
  131. return (sloodleserverroot != "" && sloodlepwd != "" && sloodlecontrollerid > 0 && sloodlemoduleid > 0);
  132. }
  133. // Checks if the given agent is permitted to control this object
  134. // Returns TRUE if so, or FALSE if not
  135. integer sloodle_check_access_ctrl(key id)
  136. {
  137. // Check the access mode
  138. if (sloodleobjectaccesslevelctrl == SLOODLE_OBJECT_ACCESS_LEVEL_GROUP) {
  139. return llSameGroup(id);
  140. } else if (sloodleobjectaccesslevelctrl == SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC) {
  141. return TRUE;
  142. }
  143. // Assume it's owner mode
  144. return (id == llGetOwner());
  145. }
  146. // Checks if the given agent is permitted to user this object
  147. // Returns TRUE if so, or FALSE if not
  148. integer sloodle_check_access_use(key id)
  149. {
  150. // Check the access mode
  151. if (sloodleobjectaccessleveluse == SLOODLE_OBJECT_ACCESS_LEVEL_GROUP) {
  152. return llSameGroup(id);
  153. } else if (sloodleobjectaccessleveluse == SLOODLE_OBJECT_ACCESS_LEVEL_PUBLIC) {
  154. return TRUE;
  155. }
  156. // Assume it's owner mode
  157. return (id == llGetOwner());
  158. }
  159. // Add the given agent to our command dialog list
  160. sloodle_add_cmd_dialog(key id)
  161. {
  162. // Does the person already exist?
  163. integer pos = llListFindList(cmddialog, [id]);
  164. if (pos < 0) {
  165. // No - add the agent to the end
  166. cmddialog += [id, llGetUnixTime()];
  167. } else {
  168. // Yes - update the time
  169. cmddialog = llListReplaceList(cmddialog, [llGetUnixTime()], pos + 1, pos + 1);
  170. }
  171. }
  172. // Remove the given agent from our command dialog list
  173. sloodle_remove_cmd_dialog(key id)
  174. {
  175. // Is the person in the list?
  176. integer pos = llListFindList(cmddialog, [id]);
  177. if (pos >= 0) {
  178. // Yes - remove them and their timestamp
  179. cmddialog = llDeleteSubList(cmddialog, pos, pos + 1);
  180. }
  181. }
  182. // Purge the command dialog list of old activity
  183. sloodle_purge_cmd_dialog()
  184. {
  185. // Store the current timestamp
  186. integer curtime = llGetUnixTime();
  187. // Go through each command dialog
  188. integer i = 0;
  189. while (i < llGetListLength(cmddialog)) {
  190. // Is the current timestamp more than 12 seconds old?
  191. if ((curtime - llList2Integer(cmddialog, i + 1)) > 12) {
  192. // Yes - remove it
  193. cmddialog = llDeleteSubList(cmddialog, i, i + 1);
  194. } else {
  195. // No - advance to the next
  196. i += 2;
  197. }
  198. }
  199. }
  200. // Does the object have valid permissions?
  201. // Returns TRUE if so, or FALSE otherwise
  202. integer valid_perms(string obj)
  203. {
  204. integer perms_owner = llGetInventoryPermMask(obj, MASK_OWNER);
  205. integer perms_next = llGetInventoryPermMask(obj, MASK_NEXT);
  206. return (!((perms_owner & PERM_COPY) && (perms_owner & PERM_TRANSFER) && (perms_next & PERM_COPY) && (perms_next & PERM_TRANSFER)));
  207. }
  208. // Returns a list of all inventory
  209. list get_inventory(integer type)
  210. {
  211. list inv = [];
  212. integer num = llGetInventoryNumber(type);
  213. integer i = 0;
  214. for (i=0; i < num; i++) {
  215. if (llGetInventoryName(type, i)!="sloodle_config") //dont give away configuration files!
  216. inv += [llGetInventoryName(type, i)];
  217. }
  218. return inv;
  219. }
  220. // Checks and validates an inventory drop.
  221. // Returns TRUE if it is OK, or FALSE if not.
  222. integer sloodle_check_drop()
  223. {
  224. // Our new object is stored in variable "submit_obj"
  225. sloodle_translation_request(SLOODLE_TRANSLATE_HOVER_TEXT, [<1.0,0.0,0.0>, 0.9], "assignment:checkingitem", [], NULL_KEY, "assignment");
  226. // Make sure it exists
  227. if (llGetInventoryType(submit_obj) == INVENTORY_NONE || submit_obj == "") {
  228. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:submissionerror", [], NULL_KEY, "assignment");
  229. return FALSE;
  230. }
  231. // Make sure it is the correct type
  232. // *** Fire Centaur Change January 2010
  233. //--- changed this to accept all objects EXCEPT scripts.
  234. //if (llGetInventoryType(submit_obj) == INVENTORY_OBJECT) {
  235. if (llGetInventoryType(submit_obj) == INVENTORY_SCRIPT) {
  236. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:objectsonly", [], NULL_KEY, "assignment");
  237. llRemoveInventory(submit_obj);
  238. return FALSE;
  239. }
  240. // Determine the object ID and creator
  241. key obj_id = llGetInventoryKey(submit_obj);
  242. key obj_creator = llGetInventoryCreator(submit_obj);
  243. // Make sure the creator is the expected user
  244. if (obj_creator != current_user) {
  245. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:creatoronly", [], NULL_KEY, "assignment");
  246. llRemoveInventory(submit_obj);
  247. return FALSE;
  248. }
  249. // Make sure the permissions are correct
  250. if (valid_perms(submit_obj)) {
  251. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:invalidperms", [], NULL_KEY, "assignment");
  252. llRemoveInventory(submit_obj);
  253. return FALSE;
  254. }
  255. // Seems OK - submit it
  256. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:itemok", [submit_obj, llKey2Name(current_user)], NULL_KEY, "assignment");
  257. return TRUE;
  258. }
  259. /// STATES ///
  260. // Default state - waiting for configuration
  261. default
  262. {
  263. state_entry()
  264. {
  265. // Starting again with a new configuration
  266. isconfigured = FALSE;
  267. eof = FALSE;
  268. // Reset our data
  269. sloodleserverroot = "";
  270. sloodlepwd = "";
  271. sloodlecontrollerid = 0;
  272. sloodlemoduleid = 0;
  273. sloodleobjectaccessleveluse = 0;
  274. sloodleobjectaccesslevelctrl = 0;
  275. sloodleserveraccesslevel = 0;
  276. }
  277. link_message( integer sender_num, integer num, string str, key id)
  278. {
  279. // Check the channel
  280. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  281. // Split the message into lines
  282. list lines = llParseString2List(str, ["\n"], []);
  283. integer numlines = llGetListLength(lines);
  284. integer i = 0;
  285. for (i=0; i < numlines; i++) {
  286. isconfigured = sloodle_handle_command(llList2String(lines, i));
  287. }
  288. // If we've got all our data AND reached the end of the configuration data, then move on
  289. if (eof == TRUE) {
  290. if (isconfigured == TRUE) {
  291. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configurationreceived", [], NULL_KEY, "");
  292. state check_assignment;
  293. } else {
  294. // Got all configuration but, it's not complete... request reconfiguration
  295. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "configdatamissing", [], NULL_KEY, "");
  296. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:reconfigure", NULL_KEY);
  297. eof = FALSE;
  298. }
  299. }
  300. }
  301. }
  302. touch_start(integer num_detected)
  303. {
  304. // Attempt to request a reconfiguration
  305. if (llDetectedKey(0) == llGetOwner()) {
  306. llMessageLinked(LINK_THIS, SLOODLE_CHANNEL_OBJECT_DIALOG, "do:requestconfig", NULL_KEY);
  307. }
  308. }
  309. }
  310. // Checking that the assignment is accessible
  311. state check_assignment
  312. {
  313. state_entry()
  314. {
  315. // Check the assignment details
  316. sloodle_translation_request(SLOODLE_TRANSLATE_HOVER_TEXT, [<0.0,1.0,0.0>, 0.9], "assignment:checking", [], NULL_KEY, "assignment");
  317. string body = "sloodlecontrollerid=" + (string)sloodlecontrollerid;
  318. body += "&sloodlepwd=" + sloodlepwd;
  319. body += "&sloodlemoduleid=" + (string)sloodlemoduleid;
  320. httpcheck = llHTTPRequest(sloodleserverroot + SLOODLE_PRIMDROP_LINKER, [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], body);
  321. llSetTimerEvent(0.0);
  322. llSetTimerEvent(8.0);
  323. }
  324. state_exit()
  325. {
  326. llSetTimerEvent(0.0);
  327. httpcheck = NULL_KEY;
  328. llSetText("", <0.0,0.0,0.0>, 0.0);
  329. }
  330. timer()
  331. {
  332. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "httptimeout", [], NULL_KEY, "");
  333. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "resetting", [], NULL_KEY, "");
  334. sloodle_reset();
  335. }
  336. http_response(key id, integer status, list meta, string body)
  337. {
  338. // Is this the expected data?
  339. if (id != httpcheck) return;
  340. httpcheck = NULL_KEY;
  341. // Check that we got a proper response
  342. if (status != 200) {
  343. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "httperror:code", [status], NULL_KEY, "");
  344. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "resetting", [], NULL_KEY, "");
  345. sloodle_error_code(SLOODLE_TRANSLATE_SAY, NULL_KEY,status); //send message to error_message.lsl
  346. sloodle_reset();
  347. return;
  348. }
  349. if (body == "") {
  350. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "httpempty", [], NULL_KEY, "");
  351. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "resetting", [], NULL_KEY, "");
  352. sloodle_reset();
  353. return;
  354. }
  355. // Split the data up into lines
  356. list lines = llParseStringKeepNulls(body, ["\n"], []);
  357. integer numlines = llGetListLength(lines);
  358. // Extract all the status fields
  359. list statusfields = llParseStringKeepNulls( llList2String(lines,0), ["|"], [] );
  360. // Get the statuscode
  361. integer statuscode = llList2Integer(statusfields,0);
  362. // Was it an error code?
  363. if (statuscode == -601) {
  364. // Failed to connect to the assignment, possibly because it is the wrong type, or because it is invisible
  365. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:connectionfailed", [], NULL_KEY, "assignment");
  366. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "resetting", [], NULL_KEY, "");
  367. sloodle_reset();
  368. return;
  369. } else if (statuscode <= 0) {
  370. // Get the error message if one was given
  371. if (numlines > 1) {
  372. string errmsg = llList2String(lines, 1);
  373. sloodle_debug("ERROR " + (string)statuscode + ": " + errmsg);
  374. }
  375. //sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "servererror", [statuscode], NULL_KEY, "");
  376. sloodle_error_code(SLOODLE_TRANSLATE_SAY, NULL_KEY,statuscode); //send message to error_message.lsl
  377. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "resetting", [], NULL_KEY, "");
  378. sloodle_reset();
  379. return;
  380. }
  381. // Extract the assignment information
  382. assignmentname = llList2String(lines, 1);
  383. assignmentsummary = llList2String(lines, 2);
  384. llSay(0, assignmentsummary);
  385. state ready;
  386. }
  387. on_rez(integer param)
  388. {
  389. state default;
  390. }
  391. }
  392. // Ready to be used
  393. state ready
  394. {
  395. state_entry()
  396. {
  397. // Display summary information
  398. sloodle_translation_request(SLOODLE_TRANSLATE_HOVER_TEXT, [<1.0,0.5,0.0>, 1.0], "assignment:ready", [assignmentname], NULL_KEY, "assignment");
  399. // Listen for dialog commands from any avatar
  400. llListen(SLOODLE_CHANNEL_AVATAR_DIALOG, "", NULL_KEY, "");
  401. // Regularly purge the list of dialog user entries
  402. llSetTimerEvent(0.0);
  403. llSetTimerEvent(12.0);
  404. // Clear our current user, to avoid any confusion
  405. current_user = NULL_KEY;
  406. }
  407. state_exit()
  408. {
  409. llSetTimerEvent(0.0);
  410. llSetText("", <0.0,0.0,0.0>, 0.0);
  411. }
  412. touch_start(integer num_detected)
  413. {
  414. // Go through each toucher
  415. integer i = 0;
  416. key id = NULL_KEY;
  417. integer level = 0;
  418. for (i=0; i < num_detected; i++) {
  419. id = llDetectedKey(i);
  420. // Can this avatar use and/or control this item?
  421. if (sloodle_check_access_ctrl(id)) level = 2;
  422. else if (sloodle_check_access_use(id)) level = 1;
  423. // Show the appropriate menu, or report the lack of permission
  424. if (level == 2) {
  425. // Teacher menu
  426. sloodle_add_cmd_dialog(id);
  427. sloodle_translation_request(SLOODLE_TRANSLATE_DIALOG, [SLOODLE_CHANNEL_AVATAR_DIALOG] + teacherbuttons, "assignment:primdropteachermenu", [0,1,2,3,4], id, "assignment");
  428. } else if (level == 1) {
  429. // General user menu
  430. sloodle_add_cmd_dialog(id);
  431. sloodle_translation_request(SLOODLE_TRANSLATE_DIALOG, [SLOODLE_CHANNEL_AVATAR_DIALOG] + userbuttons, "assignment:primdropmenu", [0,1,2,3], id, "assignment");
  432. } else {
  433. // Report the lack of permission
  434. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "nopermission:use", [llDetectedName(i)], NULL_KEY, "");
  435. }
  436. }
  437. }
  438. listen(integer channel, string name, key id, string msg)
  439. {
  440. // Check the channel
  441. if (channel == SLOODLE_CHANNEL_AVATAR_DIALOG) {
  442. // Ignore non-avatars
  443. if (llGetOwnerKey(id) != id) return;
  444. // Make sure we are listening to this user
  445. if (llListFindList(cmddialog, [id]) < 0) return;
  446. sloodle_remove_cmd_dialog(id);
  447. // Make sure the given user is allowed to use this object
  448. if (!sloodle_check_access_use(id)) {
  449. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "nopermission:use", [name], NULL_KEY, "");
  450. return;
  451. }
  452. // Check if the user can control this item
  453. integer canctrl = sloodle_check_access_ctrl(id);
  454. // Store the user
  455. current_user = id;
  456. // Check the command
  457. if (msg == MENU_BUTTON_CANCEL) {
  458. // Cancel the menu
  459. // Nothing to do
  460. return;
  461. } else if (msg == MENU_BUTTON_SUMMARY) {
  462. // Chat the assignment summary text
  463. llSay(0, assignmentsummary);
  464. } else if (msg == MENU_BUTTON_SUBMIT) {
  465. // Wait for a drop
  466. state drop;
  467. } else if (msg == MENU_BUTTON_ONLINE) {
  468. // Give the user a URL
  469. llLoadURL(id, assignmentname, sloodleserverroot + SLOODLE_ASSIGNMENT_VIEW + "?id=" + (string)sloodlemoduleid);
  470. } else if (msg == MENU_BUTTON_TAKE_ALL && canctrl) {
  471. // User wants to take all objects to their inventory
  472. list inv;
  473. inv+= get_inventory(INVENTORY_ANIMATION);
  474. inv+= get_inventory(INVENTORY_GESTURE);
  475. inv+= get_inventory(INVENTORY_LANDMARK);
  476. inv+= get_inventory(INVENTORY_NOTECARD);
  477. inv+= get_inventory(INVENTORY_OBJECT);
  478. if (inv == []) {
  479. // No submissions available
  480. sloodle_translation_request(SLOODLE_TRANSLATE_IM, [], "assignment:nosubmissions", [], id, "assignment");
  481. } else {
  482. // Give all items into a new folder
  483. llGiveInventoryList(id, assignmentname, inv);
  484. sloodle_translation_request(SLOODLE_TRANSLATE_IM, [], "assignment:allgiven", [assignmentname], id, "assignment");
  485. }
  486. }
  487. }
  488. }
  489. on_rez(integer param)
  490. {
  491. state default;
  492. }
  493. }
  494. // Waiting for an object to be dropped
  495. state drop
  496. {
  497. state_entry()
  498. {
  499. // Instruct the inventory manager to receive a drop
  500. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_PRIMDROP_INVENTORY, PRIMDROP_RECEIVE_DROP, NULL_KEY);
  501. // Prepare to receive a submission
  502. sloodle_translation_request(SLOODLE_TRANSLATE_HOVER_TEXT, [<0.0,0.5,1.0>, 1.0], "assignment:waitingforsubmission", [llKey2Name(current_user)], NULL_KEY, "assignment");
  503. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:dropsubmission", [llKey2Name(current_user)], NULL_KEY, "assignment");
  504. // Allow the user 60 seconds to make their submission
  505. llSetTimerEvent(0.0);
  506. llSetTimerEvent(60.0);
  507. }
  508. state_exit()
  509. {
  510. llSetTimerEvent(0.0);
  511. }
  512. timer()
  513. {
  514. // Submission timed-out
  515. llSetTimerEvent(0.0);
  516. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:submittimeout", [llKey2Name(current_user)], NULL_KEY, "assignment");
  517. llMessageLinked(LINK_SET, SLOODLE_CHANNEL_PRIMDROP_INVENTORY, PRIMDROP_CANCEL_DROP, NULL_KEY);
  518. state ready;
  519. }
  520. link_message(integer sender_num, integer num, string sval, key kval)
  521. {
  522. // Check the channel
  523. if (num == SLOODLE_CHANNEL_PRIMDROP_INVENTORY) {
  524. // Split the message
  525. list parts = llParseStringKeepNulls(sval, ["|"], []);
  526. if (llGetListLength(parts) < 2) return;
  527. string cmd = llList2String(parts, 0);
  528. string val = llList2String(parts, 1);
  529. // Check the command
  530. if (cmd == PRIMDROP_FINISHED_DROP) {
  531. // Cancel the timeout
  532. llSetTimerEvent(0.0);
  533. // Store the submitted object and check it
  534. submit_obj = val;
  535. if (sloodle_check_drop()) state submitting;
  536. else state ready;
  537. }
  538. }
  539. }
  540. on_rez(integer param)
  541. {
  542. state default;
  543. }
  544. }
  545. // Submitting an object which was dropped
  546. state submitting
  547. {
  548. state_entry()
  549. {
  550. if (submit_obj == "") {
  551. llSay(0, "ERROR: no object to submit.");
  552. state ready;
  553. return;
  554. }
  555. // Check the assignment details
  556. sloodle_translation_request(SLOODLE_TRANSLATE_HOVER_TEXT, [<1.0,0.0,0.0>, 0.9], "assignment:submitting", [llKey2Name(current_user)], NULL_KEY, "assignment");
  557. // Build the body of data
  558. string body = "sloodlecontrollerid=" + (string)sloodlecontrollerid;
  559. body += "&sloodlepwd=" + sloodlepwd;
  560. body += "&sloodlemoduleid=" + (string)sloodlemoduleid;
  561. body += "&sloodleuuid=" + (string)current_user;
  562. body += "&sloodleavname=" + llEscapeURL(llKey2Name(current_user));
  563. body += "&sloodleserveraccesslevel=" + (string)sloodleserveraccesslevel;
  564. body += "&sloodleobjname=" + submit_obj;
  565. body += "&sloodleprimcount=" + (string)llGetObjectPrimCount(llGetInventoryKey(submit_obj));
  566. body += "&sloodleprimdropname=" + llGetObjectName();
  567. body += "&sloodleprimdropuuid=" + (string)llGetKey();
  568. body += "&sloodleregion=" + llGetRegionName();
  569. body += "&sloodlepos=" + (string)llGetPos();
  570. // Send the HTTP request
  571. httpsubmit = llHTTPRequest(sloodleserverroot + SLOODLE_PRIMDROP_LINKER, [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], body);
  572. llSetTimerEvent(0.0);
  573. llSetTimerEvent(8.0);
  574. }
  575. state_exit()
  576. {
  577. llSetTimerEvent(0.0);
  578. httpsubmit = NULL_KEY;
  579. llSetText("", <0.0,0.0,0.0>, 0.0);
  580. }
  581. timer()
  582. {
  583. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "httptimeout", [], NULL_KEY, "");
  584. state ready;
  585. }
  586. http_response(key id, integer status, list meta, string body)
  587. {
  588. // Is this the expected data?
  589. if (id != httpsubmit) return;
  590. httpsubmit = NULL_KEY;
  591. // Check that we got a proper response
  592. if (status != 200) {
  593. sloodle_error_code(SLOODLE_TRANSLATE_SAY, NULL_KEY,status); //send message to error_message.lsl
  594. state ready;
  595. return;
  596. }
  597. if (body == "") {
  598. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "httpempty", [], NULL_KEY, "");
  599. state ready;
  600. return;
  601. }
  602. // Split the data up into lines
  603. list lines = llParseStringKeepNulls(body, ["\n"], []);
  604. integer numlines = llGetListLength(lines);
  605. // Extract all the status fields
  606. list statusfields = llParseStringKeepNulls( llList2String(lines,0), ["|"], [] );
  607. integer statuscode = llList2Integer(statusfields,0);
  608. // Get the user's name
  609. string current_user_name = llKey2Name(current_user);
  610. // Has an error been reported?
  611. if (statuscode < 0) {
  612. // Check if it's a known code
  613. if (statuscode == -10201) sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:nopermission", [current_user_name], NULL_KEY, "assignment");
  614. else if (statuscode == -10202) sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:early", [current_user_name], NULL_KEY, "assignment");
  615. else if (statuscode == -10203) sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:late", [current_user_name], NULL_KEY, "assignment");
  616. else if (statuscode == -10205) sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:noresubmit", [current_user_name], NULL_KEY, "assignment");
  617. else {
  618. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:submissionfailed", [current_user_name, statuscode], NULL_KEY, "assignment");
  619. sloodle_error_code(SLOODLE_TRANSLATE_SAY, NULL_KEY,statuscode); //send message to error_message.lsl
  620. }
  621. // Debug output, if possible
  622. if (numlines > 1) {
  623. string errmsg = llList2String(lines, 1);
  624. sloodle_debug("ERROR " + (string)statuscode + ": " + errmsg);
  625. }
  626. state ready;
  627. return;
  628. }
  629. // Success
  630. sloodle_translation_request(SLOODLE_TRANSLATE_SAY, [0], "assignment:submissionok", [current_user_name], NULL_KEY, "assignment");
  631. state ready;
  632. }
  633. on_rez(integer param)
  634. {
  635. state default;
  636. }
  637. }
  638. // Please leave the following line intact to show where the script lives in Git:
  639. // SLOODLE LSL Script Git Location: mod/primdrop-1.0/objects/default/assets/sloodle_mod_primdrop-1.0.lslp