Advertisement
innula

Fragment for Remote Vendor

Apr 25th, 2021
1,762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. integer iPrice;
  2. key kProductRequest;
  3. key kKVPReadRequest;
  4.  
  5.  
  6. key kToucher;
  7.  
  8.  
  9. string strURL;
  10. string strKVPKeyForServer = "CurrentURL:";
  11. string strProduct;
  12. string strRequest;
  13. string strMyExperience= "My Experience Name";
  14.  
  15.  
  16. default {
  17.     state_entry() {
  18.         if(llList2String(llGetExperienceDetails(NULL_KEY),0)!=strMyExperience){
  19.             llOwnerSay("Please ensure that "+strMyExperience+" is able to run on this parcel");
  20.         }
  21.         kKVPReadRequest=llReadKeyValue(strKVPKeyForServer);//ask for value of current url
  22.     }
  23.  
  24.     dataserver(key queryid, string data) {
  25.         if(queryid == kKVPReadRequest){
  26.             integer success = (integer)llGetSubString(data,0,0);
  27.             data = llDeleteSubString(data,0,1);
  28.             if(success){
  29.                 strURL  = data;
  30.                 if(llStringLength(kProductRequest)){
  31.                 //then there's an outstanding request
  32.                     kProductRequest = llHTTPRequest(strURL, [HTTP_METHOD,"POST"],strRequest);
  33.                 }
  34.             }
  35.             else{
  36.                 llOwnerSay("Could not read server url because "+llGetExperienceErrorMessage((integer)data));
  37.             }
  38.         }
  39.     }
  40.  
  41.     money(key id, integer amount) {
  42.         //don't know how we got here, but on the way we assigned values to kToucher and strProduct
  43.  
  44.         if(id == kToucher && amount == iPrice){
  45.             strRequest = (string)kToucher+"~"+strProduct;
  46.             kProductRequest = llHTTPRequest(strURL, [HTTP_METHOD,"POST"],strRequest);
  47.         }
  48.     }
  49.  
  50.     http_response(key request_id, integer status, list metadata, string body) {
  51.        
  52.         if(kProductRequest == request_id){
  53.             if(200 != status){
  54.                 llOwnerSay("Need to ask for new url");
  55.                 kKVPReadRequest=llReadKeyValue(strKVPKeyForServer);//ask for value of current url
  56.  
  57.             }
  58.             else{
  59.                 kProductRequest = "";
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement