Skip to content

Instantly share code, notes, and snippets.

@typhartez
Last active December 7, 2020 10:03
Show Gist options
  • Select an option

  • Save typhartez/6c520a98e46a7062cfec3d82569dfe46 to your computer and use it in GitHub Desktop.

Select an option

Save typhartez/6c520a98e46a7062cfec3d82569dfe46 to your computer and use it in GitHub Desktop.
Key to channel

Make a llListen() usable integer from an UUID, using an application key (integer specific to that product).

The channel will follow the application key sign (if negative, the channel will be negative too).

integer APP_KEY = 455867;

integer key2chan(key id, integer app) {
    integer mult = 1;
    if (app < 0) mult = -1;
    return mult * ((app ^ (integer)("0x" + (string)id)) & 0x7fffffff);
}

default {
    state_entry() {
        // use owner key to have any object knowing APP_KEY talking with us
        integer negative_channel_for_listeners = key2chan(llGetOwner(), -APP_KEY);
        // use object key to restrict to our object (ideal for RLV replies)
        integer positive_channel_for_rlv = key2chan(llGetKey(), APP_KEY);
    }
}

String version, negative channel

string APPKEY="c77f2965-7061-41a2-b84a-77ad84bdbfdd"; // get this from any object

integer key2chan(key user) {
    return 0x80000000 | ((integer)("0x"+llGetSubString(user, 0, 7)) ^ (integer)("0x"+llGetSubString(APPKEY, 0, 7)));
}

default {
    state_entry() {
        // use owner key to have any object knowing APP_KEY talking with us
        integer negative_channel_for_listeners = key2chan(llGetOwner());
    }
}

String version, positive channel

string APPKEY="c77f2965-7061-41a2-b84a-77ad84bdbfdd"; // get this from any object

integer key2chan(key user) {
    return 0x7fffffff & ((integer)("0x"+llGetSubString(user, 0, 7)) ^ (integer)("0x"+llGetSubString(APPKEY, 0, 7)));
}

default {
    state_entry() {
        // use owner key to have any object knowing APP_KEY talking with us
        integer positive_channel_for_listeners = key2chan(llGetOwner());
    }
}

Simple random channel for user

integer key2chan(key user) {
    return 0x80000000 | ((integer)("0x"+llGetSubString(user, 0, 7)) ^ ((integer)llFrand(0x7FFFFF80) + 1));
}

default {
    state_entry() {
        // use owser key to have a unique menu channel
        integer menu_channel = key2chan(llGetOwner());
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment