Advertisement
Guest User

Untitled

a guest
Jan 9th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. // Code by Gwyneth Llewelyn to register avatars on WordPress sites
  2. //
  3. // Global Variables
  4. key avatar;
  5. string avatarName;
  6. key registrationResponse; // to send the PermURL to the blog
  7. key webResponse; // to send avatar requests to the blog
  8. string objectVersion = "0.2.5";
  9. string secret = "";
  10. integer secretNumber = ;
  11. integer listener;
  12.  
  13. // modified by SignpostMarv
  14. string http_host = "http://tinkersinc.co.uk";
  15.  
  16. default
  17. {
  18. state_entry()
  19. {
  20. avatar = llGetOwner();
  21. avatarName = llKey2Name(avatar);
  22. // llMinEventDelay(2.0); // breaks on OpenSim
  23. llRequestURL(); // this sets the object up to accept external HTTP-in calls
  24. }
  25.  
  26. on_rez(integer startParam)
  27. {
  28. llResetScript();
  29. }
  30.  
  31. touch_start(integer howmany) // Allow owner to reset this
  32. {
  33.  
  34. string regAvatarName = llKey2Name(llDetectedKey(0));
  35. string regAvatarKey = llDetectedKey(0);
  36. string message =
  37. "avatar_name=" + llEscapeURL(regAvatarName) +
  38. "&avatar_key=" + llEscapeURL(regAvatarKey) +
  39. "&signature=" + llMD5String((string)llGetKey() + secret, secretNumber);
  40. // llOwnerSay("DEBUG: Message to send to blog is: " + message);
  41. webResponse = llHTTPRequest(http_host + "/wp-content/plugins/sl-user-create/register-avatar.php",
  42. [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
  43. message);
  44. }
  45.  
  46. changed(integer what)
  47. {
  48. if (what & CHANGED_OWNER)
  49. llResetScript(); // make sure the new owner gets a fresh PermURL!
  50. if (what & (CHANGED_REGION | CHANGED_TELEPORT) ) // you can add CHANGED_REGION_START on SL, but not for OpenSim
  51. {
  52.  
  53. llRequestURL();
  54. }
  55. }
  56.  
  57. // This is just to catch that our website has the widget active
  58. http_response(key request_id, integer status, list metadata, string body)
  59. {
  60. body = llStringTrim(body, STRING_TRIM);
  61. if (request_id == registrationResponse)
  62. {
  63. if (status == 200)
  64. {
  65. llOwnerSay("PermURL sent to gateway! Msg. id is " + body);
  66. }
  67. else if (status == 499)
  68. {
  69. llOwnerSay("Timeout waiting for gateway! Your PermURL might still be sent, please be patient");
  70. }
  71. else
  72. {
  73. llOwnerSay("PermURL NOT sent, registration object not activated. Status was " + (string)status + "; error message: " + body);
  74. }
  75. }
  76. else if (request_id == webResponse)
  77. {
  78. if (status == 200)
  79. {
  80. llOwnerSay("New avatar registration activated on Tinkers Inc. website! Msg. received is " + body);
  81. // parse result to send user the password
  82.  
  83. list result = llParseString2List(body, ["|"], []);
  84. key IMuser = llList2Key(result, 0);
  85. string command = llList2String(result, 1);
  86. string msg = llList2String(result, 2);
  87.  
  88. if (command == "fail")
  89. {
  90. llSetTimerEvent(60.0);
  91. integer channel = (integer) llFrand(5000.0) + 1000;
  92. llDialog(IMuser, "You are already registered to " + msg + " Reset password?", ["Reset"], channel);
  93. listener = llListen(channel, "", IMuser, "Reset");
  94. }
  95. else
  96. llInstantMessage(IMuser, msg);
  97. }
  98. else if (status == 499)
  99. {
  100. llOwnerSay("Timeout waiting for WordPress site!");
  101. }
  102. else
  103. {
  104. llOwnerSay("Avatar NOT registered. Request to WordPress site returned " + (string)status + "; error message: " + body);
  105. }
  106. }
  107. llSetText("", <0.0, 0.0, 0.0>, 1.0);
  108. }
  109.  
  110. listen(integer channel, string name, key id, string message)
  111. {
  112. llSetText("Sending password reset request to " + http_host + "...", <0.6, 0.6, 0.1>, 1.0);
  113. string msg =
  114. "avatar_name=" + llEscapeURL(name) +
  115. "&avatar_key=" + llEscapeURL(id) +
  116. "&password=true" +
  117. "&signature=" + llMD5String((string)llGetKey() + secret, secretNumber);
  118. // llOwnerSay("DEBUG: Message to send to blog is: " + msg);
  119. webResponse = llHTTPRequest(http_host + "/wp-content/plugins/sl-user-create/register-avatar.php",
  120. [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
  121. msg);
  122. }
  123.  
  124. timer()
  125. {
  126. llListenRemove(listener);
  127. llSetTimerEvent(0.0);
  128. }
  129.  
  130. // These are requests made from our blog to this object
  131. http_request(key id, string method, string body)
  132. {
  133. if (method == URL_REQUEST_GRANTED)
  134. {
  135. llSetText("Sending PermURL to blog...", <0.6, 0.6, 0.1>, 1.0);
  136.  
  137. string avatarName = llKey2Name(llGetOwner());
  138. string message =
  139. "object_version=" + llEscapeURL(objectVersion) +
  140. "&PermURL=" + llEscapeURL(body) +
  141. "&signature=" + llMD5String((string)llGetKey() + secret, secretNumber);
  142. // llOwnerSay("DEBUG: Message to send to blog is: " + message);
  143. registrationResponse = llHTTPRequest(http_host + "/wp-content/plugins/sl-user-create/register-object.php",
  144. [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
  145. message);
  146. }
  147. else if (method == "POST" || method == "GET")
  148. {
  149. if (body == "") // weird, no request
  150. {
  151. llHTTPResponse(id, 403, "Empty message received");
  152. }
  153. else
  154. {
  155. list params = llParseStringKeepNulls(body, ["&", "="], []);
  156.  
  157. if (llList2String(params, 0) == "command" && llList2String(params, 1) == "die") {
  158. llHTTPResponse(id, 200, "Attempting to kill object in-world");
  159. llDie();
  160.  
  161. }
  162. else
  163. {
  164. llHTTPResponse(id, 403, "Command not found");
  165. }
  166. }
  167. }
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement