Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- key value store via PHP only
- LSL----------------------------------------------------------------------------------------------
- string PHPURL = "https://opushub.000webhostapp.com/kvs/keyvaluestore.php";
- integer working;
- integer handle;
- key user;
- string mKey;
- TextBox(key user, string msg, integer channel)
- {
- llListenRemove(handle);
- handle = llListen(channel, "",user,"");
- llTextBox(user,msg,channel);
- }
- string buildbody(string func, string keyvalue, string value, string pvalue)
- {
- string body = "arg="+llStringToBase64("abc123easy")+"&";
- list modules = ["func="+func, "key="+keyvalue, "value="+(string)value, "pvalue="+pvalue];
- return body+llDumpList2String(modules,"&");
- }
- ReadKeyValue(string input)
- {
- llHTTPRequest(PHPURL,[HTTP_METHOD,"POST",HTTP_MIMETYPE,"application/x-www-form-urlencoded"],buildbody("get",input,"#","#"));
- }
- SetKeyValue(string input, string value)
- {
- llHTTPRequest(PHPURL,[HTTP_METHOD,"POST",HTTP_MIMETYPE,"application/x-www-form-urlencoded"],buildbody("set",input,value,"#"));
- }
- integer catcherror(string input)
- {
- if(input == "FNF" || input == "CONF") return 1;
- else return 0;
- }
- error(string input)
- {
- if(input == "FNF") llSay(0,"error, key not found.");
- if(input == "CONF") llSay(0,"key-value set!");
- else llSay(0,input);
- }
- default
- {
- state_entry()
- {
- llSay(0, "Hello, Avatar!");
- }
- touch_start(integer total_number)
- {
- if(!working)
- {
- working=1;
- TextBox(user=llDetectedKey(0),"input key you want to set",-40);
- }
- }
- listen(integer channel, string name, key id, string message)
- {
- if(channel == -40)
- {
- mKey = message;
- TextBox(user,"input key's value",-41);
- }
- if(channel == -41)
- {
- SetKeyValue(mKey,message);
- }
- }
- http_response(key id, integer status, list meta, string body)
- {
- if(catcherror(body)) error(body);
- else
- {
- llListenRemove(handle);
- working=0;
- llSay(0,"value: "+body);
- }
- }
- }
- PHP-----------------------------------------------------------------------------------------------------------------
- <?php
- $password = "abc123easy";
- $arg = $_POST['arg'];
- $func = $_POST['func'];
- $key = $_POST['key'];
- $value = $_POST['value'];
- $pvalue = $_POST['pvalue'];
- if(base64_decode($arg) == $password)
- {
- if($func == "get")
- {
- $file = @fopen($key,"r") or die("FNF");
- $msg = fread($file,filesize($key));
- fclose($file);
- die($msg);
- }
- if($func == "set")
- {
- $file = fopen($key,"w");
- fwrite($file,$value);
- fclose($file);
- die("CONF");
- }
- if($func == "upd")
- {
- $file = fopen($key,"r");
- $tmpvalue = fread($file,filesize($key));
- if($tmpvalue == $pvalue)
- {
- $file = fopen($key,"w");
- fwrite($file,$value);
- fclose($file);
- die("UCONF");
- }
- else
- {
- fclose($file);
- die("FAIL");
- }
- }
- }
- else die("UA");
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement