Product Updater Client.lsl 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. // :CATEGORY:Updater
  2. // :NAME:Open Updater
  3. // :AUTHOR:Ferd Frederix
  4. // :KEYWORDS:
  5. // :CREATED:2013-09-06
  6. // :EDITED:2014-02-24
  7. // :ID:586
  8. // :NUM:802
  9. // :REV:1.1
  10. // :WORLD:Second Life, OpenSim
  11. // :DESCRIPTION:
  12. // Grid-wide Updater for products. This is the Client
  13. // :CODE:
  14. // Script by Ferd Frederix
  15. // fred@mitsi.com
  16. // License: CC-BY-NC
  17. // This means you must leave the headers in this script intact, and it is not to be sold by itself, not even for a Linden
  18. // You are allowed to use and sell Products that use this script.
  19. //
  20. // Open Update Client
  21. // Updater that goes into any product.
  22. // Rev 1.0 5/24/2013 Initial release
  23. // Rev 1.1 2/21/2014 changed UUID to a valid one as people do not know how to read instructions.
  24. // Put this script into any prim and give the prim to someone.
  25. // When that product is rezzed, it will check for updates from a Server prim
  26. // You must make the name of the Prim "Name-VN", where N is a version number such as 1, 1.0, 2 and so on.
  27. // The Name must not have a | in it.
  28. // The product MUST have a name followed by -V and a version number
  29. //
  30. // Examples: Horsie-V1.0 ( Same as V1)
  31. // Horsie-V1 ( Same as V1.0)
  32. // Horsie-V1.1 ( if inside the updater, this will be sent if the version of Horsie is less than 1.1 )
  33. // Horsie-V4.1.1 ( This is an illegal number as it has 2 decimals, and will not update as you expect)
  34. // Horsie|From Me-V4.1 ( This is an illegal name as it has a "|" in it)
  35. //////////////////////////////////////////////////////////
  36. // IMPORTANT CONFIGURATION //
  37. //////////////////////////////////////////////////////////
  38. // You MUST put in a UUID from this web site here and put the same UUID in the updater script
  39. // Get a UUID from Latif Khalifa at:
  40. //
  41. // http://gridurl.appspot.com/random
  42. //
  43. // You only need to do this once for the server that has the same key. That server has to have a copy of the object in it.
  44. // You can run more than one server, just make sure that the product goes into the correct server and that the key inside this script in that product matches the key inside the server
  45. string UUID = "92e723e8-3653-451c-816d-23f920cd02c8"; // You MUST change this
  46. integer CHATTY = TRUE; // When TRUE, tells the prim owner it is checking for updates. If FALSE, this script is silent.
  47. //////////////////////////////////////////////////////////
  48. // CODE BEGINS, Move on, nothing here to change //
  49. //////////////////////////////////////////////////////////
  50. // Just for Debugging
  51. integer debug = FALSE; // Show what is happenning in chat if TRUE
  52. DEBUG(string msg)
  53. {
  54. if (debug)
  55. llOwnerSay(llGetScriptName() + " : " + msg);
  56. }
  57. // globals
  58. key http_request_id; // this key of for the update request
  59. key URL_request_id; // this key is for the HTTP-In
  60. string serverURL; // This will become out HTTP-I URL
  61. key Request(string cmd)
  62. {
  63. DEBUG("Sending:"+serverURL+"?"+cmd);
  64. return llHTTPRequest( serverURL+"?"+cmd, [HTTP_METHOD, "GET"], "");
  65. }
  66. CheckForUpdate()
  67. {
  68. // Check for an update from the server prim
  69. string AvatarName = llKey2Name(llGetOwner());
  70. string AvatarNameESC = llEscapeURL(AvatarName);
  71. string ProductName = llEscapeURL(llGetObjectName());
  72. //Product Name|UUID|Avatar Name is the message
  73. string query = "?q=" + ProductName + "|"+ (string) llGetOwner() +"|" + AvatarName;
  74. DEBUG("URL:" + serverURL);
  75. http_request_id = llHTTPRequest(serverURL + query,[HTTP_METHOD,"POST"],"");
  76. }
  77. default
  78. {
  79. on_rez(integer param)
  80. {
  81. llResetScript();
  82. }
  83. state_entry()
  84. {
  85. if (CHATTY)
  86. llOwnerSay( "Checking for updates");
  87. string keyURL = "http://gridurl.appspot.com/get/"+ llEscapeURL(UUID);
  88. DEBUG(keyURL);
  89. URL_request_id = llHTTPRequest(keyURL, [HTTP_METHOD, "GET"], ""); // find the server
  90. }
  91. http_response(key request_id, integer status, list metadata, string body)
  92. {
  93. if (URL_request_id == request_id)
  94. {
  95. URL_request_id = NULL_KEY; // the same event sometimes shows up more then once
  96. if(status == 200)
  97. {
  98. DEBUG("Server URL is :" + body);
  99. serverURL = body;
  100. CheckForUpdate(); // let's see if there is an update by connecting to the URL we just got
  101. }
  102. }
  103. else if (http_request_id == request_id)
  104. {
  105. if(status == 200)
  106. {
  107. DEBUG("Success response:" + body); // report what was returned from update request
  108. }
  109. else
  110. {
  111. DEBUG("Fail response:" + body); // report what was returned from update request
  112. }
  113. }
  114. }
  115. }