Jump to content

Channel & Data Hash from Owner Key


Sean Martin
 Share

You are about to reply to a thread that has been inactive for 4125 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Below is an example of some code I can't get to work. Something is off and I just can't pinpoint where.

I get the data hashing just fine, the channel number generates and shows a negative value in the debug llSay.

But when attempting to actually use that value in a channel, I get errors.

It's probably something simple so thought I would toss it up here for help.

This code goes in object Send Data

//DATA SEND CODE
integer g_channelHandle;
integer g_channel;
string Msgdata;
string Pass = "N1a2r3f4";
string RegionName;

list SignupNames = ["NameTest1","NameTest2"];
list SignupKeys = ["key1","key2"];
list PlayerScore = ["0","0"];
list PlayerScrewCount = ["0","0"];
integer GameNum = 1;

integer KeyToChannel(key id)
{
    string str = (string) id;
    integer channel = 5381;
    integer i;
    for( i = 20 ; i >= 0 ; i-- )
    {
        channel = ( ( channel << 5 ) + channel ) + llSubStringIndex( " -0123456789abcdef", llGetSubString(str, i, i) );
    }
    if( channel == DEBUG_CHANNEL || ( channel >= -100000 && channel<= 100000 ) )
    // Don't allow auto generated channels between -100 000 and 100 000 - or debug channel
    // Reserve them for other purposes (like llDialog)
    channel = channel + 123456;//Add value to it if it reaches this point.
    return channel;
}

CryptMe()
{
    llListenRemove(g_channelHandle);
    RegionName = llGetRegionName();
    integer g_channelHandle;
    integer g_channel;
    g_channel = KeyToChannel( llGetOwner() );//use owners key to hash channel
    g_channel = g_channel + (GameNum * 2);//change depending on it's game number.
    g_channel = g_channel / 200;//cut it down for testing.
    g_channelHandle = llListen( g_channel, "", NULL_KEY, "" );
    Pass = "S1e2c3r4e5t6"+RegionName+(string)g_channel;
    llSay(0,"Hash Channel after crypt: "+(string)g_channel);//Hash value right after crypting
}

SendPlayerData()
{
        //Collect & compress data packets
        Msgdata = "SetDataSignupNames"+(string)GameNum+","+ llList2CSV(SignupNames);
        SendMsgData();
        Msgdata = "SetDataSignupKeys"+(string)GameNum+","+ llList2CSV(SignupKeys);
        SendMsgData();
        Msgdata = "SetDataPlayerScore"+(string)GameNum+","+ llList2CSV(PlayerScore);
        SendMsgData();
        Msgdata = "SetDataPlayerScrewCount"+(string)GameNum+","+ llList2CSV(PlayerScrewCount);
        SendMsgData();
}
SendMsgData()
{
    //Send to Data Receiver object
    string crypt = llXorBase64StringsCorrect(llStringToBase64(Msgdata), llStringToBase64(Pass));
    
    llSay(0,"DEBUG: \n Hash channel after touch: "+(string)g_channel+" \n Hashed Data: " + crypt);
    llRegionSay(g_channel,crypt);//Actual attempt usually gives errors.
}

default
{
    touch_start(integer total_number)
    {
        CryptMe();
        SendPlayerData();
    }
}

 

This code goes in object Data Receiver

integer g_channelHandle;
integer g_channel;
string Msgdata;
string Pass = "N1a2r3f4";
string RegionName;
integer GameNum = 1;
key whoheard = NULL_KEY;
list temp;

//KEY 2 CHANNEL
integer KeyToChannel(key id)
{
    string str = (string) id;
    integer channel = 5381;
    integer i;
    for( i = 20 ; i >= 0 ; i-- )
    {
        channel = ( ( channel << 5 ) + channel ) + llSubStringIndex( " -0123456789abcdef", llGetSubString(str, i, i) );
    }
    if( channel == DEBUG_CHANNEL || ( channel >= -100000 && channel<= 100000 ) )
    // Don't allow auto generated channels between -100 000 and 100 000 - or debug channel
    // Reserve them for other purposes (like llDialog)
    channel = channel + 123456;//Add value to it if it reaches this point.
    return channel;
}

