Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Code by Gwyneth Llewelyn to register avatars on WordPress sites
- //
- // Global Variables
- key avatar;
- string avatarName;
- key registrationResponse; // to send the PermURL to the blog
- key webResponse; // to send avatar requests to the blog
- string objectVersion = "0.2.5";
- string secret = "BBKsMKbnJl8w90TcqhKPsxzK1UoGjdnfyl7A";
- integer secretNumber = 6969;
- integer listener;
- // modified by SignpostMarv
- string http_host = "http://tinkersinc.co.uk";
- default
- {
- state_entry()
- {
- avatar = llGetOwner();
- avatarName = llKey2Name(avatar);
- llSetText("Registering with your blog at " + http_host + "\nand requesting PermURL from SL...", <0.8, 0.8, 0.1>, 1.0);
- // llMinEventDelay(2.0); // breaks on OpenSim
- llRequestURL(); // this sets the object up to accept external HTTP-in calls
- }
- on_rez(integer startParam)
- {
- llResetScript();
- }
- touch_start(integer howmany) // Allow owner to reset this
- {
- llSetText("Sending registration request to " + http_host + "...", <0.6, 0.6, 0.1>, 1.0);
- string regAvatarName = llKey2Name(llDetectedKey(0));
- string regAvatarKey = llDetectedKey(0);
- string message =
- "avatar_name=" + llEscapeURL(regAvatarName) +
- "&avatar_key=" + llEscapeURL(regAvatarKey) +
- "&signature=" + llMD5String((string)llGetKey() + secret, secretNumber);
- // llOwnerSay("DEBUG: Message to send to blog is: " + message);
- webResponse = llHTTPRequest(http_host + "/wp-content/plugins/sl-user-create/register-avatar.php",
- [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
- message);
- }
- changed(integer what)
- {
- if (what & CHANGED_OWNER)
- llResetScript(); // make sure the new owner gets a fresh PermURL!
- if (what & (CHANGED_REGION | CHANGED_TELEPORT) ) // you can add CHANGED_REGION_START on SL, but not for OpenSim
- {
- llSetText("Requesting PermURL from SL...", <0.8, 0.8, 0.1>, 1.0);
- llRequestURL();
- }
- }
- // This is just to catch that our website has the widget active
- http_response(key request_id, integer status, list metadata, string body)
- {
- body = llStringTrim(body, STRING_TRIM);
- if (request_id == registrationResponse)
- {
- if (status == 200)
- {
- llOwnerSay("PermURL sent to gateway! Msg. id is " + body);
- }
- else if (status == 499)
- {
- llOwnerSay("Timeout waiting for gateway! Your PermURL might still be sent, please be patient");
- }
- else
- {
- llOwnerSay("PermURL NOT sent, registration object not activated. Status was " + (string)status + "; error message: " + body);
- }
- }
- else if (request_id == webResponse)
- {
- if (status == 200)
- {
- llOwnerSay("New avatar registration activated on WordPress site! Msg. received is " + body);
- // parse result to send user the password
- list result = llParseString2List(body, ["|"], []);
- // key IMuser =llUnescapeURL( llStringTrim( llList2String(result, 0) , STRING_TRIM ) );
- // key IMuser = (key)llList2Key(result, 0);
- string userKey = llGetSubString(body,1,llSubStringIndex(body,"|")-1);
- key IMuser = (key) userKey;
- string command = llList2String(result, 1);
- string msg = llList2String(result, 2);
- if (command == "fail")
- {
- llSetTimerEvent(60.0);
- integer channel = (integer) llFrand(5000.0) + 1000;
- llDialog(IMuser, "You are already registered to " + msg + " Reset password?", ["Reset"], channel);
- llOwnerSay((string)IMuser+" "+llKey2Name(IMuser));
- listener = llListen(channel, "", IMuser, "Reset");
- }
- else
- llInstantMessage(IMuser, msg);
- }
- else if (status == 499)
- {
- llOwnerSay("Timeout waiting for WordPress site!");
- }
- else
- {
- llOwnerSay("Avatar NOT registered. Request to WordPress site returned " + (string)status + "; error message: " + body);
- }
- }
- llSetText("", <0.0, 0.0, 0.0>, 1.0);
- }
- listen(integer channel, string name, key id, string message)
- {
- llSetText("Sending password reset request to " + http_host + "...", <0.6, 0.6, 0.1>, 1.0);
- string msg =
- "avatar_name=" + llEscapeURL(name) +
- "&avatar_key=" + llEscapeURL(id) +
- "&password=true" +
- "&signature=" + llMD5String((string)llGetKey() + secret, secretNumber);
- // llOwnerSay("DEBUG: Message to send to blog is: " + msg);
- webResponse = llHTTPRequest(http_host + "/wp-content/plugins/sl-user-create/register-avatar.php",
- [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
- msg);
- }
- timer()
- {
- llListenRemove(listener);
- llSetTimerEvent(0.0);
- }
- // These are requests made from our blog to this object
- http_request(key id, string method, string body)
- {
- if (method == URL_REQUEST_GRANTED)
- {
- llSetText("Sending PermURL to blog...", <0.6, 0.6, 0.1>, 1.0);
- string avatarName = llKey2Name(llGetOwner());
- string message =
- "object_version=" + llEscapeURL(objectVersion) +
- "&PermURL=" + llEscapeURL(body) +
- "&signature=" + llMD5String((string)llGetKey() + secret, secretNumber);
- // llOwnerSay("DEBUG: Message to send to blog is: " + message);
- registrationResponse = llHTTPRequest(http_host + "/wp-content/plugins/sl-user-create/register-object.php",
- [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"],
- message);
- }
- else if (method == "POST" || method == "GET")
- {
- if (body == "") // weird, no request
- {
- llHTTPResponse(id, 403, "Empty message received");
- }
- else
- {
- list params = llParseStringKeepNulls(body, ["&", "="], []);
- if (llList2String(params, 0) == "command" && llList2String(params, 1) == "die") {
- llHTTPResponse(id, 200, "Attempting to kill object in-world");
- llDie();
- }
- else
- {
- llHTTPResponse(id, 403, "Command not found");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement