sloodle_error_message_handler.lslp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. /**********************************************************************************************
  4. * sloodle_error_message_handler.lsl
  5. * Copyright (c) 2009 Paul Preibisch
  6. * Released under the GNU GPL 3.0
  7. * This script can be used in your scripts, but you must include this copyright header
  8. * as per the GPL Licence
  9. * For more information about GPL 3.0 - see: http://www.gnu.org/copyleft/gpl.html
  10. *
  11. * This script is intended to translate error messages sent via linked messages from sloodle scripts.
  12. * All Sloodle Status codes from our wiki at: http://slisweb.sjsu.edu/sl/index.php/Sloodle_status_codes
  13. * have been added to an LSL list. I have also added standard HTTP error status's so we can give more
  14. * detailed information to our lovely sloodlers during the confuration stage of Sloodle.
  15. *
  16. * USE: To use this script, simply include our premade function "sloodle_error_code" in your script
  17. * sloodle_error_code(string method, key avuuid,integer statuscode){
  18. * llMessageLinked(LINK_SET, SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST, method+"|"+(string)avuuid+"|
  19. * +(string)statuscode, NULL_KEY);
  20. * }
  21. *
  22. * Then in your code, use it like: sloodle_error_code(SLOODLE_TRANSLATE_SAY, NULL_KEY,statuscode);
  23. *
  24. * All messages should be sent on this channel:
  25. * integer SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST=-1828374651;
  26. *
  27. * This script is part of the SLOODLE Project see http://sloodle.org
  28. *
  29. * Copyright
  30. * Paul G. Preibisch (Fire Centaur in SL) fire@b3dMultiTech.com
  31. * Edmund Edgar
  32. /**********************************************************************************************/
  33. integer SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST=-1828374651;
  34. list errorMessages;
  35. // Translation output methods
  36. string SLOODLE_TRANSLATE_LINK = "link"; // No output parameters - simply returns the translation on SLOODLE_TRANSLATION_RESPONSE link message channel
  37. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  38. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  39. string SLOODLE_TRANSLATE_SHOUT = "shout"; // 1 output parameter: chat channel number
  40. string SLOODLE_TRANSLATE_REGION_SAY = "regionsay"; // 1 output parameter: chat channel number
  41. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  42. 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.
  43. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  44. string SLOODLE_TRANSLATE_LOAD_URL_PARALLEL = "loadurlpar"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  45. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  46. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  47. string sloodle_get_error_string(integer statusCode){
  48. list found =fncFindStride(errorMessages, [statusCode],3);
  49. integer index = llList2Integer(found,0);
  50. list values;
  51. string trans;
  52. if (llList2Integer(found,0)!=-1){
  53. values = fncGetStride(errorMessages, index, 3); //will return a stride of len 3 - ie: [-213,"error message"]
  54. trans = llList2String(values,1);
  55. }
  56. return trans;
  57. }
  58. /****************************************************************
  59. * integer fncStrideCount(list source, integer stride)
  60. *
  61. * Returns the number of strides found within a list.
  62. * Source is the list to operate on, and stride is the length of each stride within the list.
  63. * list Source = ["A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"];
  64. * integer Result = fncStrideCount(Source, 3);
  65. * Returns 3
  66. * Returns number of Strides in a List
  67. *********************************************************************/
  68. integer fncStrideCount(list lstSource, integer intStride)
  69. {
  70. return llGetListLength(lstSource) / intStride;
  71. }
  72. /*********************************************************************
  73. * list fncGetStride(list source, integer index, integer stride)
  74. * Returns a single stride from the list.
  75. * Source is the list to retrieve from, index is which stride to return (zero indexed), and stride is the length of each stride.
  76. * list Source = ["A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"];
  77. *
  78. * list Result = fncGetStride(Source, 1, 3);
  79. *
  80. * Returns ["B1", "B2", "B3"]
  81. * On failure returns an empty list
  82. **********************************************************************/
  83. list fncGetStride(list lstSource, integer intIndex, integer intStride)
  84. {
  85. integer intNumStrides = fncStrideCount(lstSource, intStride);
  86. if (intNumStrides != 0 && intIndex < intNumStrides)
  87. {
  88. integer intOffset = intIndex * intStride;
  89. return llList2List(lstSource, intOffset, intOffset + (intStride - 1));
  90. }
  91. return [];
  92. }
  93. /****************************************************************
  94. * list fncFindStride(list source, list item, integer stride)
  95. *
  96. * Returns the stride number and element number of an element within a stride, within a list. (zero indexed)
  97. * Source is the list to search, item is a single element list containing the item to search for, and stride is the length of each stride.
  98. * list Source = ["A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"];
  99. * list Item = ["B3"];
  100. *
  101. * list Result = fncFindStride(Source, Item, 3);
  102. * Returns [1, 2].
  103. * The first number is which stride Item is in.
  104. * The second is which element of the stride is Item.
  105. *
  106. * If item is not found, it will return [-1, -1]
  107. *********************************************************************/
  108. list fncFindStride(list lstSource, list lstItem, integer intStride)
  109. {
  110. integer intListIndex = llListFindList(lstSource, lstItem);
  111. if (intListIndex == -1) { return [-1, -1]; }
  112. integer intStrideIndex = intListIndex / intStride;
  113. integer intSubIndex = intListIndex % intStride;
  114. return [intStrideIndex, intSubIndex];
  115. }
  116. default {
  117. on_rez(integer start_param) {
  118. llResetScript();
  119. }
  120. state_entry() {
  121. errorMessages=[-1 ,"An unspecified error occured","MISC"];
  122. errorMessages+=[-101,"An unknown system error occured","SYSTEM"];
  123. errorMessages+=[-102,"Could not connect to the database.","SYSTEM"];
  124. errorMessages+=[-103,"Could not fetch data we expected to be there. ","SYSTEM"];
  125. errorMessages+=[-104,"Data formatting error ","SYSTEM"];
  126. errorMessages+=[-105,"XMLRPC error","SYSTEM"];
  127. errorMessages+=[-106,"The Sloodle module is not installed in Moodle ","SYSTEM"];
  128. errorMessages+=[-111,"System is temporarily down for maintenance. ","SYSTEM"];
  129. errorMessages+=[-121,"Failed to send required email ","SYSTEM"];
  130. errorMessages+=[-131,"Failed to load plugins ","PLUGIN"];
  131. errorMessages+=[-132,"The required plugin was not found ","PLUGIN"];
  132. errorMessages+=[-201,"There was an unspecified problem authenticating the object. ","OBJECT_AUTH"];
  133. errorMessages+=[-212,"Object did not supply the necessary information to authenticate itself. ","OBJECT_AUTH"];
  134. errorMessages+=[-213,"Object authentication key was invalid ","OBJECT_AUTH"];
  135. errorMessages+=[-214,"Object not authorised in this context ","OBJECT_AUTH"];
  136. errorMessages+=[-215,"Prim password access has been disabled for this Controller. ","OBJECT_AUTH"];
  137. errorMessages+=[-216,"Object not found in database","USER_AUTH"];
  138. errorMessages+=[-217,"Could not save HTTP-in URL (v2.0 etc)","OBJECT_AUTH"];
  139. errorMessages+=[-218,"Active object not found while trying to save HTTP-in URL (v2.0 etc)","OBJECT_AUTH"];
  140. errorMessages+=[-219,"Sending configuration to object via HTTP-in URL failed","OBJECT_AUTH"];
  141. errorMessages+=[-301,"There was an unspecified problem authenticating the user. ","USER_AUTH"];
  142. errorMessages+=[-311,"Object did not supply the necessary information to authenticate the user. ","USER_AUTH"];
  143. errorMessages+=[-321,"User was not registered and we weren't allowed to register them automatically. ","USER_AUTH"];
  144. errorMessages+=[-322,"User was not registered and we tried to register them but failed. ","USER_AUTH"];
  145. errorMessages+=[-331,"User did not have permission to access the resources requested . ","USER_AUTH"];
  146. errorMessages+=[-341,"Password cannot be reset via Sloodle, as user was not auto-registered (or has since registered an email account). ","USER_AUTH"];
  147. errorMessages+=[-401,"There was an unspecified problem involving course enrolment. ","USER_ENROL"];
  148. errorMessages+=[-421,"User was not enrolled on the course and we weren't allowed to enrol them automatically","USER_ENROL"];
  149. errorMessages+=[-422,"User was not enrolled on the course and tried to enrol them but failed. ","USER_ENROL"];
  150. errorMessages+=[-501,"There was an unspecified problem involving the course you ar trying to use. ","COURSE"];
  151. errorMessages+=[-511,"The course you are trying to use was not specified. ","COURSE"];
  152. errorMessages+=[-512,"The course you are trying to use was not found. ","COURSE"];
  153. errorMessages+=[-513,"The course you are trying to use was inactive. ","COURSE"];
  154. errorMessages+=[-514,"The course you are trying to use was forbidden from being used with Sloodle. ","COURSE"];
  155. errorMessages+=[-601,"There was an unspecifed problem involving the module you're trying to use. ","MODULE"];
  156. errorMessages+=[-611,"The module you are trying to use was not specified.","MODULE"];
  157. errorMessages+=[-612,"The module you are trying to use was found. ","MODULE"];
  158. errorMessages+=[-613,"The module you are trying to use was inactive. ","MODULE"];
  159. errorMessages+=[-614,"The module you are trying to use was forbidden from being used by Sloodle. ","MODULE"];
  160. errorMessages+=[-701,"There was an unspecifed problem involving the module instance you're trying to use. ","MODULE_INSTANCE"];
  161. errorMessages+=[-711,"The module instance you are trying to use was not specified. ","MODULE_INSTANCE"];
  162. errorMessages+=[-712,"The module instance you are trying to use was not found. ","MODULE_INSTANCE"];
  163. errorMessages+=[-713,"The module instance you are trying to use was inactive. ","MODULE_INSTANCE"];
  164. errorMessages+=[-714,"The module instance you are trying to use was forbidden from being used by Sloodle. ","MODULE_INSTANCE"];
  165. errorMessages+=[-801,"Requested script permanently deleted. ","REQUEST"];
  166. errorMessages+=[-802,"Requested script moved (new location may be specified in the first data line) ","REQUEST"];
  167. errorMessages+=[-811,"Request incomplete (not all required data present) ","REQUEST"];
  168. errorMessages+=[-812,"Requested resource could not be found (although the request itself was handled successfully) ","REQUEST"];
  169. errorMessages+=[-901,"Unknown profile error ","PROFILE"];
  170. errorMessages+=[-902,"Profile does not exist ","PROFILE"];
  171. errorMessages+=[-903,"Profile already exists ","PROFILE"];
  172. errorMessages+=[-904,"Unknown profile command ","PROFILE"];
  173. errorMessages+=[-777000,"Transaction for this user was not found","TRANSACTION"];
  174. errorMessages+=[10001,"Obtained results successfully","CHOICE_QUERY"];
  175. errorMessages+=[10011,"Added new choice selection for user ","CHOICE_SELECT"];
  176. errorMessages+=[10012,"Updated choice selection for user ","CHOICE_SELECT"];
  177. errorMessages+=[10013,"User had previously selected the same option ","CHOICE_SELECT"];
  178. errorMessages+=[10101,"Successfully added a chat message into the database (commonly used as a side-effect code) ","CHAT_MESSAGE"];
  179. errorMessages+=[-10001,"Unable to query choice status for unknown reason ","CHOICE_QUERY"];
  180. errorMessages+=[-10011,"The user has already selected a choice, and choices cannot be updated ","CHOICE_SELECT"];
  181. errorMessages+=[-10012,"Maximum number of selections for this choice already made ","CHOICE_SELECT"];
  182. errorMessages+=[-10013,"Choice is not yet open for selections ","CHOICE_SELECT"];
  183. errorMessages+=[-10014,"Choice has been closed ","CHOICE_SELECT"];
  184. errorMessages+=[-10015,"Specified option not found in choice ","CHOICE_SELECT"];
  185. errorMessages+=[-10016,"Unable to make choice selection for unknown reason (usually more data appended in data lines) ","CHOICE_SELECT"];
  186. errorMessages+=[-10021,"Unable to query list of choice instances for unknown reason ","CHOICE_LIST_QUERY"];
  187. errorMessages+=[-10022,"Not choice instances available in course ","CHOICE_LIST_QUERY"];
  188. errorMessages+=[-10101,"Failed to add chat message to database ","CHAT_MESSAGE"];
  189. errorMessages+=[-10201,"User is not authorised to submit assignments ","ASSIGNMENT"];
  190. errorMessages+=[-10202,"Assignment is not yet open for submissions ","ASSIGNMENT"];
  191. errorMessages+=[-10203,"Assignment due date has passed, and is closed for submissions ","ASSIGNMENT"];
  192. errorMessages+=[-10204,"Assignment due date has passed, but is still accepting submissions (typically a side effect code) ","ASSIGNMENT"];
  193. errorMessages+=[-10205,"Resubmissions are not permitted ","ASSIGNMENT"];
  194. errorMessages+=[-10301,"Student has used all quiz attempts ","QUIZ"];
  195. errorMessages+=[-10302,"Quiz requires password - this is not supported by Sloodle ","QUIZ"];
  196. errorMessages+=[-10303," Error loading questions ","QUIZ"];
  197. errorMessages+=[-10401,"Blogging is disabled on this site. ","BLOG"];
  198. errorMessages+=[-10402,"User does not have permission to write blogs ","BLOG"];
  199. errorMessages+=[-10501,"There are no slides in this presentation. ","PRESENTER"];
  200. errorMessages+=[301 ,"HTTP Server error (301)\"Moved Permanently\" - The page you are trying to connect to has moved","HTTP"];
  201. string errMess= "HTTP Server error (400)\"Bad Request\" - The Web server considers the data stream ";
  202. errMess+= "sent by your Second Life object to be 'malformed' i.e. it has not sent a complete HTTP request. In such cases ";
  203. errMess+= "the web server is unable to process the request. Have you recently added beta code to your server?";
  204. errorMessages+=[400 ,errMess,"HTTP"];
  205. errMess = "HTTP Server error (401) \"Unauthorized\" - It seams Sloodle is trying to access a password protected directory on ";
  206. errMess+= "your server. In such cases you should check whether you have specified the correct folder during installation.";
  207. errorMessages+=[401 ,errMess,"HTTP"];
  208. errMess = "HTTP Server error (403) \"Forbidden\" - This error message means that Sloodle is trying to open a folder or a file ";
  209. errMess += "it does not have access to. If you are receiving this error message on your website, you should check the .htaccess files in your ";
  210. errMess += "web hosting account for any restrictive rules.";
  211. errorMessages+=[403 ,errMess,"HTTP"];
  212. errMess = "HTTP Server error (404) \"Not Found\" - It seams Sloodle is trying to access a non-existent page or a folder. ";
  213. errMess += "In such cases you should check if the link you are trying to access is correct.";
  214. errorMessages+=[404 ,errMess,"HTTP"];
  215. errMess ="An internal server error has occured. This is a standard HTTP 500 error, Perhaps Sloodle is trying to access code that is broken. Have you installed any beta software recently? Make sure you make backups before upgrading your Sloodle. ";
  216. errMess +="Error 500 is a \'catch-all\' error generated by the Web server. Basically something has gone wrong, but the server can not be more specific about the error condition in its response to Sloodle.";
  217. errorMessages+=[500 ,errMess,"HTTP"];
  218. errMess = "An HTTP 503 error has occured. This is a standard HTTP error that means \"Service Unavailable.\"";
  219. errMess +="It can have nothing to do with Sloodle - but instead, an essential program on your server may have crashed";
  220. errMess +=" You often see HTTP 503 when a website has exceeded its monthly bandwidth allowance";
  221. errMess +=" It could also mean a connection to a database has failed or is misconfigured. Most likely, you never typed the address of your sloodle website correctly during the Sloodle configuration stage.";
  222. errMess +="Click the mouse on the object you are trying to configure, and try again with the correct address.";
  223. errorMessages+=[503 ,errMess,"HTTP"];
  224. }
  225. link_message(integer sender_num, integer channel, string str, key id) {
  226. if (channel==SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST){
  227. //message will be in the format
  228. //status code|senderuuid;
  229. list fields = llParseStringKeepNulls(str, ["|"], []);
  230. integer numfields = llGetListLength(fields);
  231. string method= llList2String(fields,0);
  232. key senderUuid = llList2Key(fields,1);
  233. integer statusCode = llList2Integer(fields,2);
  234. //TRANSLATE status code//
  235. string trans = sloodle_get_error_string(statusCode);
  236. if (trans == "") {
  237. // Error code missing.
  238. // In Sloodle 2, the script sending the error may send us a message to say to the user.
  239. // For example, if you don't have enough points to use an object, there may be a user-defined message telling you that.
  240. // If we intended to produce a message in the right language on the server side, we leave the error string undefined on purpose.
  241. if (llGetListLength(fields) > 3) {
  242. trans = llList2String(fields,3);
  243. }
  244. }
  245. if (trans!=""){
  246. if (method == SLOODLE_TRANSLATE_SAY) llSay(0,"Error Message: "+trans);
  247. else if (method==SLOODLE_TRANSLATE_IM) llInstantMessage(senderUuid,"Error Message: " + trans);
  248. }else llSay(0,"Error Message Translation not found - please view http://slisweb.sjsu.edu/sl/index.php/Sloodle_status_codes for more information: Error Code: "+(string)statusCode);
  249. }
  250. }
  251. }
  252. // Please leave the following line intact to show where the script lives in Git:
  253. // SLOODLE LSL Script Git Location: assets/misc/sloodle_error_message_handler.lslp