router.lslp 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. /* The line above should be left blank to avoid script errors in OpenSim.
  3. router
  4. Part of the Sloodle project (www.sloodle.org)
  5. Copyright (c) 2006-9 Sloodle (various contributors)
  6. Released under the GNU GPL
  7. Contributors:
  8. Edmund Edgar
  9. Paul Preibisch
  10. This script receives requests from SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG linked message channel, and passes it along to 6 sloodle_quiz_question_handler scripts in waiting
  11. After it passes it along, it marks that script as busy, until that script notifies the router it is free again for work. I created this to help spead up the response time of
  12. http requests
  13. */
  14. integer SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG = -1639271126; // Tells the question handler scripts to ask the question with the ID in str to the avatar with key VIA DIALOG.
  15. list slots = [NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY,NULL_KEY];
  16. integer len;
  17. integer SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG0 = -170000; // Tells the question handler scripts to ask the question with the ID in str to the avatar with key VIA DIALOG.
  18. integer SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG1 = -1700001; // Tells the question handler scripts to ask the question with the ID in str to the avatar with key VIA DIALOG.
  19. integer SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG2 = -1700002; // Tells the question handler scripts to ask the question with the ID in str to the avatar with key VIA DIALOG.
  20. integer SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG3= -1700003; // Tells the question handler scripts to ask the question with the ID in str to the avatar with key VIA DIALOG.
  21. integer SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG4 = -1700004; // Tells the question handler scripts to ask the question with the ID in str to the avatar with key VIA DIALOG.
  22. integer SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG5 = -1700005; // Tells the question handler scripts to ask the question with the ID in str to the avatar with key VIA DIALOG.
  23. integer SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG6 = -1700006; // Tells the question handler scripts to ask the question with the ID in str to the avatar with key VIA DIALOG.
  24. integer SLOODLE_CHANNEL_QUESTION_ASKED_AVATAR = -1639271105; //Sent by main quiz script to tell UI scripts that question has been asked to avatar with key. String contains question ID + "|" + question text
  25. list qChannels;
  26. integer SLOODLE_CHANNEL_ANSWER_SCORE_FOR_AVATAR = -1639271113; // Tells anyone who might be interested that we scored the answer. Score in string, avatar in key.
  27. debug (string message ){
  28. list params = llGetPrimitiveParams ([PRIM_MATERIAL ]);
  29. if (llList2Integer (params ,0)==PRIM_MATERIAL_FLESH){
  30. llOwnerSay("memory: "+(string)llGetFreeMemory()+" Script name: "+llGetScriptName ()+": " +message );
  31. }
  32. }
  33. default {
  34. state_entry() {
  35. qChannels =[SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG0,SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG1,SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG2,SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG3,SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG4,SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG5];
  36. len= llGetListLength(slots);
  37. }
  38. link_message(integer sender_num, integer num, string str, key user_key) {
  39. if (num==SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG){
  40. key not_used;
  41. integer index=0;
  42. integer free=-1;
  43. do{
  44. not_used = llList2Key(slots,index);
  45. if (not_used==NULL_KEY){
  46. free=index;
  47. slots = llListReplaceList(slots , [user_key], free, free);
  48. }
  49. if (index>=len-1){
  50. index=0;
  51. }else{
  52. index++;
  53. }
  54. } while(not_used!=NULL_KEY);
  55. llOwnerSay(llList2CSV(slots));
  56. llMessageLinked(LINK_SET, llList2Integer(qChannels, free), str, user_key);
  57. }else
  58. if (num==SLOODLE_CHANNEL_QUESTION_ASKED_AVATAR){
  59. integer found = llListFindList(slots, [user_key]);
  60. if (found!=-1){
  61. slots=llListReplaceList(slots, [NULL_KEY], found, found);
  62. debug("-----------------------------------slot "+(string)found+" is now available");
  63. }
  64. }
  65. }
  66. }