This is a very secure authenticated message system for chat. It could use some tweaking, as if the message contains commas it will likely break.
//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();
}
}
Examples