CryptMe()
{
    llListenRemove(g_channelHandle);
    RegionName = llGetRegionName();
    integer g_channelHandle;
    integer g_channel;
    g_channel = KeyToChannel( llGetOwner() );//use owners key to hash channel
    g_channel = g_channel + (GameNum * 2);//change depending on it's game number.
    g_channel = g_channel / 200;//cut it down for testing.
    g_channelHandle = llListen( g_channel, "", NULL_KEY, "" );
    Pass = "S1e2c3r4e5t6"+RegionName+(string)g_channel;
    llSay(0,"Hash Channel after crypt: "+(string)g_channel);//Hash value right after crypting
}
SendMsgData()
{
    string crypt = llXorBase64StringsCorrect(llStringToBase64(Msgdata), llStringToBase64(Pass));
    llRegionSay(g_channel,crypt);
}
default
{
    state_entry()
    {
        CryptMe();
    }
    on_rez(integer RezAmount)
    {
        CryptMe();
    }

    touch_start(integer total_number)
    {
        llResetScript();
    }
    
    listen(integer chan, string name, key who, string tmpMsg)
    {
        string msg = tmpMsg;
        temp = llCSV2List(msg);
        msg = llBase64ToString(llXorBase64StringsCorrect(tmpMsg, llStringToBase64(Pass)));
        if((string)llList2String(temp, 0) == "SetDataSignupNames")
        {
            llSay(0,(string)temp);
        }
        if((string)llList2String(temp, 0) == "SetDataSignupKeys")
        {
            llSay(0,(string)temp);
        }
        if((string)llList2String(temp, 0) == "SetDataPlayerScore")
        {
            llSay(0,(string)temp);
        }
        if((string)llList2String(temp, 0) == "SetDataPlayerScrewCount")
        {
            llSay(0,(string)temp);
        }
    }
}

 Part of this code was started from a key to channel post elsewhere. Which generates the negative channel from the owners key. As I said that seems to work fine as I post it in chat after it's generated.

But something is going wrong with usage.

Thanks for any help.

Link to comment
Share on other sites

Ok found a fix after messing with it a bit more. Integer g_channel was declaired twice causing it to reset to 0. And some parsing issues we're fixed after it finally sent correctly.

Posting code incase others need it.

Wouldn't hurt to see it cleaned up a bit more for others to use. But it should work well enough.

Data Send

integer g_channelHandle;integer g_channel;string Msgdata;string Pass = "N1a2r3f4";//Placeholder password. Will be changed in hash below.string RegionName;list SignupNames = ["NameTest1","NameTest2"];list SignupKeys = ["key1","key2"];list PlayerScore = ["3","4"];list PlayerScrewCount = ["5","6"];integer GameNum = 1;integer TestChan;integer KeyToChannel(key id){    string str = (string) id;    integer channel = 5381;    integer i;    for( i = 20 ; i >= 0 ; i-- )    {        channel = ( ( channel << 5 ) + channel ) + llSubStringIndex( " -0123456789abcdef", llGetSubString(str, i, i) );    }    if( channel == DEBUG_CHANNEL || ( channel >= -100000 && channel<= 100000 ) )    // Don't allow auto generated channels between -100 000 and 100 000 - or debug channel    // Reserve them for other purposes (like llDialog)    channel = channel + 123456;//Add value to it if it reaches this point.    return channel;}CryptMe(){    llListenRemove(g_channelHandle);    RegionName = llGetRegionName();    g_channelHandle;    g_channel;    g_channel = KeyToChannel( llGetOwner() );//use owners key to hash channel    g_channel = g_channel + (GameNum * 2);//change depending on it's game number.    g_channel = g_channel / 200;//cut it down for testing.    g_channelHandle = llListen( g_channel, "", NULL_KEY, "" );    Pass = "S1e2c3r4e5t6"+RegionName+(string)g_channel;}SendPlayerData(){        //Collect & compress data        Msgdata = "SetDataSignupNames"+(string)GameNum+","+ llList2CSV(SignupNames);        SendMsgData();        Msgdata = "SetDataSignupKeys"+(string)GameNum+","+ llList2CSV(SignupKeys);        SendMsgData();        Msgdata = "SetDataPlayerScore"+(string)GameNum+","+ llList2CSV(PlayerScore);        SendMsgData();        Msgdata = "SetDataPlayerScrewCount"+(string)GameNum+","+ llList2CSV(PlayerScrewCount);        SendMsgData();}SendMsgData(){    //Send to Data Receiver object    string crypt = llXorBase64StringsCorrect(llStringToBase64(Msgdata), llStringToBase64(Pass));    llRegionSay(g_channel,crypt);}default{    state_entry()    {        CryptMe();    }    on_rez(integer RezAmount)    {        CryptMe();    }    touch_start(integer total_number)    {        SendPlayerData();    }}

 

