UpdateSubscriber_1_1.lsl 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. // :CATEGORY:Updater
  2. // :NAME:UpdateSubscriber
  3. // :AUTHOR:Emma Nowhere
  4. // :CREATED:2010-01-10 05:20:56.000
  5. // :EDITED:2013-09-18 15:39:08
  6. // :ID:938
  7. // :NUM:1348
  8. // :REV:1.0
  9. // :WORLD:Second Life
  10. // :DESCRIPTION:
  11. // UpdateSubscriber 1.lsl
  12. // :CODE:
  13. //////////////////////////////////////////////////////////////////////////////////////
  14. //
  15. // UpdateSubscriber
  16. // Version 1.01 Release
  17. // Copyright (C) 2007, Emma Nowhere
  18. // emma.nowhere@yahoo.com
  19. //
  20. // Place inside a prim that you want to receive object updates from an
  21. // UpdateServer. You should have your UpdateServer already set up
  22. // before adding this script to a prim.
  23. //
  24. // At startup the script will broadcast a request for all UpdateServers
  25. // in the region and output the results to you.
  26. //
  27. // You need to register with a specific UpdateServer to enable updates
  28. // to be received.
  29. //
  30. // To lock onto a specific UpdateServer, type:
  31. //
  32. // /128 UpdateSubscriberRegister <subscriberkey> <serverkey>
  33. //
  34. // where <subscriberkey> is the key of the prin containing the script
  35. // and <serverkey> is the key shown next to the UpdateServer name that is
  36. // displayed when this script displays the available UpdateServers in
  37. // the region.
  38. //
  39. // License:
  40. //
  41. // This library is free software; you can redistribute it and/or
  42. // modify it under the terms of the GNU Lesser General Public License
  43. // as published by the Free Software Foundation; either
  44. // version 2.1 of the License, or (at your option) any later version.
  45. //
  46. // This library is distributed in the hope that it will be useful,
  47. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  48. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  49. // GNU Lesser General Public License for more details.
  50. //
  51. // You should have received a copy of the GNU Lesser General Public License
  52. // along with this library; if not, write to the Free Software
  53. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  54. //
  55. //////////////////////////////////////////////////////////////////////////////////////
  56. integer listenChannel = 128;
  57. integer listenHandle = 0;
  58. string scriptName;
  59. key subscriberKey;
  60. key serverKey;
  61. integer registered = FALSE;
  62. integer containsItem(string itemName) {
  63. integer total = llGetInventoryNumber(INVENTORY_ALL);
  64. integer i;
  65. for (i = 0; i < total; i++) {
  66. string name = llGetInventoryName(INVENTORY_ALL, i);
  67. if ((name != scriptName) && (itemName == name)) return TRUE;
  68. }
  69. return FALSE;
  70. }
  71. default {
  72. state_entry() {
  73. scriptName = llGetScriptName();
  74. subscriberKey = llGetKey();
  75. llSay(0, "UpdateSubscriber installed in object " + llGetObjectName() + " (" + (string)subscriberKey + ")");
  76. listenHandle = llListen(listenChannel, "", NULL_KEY, "");
  77. llSay(0, "UpdateSubscriber listening on channel #" + (string)listenChannel);
  78. llRegionSay(listenChannel, "UpdateServersQuery");
  79. }
  80. listen(integer channel, string name, key id, string message) {
  81. list parsed = llParseString2List(message, [" "], []);
  82. integer l = llGetListLength(parsed);
  83. if (l == 0) return;
  84. string command = llList2String(parsed, 0);
  85. if (!registered) {
  86. if ((l == 3) && (command == "UpdateSubscriberRegister")) {
  87. if ((key)llList2String(parsed, 1) != subscriberKey) return;
  88. serverKey = (key)llList2String(parsed, 2);
  89. llListenRemove(listenHandle);
  90. listenHandle = llListen(listenChannel, "", serverKey, "");
  91. llSay(0, "Registered to Update Server " + llKey2Name(serverKey) + " (" + (string)serverKey + ")");
  92. registered = TRUE;
  93. }
  94. else if ((l == 2) && (command == "UpdateServerAvailable")) {
  95. key serverKey = (key)llList2String(parsed, 1);
  96. string msg = "Update Server available:\n" + llKey2Name(serverKey) + " (" + (string)serverKey + ")\n\n" +
  97. "Copy and paste the following line to register to this server:\n\n" +
  98. "/128 UpdateSubscriberRegister " + (string)subscriberKey + " " + (string)serverKey + "\n\n";
  99. llSay(0, msg);
  100. }
  101. return;
  102. }
  103. if ((l == 2) && (command == "UpdateAvailable")) {
  104. string itemName = llUnescapeURL(llList2String(parsed, 1));
  105. if (containsItem(itemName)) {
  106. llSay(0, "Deleting old version of item " + itemName);
  107. llRemoveInventory(itemName);
  108. llSay(0, "Requesting new version of item " + itemName);
  109. llRegionSay(listenChannel, "UpdateRequest " + llEscapeURL(itemName) + " " + (string)subscriberKey + " " + (string)serverKey);
  110. }
  111. }
  112. else if ((l == 2) && (command == "UpdateSubscribersQuery")) {
  113. key serverKey = (key)llList2String(parsed, 1);
  114. llRegionSay(listenChannel, "UpdateSubscriberRegistered " + (string)serverKey + " " + (string)subscriberKey);
  115. }
  116. }
  117. }
  118. // END //