User:Jana Kamachi/Trash/Simple

From Second Life Wiki
Jump to navigation Jump to search

If you like this script, or any script I've released, please post on my Talk page, or I'll most likely never see it o: If you want to improve a script, just go for it!


This is a very simple example showing how to secure some basic cross-object communication. The key to this is using a unique modifier. But the values have to be the same in each script!

Part 1

Stick into an object called "hash1"

integer COMMAND_CHANNEL = 0;
key     hash2_key       = "";

integer modifier        = 40505;


default
{
    state_entry()
    {
        llListen(COMMAND_CHANNEL,"hash2","","");
    }
    
    listen(integer p, string name, key id, string msg){
        if(msg == "key"){
            hash2_key = id;
            llSay(0,"master found: " + (string)id);
            llSay(COMMAND_CHANNEL,"9" + (string)(llGetUnixTime() + modifier));
        }
    }
}

Part 2

Stick this into an item called "hash2".

integer COMMAND_CHANNEL = 0;
integer MODIFIER        = 40505;

auth(integer x){
    integer t = llGetUnixTime() + MODIFIER;
    if(t - x < 3){
        llSay(0,"Confirmed, good hash.");
        return;
    }else{
        llSay(0,"Illegal Hash");   
    }
       
}

default
{
    state_entry()
    {
        llListen(COMMAND_CHANNEL,"hash1","","");
        llSay(COMMAND_CHANNEL,"key");
    }
    
    listen(integer c, string name, key id, string msg){
        if(llGetSubString(msg,0,0) == "9"){
            llSay(0,"Got Hash " + msg + ", auth...");   
            auth((integer)llGetSubString(msg,1,llStringLength(msg)));
        }   
    }
}