Data Receiver

integer g_channelHandle;integer g_channel;string Msgdata;string Pass = "N1a2r3f4";string RegionName;integer GameNum = 1;key whoheard = NULL_KEY;list temp;//KEY 2 CHANNELinteger KeyToChannel(key id){    string str = (string) id;    integer channel = 5381;    integer i;    for( i = 20 ; i >= 0 ; i-- )    {        channel = ( ( channel << 5 ) + channel ) + llSubStringIndex( " -0123456789abcdef", llGetSubString(str, i, i) );    }    if( channel == DEBUG_CHANNEL || ( channel >= -100000 && channel<= 100000 ) )    // Don't allow auto generated channels between -100 000 and 100 000 - or debug channel    // Reserve them for other purposes (like llDialog)    channel = channel + 123456;//Add value to it if it reaches this point.    return channel;}CryptMe(){    llListenRemove(g_channelHandle);    RegionName = llGetRegionName();    g_channelHandle;    g_channel;    g_channel = KeyToChannel( llGetOwner() );//use owners key to hash channel    g_channel = g_channel + (GameNum * 2);//change depending on it's game number.    g_channel = g_channel / 200;//cut it down for testing.    g_channelHandle = llListen( g_channel, "", NULL_KEY, "" );    Pass = "S1e2c3r4e5t6"+RegionName+(string)g_channel;//Change this to your own password.}SendMsgData(){    string crypt = llXorBase64StringsCorrect(llStringToBase64(Msgdata), llStringToBase64(Pass));    llRegionSay(g_channel,crypt);}default{    state_entry()    {        CryptMe();    }    on_rez(integer RezAmount)    {        CryptMe();    }    touch_start(integer total_number)    {        llResetScript();    }        listen(integer chan, string name, key who, string tmpMsg)    {        string msg = tmpMsg;        msg = llBase64ToString(llXorBase64StringsCorrect(tmpMsg, llStringToBase64(Pass)));//decode        temp = llCSV2List(msg);//convert to list again                //pull data from list and place into variables (llSay for testing)        if((string)llList2String(temp, 0) == "SetDataSignupNames"+(string)GameNum)        {            llSay(0,(string)llList2String(temp, 1));            llSay(0,(string)llList2String(temp, 2));            llSay(0,(string)llList2String(temp, 3));            llSay(0,(string)llList2String(temp, 4));        }        if((string)llList2String(temp, 0) == "SetDataSignupKeys"+(string)GameNum)        {            llSay(0,(string)llList2String(temp, 1));            llSay(0,(string)llList2String(temp, 2));            llSay(0,(string)llList2String(temp, 3));            llSay(0,(string)llList2String(temp, 4));        }        if((string)llList2String(temp, 0) == "SetDataPlayerScore"+(string)GameNum)        {            llSay(0,(string)llList2String(temp, 1));            llSay(0,(string)llList2String(temp, 2));            llSay(0,(string)llList2String(temp, 3));            llSay(0,(string)llList2String(temp, 4));        }        if((string)llList2String(temp, 0) == "SetDataPlayerScrewCount"+(string)GameNum)        {            llSay(0,(string)llList2String(temp, 1));            llSay(0,(string)llList2String(temp, 2));            llSay(0,(string)llList2String(temp, 3));            llSay(0,(string)llList2String(temp, 4));        }    }}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4125 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...