RandyThiemann

Untitled

Oct 14th, 2018
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <VEOS.lsl>
  2. key notecardQueryId;
  3. string notecardName;
  4. integer notecardLine;
  5. key requestKey;
  6. key initializeHTTP;
  7. string basename;
  8. string server;
  9. integer disabled = FALSE;
  10. string handling = "";
  11.  
  12. initialize()
  13. {
  14.     if(llGetInventoryNumber(INVENTORY_NOTECARD) == 0)
  15.     {
  16.         llOwnerSay("Please drop the VEOS-SETTINGS notecard into this object.");
  17.     }
  18.     else
  19.     {
  20.         llListen(VEOS_CLIENT_CHANNEL, "", NULL_KEY, "");
  21.         requestKey = llReadKeyValue("VEOS-basename");
  22.     }
  23. }
  24.  
  25. integer startswith(string haystack, string needle)
  26. {
  27.     return llDeleteSubString(haystack, llStringLength(needle), 0x7FFFFFF0) == needle;
  28. }
  29.  
  30. default
  31. {
  32.     state_entry()
  33.     {
  34.         initialize();
  35.         llTargetOmega(<0,0,0>, 0, 0);
  36.     }
  37.    
  38.     touch_start(integer num)
  39.     {
  40.         if(llGetOwner() == llDetectedKey(0))
  41.         {
  42.             llResetScript();
  43.         }
  44.     }
  45.    
  46.     changed(integer change)
  47.     {
  48.         if(change & CHANGED_INVENTORY)
  49.         {
  50.             llResetScript();
  51.         }
  52.     }
  53.    
  54.     on_rez(integer param)
  55.     {
  56.         llResetScript();
  57.     }
  58.    
  59.     dataserver(key query_id, string data)
  60.     {
  61.         if(disabled) return;
  62.         if(query_id == notecardQueryId)
  63.         {
  64.             if(data == EOF)
  65.             {
  66.                 llOwnerSay("Done sending settings. Read " + (string) notecardLine + " notecard lines.");
  67.                 llRegionSay(VEOS_SERVER_CHANNEL, "mode=settings-complete");
  68.                 return;
  69.             }
  70.            
  71.             data = llStringTrim(llList2String(llParseStringKeepNulls(llStringTrim(data, STRING_TRIM), ["#"], []), 0), STRING_TRIM);
  72.            
  73.             if(data != "KV_SETTINGS" && data != "SERVER_STAFF" && data != "SERVER_TELEPORT_PUBLIC" && data != "SERVER_TELEPORT_STAFF" && data != "SERVER_MOTD")
  74.             {
  75.                 if(handling == "KV_SETTINGS" && data != "")
  76.                 {
  77.                     string k = llStringTrim(llList2String(llParseStringKeepNulls(data, ["="], []), 0), STRING_TRIM);
  78.                     string v = llStringTrim(llList2String(llParseStringKeepNulls(data, ["="], []), 1), STRING_TRIM);
  79.                     if(v == "delete")
  80.                     {
  81.                         llDeleteKeyValue(server + " - " + k);
  82.                     }
  83.                     else
  84.                     {
  85.                         llUpdateKeyValue(server + " - " + k, v, FALSE, "");
  86.                     }
  87.                 }
  88.                 else if(handling == "SERVER_STAFF" && data != "")
  89.                 {
  90.                     llRegionSay(VEOS_SERVER_CHANNEL, "mode=setting-staff\nvalue=" + data);
  91.                 }
  92.                 else if(handling == "SERVER_TELEPORT_PUBLIC" && data != "")
  93.                 {
  94.                     llRegionSay(VEOS_SERVER_CHANNEL, "mode=setting-teleport-public\nvalue=" + data);
  95.                 }
  96.                 else if(handling == "SERVER_TELEPORT_STAFF" && data != "")
  97.                 {
  98.                     llRegionSay(VEOS_SERVER_CHANNEL, "mode=setting-teleport-staff\nvalue=" + data);
  99.                 }
  100.                 else if(handling == "SERVER_MOTD" && data != "")
  101.                 {
  102.                     llRegionSay(VEOS_SERVER_CHANNEL, "mode=setting-motd\nvalue=" + data);
  103.                 }
  104.                 else if(handling == "VEOS_ZONES" && data != "")
  105.                 {
  106.                     llRegionSay(VEOS_SERVER_CHANNEL, "mode=setting-zones\nvalue=" + data);
  107.                 }
  108.             }
  109.            
  110.             if(data == "KV_SETTINGS")
  111.             {
  112.                 handling = "KV_SETTINGS";
  113.                 llOwnerSay("Sending KV settings...");
  114.             }
  115.             else if(data == "SERVER_STAFF")
  116.             {
  117.                 handling = "SERVER_STAFF";
  118.                 llOwnerSay("Sending staff settings...");
  119.             }
  120.             else if(data == "SERVER_TELEPORT_PUBLIC")
  121.             {
  122.                 handling = "SERVER_TELEPORT_PUBLIC";
  123.                 llOwnerSay("Sending public teleport settings...");
  124.             }
  125.             else if(data == "SERVER_TELEPORT_STAFF")
  126.             {
  127.                 handling = "SERVER_TELEPORT_STAFF";
  128.                 llOwnerSay("Sending staff teleport settings...");
  129.             }
  130.             else if(data == "VEOS_ZONES")
  131.             {
  132.                 handling = "VEOS_ZONES";
  133.                 llOwnerSay("Sending VEOS zones...");
  134.             }
  135.             else if(data == "SERVER_MOTD")
  136.             {
  137.                 handling = "SERVER_MOTD";
  138.                 llOwnerSay("Sending MOTD settings...");
  139.             }
  140.            
  141.             ++notecardLine;
  142.             notecardQueryId = llGetNotecardLine(notecardName, notecardLine);
  143.         }
  144.         else if(query_id == requestKey)
  145.         {
  146.             string arg = "sim=" + llEscapeURL(llGetRegionName());
  147.             if((integer)llGetSubString(data, 0, 0) == 1)
  148.             {
  149.                 baseName = llGetSubString(data, 2, -1);
  150.             }
  151.             initializeHTTP = llHTTPRequest(baseName, [HTTP_METHOD, "POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"], arg);
  152.         }
  153.     }
  154.    
  155.     http_response(key id, integer status, list meta, string body)
  156.     {
  157.         if(disabled) return;
  158.         if(id != initializeHTTP) return;
  159.         if(status != 200)
  160.         {
  161.             llOwnerSay("Something went wrong... Try clicking me in a few minutes.");
  162.             return;
  163.         }
  164.        
  165.         if(body == "DIE" || body == "SIM_NOT_REGISTERED")
  166.         {
  167.             llOwnerSay("Your sim has been ejected from the VEOS system or has not been registered.");
  168.             disabled = TRUE;
  169.         }
  170.         else
  171.         {
  172.             server = llList2String(llParseStringKeepNulls(body, ["\n"], []), 1);
  173.             notecardLine = 0;
  174.             notecardName = llGetInventoryName(INVENTORY_NOTECARD, notecardLine);
  175.            
  176.             llOwnerSay("Sending new settings...");
  177.             llRegionSay(VEOS_SERVER_CHANNEL, "mode=clear-settings");
  178.             llRegionSay(VEOS_SERVER_CHANNEL, "mode=region-pos");
  179.             notecardQueryId = llGetNotecardLine(notecardName, notecardLine);
  180.         }
  181.     }
  182.    
  183.     listen(integer c, string n, key k, string m)
  184.     {
  185.         if(disabled) return;
  186.         if(m == "RESEND-SERVER-SETTINGS")
  187.         {
  188.             llResetScript();
  189.         }
  190.         else if(startswith(m, "REGION-POS"))
  191.         {
  192.             llSetRegionPos((vector)llList2String(llParseString2List(m, ["\n"], []), 1));
  193.             llSetRot(llList2Rot(llGetObjectDetails(k, [OBJECT_ROT]), 0));
  194.             llTargetOmega(<1.0,0.0,0.0>*llGetRot(),1.0,0.1);
  195.         }
  196.     }
  197. }
Advertisement