Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Script by Gayngel of The Script Yard.
- //Join The Script Yard Group: secondlife:///app/group/4921b4f0-c21e-7866-c0c2-791d10bb5502/about
- //Visit The Script Yard Marketplace: https://marketplace.secondlife.com/stores/149734
- // This is a barebones script to store the scripts url persistently in a Google Sheet.
- // The server will send a greeting when requested by a client terminal.
- // The server saves it's url to a Google Sheet via Google App Script. The client will request the url of the server from the spreadsheet and then request the server to greet the avatar who touched the object and requested a greeting from the menu.
- // Get the Google App Script from https://pastebin.com/Cc9ZbYyj and follow the instructions in the app script to setup.
- // Once set up paste the app url below.
- string app_url = "https://script.google.com/macros/s/AKfycbz-rAtEqm5clysDSL3l3-9kYqfwrDjSpFg7u4PuF9208F-ON3g/exec"; // place the url of Google App Script here.
- string spreadsheet = ""; // The Google App Script will create a spreadsheet in your Google Drive to store the url of the drop box. You can write a name here or leave it blank. If you leave the string blank the spreadsheet will automatically be called the "NameOfParcelDropBoxIsOn Dropbox".
- list parceldetails;
- string parcelname;
- string url;
- key reqURL;
- key http_req;
- key sheet_req;
- integer allow =FALSE;
- default
- {
- on_rez(integer start_param)
- {
- llSetObjectDesc("");
- llResetScript();
- }
- state_entry()
- {
- allow = FALSE; // verbosity just in case
- llReleaseURL(url); // verbosity just in case
- parceldetails = llGetParcelDetails(llGetPos(),[PARCEL_DETAILS_NAME]);
- parcelname = llList2String(parceldetails,0);
- reqURL =llRequestURL();
- }
- http_request(key id, string method, string body)
- {
- if (id == reqURL)
- {
- if (method == URL_REQUEST_DENIED)
- llOwnerSay("The following error occurred while attempting to get a free URL for this device:\n \n" + body);
- else if (method == URL_REQUEST_GRANTED)
- {
- url = body;
- }
- if(app_url != "")
- {
- http_req = llHTTPRequest(app_url+"?server_url="+url+"&obj_key="+(string)llGetKey(),[HTTP_METHOD,"GET"],""); // send the server's url to the spreadsheet to be stored.
- }
- else
- llOwnerSay("Please add the URL of the Google App Script at the top of the script");
- } // if (id == reqURL)
- else if (method == "POST")
- {
- list tmp = llParseString2List(body,["="],[""]);
- string cmd = llToLower(llList2String(tmp,0));
- string ref = llList2String(tmp,1);
- if(cmd == "url_ok")
- {
- string ssID = llGetObjectDesc();
- if(ssID == "") // if the spreadsheet doesn't exist create one
- {
- if(spreadsheet == "")
- {
- spreadsheet = parcelname + " greeter.";
- }
- llOwnerSay("Creating spreadsheet named " + spreadsheet);
- if(app_url != "")
- sheet_req = llHTTPRequest(app_url+ "?url="+url+"&spreadsheet=" + llEscapeURL(spreadsheet),[HTTP_METHOD,"POST"],"Create"); // instruct the App Script to create a spreadsheet
- }
- else if(ssID != "") // if the spreadsheet exists
- {
- llOwnerSay("The spreadsheet database is ready.");
- llOwnerSay("This server can now be contacted");
- allow = TRUE;
- sheet_req = llHTTPRequest(app_url+ "?url="+url,[HTTP_METHOD,"POST"],"Send_URL"); // update the url of the server and store in the spreadsheet
- }
- } //if(cmd == "url_ok")
- else if(cmd == "url_invalid")
- {
- llSetObjectDesc("");
- llOwnerSay("Can not save this server's URL to the spreadsheet as the Google App Script is tied to another server. Please create a new app script and paste it's url at the top of the script.");
- }
- else if(cmd == "spreadsheetready")
- {
- llSetObjectDesc(ref);
- llOwnerSay("The spreadsheet database has been created.");
- allow = TRUE;
- sheet_req = llHTTPRequest(app_url+ "?url="+url,[HTTP_METHOD,"POST"],"Send_URL");
- llOwnerSay("This server can now be contacted");
- }
- else if(cmd == "url_added")
- {
- llOwnerSay("The url of your server has been updated in the spreadsheet database.");
- }
- else if(cmd == "request_greeting")
- {
- key av = (key)ref;
- if(allow == TRUE)
- {
- llInstantMessage(av,"Hello World!");
- }
- } //else if(cmd == "request_redelivery")
- } // method is post
- }
- changed(integer change)
- {
- if(change & CHANGED_REGION_START || change & CHANGED_REGION || change & CHANGED_INVENTORY || change & CHANGED_TELEPORT)
- {
- llReleaseURL(url); // verbosity just in case
- llResetScript();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement