error_messages.lslp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. /**********************************************************************************************
  4. * error_messages.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 as per the GPL Licence
  8. * For more information about GPL 3.0 - see: http://www.gnu.org/copyleft/gpl.html
  9. *
  10. *
  11. * This script is part of the SLOODLE Project see http://sloodle.org
  12. *
  13. * Copywrite
  14. * Paul G. Preibisch (Fire Centaur in SL)
  15. * fire@b3dMultiTech.com
  16. /**********************************************************************************************/
  17. integer SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST=-1828374651;
  18. list errorMessages;
  19. // Translation output methods
  20. string SLOODLE_TRANSLATE_LINK = "link"; // No output parameters - simply returns the translation on SLOODLE_TRANSLATION_RESPONSE link message channel
  21. string SLOODLE_TRANSLATE_SAY = "say"; // 1 output parameter: chat channel number
  22. string SLOODLE_TRANSLATE_WHISPER = "whisper"; // 1 output parameter: chat channel number
  23. string SLOODLE_TRANSLATE_SHOUT = "shout"; // 1 output parameter: chat channel number
  24. string SLOODLE_TRANSLATE_REGION_SAY = "regionsay"; // 1 output parameter: chat channel number
  25. string SLOODLE_TRANSLATE_OWNER_SAY = "ownersay"; // No output parameters
  26. 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.
  27. string SLOODLE_TRANSLATE_LOAD_URL = "loadurl"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  28. string SLOODLE_TRANSLATE_LOAD_URL_PARALLEL = "loadurlpar"; // Recipient avatar should be identified in link message keyval. 1 output parameter giving URL to load.
  29. string SLOODLE_TRANSLATE_HOVER_TEXT = "hovertext"; // 2 output parameters: colour <r,g,b>, and alpha value
  30. string SLOODLE_TRANSLATE_IM = "instantmessage"; // Recipient avatar should be identified in link message keyval. No output parameters.
  31. string sloodle_get_error_string(integer statusCode){
  32. list found =fncFindStride(errorMessages, [statusCode],3);
  33. integer index = llList2Integer(found,0);
  34. list values;
  35. string trans;
  36. if (llList2Integer(found,0)!=-1){
  37. values = fncGetStride(errorMessages, index, 3); //will return a stride of len 3 - ie: [-213,"error message"]
  38. trans = llList2String(values,1);
  39. }
  40. return trans;
  41. }
  42. /****************************************************************
  43. * integer fncStrideCount(list source, integer stride)
  44. *
  45. * Returns the number of strides found within a list.
  46. * Source is the list to operate on, and stride is the length of each stride within the list.
  47. * list Source = ["A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"];
  48. * integer Result = fncStrideCount(Source, 3);
  49. * Returns 3
  50. * Returns number of Strides in a List
  51. *********************************************************************/
  52. integer fncStrideCount(list lstSource, integer intStride)
  53. {
  54. return llGetListLength(lstSource) / intStride;
  55. }
  56. /*********************************************************************
  57. * list fncGetStride(list source, integer index, integer stride)
  58. * Returns a single stride from the list.
  59. * Source is the list to retrieve from, index is which stride to return (zero indexed), and stride is the length of each stride.
  60. * list Source = ["A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"];
  61. *
  62. * list Result = fncGetStride(Source, 1, 3);
  63. *
  64. * Returns ["B1", "B2", "B3"]
  65. * On failure returns an empty list
  66. **********************************************************************/
  67. list fncGetStride(list lstSource, integer intIndex, integer intStride)
  68. {
  69. integer intNumStrides = fncStrideCount(lstSource, intStride);
  70. if (intNumStrides != 0 && intIndex < intNumStrides)
  71. {
  72. integer intOffset = intIndex * intStride;
  73. return llList2List(lstSource, intOffset, intOffset + (intStride - 1));
  74. }
  75. return [];
  76. }
  77. /****************************************************************
  78. * list fncFindStride(list source, list item, integer stride)
  79. *
  80. * Returns the stride number and element number of an element within a stride, within a list. (zero indexed)
  81. * 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.
  82. * list Source = ["A1", "A2", "A3", "B1", "B2", "B3", "C1", "C2", "C3"];
  83. * list Item = ["B3"];
  84. *
  85. * list Result = fncFindStride(Source, Item, 3);
  86. * Returns [1, 2].
  87. * The first number is which stride Item is in.
  88. * The second is which element of the stride is Item.
  89. *
  90. * If item is not found, it will return [-1, -1]
  91. *********************************************************************/
  92. list fncFindStride(list lstSource, list lstItem, integer intStride)
  93. {
  94. integer intListIndex = llListFindList(lstSource, lstItem);
  95. if (intListIndex == -1) { return [-1, -1]; }
  96. integer intStrideIndex = intListIndex / intStride;
  97. integer intSubIndex = intListIndex % intStride;
  98. return [intStrideIndex, intSubIndex];
  99. }
  100. default {
  101. on_rez(integer start_param) {
  102. llResetScript();
  103. }
  104. state_entry() {
  105. errorMessages=[-1 ,"An unspecified error occured","MISC"];
  106. errorMessages+=[-101,"An unknown system error occured","SYSTEM"];
  107. errorMessages+=[-102,"Could not connect to the database.","SYSTEM"];
  108. errorMessages+=[-103,"Could not fetch data we expected to be there. ","SYSTEM"];
  109. errorMessages+=[-104,"Data formatting error ","SYSTEM"];
  110. errorMessages+=[-105,"XMLRPC error","SYSTEM"];
  111. errorMessages+=[-106,"The Sloodle module is not installed in Moodle ","SYSTEM"];
  112. errorMessages+=[-111,"System is temporarily down for maintenance. ","SYSTEM"];
  113. errorMessages+=[-121,"Failed to send required email ","SYSTEM"];
  114. errorMessages+=[-131,"Failed to load plugins ","PLUGIN"];
  115. errorMessages+=[-132,"The required plugin was not found ","PLUGIN"];
  116. errorMessages+=[-201," There was an unspecified problem authenticating the object. ","OBJECT_AUTH"];
  117. errorMessages+=[-212,"Object did not supply the necessary information to authenticate itself. ","OBJECT_AUTH"];
  118. errorMessages+=[-213,"Object authentication key was invalid ","OBJECT_AUTH"];
  119. errorMessages+=[-214,"Object not authorised in this context ","OBJECT_AUTH"];
  120. errorMessages+=[-215,"Prim password access has been disabled for this Controller. ","OBJECT_AUTH"];
  121. errorMessages+=[-301,"Object not found in database ","USER AUTH"];
  122. errorMessages+=[-311,"Object did not supply the necessary information to authenticate the user. ","USER AUTH"];
  123. errorMessages+=[-321,"User was not registered and we weren't allowed to register them automatically. ","USER_AUTH"];
  124. errorMessages+=[-322,"User was not registered and we tried to register them but failed. ","USER_AUTH"];
  125. errorMessages+=[-331,"User did not have permission to access the resources requested . ","USER_AUTH"];
  126. errorMessages+=[-341,"Password cannot be reset via Sloodle, as user was not auto-registered (or has since registered an email account). ","USER_AUTH"];
  127. errorMessages+=[-401,"There was an unspecified problem involving course enrolment. ","USER_ENROL"];
  128. errorMessages+=[-421,"User was not enrolled on the course and we weren't allowed to enrol them automatically","USER_ENROL"];
  129. errorMessages+=[-422,"User was not enrolled on the course and tried to enrol them but failed. ","USER_ENROL"];
  130. errorMessages+=[-501,"There was an unspecified problem involving the course you ar trying to use. ","COURSE"];
  131. errorMessages+=[-511,"The course you are trying to use was not specified. ","COURSE"];
  132. errorMessages+=[-512,"The course you are trying to use was not found. ","COURSE"];
  133. errorMessages+=[-513,"The course you are trying to use was inactive. ","COURSE"];
  134. errorMessages+=[-514,"The course you are trying to use was forbidden from being used with Sloodle. ","COURSE"];
  135. errorMessages+=[-601,"There was an unspecifed problem involving the module you're trying to use. ","MODULE"];
  136. errorMessages+=[-611,"The module you are trying to use was not specified.","MODULE"];
  137. errorMessages+=[-612,"The module you are trying to use was found. ","MODULE"];
  138. errorMessages+=[-613,"The module you are trying to use was inactive. ","MODULE"];
  139. errorMessages+=[-614,"The module you are trying to use was forbidden from being used by Sloodle. ","MODULE"];
  140. errorMessages+=[-701,"There was an unspecifed problem involving the module instance you're trying to use. ","MODULE_INSTANCE"];
  141. errorMessages+=[-711,"The module instance you are trying to use was not specified. ","MODULE_INSTANCE"];
  142. errorMessages+=[-712,"The module instance you are trying to use was not found. ","MODULE_INSTANCE"];
  143. errorMessages+=[-713,"The module instance you are trying to use was inactive. ","MODULE_INSTANCE"];
  144. errorMessages+=[-714,"The module instance you are trying to use was forbidden from being used by Sloodle. ","MODULE_INSTANCE"];
  145. errorMessages+=[-801,"Requested script permanently deleted. ","REQUEST"];
  146. errorMessages+=[-802,"Requested script moved (new location may be specified in the first data line) ","REQUEST"];
  147. errorMessages+=[-811,"Request incomplete (not all required data present) ","REQUEST"];
  148. errorMessages+=[-812,"Requested resource could not be found (although the request itself was handled successfully) ","REQUEST"];
  149. errorMessages+=[-901,"Unknown profile error ","PROFILE"];
  150. errorMessages+=[-902,"Profile does not exist ","PROFILE"];
  151. errorMessages+=[-903,"Profile already exists ","PROFILE"];
  152. errorMessages+=[-904,"Unknown profile command ","PROFILE"];
  153. errorMessages+=[-777000,"Transaction for this user was not found","TRANSACTION"];
  154. errorMessages+=[10001,"Obtained results successfully","CHOICE_QUERY"];
  155. errorMessages+=[10011,"Added new choice selection for user ","CHOICE_SELECT"];
  156. errorMessages+=[10012,"Updated choice selection for user ","CHOICE_SELECT"];
  157. errorMessages+=[10013,"User had previously selected the same option ","CHOICE_SELECT"];
  158. errorMessages+=[10101,"Successfully added a chat message into the database (commonly used as a side-effect code) ","CHAT_MESSAGE"];
  159. errorMessages+=[-10001,"Unable to query choice status for unknown reason ","CHOICE_QUERY"];
  160. errorMessages+=[-10011,"The user has already selected a choice, and choices cannot be updated ","CHOICE_SELECT"];
  161. errorMessages+=[-10012,"Maximum number of selections for this choice already made ","CHOICE_SELECT"];
  162. errorMessages+=[-10013,"Choice is not yet open for selections ","CHOICE_SELECT"];
  163. errorMessages+=[-10014,"Choice has been closed ","CHOICE_SELECT"];
  164. errorMessages+=[-10015,"Specified option not found in choice ","CHOICE_SELECT"];
  165. errorMessages+=[-10016,"Unable to make choice selection for unknown reason (usually more data appended in data lines) ","CHOICE_SELECT"];
  166. errorMessages+=[-10021,"Unable to query list of choice instances for unknown reason ","CHOICE_LIST_QUERY"];
  167. errorMessages+=[-10022,"Not choice instances available in course ","CHOICE_LIST_QUERY"];
  168. errorMessages+=[-10101,"Failed to add chat message to database ","CHAT_MESSAGE"];
  169. errorMessages+=[-10201,"User is not authorised to submit assignments ","ASSIGNMENT"];
  170. errorMessages+=[-10202,"Assignment is not yet open for submissions ","ASSIGNMENT"];
  171. errorMessages+=[-10203,"Assignment due date has passed, and is closed for submissions ","ASSIGNMENT"];
  172. errorMessages+=[-10204,"Assignment due date has passed, but is still accepting submissions (typically a side effect code) ","ASSIGNMENT"];
  173. errorMessages+=[-10205,"Resubmissions are not permitted ","ASSIGNMENT"];
  174. errorMessages+=[-10301,"Student has used all quiz attempts ","QUIZ"];
  175. errorMessages+=[-10302,"Quiz requires password - this is not supported by Sloodle ","QUIZ"];
  176. errorMessages+=[-10303," Error loading questions ","QUIZ"];
  177. errorMessages+=[-10401,"Blogging is disabled on this site. ","BLOG"];
  178. errorMessages+=[-10402,"User does not have permission to write blogs ","BLOG"];
  179. errorMessages+=[-10501,"There are no slides in this presentation. ","PRESENTER"];
  180. }
  181. link_message(integer sender_num, integer channel, string str, key id) {
  182. if (channel==SLOODLE_CHANNEL_ERROR_TRANSLATION_REQUEST){
  183. //message will be in the format
  184. //status code|senderuuid;
  185. list fields = llParseStringKeepNulls(str, ["|"], []);
  186. integer numfields = llGetListLength(fields);
  187. string method= llList2String(fields,0);
  188. key senderUuid = llList2Key(fields,1);
  189. integer statusCode = llList2Integer(fields,2);
  190. //TRANSLATE status code//
  191. string trans = sloodle_get_error_string(statusCode);
  192. if (trans!=""){
  193. if (method == SLOODLE_TRANSLATE_SAY) llSay(0,"Error Message: "+trans);
  194. else if (method==SLOODLE_TRANSLATE_IM) llInstantMessage(senderUuid,"Error Message: " + trans);
  195. }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);
  196. }
  197. }
  198. }
  199. // Please leave the following line intact to show where the script lives in Git:
  200. // SLOODLE LSL Script Git Location: assets/misc/error_messages.lslp