OsListenRegex
From OpenSimulator
(Difference between revisions)
(Add exemple using OS_LISTEN_REGEX_NAME) |
|||
Line 6: | Line 6: | ||
|description=Allows the server to filter listen events by regular expressions. name or message parameters can be regular expressions, these are behaviours are controlled via the regexBitField parameter using the constants [[OS_LISTEN_REGEX_NAME]] and [[OS_LISTEN_REGEX_MESSAGE]]. | |description=Allows the server to filter listen events by regular expressions. name or message parameters can be regular expressions, these are behaviours are controlled via the regexBitField parameter using the constants [[OS_LISTEN_REGEX_NAME]] and [[OS_LISTEN_REGEX_MESSAGE]]. | ||
If the regex strings are invalid, an error will be shouted on the debug channel. | If the regex strings are invalid, an error will be shouted on the debug channel. | ||
+ | |ossl_example= | ||
+ | '''With OS_LISTEN_REGEX_NAME:''' Filter only the detected name | ||
+ | <source lang="lsl"> | ||
+ | // | ||
+ | // osListenRegex Script Example | ||
+ | // Author: djphil | ||
+ | // | ||
+ | |||
+ | integer channelID = PUBLIC_CHANNEL; | ||
+ | integer handler; | ||
+ | integer swith; | ||
+ | |||
+ | default | ||
+ | { | ||
+ | state_entry() | ||
+ | { | ||
+ | llSay(PUBLIC_CHANNEL, "Touch to see osListenRegex usage."); | ||
+ | llSay(PUBLIC_CHANNEL, "This with the use of the Regex Bitfield OS_LISTEN_REGEX_NAME."); | ||
+ | llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0); | ||
+ | } | ||
+ | |||
+ | touch_start(integer number) | ||
+ | { | ||
+ | if (swith = !swith) | ||
+ | { | ||
+ | string name = llDetectedName(0); | ||
+ | handler = osListenRegex(channelID, name, NULL_KEY, "", OS_LISTEN_REGEX_NAME); | ||
+ | llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is open."); | ||
+ | llSay(PUBLIC_CHANNEL, "The regex name is " + (string)name); | ||
+ | llSetText("[ON]", <1.0, 1.0, 1.0>, 1.0); | ||
+ | llSetTimerEvent(30.0); | ||
+ | } | ||
+ | |||
+ | else | ||
+ | { | ||
+ | llSetTimerEvent(0.0); | ||
+ | llListenRemove(handler); | ||
+ | llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is closed."); | ||
+ | llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | listen(integer channel, string name, key id, string message) | ||
+ | { | ||
+ | if (channel == channelID) | ||
+ | { | ||
+ | llSay(PUBLIC_CHANNEL, (string)channel + ") " + (string)id + " " + name + " " + message); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | timer() | ||
+ | { | ||
+ | swith = !swith; | ||
+ | llSetTimerEvent(0.0); | ||
+ | llListenRemove(handler); | ||
+ | llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is closed."); | ||
+ | llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0); | ||
+ | } | ||
+ | } | ||
+ | </source> | ||
|additional_info=This function was added in 0.7.5-post-fixes | |additional_info=This function was added in 0.7.5-post-fixes | ||
}} | }} | ||
− | |||
== See Also == | == See Also == | ||
* [[osRegexIsMatch]] | * [[osRegexIsMatch]] | ||
* [http://wiki.secondlife.com/wiki/llListen llListen] | * [http://wiki.secondlife.com/wiki/llListen llListen] | ||
* [http://wiki.secondlife.com/wiki/listen listen] | * [http://wiki.secondlife.com/wiki/listen listen] |
Revision as of 23:39, 12 December 2020
integer osListenRegex(integer channelID, string name, key ID, string msg, integer regexBitfield)
| |
Allows the server to filter listen events by regular expressions. name or message parameters can be regular expressions, these are behaviours are controlled via the regexBitField parameter using the constants OS_LISTEN_REGEX_NAME and OS_LISTEN_REGEX_MESSAGE.
If the regex strings are invalid, an error will be shouted on the debug channel. | |
Threat Level | Low |
Permissions | Use of this function is always allowed by default |
Extra Delay | 0 seconds |
Example(s) | |
With OS_LISTEN_REGEX_NAME: Filter only the detected name
// // osListenRegex Script Example // Author: djphil // integer channelID = PUBLIC_CHANNEL; integer handler; integer swith; default { state_entry() { llSay(PUBLIC_CHANNEL, "Touch to see osListenRegex usage."); llSay(PUBLIC_CHANNEL, "This with the use of the Regex Bitfield OS_LISTEN_REGEX_NAME."); llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0); } touch_start(integer number) { if (swith = !swith) { string name = llDetectedName(0); handler = osListenRegex(channelID, name, NULL_KEY, "", OS_LISTEN_REGEX_NAME); llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is open."); llSay(PUBLIC_CHANNEL, "The regex name is " + (string)name); llSetText("[ON]", <1.0, 1.0, 1.0>, 1.0); llSetTimerEvent(30.0); } else { llSetTimerEvent(0.0); llListenRemove(handler); llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is closed."); llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0); } } listen(integer channel, string name, key id, string message) { if (channel == channelID) { llSay(PUBLIC_CHANNEL, (string)channel + ") " + (string)id + " " + name + " " + message); } } timer() { swith = !swith; llSetTimerEvent(0.0); llListenRemove(handler); llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is closed."); llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0); } } | |
Notes | |
This function was added in 0.7.5-post-fixes |