Advertisement
Guest User

Untitled

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