Difference between revisions of "UUID2Channel"
(→Suggested Improvement: comment was correct, it was capable of returning 0.) |
m (Added a few links as well as a category) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
[[Category:LSL Examples]] | |||
== Description == | |||
Well, I've figured out a more effective way of using the UUID2Channel method, you know. | Varying functions to convert a Key ([[UUID]]) to an [[Integer]], for use as a [[:Category:LSL_Chat|LSL Chat]] Channel. | ||
The one where you put a hexadecimal prefix | |||
== Method 1 - Simple == | |||
Well, I've figured out a more effective way of using the {{mono|UUID2Channel}} method, you know. | |||
The one where you put a hexadecimal prefix in front of a person's UUID. Always generates | |||
negative integers, for safety. | negative integers, for safety. | ||
= | <syntaxhighlight lang="lsl2"> | ||
// Project Neox was here. | // Project Neox was here. | ||
// Web Gearbox was here too | // Web Gearbox was here too | ||
integer | integer Key2Chan(key ID) { | ||
return 0x80000000 | (integer)("0x" + (string) | return 0x80000000 | (integer)("0x"+(string)ID); | ||
} | } | ||
</ | </syntaxhighlight> | ||
=== | ==== Improvement - App Key ==== | ||
This generates a unique channel ID from the | This generates a unique channel ID from the input key, but also XOR's it with another value, this value should be application specific. | ||
I encountered an issue where one of the commonly used combat meters (Gorean Meter I think) is using the exact function above to generate its personal channel numbers, and starts complaining - loudly (shouts) - if you put other data on the same channel (user is flooding their own channels!). | I encountered an issue where one of the commonly used combat meters (Gorean Meter I think) is using the exact function above to generate its personal channel numbers, and starts complaining - loudly (shouts) - if you put other data on the same channel (user is flooding their own channels!). | ||
Line 24: | Line 27: | ||
As such you shouldn't really use the above function directly for channel IDs, if everyone did, it would negate the entire point of the function, the version below allows you to supply a random constant number to push the allocations around so we're not going to see same-user collisions between applications. | As such you shouldn't really use the above function directly for channel IDs, if everyone did, it would negate the entire point of the function, the version below allows you to supply a random constant number to push the allocations around so we're not going to see same-user collisions between applications. | ||
< | <syntaxhighlight lang="lsl2"> | ||
// modified channel generator to include per-application key, preventing cross-application collisions | // modified channel generator to include per-application key, preventing cross-application collisions | ||
// - Iain Maltz | // - Iain Maltz | ||
integer | integer Key2AppChan(key ID, integer App) { | ||
{ | return 0x80000000 | ((integer)("0x"+(string)ID) ^ App); | ||
return 0x80000000 | (((integer)("0x"+(string) | } | ||
</syntaxhighlight> | |||
== Method 2 - Defined Base/Range == | |||
<syntaxhighlight lang="lsl2"> | |||
// # Base/Range-Method Channel Generator. | |||
// > Allows for limiting the channel-band spread to only the amount needed for the application. | |||
// - Faust Vollmar | |||
integer uiKey2Range(key vkID, integer viBase, integer viRange) | |||
{// # Result will be added or subtracted dependent on viBase being positive or negative, for intuitive results. | |||
// > Example: -56000/1000 will result in -56000 to -56999, whereas 56000/1000 will result in 56000 to 56999 | |||
integer viMult = 1; | |||
if( viBase < 0 ) { viMult = -1; } | |||
return (viBase+(viMult*(((integer)("0x"+(string)vkID)&0x7FFFFFFF)%viRange))); | |||
} | } | ||
</ | </syntaxhighlight> |
Latest revision as of 17:31, 15 December 2022
Description
Varying functions to convert a Key (UUID) to an Integer, for use as a LSL Chat Channel.
Method 1 - Simple
Well, I've figured out a more effective way of using the UUID2Channel method, you know. The one where you put a hexadecimal prefix in front of a person's UUID. Always generates negative integers, for safety.
// Project Neox was here.
// Web Gearbox was here too
integer Key2Chan(key ID) {
return 0x80000000 | (integer)("0x"+(string)ID);
}
Improvement - App Key
This generates a unique channel ID from the input key, but also XOR's it with another value, this value should be application specific.
I encountered an issue where one of the commonly used combat meters (Gorean Meter I think) is using the exact function above to generate its personal channel numbers, and starts complaining - loudly (shouts) - if you put other data on the same channel (user is flooding their own channels!).
As such you shouldn't really use the above function directly for channel IDs, if everyone did, it would negate the entire point of the function, the version below allows you to supply a random constant number to push the allocations around so we're not going to see same-user collisions between applications.
// modified channel generator to include per-application key, preventing cross-application collisions
// - Iain Maltz
integer Key2AppChan(key ID, integer App) {
return 0x80000000 | ((integer)("0x"+(string)ID) ^ App);
}
Method 2 - Defined Base/Range
// # Base/Range-Method Channel Generator.
// > Allows for limiting the channel-band spread to only the amount needed for the application.
// - Faust Vollmar
integer uiKey2Range(key vkID, integer viBase, integer viRange)
{// # Result will be added or subtracted dependent on viBase being positive or negative, for intuitive results.
// > Example: -56000/1000 will result in -56000 to -56999, whereas 56000/1000 will result in 56000 to 56999
integer viMult = 1;
if( viBase < 0 ) { viMult = -1; }
return (viBase+(viMult*(((integer)("0x"+(string)vkID)&0x7FFFFFFF)%viRange)));
}