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 = "https://script.google.com/macros/s/AKfycbz-rAtEqm5clysDSL3l3-9kYqfwrDjSpFg7u4PuF9208F-ON3g/exec"; // place the url of Google App Script here.
- string url;
- key reqURL;
- key server_req;
- key app_req;
- integer allow =FALSE; // only allow a user to touch the object if a URL has been granted to the script.
- integer wait = FALSE; // if someone is using the terminal the next user must wait their turn
- integer listen_chan;
- integer listen_handle;
- key recipient;
- default
- {
- on_rez(integer start_param)
- {
- llResetScript();
- }
- state_entry()
- {
- allow = FALSE; // verbosity just in case
- llReleaseURL(url); // verbosity just in case
- 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 != "")
- {
- llOwnerSay("This terminal can now request greetings from the server");
- allow = TRUE;
- }
- else
- llOwnerSay("Please add the URL of the Google App Script at the top of the script");
- }
- }
- else if(id == server_req)
- {
- if(body == "redelivery_ok")
- {
- wait = TRUE; // verbosity just in case
- allow = TRUE; // verbosity just in case
- llListenRemove(listen_handle); // verbosity just in case
- }
- }
- else if(method == "POST")
- {
- list tmp = llParseString2List(body,["="],[""]);
- string cmd = llToLower(llList2String(tmp,0));
- string ref = llList2String(tmp,1);
- if(cmd == "server_url")
- {
- server_req = llHTTPRequest(llUnescapeURL(ref),[HTTP_METHOD,"POST"],"request_greeting="+(string)recipient); // instruct server to send a greeting
- }
- }
- }
- touch_end(integer num)
- {
- key toucher = llDetectedKey(0);
- if(allow == TRUE) // only allow a user to touch the object if a URL has been granted to the script.
- {
- if(wait == FALSE) // if someone is using the terminal the next user to touch must wait their turn
- {
- wait = TRUE; // other users must wait their turn
- llListenRemove(listen_handle);
- listen_chan = ((integer)("0x"+llGetSubString((string)toucher,-8,-1)) - 723) | 0x8000000;
- listen_handle = llListen(listen_chan,"",toucher,"");
- llDialog(toucher,"\nSelect Greet to get a greeting from the server.",["Greet"],listen_chan);
- }
- else // other users must wait their turn
- {
- llRegionSayTo(toucher,0,"Someone is already using this terminal, please wait.");
- }
- }
- else
- {
- llRegionSayTo(toucher,0,"This server is currently offline.");
- }
- }
- listen(integer chan, string name, key id, string msg)
- {
- if(chan == listen_chan)
- {
- if(msg == "Greet")
- {
- llListenRemove(listen_handle);
- wait = FALSE; //allow next user to use the terminal
- allow = TRUE; // only allow a user to touch the object if a URL has been granted to the script.
- //http request to google app script to get url of drop box
- recipient = id;
- app_req = llHTTPRequest(app+"?client_url="+url,[HTTP_METHOD,"GET"],""); // request url of server from spreadsheet database
- }
- }
- }
- 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