router.lslp 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 =[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];
  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. default {
  28. state_entry() {
  29. llOwnerSay("Hello Scripter");
  30. len= llGetListLength(slots);
  31. }
  32. link_message(integer sender_num, integer num, string str, key user_key) {
  33. if (num==SLOODLE_CHANNEL_QUIZ_ASK_QUESTION_DIALOG){
  34. key not_used;
  35. integer index=0;
  36. integer free=-1;
  37. do{
  38. not_used = llList2Key(slots,index);
  39. if (not_used==NULL_KEY){
  40. free=index;
  41. llOwnerSay("found free: "+(string)index);
  42. slots = llListReplaceList(slots , [user_key], free, free);
  43. }
  44. if (index>=len-1){
  45. index=0;
  46. }else{
  47. index++;
  48. }
  49. } while(not_used!=NULL_KEY);
  50. llOwnerSay(llList2CSV(slots));
  51. llMessageLinked(LINK_SET, llList2Integer(qChannels, free), str, user_key);
  52. }else
  53. if (num==SLOODLE_CHANNEL_QUESTION_ASKED_AVATAR){
  54. integer found = llListFindList(slots, [user_key]);
  55. if (found!=-1){
  56. slots=llListReplaceList(slots, [NULL_KEY], found, found);
  57. llOwnerSay("-----------------------------------slot "+(string)found+" is now available");
  58. }
  59. }
  60. }
  61. }