Authenticated Chat

From Second Life Wiki
Revision as of 17:42, 29 August 2007 by Gigs Taggart (talk | contribs) (new)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Here's a method of authenticated chat with shared secret.


//By: Gigs Taggart
//Released under BSD license

key gSetupQueryId;

integer gSetupNotecardLine;

string  gSetupNotecardName = "setup";

string gPassword;


//to sign a message we hash message+gSecret+llGetKey()
string sign_message(string message)
{
        string hash=llMD5String(message+gPassword+(string)llGetKey(), 0);
        return llList2CSV([message,hash]);
}


//to verify a message we do all the same stuff except we get the sender's key
integer verify_message(string message, key sender)
{
    list incoming=llCSV2List(message);
    string hash=llMD5String(llList2String(incoming, 0) +gPassword+(string)sender, 0);
    if (llList2String(incoming,1)!=hash)
        return FALSE;
    else
        return TRUE;
}

readSettingsNotecard()
{
   gSetupNotecardLine = 0;
   gSetupQueryId = llGetNotecardLine(gSetupNotecardName,gSetupNotecardLine); 
}


default
{
    state_entry()
    {
         readSettingsNotecard();
    }
    dataserver(key queryId, string data)
    {
        if(queryId == gSetupQueryId) 
        {
            if(data != EOF)
            {
                list tmp = llParseString2List(data, ["="], []);
                string setting = llList2String(tmp,0);
                if (setting == "password")
                {
                    gPassword=llList2String(tmp,1);
                }
                    
                gSetupQueryId = llGetNotecardLine(gSetupNotecardName,++gSetupNotecardLine); 
            }
            else
            {
                state running;   
            }
        }
    }           
    changed(integer change)
    {
        llResetScript();
    }
}

state running
{

    changed(integer change)
    {
        llResetScript();
    }
}