| Anonymous | Login | Signup for a new account | 2013-05-25 00:56 UTC | ![]() |
| Main | My View | View Issues | Change Log | Roadmap | Summary | My Account |
| View Issue Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||||
| ID | Project | Category | View Status | Date Submitted | Last Update | ||||
| 0006106 | opensim | [REGION] Script Functions | public | 2012-07-25 14:17 | 2012-10-26 02:07 | ||||
| Reporter | SignpostMarv | ||||||||
| Assigned To | justincc | ||||||||
| Priority | normal | Severity | minor | Reproducibility | have not tried | ||||
| Status | resolved | Resolution | fixed | ||||||
| Platform | OS | OS Version | |||||||
| Product Version | master (dev code) | ||||||||
| Target Version | Fixed in Version | ||||||||
| Summary | 0006106: ability for listeners to be filtered by regular expression | ||||||||
| Description | Added a function that behaves identically to llListen() except for a new parameter which acts as a bitfield to indicate which of the string parameters should be treated as a regular expression. 1 corresponds to the name parameter 2 corresponds to the message parameter so 3 corresponds to both :D | ||||||||
| Steps To Reproduce | string input; output() { llOwnerSay("/me recorded: " + input); llOwnerSay("/me receieved: " + (string)((integer)input)); input = ""; llSetTimerEvent(0); } display() { llSetText(input, ZERO_VECTOR, 1); } default { state_entry() { input = ""; osListenRegex(0, "", NULL_KEY, "^(\\d|Enter|Backspace|Del)$", 2); } listen(integer c, string n, key i, string m) { llOwnerSay("/me heard: " + m); if(osRegexIsMatch(m, "^\\d$")) { input += m; } else if(m == "Enter") { output(); return; } else if(m == "Backspace" && input != "") { input = llGetSubString(input, 0, -2); } else if(m == "Del") { input = ""; display(); llSetTimerEvent(0); return; } display(); llSetTimerEvent(2); } timer() { output(); } } | ||||||||
| Tags | No tags attached. | ||||||||
| Git Revision or version number | 3cf8edf | ||||||||
| Run Mode | Standalone (1 Region) | ||||||||
| Physics Engine | BasicPhysics | ||||||||
| Environment | .NET / Windows32 | ||||||||
| Mono Version | None | ||||||||
| Viewer | |||||||||
| Attached Files | From 4917e3936c3951e9da5c993d03e9fcc4e117b941 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Wed, 25 Jul 2012 15:11:57 +0100
Subject: [PATCH] adding ability for listeners to be filtered by regular
expressions
---
.../Scripting/WorldComm/WorldCommModule.cs | 91 +++++++++++++++++-----
OpenSim/Region/Framework/Interfaces/IWorldComm.cs | 30 ++++++-
.../Shared/Api/Implementation/OSSL_Api.cs | 44 +++++++++++
.../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 14 ++++
.../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 ++
5 files changed, 162 insertions(+), 22 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index 8358bc0..99a77fb 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -28,6 +28,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Text.RegularExpressions;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
@@ -179,6 +180,26 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
}
/// <summary>
+ /// Create a listen event callback with the specified filters.
+ /// The parameters localID,itemID are needed to uniquely identify
+ /// the script during 'peek' time. Parameter hostID is needed to
+ /// determine the position of the script.
+ /// </summary>
+ /// <param name="localID">localID of the script engine</param>
+ /// <param name="itemID">UUID of the script engine</param>
+ /// <param name="hostID">UUID of the SceneObjectPart</param>
+ /// <param name="channel">channel to listen on</param>
+ /// <param name="name">name to filter on</param>
+ /// <param name="id">key to filter on (user given, could be totally faked)</param>
+ /// <param name="msg">msg to filter on</param>
+ /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
+ /// <returns>number of the scripts handle</returns>
+ public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ {
+ return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg, regexBitfield);
+ }
+
+ /// <summary>
/// Sets the listen event with handle as active (active = TRUE) or inactive (active = FALSE).
/// The handle used is returned from Listen()
/// </summary>
@@ -467,6 +488,11 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg)
{
+ return AddListener(localID, itemID, hostID, channel, name, id, msg, 0);
+ }
+
+ public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ {
// do we already have a match on this particular filter event?
List<ListenerInfo> coll = GetListeners(itemID, channel, name, id, msg);
@@ -485,7 +511,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
if (newHandle > 0)
{
- ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg);
+ ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg, regexBitfield);
List<ListenerInfo> listeners;
if (!m_listeners.TryGetValue(channel,out listeners))
@@ -651,7 +677,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
continue;
}
- if (li.GetName().Length > 0 && !li.GetName().Equals(name))
+ if (li.GetName().Length > 0 && (
+ ((li.GetRegexBitfield() & 1) != 1 && !li.GetName().Equals(name)) ||
+ ((li.GetRegexBitfield() & 1) == 1 && !Regex.IsMatch(name, li.GetName()))
+ ))
{
continue;
}
@@ -659,7 +688,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
continue;
}
- if (li.GetMessage().Length > 0 && !li.GetMessage().Equals(msg))
+ bool test = (li.GetRegexBitfield() & 2) == 2;
+ bool test2 = test && Regex.IsMatch(msg, li.GetMessage());
+ if (li.GetMessage().Length > 0 && (
+ ((li.GetRegexBitfield() & 2) != 2 && !li.GetMessage().Equals(msg)) ||
+ ((li.GetRegexBitfield() & 2) == 2 && !Regex.IsMatch(msg, li.GetMessage()))
+ ))
{
continue;
}
@@ -680,25 +714,25 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
foreach (ListenerInfo l in list)
{
if (l.GetItemID() == itemID)
+ {
data.AddRange(l.GetSerializationData());
+ }
}
}
}
return (Object[])data.ToArray();
}
- public void AddFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data)
+ public void AddFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
int idx = 0;
- Object[] item = new Object[6];
+ Object[] item = new Object[7];
while (idx < data.Length)
{
- Array.Copy(data, idx, item, 0, 6);
+ Array.Copy(data, idx, item, 0, 7);
- ListenerInfo info =
- ListenerInfo.FromData(localID, itemID, hostID, item);
+ ListenerInfo info = ListenerInfo.FromData(localID, itemID, hostID, item);
lock (m_listeners)
{
@@ -712,7 +746,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
}
}
- public class ListenerInfo: IWorldCommListenerInfo
+ public class ListenerInfo : IWorldCommListenerInfo
{
private bool m_active; // Listener is active or not
private int m_handle; // Assigned handle of this listener
@@ -723,19 +757,29 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
private UUID m_id; // ID to filter messages from
private string m_name; // Object name to filter messages from
private string m_message; // The message
+ private byte m_regexBitfield; // The regex bitfield
public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message)
{
- Initialise(handle, localID, ItemID, hostID, channel, name, id, message);
+ Initialise(handle, localID, ItemID, hostID, channel, name, id, message, 0);
+ }
+
+ public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
+ {
+ Initialise(handle, localID, ItemID, hostID, channel, name, id, message, regexBitfield);
}
public ListenerInfo(ListenerInfo li, string name, UUID id, string message)
{
- Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message);
+ Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, 0);
}
- private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name,
- UUID id, string message)
+ public ListenerInfo(ListenerInfo li, string name, UUID id, string message, byte regexBitfield)
+ {
+ Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, regexBitfield);
+ }
+
+ private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
{
m_active = true;
m_handle = handle;
@@ -746,11 +790,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
m_name = name;
m_id = id;
m_message = message;
+ m_regexBitfield = regexBitfield;
}
public Object[] GetSerializationData()
{
- Object[] data = new Object[6];
+ Object[] data = new Object[7];
data[0] = m_active;
data[1] = m_handle;
@@ -758,16 +803,19 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
data[3] = m_name;
data[4] = m_id;
data[5] = m_message;
+ data[6] = m_regexBitfield;
return data;
}
public static ListenerInfo FromData(uint localID, UUID ItemID, UUID hostID, Object[] data)
{
- ListenerInfo linfo = new ListenerInfo((int)data[1], localID,
- ItemID, hostID, (int)data[2], (string)data[3],
- (UUID)data[4], (string)data[5]);
- linfo.m_active=(bool)data[0];
+ ListenerInfo linfo = new ListenerInfo((int)data[1], localID, ItemID, hostID, (int)data[2], (string)data[3], (UUID)data[4], (string)data[5]);
+ linfo.m_active = (bool)data[0];
+ if (data.Length >= 7)
+ {
+ linfo.m_regexBitfield = (byte)data[6];
+ }
return linfo;
}
@@ -826,5 +874,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
return m_id;
}
+
+ public byte GetRegexBitfield()
+ {
+ return m_regexBitfield;
+ }
}
}
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index 4e74781..39832c6 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -45,6 +45,14 @@ namespace OpenSim.Region.Framework.Interfaces
void Deactivate();
void Activate();
UUID GetID();
+
+ /// <summary>
+ /// Bitfield indicating which strings should be processed as regex.
+ /// 1 corresponds to IWorldCommListenerInfo::GetName()
+ /// 2 corresponds to IWorldCommListenerInfo::GetMessage()
+ /// </summary>
+ /// <returns></returns>
+ byte GetRegexBitfield();
}
public interface IWorldComm
@@ -60,7 +68,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// the script during 'peek' time. Parameter hostID is needed to
/// determine the position of the script.
/// </summary>
- /// <param name="localID">localID of the script engine</param>
+ /// <param name="LocalID">localID of the script engine</param>
/// <param name="itemID">UUID of the script engine</param>
/// <param name="hostID">UUID of the SceneObjectPart</param>
/// <param name="channel">channel to listen on</param>
@@ -71,6 +79,23 @@ namespace OpenSim.Region.Framework.Interfaces
int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg);
/// <summary>
+ /// Create a listen event callback with the specified filters.
+ /// The parameters localID,itemID are needed to uniquely identify
+ /// the script during 'peek' time. Parameter hostID is needed to
+ /// determine the position of the script.
+ /// </summary>
+ /// <param name="LocalID">localID of the script engine</param>
+ /// <param name="itemID">UUID of the script engine</param>
+ /// <param name="hostID">UUID of the SceneObjectPart</param>
+ /// <param name="channel">channel to listen on</param>
+ /// <param name="name">name to filter on</param>
+ /// <param name="id">key to filter on (user given, could be totally faked)</param>
+ /// <param name="msg">msg to filter on</param>
+ /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
+ /// <returns>number of the scripts handle</returns>
+ int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield);
+
+ /// <summary>
/// This method scans over the objects which registered an interest in listen callbacks.
/// For everyone it finds, it checks if it fits the given filter. If it does, then
/// enqueue the message for delivery to the objects listen event handler.
@@ -121,7 +146,6 @@ namespace OpenSim.Region.Framework.Interfaces
void ListenRemove(UUID itemID, int handle);
void DeleteListener(UUID itemID);
Object[] GetSerializationData(UUID itemID);
- void CreateFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data);
+ void CreateFromData(uint localID, UUID itemID, UUID hostID, Object[] data);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index e0b4db6..8550374 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3288,5 +3288,49 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
UUID test;
return UUID.TryParse(thing, out test) ? 1 : 0;
}
+
+ public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
+ {
+ CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ m_host.AddScriptLPS(1);
+ UUID keyID;
+ UUID.TryParse(ID, out keyID);
+
+ if((regexBitfield & 1) == 1){ // if we want the name to be used as a regular expression, ensure it is valid first.
+ try
+ {
+ Regex.IsMatch("", name);
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Name regex is invalid.");
+ return -1;
+ }
+ }
+ if ((regexBitfield & 2) == 2) // if we want the msg to be used as a regular expression, ensure it is valid first.
+ {
+ try
+ {
+ Regex.IsMatch("", msg);
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Message regex is invalid.");
+ return -1;
+ }
+ }
+
+ IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
+ return (wComm == null) ? -1 : wComm.Listen(
+ m_host.LocalId,
+ m_item.ItemID,
+ m_host.UUID,
+ channelID,
+ name,
+ keyID,
+ msg,
+ (byte)regexBitfield
+ );
+ }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index c9403eb..9f7b331 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -283,5 +283,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// <param name="thing"></param>
/// <returns>1 if thing is a valid UUID, 0 otherwise</returns>
LSL_Integer osIsUUID(string thing);
+
+ /// <summary>
+ /// Identical to llListen except for a bitfield which indicates which string parameters should be parsed as regex patterns.
+ /// </summary>
+ /// <param name="channelID"></param>
+ /// <param name="name"></param>
+ /// <param name="ID"></param>
+ /// <param name="msg"></param>
+ /// <param name="regexBitfield">
+ /// 1 corresponds to name
+ /// 2 corresponds to msg
+ /// </param>
+ /// <returns></returns>
+ LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 99995a7..9f7e604 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -935,5 +935,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
return m_OSSL_Functions.osIsUUID(thing);
}
+
+ public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
+ {
+ return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield);
+ }
}
}
--
1.7.11.msysgit.1
From 4917e3936c3951e9da5c993d03e9fcc4e117b941 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Wed, 25 Jul 2012 15:11:57 +0100
Subject: [PATCH 1/4] adding ability for listeners to be filtered by regular
expressions
---
.../Scripting/WorldComm/WorldCommModule.cs | 91 +++++++++++++++++-----
OpenSim/Region/Framework/Interfaces/IWorldComm.cs | 30 ++++++-
.../Shared/Api/Implementation/OSSL_Api.cs | 44 +++++++++++
.../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 14 ++++
.../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 ++
5 files changed, 162 insertions(+), 22 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index 8358bc0..99a77fb 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -28,6 +28,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Text.RegularExpressions;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
@@ -179,6 +180,26 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
}
/// <summary>
+ /// Create a listen event callback with the specified filters.
+ /// The parameters localID,itemID are needed to uniquely identify
+ /// the script during 'peek' time. Parameter hostID is needed to
+ /// determine the position of the script.
+ /// </summary>
+ /// <param name="localID">localID of the script engine</param>
+ /// <param name="itemID">UUID of the script engine</param>
+ /// <param name="hostID">UUID of the SceneObjectPart</param>
+ /// <param name="channel">channel to listen on</param>
+ /// <param name="name">name to filter on</param>
+ /// <param name="id">key to filter on (user given, could be totally faked)</param>
+ /// <param name="msg">msg to filter on</param>
+ /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
+ /// <returns>number of the scripts handle</returns>
+ public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ {
+ return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg, regexBitfield);
+ }
+
+ /// <summary>
/// Sets the listen event with handle as active (active = TRUE) or inactive (active = FALSE).
/// The handle used is returned from Listen()
/// </summary>
@@ -467,6 +488,11 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg)
{
+ return AddListener(localID, itemID, hostID, channel, name, id, msg, 0);
+ }
+
+ public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ {
// do we already have a match on this particular filter event?
List<ListenerInfo> coll = GetListeners(itemID, channel, name, id, msg);
@@ -485,7 +511,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
if (newHandle > 0)
{
- ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg);
+ ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg, regexBitfield);
List<ListenerInfo> listeners;
if (!m_listeners.TryGetValue(channel,out listeners))
@@ -651,7 +677,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
continue;
}
- if (li.GetName().Length > 0 && !li.GetName().Equals(name))
+ if (li.GetName().Length > 0 && (
+ ((li.GetRegexBitfield() & 1) != 1 && !li.GetName().Equals(name)) ||
+ ((li.GetRegexBitfield() & 1) == 1 && !Regex.IsMatch(name, li.GetName()))
+ ))
{
continue;
}
@@ -659,7 +688,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
continue;
}
- if (li.GetMessage().Length > 0 && !li.GetMessage().Equals(msg))
+ bool test = (li.GetRegexBitfield() & 2) == 2;
+ bool test2 = test && Regex.IsMatch(msg, li.GetMessage());
+ if (li.GetMessage().Length > 0 && (
+ ((li.GetRegexBitfield() & 2) != 2 && !li.GetMessage().Equals(msg)) ||
+ ((li.GetRegexBitfield() & 2) == 2 && !Regex.IsMatch(msg, li.GetMessage()))
+ ))
{
continue;
}
@@ -680,25 +714,25 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
foreach (ListenerInfo l in list)
{
if (l.GetItemID() == itemID)
+ {
data.AddRange(l.GetSerializationData());
+ }
}
}
}
return (Object[])data.ToArray();
}
- public void AddFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data)
+ public void AddFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
int idx = 0;
- Object[] item = new Object[6];
+ Object[] item = new Object[7];
while (idx < data.Length)
{
- Array.Copy(data, idx, item, 0, 6);
+ Array.Copy(data, idx, item, 0, 7);
- ListenerInfo info =
- ListenerInfo.FromData(localID, itemID, hostID, item);
+ ListenerInfo info = ListenerInfo.FromData(localID, itemID, hostID, item);
lock (m_listeners)
{
@@ -712,7 +746,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
}
}
- public class ListenerInfo: IWorldCommListenerInfo
+ public class ListenerInfo : IWorldCommListenerInfo
{
private bool m_active; // Listener is active or not
private int m_handle; // Assigned handle of this listener
@@ -723,19 +757,29 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
private UUID m_id; // ID to filter messages from
private string m_name; // Object name to filter messages from
private string m_message; // The message
+ private byte m_regexBitfield; // The regex bitfield
public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message)
{
- Initialise(handle, localID, ItemID, hostID, channel, name, id, message);
+ Initialise(handle, localID, ItemID, hostID, channel, name, id, message, 0);
+ }
+
+ public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
+ {
+ Initialise(handle, localID, ItemID, hostID, channel, name, id, message, regexBitfield);
}
public ListenerInfo(ListenerInfo li, string name, UUID id, string message)
{
- Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message);
+ Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, 0);
}
- private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name,
- UUID id, string message)
+ public ListenerInfo(ListenerInfo li, string name, UUID id, string message, byte regexBitfield)
+ {
+ Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, regexBitfield);
+ }
+
+ private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
{
m_active = true;
m_handle = handle;
@@ -746,11 +790,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
m_name = name;
m_id = id;
m_message = message;
+ m_regexBitfield = regexBitfield;
}
public Object[] GetSerializationData()
{
- Object[] data = new Object[6];
+ Object[] data = new Object[7];
data[0] = m_active;
data[1] = m_handle;
@@ -758,16 +803,19 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
data[3] = m_name;
data[4] = m_id;
data[5] = m_message;
+ data[6] = m_regexBitfield;
return data;
}
public static ListenerInfo FromData(uint localID, UUID ItemID, UUID hostID, Object[] data)
{
- ListenerInfo linfo = new ListenerInfo((int)data[1], localID,
- ItemID, hostID, (int)data[2], (string)data[3],
- (UUID)data[4], (string)data[5]);
- linfo.m_active=(bool)data[0];
+ ListenerInfo linfo = new ListenerInfo((int)data[1], localID, ItemID, hostID, (int)data[2], (string)data[3], (UUID)data[4], (string)data[5]);
+ linfo.m_active = (bool)data[0];
+ if (data.Length >= 7)
+ {
+ linfo.m_regexBitfield = (byte)data[6];
+ }
return linfo;
}
@@ -826,5 +874,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
return m_id;
}
+
+ public byte GetRegexBitfield()
+ {
+ return m_regexBitfield;
+ }
}
}
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index 4e74781..39832c6 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -45,6 +45,14 @@ namespace OpenSim.Region.Framework.Interfaces
void Deactivate();
void Activate();
UUID GetID();
+
+ /// <summary>
+ /// Bitfield indicating which strings should be processed as regex.
+ /// 1 corresponds to IWorldCommListenerInfo::GetName()
+ /// 2 corresponds to IWorldCommListenerInfo::GetMessage()
+ /// </summary>
+ /// <returns></returns>
+ byte GetRegexBitfield();
}
public interface IWorldComm
@@ -60,7 +68,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// the script during 'peek' time. Parameter hostID is needed to
/// determine the position of the script.
/// </summary>
- /// <param name="localID">localID of the script engine</param>
+ /// <param name="LocalID">localID of the script engine</param>
/// <param name="itemID">UUID of the script engine</param>
/// <param name="hostID">UUID of the SceneObjectPart</param>
/// <param name="channel">channel to listen on</param>
@@ -71,6 +79,23 @@ namespace OpenSim.Region.Framework.Interfaces
int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg);
/// <summary>
+ /// Create a listen event callback with the specified filters.
+ /// The parameters localID,itemID are needed to uniquely identify
+ /// the script during 'peek' time. Parameter hostID is needed to
+ /// determine the position of the script.
+ /// </summary>
+ /// <param name="LocalID">localID of the script engine</param>
+ /// <param name="itemID">UUID of the script engine</param>
+ /// <param name="hostID">UUID of the SceneObjectPart</param>
+ /// <param name="channel">channel to listen on</param>
+ /// <param name="name">name to filter on</param>
+ /// <param name="id">key to filter on (user given, could be totally faked)</param>
+ /// <param name="msg">msg to filter on</param>
+ /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
+ /// <returns>number of the scripts handle</returns>
+ int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield);
+
+ /// <summary>
/// This method scans over the objects which registered an interest in listen callbacks.
/// For everyone it finds, it checks if it fits the given filter. If it does, then
/// enqueue the message for delivery to the objects listen event handler.
@@ -121,7 +146,6 @@ namespace OpenSim.Region.Framework.Interfaces
void ListenRemove(UUID itemID, int handle);
void DeleteListener(UUID itemID);
Object[] GetSerializationData(UUID itemID);
- void CreateFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data);
+ void CreateFromData(uint localID, UUID itemID, UUID hostID, Object[] data);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index e0b4db6..8550374 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3288,5 +3288,49 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
UUID test;
return UUID.TryParse(thing, out test) ? 1 : 0;
}
+
+ public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
+ {
+ CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ m_host.AddScriptLPS(1);
+ UUID keyID;
+ UUID.TryParse(ID, out keyID);
+
+ if((regexBitfield & 1) == 1){ // if we want the name to be used as a regular expression, ensure it is valid first.
+ try
+ {
+ Regex.IsMatch("", name);
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Name regex is invalid.");
+ return -1;
+ }
+ }
+ if ((regexBitfield & 2) == 2) // if we want the msg to be used as a regular expression, ensure it is valid first.
+ {
+ try
+ {
+ Regex.IsMatch("", msg);
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Message regex is invalid.");
+ return -1;
+ }
+ }
+
+ IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
+ return (wComm == null) ? -1 : wComm.Listen(
+ m_host.LocalId,
+ m_item.ItemID,
+ m_host.UUID,
+ channelID,
+ name,
+ keyID,
+ msg,
+ (byte)regexBitfield
+ );
+ }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index c9403eb..9f7b331 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -283,5 +283,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// <param name="thing"></param>
/// <returns>1 if thing is a valid UUID, 0 otherwise</returns>
LSL_Integer osIsUUID(string thing);
+
+ /// <summary>
+ /// Identical to llListen except for a bitfield which indicates which string parameters should be parsed as regex patterns.
+ /// </summary>
+ /// <param name="channelID"></param>
+ /// <param name="name"></param>
+ /// <param name="ID"></param>
+ /// <param name="msg"></param>
+ /// <param name="regexBitfield">
+ /// 1 corresponds to name
+ /// 2 corresponds to msg
+ /// </param>
+ /// <returns></returns>
+ LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 99995a7..9f7e604 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -935,5 +935,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
return m_OSSL_Functions.osIsUUID(thing);
}
+
+ public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
+ {
+ return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield);
+ }
}
}
--
1.7.11.msysgit.1
From e663c76daa1be50af165908fc7f8fe5db313962f Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Thu, 26 Jul 2012 10:56:13 +0100
Subject: [PATCH 2/4] fixing a bug caused by mixed item lengths
---
.../CoreModules/Scripting/WorldComm/WorldCommModule.cs | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index 99a77fb..b954dd8 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -453,8 +453,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return m_listenerManager.GetSerializationData(itemID);
}
- public void CreateFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data)
+ public void CreateFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
m_listenerManager.AddFromData(localID, itemID, hostID, data);
}
@@ -726,22 +725,27 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
public void AddFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
int idx = 0;
- Object[] item = new Object[7];
+ Object[] item = new Object[6];
+ int dataItemLength = 6;
while (idx < data.Length)
{
- Array.Copy(data, idx, item, 0, 7);
+ dataItemLength = (idx + 7 == data.Length || (idx + 7 < data.Length && data[idx + 7] is bool)) ? 7 : 6;
+ item = new Object[dataItemLength];
+ Array.Copy(data, idx, item, 0, dataItemLength);
ListenerInfo info = ListenerInfo.FromData(localID, itemID, hostID, item);
lock (m_listeners)
{
if (!m_listeners.ContainsKey((int)item[2]))
+ {
m_listeners.Add((int)item[2], new List<ListenerInfo>());
+ }
m_listeners[(int)item[2]].Add(info);
}
- idx+=6;
+ idx+=dataItemLength;
}
}
}
--
1.7.11.msysgit.1
From 1443ebe988295f88710a3ec2842eb9ce859b2feb Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Thu, 26 Jul 2012 11:01:54 +0100
Subject: [PATCH 3/4] Implementing osRegexIsMatch to accompany osListenRegex
---
.../ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 15 +++++++++++++++
.../Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 8 ++++++++
.../Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 +++++
3 files changed, 28 insertions(+)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 8550374..9e928cb 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3332,5 +3332,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
(byte)regexBitfield
);
}
+
+ public LSL_Integer osRegexIsMatch(string input, string pattern)
+ {
+ CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ m_host.AddScriptLPS(1);
+ try
+ {
+ return Regex.IsMatch(input, pattern) ? 1 : 0;
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Possible invalid regular expression detected.");
+ return 0;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 9f7b331..fa048f3 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -297,5 +297,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// </param>
/// <returns></returns>
LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield);
+
+ /// <summary>
+ /// Wraps to bool Regex.IsMatch(string input, string pattern)
+ /// </summary>
+ /// <param name="input">string to test for match</param>
+ /// <param name="regex">string to use as pattern</param>
+ /// <returns>boolean</returns>
+ LSL_Integer osRegexIsMatch(string input, string pattern);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 9f7e604..4ad2c5f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -940,5 +940,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield);
}
+
+ public LSL_Integer osRegexIsMatch(string input, string pattern)
+ {
+ return m_OSSL_Functions.osRegexIsMatch(input, pattern);
+ }
}
}
--
1.7.11.msysgit.1
From 629484cd00d94411d15e76a35d3b8ae2c59f2ad7 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Thu, 26 Jul 2012 11:20:58 +0100
Subject: [PATCH 4/4] fixing copypasta
---
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 9e928cb..45bfa9d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3335,7 +3335,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Integer osRegexIsMatch(string input, string pattern)
{
- CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
m_host.AddScriptLPS(1);
try
{
--
1.7.11.msysgit.1
From 4917e3936c3951e9da5c993d03e9fcc4e117b941 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Wed, 25 Jul 2012 15:11:57 +0100
Subject: [PATCH 1/5] adding ability for listeners to be filtered by regular
expressions
---
.../Scripting/WorldComm/WorldCommModule.cs | 91 +++++++++++++++++-----
OpenSim/Region/Framework/Interfaces/IWorldComm.cs | 30 ++++++-
.../Shared/Api/Implementation/OSSL_Api.cs | 44 +++++++++++
.../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 14 ++++
.../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 ++
5 files changed, 162 insertions(+), 22 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index 8358bc0..99a77fb 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -28,6 +28,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Text.RegularExpressions;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
@@ -179,6 +180,26 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
}
/// <summary>
+ /// Create a listen event callback with the specified filters.
+ /// The parameters localID,itemID are needed to uniquely identify
+ /// the script during 'peek' time. Parameter hostID is needed to
+ /// determine the position of the script.
+ /// </summary>
+ /// <param name="localID">localID of the script engine</param>
+ /// <param name="itemID">UUID of the script engine</param>
+ /// <param name="hostID">UUID of the SceneObjectPart</param>
+ /// <param name="channel">channel to listen on</param>
+ /// <param name="name">name to filter on</param>
+ /// <param name="id">key to filter on (user given, could be totally faked)</param>
+ /// <param name="msg">msg to filter on</param>
+ /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
+ /// <returns>number of the scripts handle</returns>
+ public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ {
+ return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg, regexBitfield);
+ }
+
+ /// <summary>
/// Sets the listen event with handle as active (active = TRUE) or inactive (active = FALSE).
/// The handle used is returned from Listen()
/// </summary>
@@ -467,6 +488,11 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg)
{
+ return AddListener(localID, itemID, hostID, channel, name, id, msg, 0);
+ }
+
+ public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ {
// do we already have a match on this particular filter event?
List<ListenerInfo> coll = GetListeners(itemID, channel, name, id, msg);
@@ -485,7 +511,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
if (newHandle > 0)
{
- ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg);
+ ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg, regexBitfield);
List<ListenerInfo> listeners;
if (!m_listeners.TryGetValue(channel,out listeners))
@@ -651,7 +677,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
continue;
}
- if (li.GetName().Length > 0 && !li.GetName().Equals(name))
+ if (li.GetName().Length > 0 && (
+ ((li.GetRegexBitfield() & 1) != 1 && !li.GetName().Equals(name)) ||
+ ((li.GetRegexBitfield() & 1) == 1 && !Regex.IsMatch(name, li.GetName()))
+ ))
{
continue;
}
@@ -659,7 +688,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
continue;
}
- if (li.GetMessage().Length > 0 && !li.GetMessage().Equals(msg))
+ bool test = (li.GetRegexBitfield() & 2) == 2;
+ bool test2 = test && Regex.IsMatch(msg, li.GetMessage());
+ if (li.GetMessage().Length > 0 && (
+ ((li.GetRegexBitfield() & 2) != 2 && !li.GetMessage().Equals(msg)) ||
+ ((li.GetRegexBitfield() & 2) == 2 && !Regex.IsMatch(msg, li.GetMessage()))
+ ))
{
continue;
}
@@ -680,25 +714,25 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
foreach (ListenerInfo l in list)
{
if (l.GetItemID() == itemID)
+ {
data.AddRange(l.GetSerializationData());
+ }
}
}
}
return (Object[])data.ToArray();
}
- public void AddFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data)
+ public void AddFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
int idx = 0;
- Object[] item = new Object[6];
+ Object[] item = new Object[7];
while (idx < data.Length)
{
- Array.Copy(data, idx, item, 0, 6);
+ Array.Copy(data, idx, item, 0, 7);
- ListenerInfo info =
- ListenerInfo.FromData(localID, itemID, hostID, item);
+ ListenerInfo info = ListenerInfo.FromData(localID, itemID, hostID, item);
lock (m_listeners)
{
@@ -712,7 +746,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
}
}
- public class ListenerInfo: IWorldCommListenerInfo
+ public class ListenerInfo : IWorldCommListenerInfo
{
private bool m_active; // Listener is active or not
private int m_handle; // Assigned handle of this listener
@@ -723,19 +757,29 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
private UUID m_id; // ID to filter messages from
private string m_name; // Object name to filter messages from
private string m_message; // The message
+ private byte m_regexBitfield; // The regex bitfield
public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message)
{
- Initialise(handle, localID, ItemID, hostID, channel, name, id, message);
+ Initialise(handle, localID, ItemID, hostID, channel, name, id, message, 0);
+ }
+
+ public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
+ {
+ Initialise(handle, localID, ItemID, hostID, channel, name, id, message, regexBitfield);
}
public ListenerInfo(ListenerInfo li, string name, UUID id, string message)
{
- Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message);
+ Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, 0);
}
- private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name,
- UUID id, string message)
+ public ListenerInfo(ListenerInfo li, string name, UUID id, string message, byte regexBitfield)
+ {
+ Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, regexBitfield);
+ }
+
+ private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
{
m_active = true;
m_handle = handle;
@@ -746,11 +790,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
m_name = name;
m_id = id;
m_message = message;
+ m_regexBitfield = regexBitfield;
}
public Object[] GetSerializationData()
{
- Object[] data = new Object[6];
+ Object[] data = new Object[7];
data[0] = m_active;
data[1] = m_handle;
@@ -758,16 +803,19 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
data[3] = m_name;
data[4] = m_id;
data[5] = m_message;
+ data[6] = m_regexBitfield;
return data;
}
public static ListenerInfo FromData(uint localID, UUID ItemID, UUID hostID, Object[] data)
{
- ListenerInfo linfo = new ListenerInfo((int)data[1], localID,
- ItemID, hostID, (int)data[2], (string)data[3],
- (UUID)data[4], (string)data[5]);
- linfo.m_active=(bool)data[0];
+ ListenerInfo linfo = new ListenerInfo((int)data[1], localID, ItemID, hostID, (int)data[2], (string)data[3], (UUID)data[4], (string)data[5]);
+ linfo.m_active = (bool)data[0];
+ if (data.Length >= 7)
+ {
+ linfo.m_regexBitfield = (byte)data[6];
+ }
return linfo;
}
@@ -826,5 +874,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
return m_id;
}
+
+ public byte GetRegexBitfield()
+ {
+ return m_regexBitfield;
+ }
}
}
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index 4e74781..39832c6 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -45,6 +45,14 @@ namespace OpenSim.Region.Framework.Interfaces
void Deactivate();
void Activate();
UUID GetID();
+
+ /// <summary>
+ /// Bitfield indicating which strings should be processed as regex.
+ /// 1 corresponds to IWorldCommListenerInfo::GetName()
+ /// 2 corresponds to IWorldCommListenerInfo::GetMessage()
+ /// </summary>
+ /// <returns></returns>
+ byte GetRegexBitfield();
}
public interface IWorldComm
@@ -60,7 +68,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// the script during 'peek' time. Parameter hostID is needed to
/// determine the position of the script.
/// </summary>
- /// <param name="localID">localID of the script engine</param>
+ /// <param name="LocalID">localID of the script engine</param>
/// <param name="itemID">UUID of the script engine</param>
/// <param name="hostID">UUID of the SceneObjectPart</param>
/// <param name="channel">channel to listen on</param>
@@ -71,6 +79,23 @@ namespace OpenSim.Region.Framework.Interfaces
int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg);
/// <summary>
+ /// Create a listen event callback with the specified filters.
+ /// The parameters localID,itemID are needed to uniquely identify
+ /// the script during 'peek' time. Parameter hostID is needed to
+ /// determine the position of the script.
+ /// </summary>
+ /// <param name="LocalID">localID of the script engine</param>
+ /// <param name="itemID">UUID of the script engine</param>
+ /// <param name="hostID">UUID of the SceneObjectPart</param>
+ /// <param name="channel">channel to listen on</param>
+ /// <param name="name">name to filter on</param>
+ /// <param name="id">key to filter on (user given, could be totally faked)</param>
+ /// <param name="msg">msg to filter on</param>
+ /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
+ /// <returns>number of the scripts handle</returns>
+ int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield);
+
+ /// <summary>
/// This method scans over the objects which registered an interest in listen callbacks.
/// For everyone it finds, it checks if it fits the given filter. If it does, then
/// enqueue the message for delivery to the objects listen event handler.
@@ -121,7 +146,6 @@ namespace OpenSim.Region.Framework.Interfaces
void ListenRemove(UUID itemID, int handle);
void DeleteListener(UUID itemID);
Object[] GetSerializationData(UUID itemID);
- void CreateFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data);
+ void CreateFromData(uint localID, UUID itemID, UUID hostID, Object[] data);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index e0b4db6..8550374 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3288,5 +3288,49 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
UUID test;
return UUID.TryParse(thing, out test) ? 1 : 0;
}
+
+ public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
+ {
+ CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ m_host.AddScriptLPS(1);
+ UUID keyID;
+ UUID.TryParse(ID, out keyID);
+
+ if((regexBitfield & 1) == 1){ // if we want the name to be used as a regular expression, ensure it is valid first.
+ try
+ {
+ Regex.IsMatch("", name);
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Name regex is invalid.");
+ return -1;
+ }
+ }
+ if ((regexBitfield & 2) == 2) // if we want the msg to be used as a regular expression, ensure it is valid first.
+ {
+ try
+ {
+ Regex.IsMatch("", msg);
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Message regex is invalid.");
+ return -1;
+ }
+ }
+
+ IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
+ return (wComm == null) ? -1 : wComm.Listen(
+ m_host.LocalId,
+ m_item.ItemID,
+ m_host.UUID,
+ channelID,
+ name,
+ keyID,
+ msg,
+ (byte)regexBitfield
+ );
+ }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index c9403eb..9f7b331 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -283,5 +283,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// <param name="thing"></param>
/// <returns>1 if thing is a valid UUID, 0 otherwise</returns>
LSL_Integer osIsUUID(string thing);
+
+ /// <summary>
+ /// Identical to llListen except for a bitfield which indicates which string parameters should be parsed as regex patterns.
+ /// </summary>
+ /// <param name="channelID"></param>
+ /// <param name="name"></param>
+ /// <param name="ID"></param>
+ /// <param name="msg"></param>
+ /// <param name="regexBitfield">
+ /// 1 corresponds to name
+ /// 2 corresponds to msg
+ /// </param>
+ /// <returns></returns>
+ LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 99995a7..9f7e604 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -935,5 +935,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
return m_OSSL_Functions.osIsUUID(thing);
}
+
+ public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
+ {
+ return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield);
+ }
}
}
--
1.7.11.msysgit.1
From e663c76daa1be50af165908fc7f8fe5db313962f Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Thu, 26 Jul 2012 10:56:13 +0100
Subject: [PATCH 2/5] fixing a bug caused by mixed item lengths
---
.../CoreModules/Scripting/WorldComm/WorldCommModule.cs | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index 99a77fb..b954dd8 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -453,8 +453,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return m_listenerManager.GetSerializationData(itemID);
}
- public void CreateFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data)
+ public void CreateFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
m_listenerManager.AddFromData(localID, itemID, hostID, data);
}
@@ -726,22 +725,27 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
public void AddFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
int idx = 0;
- Object[] item = new Object[7];
+ Object[] item = new Object[6];
+ int dataItemLength = 6;
while (idx < data.Length)
{
- Array.Copy(data, idx, item, 0, 7);
+ dataItemLength = (idx + 7 == data.Length || (idx + 7 < data.Length && data[idx + 7] is bool)) ? 7 : 6;
+ item = new Object[dataItemLength];
+ Array.Copy(data, idx, item, 0, dataItemLength);
ListenerInfo info = ListenerInfo.FromData(localID, itemID, hostID, item);
lock (m_listeners)
{
if (!m_listeners.ContainsKey((int)item[2]))
+ {
m_listeners.Add((int)item[2], new List<ListenerInfo>());
+ }
m_listeners[(int)item[2]].Add(info);
}
- idx+=6;
+ idx+=dataItemLength;
}
}
}
--
1.7.11.msysgit.1
From 1443ebe988295f88710a3ec2842eb9ce859b2feb Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Thu, 26 Jul 2012 11:01:54 +0100
Subject: [PATCH 3/5] Implementing osRegexIsMatch to accompany osListenRegex
---
.../ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 15 +++++++++++++++
.../Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 8 ++++++++
.../Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 +++++
3 files changed, 28 insertions(+)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 8550374..9e928cb 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3332,5 +3332,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
(byte)regexBitfield
);
}
+
+ public LSL_Integer osRegexIsMatch(string input, string pattern)
+ {
+ CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ m_host.AddScriptLPS(1);
+ try
+ {
+ return Regex.IsMatch(input, pattern) ? 1 : 0;
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Possible invalid regular expression detected.");
+ return 0;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 9f7b331..fa048f3 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -297,5 +297,13 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// </param>
/// <returns></returns>
LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield);
+
+ /// <summary>
+ /// Wraps to bool Regex.IsMatch(string input, string pattern)
+ /// </summary>
+ /// <param name="input">string to test for match</param>
+ /// <param name="regex">string to use as pattern</param>
+ /// <returns>boolean</returns>
+ LSL_Integer osRegexIsMatch(string input, string pattern);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 9f7e604..4ad2c5f 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -940,5 +940,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield);
}
+
+ public LSL_Integer osRegexIsMatch(string input, string pattern)
+ {
+ return m_OSSL_Functions.osRegexIsMatch(input, pattern);
+ }
}
}
--
1.7.11.msysgit.1
From 629484cd00d94411d15e76a35d3b8ae2c59f2ad7 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Thu, 26 Jul 2012 11:20:58 +0100
Subject: [PATCH 4/5] fixing copypasta
---
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 9e928cb..45bfa9d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3335,7 +3335,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Integer osRegexIsMatch(string input, string pattern)
{
- CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
m_host.AddScriptLPS(1);
try
{
--
1.7.11.msysgit.1
From a827b14dba58de64f727827f26d94761d4c7c16e Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Fri, 27 Jul 2012 14:44:50 +0100
Subject: [PATCH 5/5] removing byte casting, using constants
---
.../CoreModules/Scripting/WorldComm/WorldCommModule.cs | 18 +++++++++---------
OpenSim/Region/Framework/Interfaces/IWorldComm.cs | 8 ++++----
.../ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 7 ++++---
.../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 4 ++--
.../ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | 14 ++++++++++++++
5 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index b954dd8..ef03cec 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -194,9 +194,9 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
/// <param name="msg">msg to filter on</param>
/// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
/// <returns>number of the scripts handle</returns>
- public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield)
{
- return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg, regexBitfield);
+ return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg, (byte)regexBitfield);
}
/// <summary>
@@ -490,7 +490,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return AddListener(localID, itemID, hostID, channel, name, id, msg, 0);
}
- public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield)
{
// do we already have a match on this particular filter event?
List<ListenerInfo> coll = GetListeners(itemID, channel, name, id, msg);
@@ -761,14 +761,14 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
private UUID m_id; // ID to filter messages from
private string m_name; // Object name to filter messages from
private string m_message; // The message
- private byte m_regexBitfield; // The regex bitfield
+ private int m_regexBitfield; // The regex bitfield
public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message)
{
Initialise(handle, localID, ItemID, hostID, channel, name, id, message, 0);
}
- public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
+ public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, int regexBitfield)
{
Initialise(handle, localID, ItemID, hostID, channel, name, id, message, regexBitfield);
}
@@ -778,12 +778,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, 0);
}
- public ListenerInfo(ListenerInfo li, string name, UUID id, string message, byte regexBitfield)
+ public ListenerInfo(ListenerInfo li, string name, UUID id, string message, int regexBitfield)
{
Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, regexBitfield);
}
- private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
+ private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, int regexBitfield)
{
m_active = true;
m_handle = handle;
@@ -818,7 +818,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
linfo.m_active = (bool)data[0];
if (data.Length >= 7)
{
- linfo.m_regexBitfield = (byte)data[6];
+ linfo.m_regexBitfield = (int)data[6];
}
return linfo;
@@ -879,7 +879,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return m_id;
}
- public byte GetRegexBitfield()
+ public int GetRegexBitfield()
{
return m_regexBitfield;
}
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index 39832c6..039f4f0 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -48,11 +48,11 @@ namespace OpenSim.Region.Framework.Interfaces
/// <summary>
/// Bitfield indicating which strings should be processed as regex.
- /// 1 corresponds to IWorldCommListenerInfo::GetName()
- /// 2 corresponds to IWorldCommListenerInfo::GetMessage()
+ /// ScriptBaseClass.OS_LISTEN_REGEX_NAME corresponds to IWorldCommListenerInfo::GetName()
+ /// ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE corresponds to IWorldCommListenerInfo::GetMessage()
/// </summary>
/// <returns></returns>
- byte GetRegexBitfield();
+ int GetRegexBitfield();
}
public interface IWorldComm
@@ -93,7 +93,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="msg">msg to filter on</param>
/// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
/// <returns>number of the scripts handle</returns>
- int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield);
+ int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield);
/// <summary>
/// This method scans over the objects which registered an interest in listen callbacks.
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 45bfa9d..6945272 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3296,7 +3296,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
UUID keyID;
UUID.TryParse(ID, out keyID);
- if((regexBitfield & 1) == 1){ // if we want the name to be used as a regular expression, ensure it is valid first.
+ if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME)
+ { // if we want the name to be used as a regular expression, ensure it is valid first.
try
{
Regex.IsMatch("", name);
@@ -3307,7 +3308,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return -1;
}
}
- if ((regexBitfield & 2) == 2) // if we want the msg to be used as a regular expression, ensure it is valid first.
+ if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) // if we want the msg to be used as a regular expression, ensure it is valid first.
{
try
{
@@ -3329,7 +3330,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
name,
keyID,
msg,
- (byte)regexBitfield
+ regexBitfield
);
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index fa048f3..694cb45 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -292,8 +292,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// <param name="ID"></param>
/// <param name="msg"></param>
/// <param name="regexBitfield">
- /// 1 corresponds to name
- /// 2 corresponds to msg
+ /// OS_LISTEN_REGEX_NAME
+ /// OS_LISTEN_REGEX_MESSAGE
/// </param>
/// <returns></returns>
LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index c3eada0..87a7247 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -660,5 +660,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
public static readonly LSLInteger RCERR_UNKNOWN = -1;
public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2;
public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3;
+
+ #region Constants for the bitfield parameter of osListenRegex
+
+ /// <summary>
+ /// process name parameter as regex
+ /// </summary>
+ public const int OS_LISTEN_REGEX_NAME = 0x1;
+
+ /// <summary>
+ /// process message parameter as regex
+ /// </summary>
+ public const int OS_LISTEN_REGEX_MESSAGE = 0x2;
+
+ #endregion
}
}
--
1.7.11.msysgit.1
From 8c5d9601519f1f321696f597410d0f02d3213609 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Wed, 25 Jul 2012 15:11:57 +0100
Subject: [PATCH 1/5] adding ability for listeners to be filtered by regular
expressions
---
.../Scripting/WorldComm/WorldCommModule.cs | 91 +++++++++++++++++-----
OpenSim/Region/Framework/Interfaces/IWorldComm.cs | 30 ++++++-
.../Shared/Api/Implementation/OSSL_Api.cs | 43 ++++++++++
.../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 15 ++++
.../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 ++
5 files changed, 162 insertions(+), 22 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index 8358bc0..99a77fb 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -28,6 +28,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Text.RegularExpressions;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
@@ -179,6 +180,26 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
}
/// <summary>
+ /// Create a listen event callback with the specified filters.
+ /// The parameters localID,itemID are needed to uniquely identify
+ /// the script during 'peek' time. Parameter hostID is needed to
+ /// determine the position of the script.
+ /// </summary>
+ /// <param name="localID">localID of the script engine</param>
+ /// <param name="itemID">UUID of the script engine</param>
+ /// <param name="hostID">UUID of the SceneObjectPart</param>
+ /// <param name="channel">channel to listen on</param>
+ /// <param name="name">name to filter on</param>
+ /// <param name="id">key to filter on (user given, could be totally faked)</param>
+ /// <param name="msg">msg to filter on</param>
+ /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
+ /// <returns>number of the scripts handle</returns>
+ public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ {
+ return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg, regexBitfield);
+ }
+
+ /// <summary>
/// Sets the listen event with handle as active (active = TRUE) or inactive (active = FALSE).
/// The handle used is returned from Listen()
/// </summary>
@@ -467,6 +488,11 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg)
{
+ return AddListener(localID, itemID, hostID, channel, name, id, msg, 0);
+ }
+
+ public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ {
// do we already have a match on this particular filter event?
List<ListenerInfo> coll = GetListeners(itemID, channel, name, id, msg);
@@ -485,7 +511,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
if (newHandle > 0)
{
- ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg);
+ ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg, regexBitfield);
List<ListenerInfo> listeners;
if (!m_listeners.TryGetValue(channel,out listeners))
@@ -651,7 +677,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
continue;
}
- if (li.GetName().Length > 0 && !li.GetName().Equals(name))
+ if (li.GetName().Length > 0 && (
+ ((li.GetRegexBitfield() & 1) != 1 && !li.GetName().Equals(name)) ||
+ ((li.GetRegexBitfield() & 1) == 1 && !Regex.IsMatch(name, li.GetName()))
+ ))
{
continue;
}
@@ -659,7 +688,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
continue;
}
- if (li.GetMessage().Length > 0 && !li.GetMessage().Equals(msg))
+ bool test = (li.GetRegexBitfield() & 2) == 2;
+ bool test2 = test && Regex.IsMatch(msg, li.GetMessage());
+ if (li.GetMessage().Length > 0 && (
+ ((li.GetRegexBitfield() & 2) != 2 && !li.GetMessage().Equals(msg)) ||
+ ((li.GetRegexBitfield() & 2) == 2 && !Regex.IsMatch(msg, li.GetMessage()))
+ ))
{
continue;
}
@@ -680,25 +714,25 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
foreach (ListenerInfo l in list)
{
if (l.GetItemID() == itemID)
+ {
data.AddRange(l.GetSerializationData());
+ }
}
}
}
return (Object[])data.ToArray();
}
- public void AddFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data)
+ public void AddFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
int idx = 0;
- Object[] item = new Object[6];
+ Object[] item = new Object[7];
while (idx < data.Length)
{
- Array.Copy(data, idx, item, 0, 6);
+ Array.Copy(data, idx, item, 0, 7);
- ListenerInfo info =
- ListenerInfo.FromData(localID, itemID, hostID, item);
+ ListenerInfo info = ListenerInfo.FromData(localID, itemID, hostID, item);
lock (m_listeners)
{
@@ -712,7 +746,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
}
}
- public class ListenerInfo: IWorldCommListenerInfo
+ public class ListenerInfo : IWorldCommListenerInfo
{
private bool m_active; // Listener is active or not
private int m_handle; // Assigned handle of this listener
@@ -723,19 +757,29 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
private UUID m_id; // ID to filter messages from
private string m_name; // Object name to filter messages from
private string m_message; // The message
+ private byte m_regexBitfield; // The regex bitfield
public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message)
{
- Initialise(handle, localID, ItemID, hostID, channel, name, id, message);
+ Initialise(handle, localID, ItemID, hostID, channel, name, id, message, 0);
+ }
+
+ public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
+ {
+ Initialise(handle, localID, ItemID, hostID, channel, name, id, message, regexBitfield);
}
public ListenerInfo(ListenerInfo li, string name, UUID id, string message)
{
- Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message);
+ Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, 0);
}
- private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name,
- UUID id, string message)
+ public ListenerInfo(ListenerInfo li, string name, UUID id, string message, byte regexBitfield)
+ {
+ Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, regexBitfield);
+ }
+
+ private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
{
m_active = true;
m_handle = handle;
@@ -746,11 +790,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
m_name = name;
m_id = id;
m_message = message;
+ m_regexBitfield = regexBitfield;
}
public Object[] GetSerializationData()
{
- Object[] data = new Object[6];
+ Object[] data = new Object[7];
data[0] = m_active;
data[1] = m_handle;
@@ -758,16 +803,19 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
data[3] = m_name;
data[4] = m_id;
data[5] = m_message;
+ data[6] = m_regexBitfield;
return data;
}
public static ListenerInfo FromData(uint localID, UUID ItemID, UUID hostID, Object[] data)
{
- ListenerInfo linfo = new ListenerInfo((int)data[1], localID,
- ItemID, hostID, (int)data[2], (string)data[3],
- (UUID)data[4], (string)data[5]);
- linfo.m_active=(bool)data[0];
+ ListenerInfo linfo = new ListenerInfo((int)data[1], localID, ItemID, hostID, (int)data[2], (string)data[3], (UUID)data[4], (string)data[5]);
+ linfo.m_active = (bool)data[0];
+ if (data.Length >= 7)
+ {
+ linfo.m_regexBitfield = (byte)data[6];
+ }
return linfo;
}
@@ -826,5 +874,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
return m_id;
}
+
+ public byte GetRegexBitfield()
+ {
+ return m_regexBitfield;
+ }
}
}
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index 4e74781..39832c6 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -45,6 +45,14 @@ namespace OpenSim.Region.Framework.Interfaces
void Deactivate();
void Activate();
UUID GetID();
+
+ /// <summary>
+ /// Bitfield indicating which strings should be processed as regex.
+ /// 1 corresponds to IWorldCommListenerInfo::GetName()
+ /// 2 corresponds to IWorldCommListenerInfo::GetMessage()
+ /// </summary>
+ /// <returns></returns>
+ byte GetRegexBitfield();
}
public interface IWorldComm
@@ -60,7 +68,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// the script during 'peek' time. Parameter hostID is needed to
/// determine the position of the script.
/// </summary>
- /// <param name="localID">localID of the script engine</param>
+ /// <param name="LocalID">localID of the script engine</param>
/// <param name="itemID">UUID of the script engine</param>
/// <param name="hostID">UUID of the SceneObjectPart</param>
/// <param name="channel">channel to listen on</param>
@@ -71,6 +79,23 @@ namespace OpenSim.Region.Framework.Interfaces
int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg);
/// <summary>
+ /// Create a listen event callback with the specified filters.
+ /// The parameters localID,itemID are needed to uniquely identify
+ /// the script during 'peek' time. Parameter hostID is needed to
+ /// determine the position of the script.
+ /// </summary>
+ /// <param name="LocalID">localID of the script engine</param>
+ /// <param name="itemID">UUID of the script engine</param>
+ /// <param name="hostID">UUID of the SceneObjectPart</param>
+ /// <param name="channel">channel to listen on</param>
+ /// <param name="name">name to filter on</param>
+ /// <param name="id">key to filter on (user given, could be totally faked)</param>
+ /// <param name="msg">msg to filter on</param>
+ /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
+ /// <returns>number of the scripts handle</returns>
+ int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield);
+
+ /// <summary>
/// This method scans over the objects which registered an interest in listen callbacks.
/// For everyone it finds, it checks if it fits the given filter. If it does, then
/// enqueue the message for delivery to the objects listen event handler.
@@ -121,7 +146,6 @@ namespace OpenSim.Region.Framework.Interfaces
void ListenRemove(UUID itemID, int handle);
void DeleteListener(UUID itemID);
Object[] GetSerializationData(UUID itemID);
- void CreateFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data);
+ void CreateFromData(uint localID, UUID itemID, UUID hostID, Object[] data);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 44de176..cec3114 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3314,5 +3314,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return Math.Max(a, b);
}
+ public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
+ {
+ CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ m_host.AddScriptLPS(1);
+ UUID keyID;
+ UUID.TryParse(ID, out keyID);
+
+ if((regexBitfield & 1) == 1){ // if we want the name to be used as a regular expression, ensure it is valid first.
+ try
+ {
+ Regex.IsMatch("", name);
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Name regex is invalid.");
+ return -1;
+ }
+ }
+ if ((regexBitfield & 2) == 2) // if we want the msg to be used as a regular expression, ensure it is valid first.
+ {
+ try
+ {
+ Regex.IsMatch("", msg);
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Message regex is invalid.");
+ return -1;
+ }
+ }
+
+ IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
+ return (wComm == null) ? -1 : wComm.Listen(
+ m_host.LocalId,
+ m_item.ItemID,
+ m_host.UUID,
+ channelID,
+ name,
+ keyID,
+ msg,
+ (byte)regexBitfield
+ );
+ }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index f73a85e..b00b08a 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -299,5 +299,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// <param name="b"></param>
/// <returns></returns>
LSL_Float osMax(double a, double b);
+
+ /// <summary>
+ /// Identical to llListen except for a bitfield which indicates which string parameters should be parsed as regex patterns.
+ /// </summary>
+ /// <param name="channelID"></param>
+ /// <param name="name"></param>
+ /// <param name="ID"></param>
+ /// <param name="msg"></param>
+ /// <param name="regexBitfield">
+ /// 1 corresponds to name
+ /// 2 corresponds to msg
+ /// </param>
+ /// <returns></returns>
+ LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield);
+
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 53daa13..45db67e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -945,5 +945,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
return m_OSSL_Functions.osMax(a, b);
}
+
+ public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
+ {
+ return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield);
+ }
}
}
--
1.7.11.msysgit.1
From 15531dda431e366766ae1a92aa856e68f060a783 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Thu, 26 Jul 2012 10:56:13 +0100
Subject: [PATCH 2/5] fixing a bug caused by mixed item lengths
---
.../CoreModules/Scripting/WorldComm/WorldCommModule.cs | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index 99a77fb..b954dd8 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -453,8 +453,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return m_listenerManager.GetSerializationData(itemID);
}
- public void CreateFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data)
+ public void CreateFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
m_listenerManager.AddFromData(localID, itemID, hostID, data);
}
@@ -726,22 +725,27 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
public void AddFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
int idx = 0;
- Object[] item = new Object[7];
+ Object[] item = new Object[6];
+ int dataItemLength = 6;
while (idx < data.Length)
{
- Array.Copy(data, idx, item, 0, 7);
+ dataItemLength = (idx + 7 == data.Length || (idx + 7 < data.Length && data[idx + 7] is bool)) ? 7 : 6;
+ item = new Object[dataItemLength];
+ Array.Copy(data, idx, item, 0, dataItemLength);
ListenerInfo info = ListenerInfo.FromData(localID, itemID, hostID, item);
lock (m_listeners)
{
if (!m_listeners.ContainsKey((int)item[2]))
+ {
m_listeners.Add((int)item[2], new List<ListenerInfo>());
+ }
m_listeners[(int)item[2]].Add(info);
}
- idx+=6;
+ idx+=dataItemLength;
}
}
}
--
1.7.11.msysgit.1
From 5a90c88281bde7e639ecc0bcf2ad6f2ec212b709 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Thu, 26 Jul 2012 11:01:54 +0100
Subject: [PATCH 3/5] Implementing osRegexIsMatch to accompany osListenRegex
---
.../ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 15 +++++++++++++++
.../Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 7 +++++++
.../Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 +++++
3 files changed, 27 insertions(+)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index cec3114..8126b5b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3357,5 +3357,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
(byte)regexBitfield
);
}
+
+ public LSL_Integer osRegexIsMatch(string input, string pattern)
+ {
+ CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ m_host.AddScriptLPS(1);
+ try
+ {
+ return Regex.IsMatch(input, pattern) ? 1 : 0;
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Possible invalid regular expression detected.");
+ return 0;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index b00b08a..7c1e28b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -314,5 +314,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// <returns></returns>
LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield);
+ /// <summary>
+ /// Wraps to bool Regex.IsMatch(string input, string pattern)
+ /// </summary>
+ /// <param name="input">string to test for match</param>
+ /// <param name="regex">string to use as pattern</param>
+ /// <returns>boolean</returns>
+ LSL_Integer osRegexIsMatch(string input, string pattern);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 45db67e..5540327 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -950,5 +950,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield);
}
+
+ public LSL_Integer osRegexIsMatch(string input, string pattern)
+ {
+ return m_OSSL_Functions.osRegexIsMatch(input, pattern);
+ }
}
}
--
1.7.11.msysgit.1
From 9849dc38511a85725b8849acae0e7f50c40e4ed1 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Thu, 26 Jul 2012 11:20:58 +0100
Subject: [PATCH 4/5] fixing copypasta
---
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 8126b5b..9401d0a 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3360,7 +3360,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Integer osRegexIsMatch(string input, string pattern)
{
- CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
m_host.AddScriptLPS(1);
try
{
--
1.7.11.msysgit.1
From cde822d3006082690fccff2e56988f1b8740d703 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Fri, 27 Jul 2012 14:44:50 +0100
Subject: [PATCH 5/5] removing byte casting, using constants
---
.../CoreModules/Scripting/WorldComm/WorldCommModule.cs | 18 +++++++++---------
OpenSim/Region/Framework/Interfaces/IWorldComm.cs | 8 ++++----
.../ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 7 ++++---
.../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 4 ++--
.../ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | 14 ++++++++++++++
5 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index b954dd8..ef03cec 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -194,9 +194,9 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
/// <param name="msg">msg to filter on</param>
/// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
/// <returns>number of the scripts handle</returns>
- public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield)
{
- return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg, regexBitfield);
+ return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg, (byte)regexBitfield);
}
/// <summary>
@@ -490,7 +490,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return AddListener(localID, itemID, hostID, channel, name, id, msg, 0);
}
- public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield)
{
// do we already have a match on this particular filter event?
List<ListenerInfo> coll = GetListeners(itemID, channel, name, id, msg);
@@ -761,14 +761,14 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
private UUID m_id; // ID to filter messages from
private string m_name; // Object name to filter messages from
private string m_message; // The message
- private byte m_regexBitfield; // The regex bitfield
+ private int m_regexBitfield; // The regex bitfield
public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message)
{
Initialise(handle, localID, ItemID, hostID, channel, name, id, message, 0);
}
- public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
+ public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, int regexBitfield)
{
Initialise(handle, localID, ItemID, hostID, channel, name, id, message, regexBitfield);
}
@@ -778,12 +778,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, 0);
}
- public ListenerInfo(ListenerInfo li, string name, UUID id, string message, byte regexBitfield)
+ public ListenerInfo(ListenerInfo li, string name, UUID id, string message, int regexBitfield)
{
Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, regexBitfield);
}
- private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
+ private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, int regexBitfield)
{
m_active = true;
m_handle = handle;
@@ -818,7 +818,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
linfo.m_active = (bool)data[0];
if (data.Length >= 7)
{
- linfo.m_regexBitfield = (byte)data[6];
+ linfo.m_regexBitfield = (int)data[6];
}
return linfo;
@@ -879,7 +879,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return m_id;
}
- public byte GetRegexBitfield()
+ public int GetRegexBitfield()
{
return m_regexBitfield;
}
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index 39832c6..039f4f0 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -48,11 +48,11 @@ namespace OpenSim.Region.Framework.Interfaces
/// <summary>
/// Bitfield indicating which strings should be processed as regex.
- /// 1 corresponds to IWorldCommListenerInfo::GetName()
- /// 2 corresponds to IWorldCommListenerInfo::GetMessage()
+ /// ScriptBaseClass.OS_LISTEN_REGEX_NAME corresponds to IWorldCommListenerInfo::GetName()
+ /// ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE corresponds to IWorldCommListenerInfo::GetMessage()
/// </summary>
/// <returns></returns>
- byte GetRegexBitfield();
+ int GetRegexBitfield();
}
public interface IWorldComm
@@ -93,7 +93,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="msg">msg to filter on</param>
/// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
/// <returns>number of the scripts handle</returns>
- int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield);
+ int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield);
/// <summary>
/// This method scans over the objects which registered an interest in listen callbacks.
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 9401d0a..8fe64e9 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3321,7 +3321,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
UUID keyID;
UUID.TryParse(ID, out keyID);
- if((regexBitfield & 1) == 1){ // if we want the name to be used as a regular expression, ensure it is valid first.
+ if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME)
+ { // if we want the name to be used as a regular expression, ensure it is valid first.
try
{
Regex.IsMatch("", name);
@@ -3332,7 +3333,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return -1;
}
}
- if ((regexBitfield & 2) == 2) // if we want the msg to be used as a regular expression, ensure it is valid first.
+ if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) // if we want the msg to be used as a regular expression, ensure it is valid first.
{
try
{
@@ -3354,7 +3355,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
name,
keyID,
msg,
- (byte)regexBitfield
+ regexBitfield
);
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 7c1e28b..938cda0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -308,8 +308,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// <param name="ID"></param>
/// <param name="msg"></param>
/// <param name="regexBitfield">
- /// 1 corresponds to name
- /// 2 corresponds to msg
+ /// OS_LISTEN_REGEX_NAME
+ /// OS_LISTEN_REGEX_MESSAGE
/// </param>
/// <returns></returns>
LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index c3eada0..87a7247 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -660,5 +660,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
public static readonly LSLInteger RCERR_UNKNOWN = -1;
public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2;
public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3;
+
+ #region Constants for the bitfield parameter of osListenRegex
+
+ /// <summary>
+ /// process name parameter as regex
+ /// </summary>
+ public const int OS_LISTEN_REGEX_NAME = 0x1;
+
+ /// <summary>
+ /// process message parameter as regex
+ /// </summary>
+ public const int OS_LISTEN_REGEX_MESSAGE = 0x2;
+
+ #endregion
}
}
--
1.7.11.msysgit.1
From 8c5d9601519f1f321696f597410d0f02d3213609 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Wed, 25 Jul 2012 15:11:57 +0100
Subject: [PATCH 1/6] adding ability for listeners to be filtered by regular
expressions
---
.../Scripting/WorldComm/WorldCommModule.cs | 91 +++++++++++++++++-----
OpenSim/Region/Framework/Interfaces/IWorldComm.cs | 30 ++++++-
.../Shared/Api/Implementation/OSSL_Api.cs | 43 ++++++++++
.../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 15 ++++
.../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 ++
5 files changed, 162 insertions(+), 22 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index 8358bc0..99a77fb 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -28,6 +28,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Text.RegularExpressions;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
@@ -179,6 +180,26 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
}
/// <summary>
+ /// Create a listen event callback with the specified filters.
+ /// The parameters localID,itemID are needed to uniquely identify
+ /// the script during 'peek' time. Parameter hostID is needed to
+ /// determine the position of the script.
+ /// </summary>
+ /// <param name="localID">localID of the script engine</param>
+ /// <param name="itemID">UUID of the script engine</param>
+ /// <param name="hostID">UUID of the SceneObjectPart</param>
+ /// <param name="channel">channel to listen on</param>
+ /// <param name="name">name to filter on</param>
+ /// <param name="id">key to filter on (user given, could be totally faked)</param>
+ /// <param name="msg">msg to filter on</param>
+ /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
+ /// <returns>number of the scripts handle</returns>
+ public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ {
+ return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg, regexBitfield);
+ }
+
+ /// <summary>
/// Sets the listen event with handle as active (active = TRUE) or inactive (active = FALSE).
/// The handle used is returned from Listen()
/// </summary>
@@ -467,6 +488,11 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg)
{
+ return AddListener(localID, itemID, hostID, channel, name, id, msg, 0);
+ }
+
+ public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ {
// do we already have a match on this particular filter event?
List<ListenerInfo> coll = GetListeners(itemID, channel, name, id, msg);
@@ -485,7 +511,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
if (newHandle > 0)
{
- ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg);
+ ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg, regexBitfield);
List<ListenerInfo> listeners;
if (!m_listeners.TryGetValue(channel,out listeners))
@@ -651,7 +677,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
continue;
}
- if (li.GetName().Length > 0 && !li.GetName().Equals(name))
+ if (li.GetName().Length > 0 && (
+ ((li.GetRegexBitfield() & 1) != 1 && !li.GetName().Equals(name)) ||
+ ((li.GetRegexBitfield() & 1) == 1 && !Regex.IsMatch(name, li.GetName()))
+ ))
{
continue;
}
@@ -659,7 +688,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
continue;
}
- if (li.GetMessage().Length > 0 && !li.GetMessage().Equals(msg))
+ bool test = (li.GetRegexBitfield() & 2) == 2;
+ bool test2 = test && Regex.IsMatch(msg, li.GetMessage());
+ if (li.GetMessage().Length > 0 && (
+ ((li.GetRegexBitfield() & 2) != 2 && !li.GetMessage().Equals(msg)) ||
+ ((li.GetRegexBitfield() & 2) == 2 && !Regex.IsMatch(msg, li.GetMessage()))
+ ))
{
continue;
}
@@ -680,25 +714,25 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
foreach (ListenerInfo l in list)
{
if (l.GetItemID() == itemID)
+ {
data.AddRange(l.GetSerializationData());
+ }
}
}
}
return (Object[])data.ToArray();
}
- public void AddFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data)
+ public void AddFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
int idx = 0;
- Object[] item = new Object[6];
+ Object[] item = new Object[7];
while (idx < data.Length)
{
- Array.Copy(data, idx, item, 0, 6);
+ Array.Copy(data, idx, item, 0, 7);
- ListenerInfo info =
- ListenerInfo.FromData(localID, itemID, hostID, item);
+ ListenerInfo info = ListenerInfo.FromData(localID, itemID, hostID, item);
lock (m_listeners)
{
@@ -712,7 +746,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
}
}
- public class ListenerInfo: IWorldCommListenerInfo
+ public class ListenerInfo : IWorldCommListenerInfo
{
private bool m_active; // Listener is active or not
private int m_handle; // Assigned handle of this listener
@@ -723,19 +757,29 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
private UUID m_id; // ID to filter messages from
private string m_name; // Object name to filter messages from
private string m_message; // The message
+ private byte m_regexBitfield; // The regex bitfield
public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message)
{
- Initialise(handle, localID, ItemID, hostID, channel, name, id, message);
+ Initialise(handle, localID, ItemID, hostID, channel, name, id, message, 0);
+ }
+
+ public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
+ {
+ Initialise(handle, localID, ItemID, hostID, channel, name, id, message, regexBitfield);
}
public ListenerInfo(ListenerInfo li, string name, UUID id, string message)
{
- Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message);
+ Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, 0);
}
- private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name,
- UUID id, string message)
+ public ListenerInfo(ListenerInfo li, string name, UUID id, string message, byte regexBitfield)
+ {
+ Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, regexBitfield);
+ }
+
+ private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
{
m_active = true;
m_handle = handle;
@@ -746,11 +790,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
m_name = name;
m_id = id;
m_message = message;
+ m_regexBitfield = regexBitfield;
}
public Object[] GetSerializationData()
{
- Object[] data = new Object[6];
+ Object[] data = new Object[7];
data[0] = m_active;
data[1] = m_handle;
@@ -758,16 +803,19 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
data[3] = m_name;
data[4] = m_id;
data[5] = m_message;
+ data[6] = m_regexBitfield;
return data;
}
public static ListenerInfo FromData(uint localID, UUID ItemID, UUID hostID, Object[] data)
{
- ListenerInfo linfo = new ListenerInfo((int)data[1], localID,
- ItemID, hostID, (int)data[2], (string)data[3],
- (UUID)data[4], (string)data[5]);
- linfo.m_active=(bool)data[0];
+ ListenerInfo linfo = new ListenerInfo((int)data[1], localID, ItemID, hostID, (int)data[2], (string)data[3], (UUID)data[4], (string)data[5]);
+ linfo.m_active = (bool)data[0];
+ if (data.Length >= 7)
+ {
+ linfo.m_regexBitfield = (byte)data[6];
+ }
return linfo;
}
@@ -826,5 +874,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
return m_id;
}
+
+ public byte GetRegexBitfield()
+ {
+ return m_regexBitfield;
+ }
}
}
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index 4e74781..39832c6 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -45,6 +45,14 @@ namespace OpenSim.Region.Framework.Interfaces
void Deactivate();
void Activate();
UUID GetID();
+
+ /// <summary>
+ /// Bitfield indicating which strings should be processed as regex.
+ /// 1 corresponds to IWorldCommListenerInfo::GetName()
+ /// 2 corresponds to IWorldCommListenerInfo::GetMessage()
+ /// </summary>
+ /// <returns></returns>
+ byte GetRegexBitfield();
}
public interface IWorldComm
@@ -60,7 +68,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// the script during 'peek' time. Parameter hostID is needed to
/// determine the position of the script.
/// </summary>
- /// <param name="localID">localID of the script engine</param>
+ /// <param name="LocalID">localID of the script engine</param>
/// <param name="itemID">UUID of the script engine</param>
/// <param name="hostID">UUID of the SceneObjectPart</param>
/// <param name="channel">channel to listen on</param>
@@ -71,6 +79,23 @@ namespace OpenSim.Region.Framework.Interfaces
int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg);
/// <summary>
+ /// Create a listen event callback with the specified filters.
+ /// The parameters localID,itemID are needed to uniquely identify
+ /// the script during 'peek' time. Parameter hostID is needed to
+ /// determine the position of the script.
+ /// </summary>
+ /// <param name="LocalID">localID of the script engine</param>
+ /// <param name="itemID">UUID of the script engine</param>
+ /// <param name="hostID">UUID of the SceneObjectPart</param>
+ /// <param name="channel">channel to listen on</param>
+ /// <param name="name">name to filter on</param>
+ /// <param name="id">key to filter on (user given, could be totally faked)</param>
+ /// <param name="msg">msg to filter on</param>
+ /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
+ /// <returns>number of the scripts handle</returns>
+ int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield);
+
+ /// <summary>
/// This method scans over the objects which registered an interest in listen callbacks.
/// For everyone it finds, it checks if it fits the given filter. If it does, then
/// enqueue the message for delivery to the objects listen event handler.
@@ -121,7 +146,6 @@ namespace OpenSim.Region.Framework.Interfaces
void ListenRemove(UUID itemID, int handle);
void DeleteListener(UUID itemID);
Object[] GetSerializationData(UUID itemID);
- void CreateFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data);
+ void CreateFromData(uint localID, UUID itemID, UUID hostID, Object[] data);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 44de176..cec3114 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3314,5 +3314,48 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return Math.Max(a, b);
}
+ public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
+ {
+ CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ m_host.AddScriptLPS(1);
+ UUID keyID;
+ UUID.TryParse(ID, out keyID);
+
+ if((regexBitfield & 1) == 1){ // if we want the name to be used as a regular expression, ensure it is valid first.
+ try
+ {
+ Regex.IsMatch("", name);
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Name regex is invalid.");
+ return -1;
+ }
+ }
+ if ((regexBitfield & 2) == 2) // if we want the msg to be used as a regular expression, ensure it is valid first.
+ {
+ try
+ {
+ Regex.IsMatch("", msg);
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Message regex is invalid.");
+ return -1;
+ }
+ }
+
+ IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
+ return (wComm == null) ? -1 : wComm.Listen(
+ m_host.LocalId,
+ m_item.ItemID,
+ m_host.UUID,
+ channelID,
+ name,
+ keyID,
+ msg,
+ (byte)regexBitfield
+ );
+ }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index f73a85e..b00b08a 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -299,5 +299,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// <param name="b"></param>
/// <returns></returns>
LSL_Float osMax(double a, double b);
+
+ /// <summary>
+ /// Identical to llListen except for a bitfield which indicates which string parameters should be parsed as regex patterns.
+ /// </summary>
+ /// <param name="channelID"></param>
+ /// <param name="name"></param>
+ /// <param name="ID"></param>
+ /// <param name="msg"></param>
+ /// <param name="regexBitfield">
+ /// 1 corresponds to name
+ /// 2 corresponds to msg
+ /// </param>
+ /// <returns></returns>
+ LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield);
+
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 53daa13..45db67e 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -945,5 +945,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
return m_OSSL_Functions.osMax(a, b);
}
+
+ public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
+ {
+ return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield);
+ }
}
}
--
1.7.11.msysgit.1
From 15531dda431e366766ae1a92aa856e68f060a783 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Thu, 26 Jul 2012 10:56:13 +0100
Subject: [PATCH 2/6] fixing a bug caused by mixed item lengths
---
.../CoreModules/Scripting/WorldComm/WorldCommModule.cs | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index 99a77fb..b954dd8 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -453,8 +453,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return m_listenerManager.GetSerializationData(itemID);
}
- public void CreateFromData(uint localID, UUID itemID, UUID hostID,
- Object[] data)
+ public void CreateFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
m_listenerManager.AddFromData(localID, itemID, hostID, data);
}
@@ -726,22 +725,27 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
public void AddFromData(uint localID, UUID itemID, UUID hostID, Object[] data)
{
int idx = 0;
- Object[] item = new Object[7];
+ Object[] item = new Object[6];
+ int dataItemLength = 6;
while (idx < data.Length)
{
- Array.Copy(data, idx, item, 0, 7);
+ dataItemLength = (idx + 7 == data.Length || (idx + 7 < data.Length && data[idx + 7] is bool)) ? 7 : 6;
+ item = new Object[dataItemLength];
+ Array.Copy(data, idx, item, 0, dataItemLength);
ListenerInfo info = ListenerInfo.FromData(localID, itemID, hostID, item);
lock (m_listeners)
{
if (!m_listeners.ContainsKey((int)item[2]))
+ {
m_listeners.Add((int)item[2], new List<ListenerInfo>());
+ }
m_listeners[(int)item[2]].Add(info);
}
- idx+=6;
+ idx+=dataItemLength;
}
}
}
--
1.7.11.msysgit.1
From 5a90c88281bde7e639ecc0bcf2ad6f2ec212b709 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Thu, 26 Jul 2012 11:01:54 +0100
Subject: [PATCH 3/6] Implementing osRegexIsMatch to accompany osListenRegex
---
.../ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 15 +++++++++++++++
.../Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 7 +++++++
.../Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 5 +++++
3 files changed, 27 insertions(+)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index cec3114..8126b5b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3357,5 +3357,20 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
(byte)regexBitfield
);
}
+
+ public LSL_Integer osRegexIsMatch(string input, string pattern)
+ {
+ CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ m_host.AddScriptLPS(1);
+ try
+ {
+ return Regex.IsMatch(input, pattern) ? 1 : 0;
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Possible invalid regular expression detected.");
+ return 0;
+ }
+ }
}
}
\ No newline at end of file
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index b00b08a..7c1e28b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -314,5 +314,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// <returns></returns>
LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield);
+ /// <summary>
+ /// Wraps to bool Regex.IsMatch(string input, string pattern)
+ /// </summary>
+ /// <param name="input">string to test for match</param>
+ /// <param name="regex">string to use as pattern</param>
+ /// <returns>boolean</returns>
+ LSL_Integer osRegexIsMatch(string input, string pattern);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index 45db67e..5540327 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -950,5 +950,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield);
}
+
+ public LSL_Integer osRegexIsMatch(string input, string pattern)
+ {
+ return m_OSSL_Functions.osRegexIsMatch(input, pattern);
+ }
}
}
--
1.7.11.msysgit.1
From 9849dc38511a85725b8849acae0e7f50c40e4ed1 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Thu, 26 Jul 2012 11:20:58 +0100
Subject: [PATCH 4/6] fixing copypasta
---
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 8126b5b..9401d0a 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3360,7 +3360,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_Integer osRegexIsMatch(string input, string pattern)
{
- CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
m_host.AddScriptLPS(1);
try
{
--
1.7.11.msysgit.1
From cde822d3006082690fccff2e56988f1b8740d703 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Fri, 27 Jul 2012 14:44:50 +0100
Subject: [PATCH 5/6] removing byte casting, using constants
---
.../CoreModules/Scripting/WorldComm/WorldCommModule.cs | 18 +++++++++---------
OpenSim/Region/Framework/Interfaces/IWorldComm.cs | 8 ++++----
.../ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 7 ++++---
.../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 4 ++--
.../ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs | 14 ++++++++++++++
5 files changed, 33 insertions(+), 18 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index b954dd8..ef03cec 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -194,9 +194,9 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
/// <param name="msg">msg to filter on</param>
/// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
/// <returns>number of the scripts handle</returns>
- public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield)
{
- return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg, regexBitfield);
+ return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg, (byte)regexBitfield);
}
/// <summary>
@@ -490,7 +490,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return AddListener(localID, itemID, hostID, channel, name, id, msg, 0);
}
- public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield)
+ public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield)
{
// do we already have a match on this particular filter event?
List<ListenerInfo> coll = GetListeners(itemID, channel, name, id, msg);
@@ -761,14 +761,14 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
private UUID m_id; // ID to filter messages from
private string m_name; // Object name to filter messages from
private string m_message; // The message
- private byte m_regexBitfield; // The regex bitfield
+ private int m_regexBitfield; // The regex bitfield
public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message)
{
Initialise(handle, localID, ItemID, hostID, channel, name, id, message, 0);
}
- public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
+ public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, int regexBitfield)
{
Initialise(handle, localID, ItemID, hostID, channel, name, id, message, regexBitfield);
}
@@ -778,12 +778,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, 0);
}
- public ListenerInfo(ListenerInfo li, string name, UUID id, string message, byte regexBitfield)
+ public ListenerInfo(ListenerInfo li, string name, UUID id, string message, int regexBitfield)
{
Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, regexBitfield);
}
- private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, byte regexBitfield)
+ private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, int regexBitfield)
{
m_active = true;
m_handle = handle;
@@ -818,7 +818,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
linfo.m_active = (bool)data[0];
if (data.Length >= 7)
{
- linfo.m_regexBitfield = (byte)data[6];
+ linfo.m_regexBitfield = (int)data[6];
}
return linfo;
@@ -879,7 +879,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return m_id;
}
- public byte GetRegexBitfield()
+ public int GetRegexBitfield()
{
return m_regexBitfield;
}
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index 39832c6..039f4f0 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -48,11 +48,11 @@ namespace OpenSim.Region.Framework.Interfaces
/// <summary>
/// Bitfield indicating which strings should be processed as regex.
- /// 1 corresponds to IWorldCommListenerInfo::GetName()
- /// 2 corresponds to IWorldCommListenerInfo::GetMessage()
+ /// ScriptBaseClass.OS_LISTEN_REGEX_NAME corresponds to IWorldCommListenerInfo::GetName()
+ /// ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE corresponds to IWorldCommListenerInfo::GetMessage()
/// </summary>
/// <returns></returns>
- byte GetRegexBitfield();
+ int GetRegexBitfield();
}
public interface IWorldComm
@@ -93,7 +93,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// <param name="msg">msg to filter on</param>
/// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
/// <returns>number of the scripts handle</returns>
- int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, byte regexBitfield);
+ int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield);
/// <summary>
/// This method scans over the objects which registered an interest in listen callbacks.
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 9401d0a..8fe64e9 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3321,7 +3321,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
UUID keyID;
UUID.TryParse(ID, out keyID);
- if((regexBitfield & 1) == 1){ // if we want the name to be used as a regular expression, ensure it is valid first.
+ if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME)
+ { // if we want the name to be used as a regular expression, ensure it is valid first.
try
{
Regex.IsMatch("", name);
@@ -3332,7 +3333,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return -1;
}
}
- if ((regexBitfield & 2) == 2) // if we want the msg to be used as a regular expression, ensure it is valid first.
+ if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) // if we want the msg to be used as a regular expression, ensure it is valid first.
{
try
{
@@ -3354,7 +3355,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
name,
keyID,
msg,
- (byte)regexBitfield
+ regexBitfield
);
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 7c1e28b..938cda0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -308,8 +308,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// <param name="ID"></param>
/// <param name="msg"></param>
/// <param name="regexBitfield">
- /// 1 corresponds to name
- /// 2 corresponds to msg
+ /// OS_LISTEN_REGEX_NAME
+ /// OS_LISTEN_REGEX_MESSAGE
/// </param>
/// <returns></returns>
LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield);
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index c3eada0..87a7247 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -660,5 +660,19 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
public static readonly LSLInteger RCERR_UNKNOWN = -1;
public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2;
public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3;
+
+ #region Constants for the bitfield parameter of osListenRegex
+
+ /// <summary>
+ /// process name parameter as regex
+ /// </summary>
+ public const int OS_LISTEN_REGEX_NAME = 0x1;
+
+ /// <summary>
+ /// process message parameter as regex
+ /// </summary>
+ public const int OS_LISTEN_REGEX_MESSAGE = 0x2;
+
+ #endregion
}
}
--
1.7.11.msysgit.1
From 928d788cea7ddd3b335276f919dfd6ac0d41b555 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Wed, 1 Aug 2012 10:41:03 +0100
Subject: [PATCH 6/6] duplicating constants
---
.../Scripting/WorldComm/WorldCommModule.cs | 23 ++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index ef03cec..68c09f7 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -651,6 +651,21 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return -1;
}
+ /// These are duplicated from ScriptBaseClass
+ /// http://opensimulator.org/mantis/view.php?id=6106#c21945
+ #region Constants for the bitfield parameter of osListenRegex
+
+ /// <summary>
+ /// process name parameter as regex
+ /// </summary>
+ public const int OS_LISTEN_REGEX_NAME = 0x1;
+
+ /// <summary>
+ /// process message parameter as regex
+ /// </summary>
+ public const int OS_LISTEN_REGEX_MESSAGE = 0x2;
+
+ #endregion
// Theres probably a more clever and efficient way to
// do this, maybe with regex.
// PM2008: Ha, one could even be smart and define a specialized Enumerator.
@@ -677,8 +692,8 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
continue;
}
if (li.GetName().Length > 0 && (
- ((li.GetRegexBitfield() & 1) != 1 && !li.GetName().Equals(name)) ||
- ((li.GetRegexBitfield() & 1) == 1 && !Regex.IsMatch(name, li.GetName()))
+ ((li.GetRegexBitfield() & OS_LISTEN_REGEX_NAME) != OS_LISTEN_REGEX_NAME && !li.GetName().Equals(name)) ||
+ ((li.GetRegexBitfield() & OS_LISTEN_REGEX_NAME) == OS_LISTEN_REGEX_NAME && !Regex.IsMatch(name, li.GetName()))
))
{
continue;
@@ -690,8 +705,8 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
bool test = (li.GetRegexBitfield() & 2) == 2;
bool test2 = test && Regex.IsMatch(msg, li.GetMessage());
if (li.GetMessage().Length > 0 && (
- ((li.GetRegexBitfield() & 2) != 2 && !li.GetMessage().Equals(msg)) ||
- ((li.GetRegexBitfield() & 2) == 2 && !Regex.IsMatch(msg, li.GetMessage()))
+ ((li.GetRegexBitfield() & OS_LISTEN_REGEX_MESSAGE) != OS_LISTEN_REGEX_MESSAGE && !li.GetMessage().Equals(msg)) ||
+ ((li.GetRegexBitfield() & OS_LISTEN_REGEX_MESSAGE) == OS_LISTEN_REGEX_MESSAGE && !Regex.IsMatch(msg, li.GetMessage()))
))
{
continue;
--
1.7.11.msysgit.1
From d07d2504abb898dce8e47e689d8fbb066c7203dc Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Tue, 23 Oct 2012 15:29:40 +0100
Subject: [PATCH 1/3] Formatting and casing correction in WorldCommModule,
trailing new line in OSSL to get git diff to not
complain
---
OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs | 6 +++---
OpenSim/Region/Framework/Interfaces/IWorldComm.cs | 2 +-
OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs | 2 +-
3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index 8358bc0..c68ed6b 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -472,8 +472,8 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
if (coll.Count > 0)
{
- // special case, called with same filter settings, return same handle
- // (2008-05-02, tested on 1.21.1 server, still holds)
+ // special case, called with same filter settings, return same
+ // handle (2008-05-02, tested on 1.21.1 server, still holds)
return coll[0].GetHandle();
}
@@ -712,7 +712,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
}
}
- public class ListenerInfo: IWorldCommListenerInfo
+ public class ListenerInfo : IWorldCommListenerInfo
{
private bool m_active; // Listener is active or not
private int m_handle; // Assigned handle of this listener
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index 4e74781..8d88065 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -60,7 +60,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// the script during 'peek' time. Parameter hostID is needed to
/// determine the position of the script.
/// </summary>
- /// <param name="localID">localID of the script engine</param>
+ /// <param name="LocalID">localID of the script engine</param>
/// <param name="itemID">UUID of the script engine</param>
/// <param name="hostID">UUID of the SceneObjectPart</param>
/// <param name="channel">channel to listen on</param>
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 29bc163..3939dcf 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3637,4 +3637,4 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
DropAttachmentAt(false, pos, rot);
}
}
-}
\ No newline at end of file
+}
--
1.7.11.msysgit.1
From 9c39fbb8abbf45f8f839d425fd1a0d99320fe989 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Tue, 23 Oct 2012 15:42:16 +0100
Subject: [PATCH 2/3] adding ability for listeners to be filtered by regular
expressions and a general-purpose function to see if a
given string matches a given regex
---
.../Scripting/WorldComm/WorldCommModule.cs | 129 ++++++++++++++++++---
OpenSim/Region/Framework/Interfaces/IWorldComm.cs | 25 ++++
.../Shared/Api/Implementation/OSSL_Api.cs | 63 ++++++++++
.../ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs | 24 ++++
.../Shared/Api/Runtime/LSL_Constants.cs | 10 ++
.../ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs | 10 ++
6 files changed, 242 insertions(+), 19 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index c68ed6b..cf0eb2a 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -28,6 +28,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Text.RegularExpressions;
using Nini.Config;
using OpenMetaverse;
using OpenSim.Framework;
@@ -170,12 +171,42 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
/// <param name="hostID">UUID of the SceneObjectPart</param>
/// <param name="channel">channel to listen on</param>
/// <param name="name">name to filter on</param>
- /// <param name="id">key to filter on (user given, could be totally faked)</param>
+ /// <param name="id">
+ /// key to filter on (user given, could be totally faked)
+ /// </param>
/// <param name="msg">msg to filter on</param>
/// <returns>number of the scripts handle</returns>
- public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg)
+ public int Listen(uint localID, UUID itemID, UUID hostID, int channel,
+ string name, UUID id, string msg)
{
- return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg);
+ return m_listenerManager.AddListener(localID, itemID, hostID,
+ channel, name, id, msg);
+ }
+
+ /// <summary>
+ /// Create a listen event callback with the specified filters.
+ /// The parameters localID,itemID are needed to uniquely identify
+ /// the script during 'peek' time. Parameter hostID is needed to
+ /// determine the position of the script.
+ /// </summary>
+ /// <param name="localID">localID of the script engine</param>
+ /// <param name="itemID">UUID of the script engine</param>
+ /// <param name="hostID">UUID of the SceneObjectPart</param>
+ /// <param name="channel">channel to listen on</param>
+ /// <param name="name">name to filter on</param>
+ /// <param name="id">
+ /// key to filter on (user given, could be totally faked)
+ /// </param>
+ /// <param name="msg">msg to filter on</param>
+ /// <param name="regexBitfield">
+ /// Bitfield indicating which strings should be processed as regex.
+ /// </param>
+ /// <returns>number of the scripts handle</returns>
+ public int Listen(uint localID, UUID itemID, UUID hostID, int channel,
+ string name, UUID id, string msg, int regexBitfield)
+ {
+ return m_listenerManager.AddListener(localID, itemID, hostID,
+ channel, name, id, msg, regexBitfield);
}
/// <summary>
@@ -465,10 +496,20 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
m_curlisteners = 0;
}
- public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg)
+ public int AddListener(uint localID, UUID itemID, UUID hostID,
+ int channel, string name, UUID id, string msg)
+ {
+ return AddListener(localID, itemID, hostID, channel, name, id,
+ msg, 0);
+ }
+
+ public int AddListener(uint localID, UUID itemID, UUID hostID,
+ int channel, string name, UUID id, string msg,
+ int regexBitfield)
{
// do we already have a match on this particular filter event?
- List<ListenerInfo> coll = GetListeners(itemID, channel, name, id, msg);
+ List<ListenerInfo> coll = GetListeners(itemID, channel, name, id,
+ msg);
if (coll.Count > 0)
{
@@ -485,7 +526,9 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
if (newHandle > 0)
{
- ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg);
+ ListenerInfo li = new ListenerInfo(newHandle, localID,
+ itemID, hostID, channel, name, id, msg,
+ regexBitfield);
List<ListenerInfo> listeners;
if (!m_listeners.TryGetValue(channel,out listeners))
@@ -626,6 +669,22 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return -1;
}
+ /// These are duplicated from ScriptBaseClass
+ /// http://opensimulator.org/mantis/view.php?id=6106#c21945
+ #region Constants for the bitfield parameter of osListenRegex
+
+ /// <summary>
+ /// process name parameter as regex
+ /// </summary>
+ public const int OS_LISTEN_REGEX_NAME = 0x1;
+
+ /// <summary>
+ /// process message parameter as regex
+ /// </summary>
+ public const int OS_LISTEN_REGEX_MESSAGE = 0x2;
+
+ #endregion
+
// Theres probably a more clever and efficient way to
// do this, maybe with regex.
// PM2008: Ha, one could even be smart and define a specialized Enumerator.
@@ -651,7 +710,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
continue;
}
- if (li.GetName().Length > 0 && !li.GetName().Equals(name))
+ if (li.GetName().Length > 0 && (
+ ((li.GetRegexBitfield() & OS_LISTEN_REGEX_NAME) != OS_LISTEN_REGEX_NAME && !li.GetName().Equals(name)) ||
+ ((li.GetRegexBitfield() & OS_LISTEN_REGEX_NAME) == OS_LISTEN_REGEX_NAME && !Regex.IsMatch(name, li.GetName()))
+ ))
{
continue;
}
@@ -659,7 +721,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
continue;
}
- if (li.GetMessage().Length > 0 && !li.GetMessage().Equals(msg))
+ if (li.GetMessage().Length > 0 && (
+ ((li.GetRegexBitfield() & OS_LISTEN_REGEX_MESSAGE) != OS_LISTEN_REGEX_MESSAGE && !li.GetMessage().Equals(msg)) ||
+ ((li.GetRegexBitfield() & OS_LISTEN_REGEX_MESSAGE) == OS_LISTEN_REGEX_MESSAGE && !Regex.IsMatch(msg, li.GetMessage()))
+ ))
{
continue;
}
@@ -692,10 +757,13 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
int idx = 0;
Object[] item = new Object[6];
+ int dataItemLength = 6;
while (idx < data.Length)
{
- Array.Copy(data, idx, item, 0, 6);
+ dataItemLength = (idx + 7 == data.Length || (idx + 7 < data.Length && data[idx + 7] is bool)) ? 7 : 6;
+ item = new Object[dataItemLength];
+ Array.Copy(data, idx, item, 0, dataItemLength);
ListenerInfo info =
ListenerInfo.FromData(localID, itemID, hostID, item);
@@ -707,7 +775,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
m_listeners[(int)item[2]].Add(info);
}
- idx+=6;
+ idx+=dataItemLength;
}
}
}
@@ -723,19 +791,33 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
private UUID m_id; // ID to filter messages from
private string m_name; // Object name to filter messages from
private string m_message; // The message
+ private int m_regexBitfield; // The regex bitfield
public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message)
{
- Initialise(handle, localID, ItemID, hostID, channel, name, id, message);
+ Initialise(handle, localID, ItemID, hostID, channel, name, id,
+ message, 0);
+ }
+
+ public ListenerInfo(int handle, uint localID, UUID ItemID,
+ UUID hostID, int channel, string name, UUID id,
+ string message, int regexBitfield)
+ {
+ Initialise(handle, localID, ItemID, hostID, channel, name, id,
+ message, regexBitfield);
}
public ListenerInfo(ListenerInfo li, string name, UUID id, string message)
{
- Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message);
+ Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, 0);
+ }
+
+ public ListenerInfo(ListenerInfo li, string name, UUID id, string message, int regexBitfield)
+ {
+ Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, regexBitfield);
}
- private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name,
- UUID id, string message)
+ private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, int regexBitfield)
{
m_active = true;
m_handle = handle;
@@ -746,11 +828,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
m_name = name;
m_id = id;
m_message = message;
+ m_regexBitfield = regexBitfield;
}
public Object[] GetSerializationData()
{
- Object[] data = new Object[6];
+ Object[] data = new Object[7];
data[0] = m_active;
data[1] = m_handle;
@@ -758,16 +841,19 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
data[3] = m_name;
data[4] = m_id;
data[5] = m_message;
+ data[6] = m_regexBitfield;
return data;
}
public static ListenerInfo FromData(uint localID, UUID ItemID, UUID hostID, Object[] data)
{
- ListenerInfo linfo = new ListenerInfo((int)data[1], localID,
- ItemID, hostID, (int)data[2], (string)data[3],
- (UUID)data[4], (string)data[5]);
- linfo.m_active=(bool)data[0];
+ ListenerInfo linfo = new ListenerInfo((int)data[1], localID, ItemID, hostID, (int)data[2], (string)data[3], (UUID)data[4], (string)data[5]);
+ linfo.m_active = (bool)data[0];
+ if (data.Length >= 7)
+ {
+ linfo.m_regexBitfield = (int)data[6];
+ }
return linfo;
}
@@ -826,5 +912,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
{
return m_id;
}
+
+ public int GetRegexBitfield()
+ {
+ return m_regexBitfield;
+ }
}
}
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index 8d88065..66b3f3a 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -45,6 +45,14 @@ namespace OpenSim.Region.Framework.Interfaces
void Deactivate();
void Activate();
UUID GetID();
+
+ /// <summary>
+ /// Bitfield indicating which strings should be processed as regex.
+ /// 1 corresponds to IWorldCommListenerInfo::GetName()
+ /// 2 corresponds to IWorldCommListenerInfo::GetMessage()
+ /// </summary>
+ /// <returns></returns>
+ int GetRegexBitfield();
}
public interface IWorldComm
@@ -70,6 +78,23 @@ namespace OpenSim.Region.Framework.Interfaces
/// <returns>number of the scripts handle</returns>
int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg);
+ /// <summary>
+ /// Create a listen event callback with the specified filters.
+ /// The parameters localID,itemID are needed to uniquely identify
+ /// the script during 'peek' time. Parameter hostID is needed to
+ /// determine the position of the script.
+ /// </summary>
+ /// <param name="LocalID">localID of the script engine</param>
+ /// <param name="itemID">UUID of the script engine</param>
+ /// <param name="hostID">UUID of the SceneObjectPart</param>
+ /// <param name="channel">channel to listen on</param>
+ /// <param name="name">name to filter on</param>
+ /// <param name="id">key to filter on (user given, could be totally faked)</param>
+ /// <param name="msg">msg to filter on</param>
+ /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
+ /// <returns>number of the scripts handle</returns>
+ int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield);
+
/// <summary>
/// This method scans over the objects which registered an interest in listen callbacks.
/// For everyone it finds, it checks if it fits the given filter. If it does, then
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
index 3939dcf..ff507f5 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3636,5 +3636,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
DropAttachmentAt(false, pos, rot);
}
+
+ public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
+ {
+ CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
+ m_host.AddScriptLPS(1);
+ UUID keyID;
+ UUID.TryParse(ID, out keyID);
+
+ // if we want the name to be used as a regular expression, ensure it is valid first.
+ if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME)
+ {
+ try
+ {
+ Regex.IsMatch("", name);
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Name regex is invalid.");
+ return -1;
+ }
+ }
+
+ // if we want the msg to be used as a regular expression, ensure it is valid first.
+ if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE)
+ {
+ try
+ {
+ Regex.IsMatch("", msg);
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Message regex is invalid.");
+ return -1;
+ }
+ }
+
+ IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
+ return (wComm == null) ? -1 : wComm.Listen(
+ m_host.LocalId,
+ m_item.ItemID,
+ m_host.UUID,
+ channelID,
+ name,
+ keyID,
+ msg,
+ regexBitfield
+ );
+ }
+
+ public LSL_Integer osRegexIsMatch(string input, string pattern)
+ {
+ CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
+ m_host.AddScriptLPS(1);
+ try
+ {
+ return Regex.IsMatch(input, pattern) ? 1 : 0;
+ }
+ catch (Exception)
+ {
+ OSSLShoutError("Possible invalid regular expression detected.");
+ return 0;
+ }
+ }
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
index 93188c9..cdd9ea8 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs
@@ -418,5 +418,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api.Interfaces
/// <param name="pos"></param>
/// <param name="rot"></param>
void osForceDropAttachmentAt(vector pos, rotation rot);
+
+ /// <summary>
+ /// Identical to llListen except for a bitfield which indicates which
+ /// string parameters should be parsed as regex patterns.
+ /// </summary>
+ /// <param name="channelID"></param>
+ /// <param name="name"></param>
+ /// <param name="ID"></param>
+ /// <param name="msg"></param>
+ /// <param name="regexBitfield">
+ /// OS_LISTEN_REGEX_NAME
+ /// OS_LISTEN_REGEX_MESSAGE
+ /// </param>
+ /// <returns></returns>
+ LSL_Integer osListenRegex(int channelID, string name, string ID,
+ string msg, int regexBitfield);
+
+ /// <summary>
+ /// Wraps to bool Regex.IsMatch(string input, string pattern)
+ /// </summary>
+ /// <param name="input">string to test for match</param>
+ /// <param name="regex">string to use as pattern</param>
+ /// <returns>boolean</returns>
+ LSL_Integer osRegexIsMatch(string input, string pattern);
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
index 62bd6b8..880841b 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs
@@ -716,5 +716,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
public static readonly LSLInteger RCERR_UNKNOWN = -1;
public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2;
public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3;
+
+ /// <summary>
+ /// process name parameter as regex
+ /// </summary>
+ public const int OS_LISTEN_REGEX_NAME = 0x1;
+
+ /// <summary>
+ /// process message parameter as regex
+ /// </summary>
+ public const int OS_LISTEN_REGEX_MESSAGE = 0x2;
}
}
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
index dee1b28..afa9ae0 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs
@@ -992,5 +992,15 @@ namespace OpenSim.Region.ScriptEngine.Shared.ScriptBase
{
m_OSSL_Functions.osForceDropAttachmentAt(pos, rot);
}
+
+ public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
+ {
+ return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield);
+ }
+
+ public LSL_Integer osRegexIsMatch(string input, string pattern)
+ {
+ return m_OSSL_Functions.osRegexIsMatch(input, pattern);
+ }
}
}
--
1.7.11.msysgit.1
From f36e8eed9fc934b2c8d831b2136066ee604de6c4 Mon Sep 17 00:00:00 2001
From: SignpostMarv <github@signpostmarv.name>
Date: Tue, 23 Oct 2012 16:02:31 +0100
Subject: [PATCH 3/3] refactoring IWorldCommListenerInfo.GetRegexBitfield()
method to be a field with a private setter
---
.../Scripting/WorldComm/WorldCommModule.cs | 20 ++++++++------------
OpenSim/Region/Framework/Interfaces/IWorldComm.cs | 3 +--
2 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
index cf0eb2a..401ff6c 100644
--- a/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
+++ b/OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs
@@ -711,8 +711,8 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
continue;
}
if (li.GetName().Length > 0 && (
- ((li.GetRegexBitfield() & OS_LISTEN_REGEX_NAME) != OS_LISTEN_REGEX_NAME && !li.GetName().Equals(name)) ||
- ((li.GetRegexBitfield() & OS_LISTEN_REGEX_NAME) == OS_LISTEN_REGEX_NAME && !Regex.IsMatch(name, li.GetName()))
+ ((li.RegexBitfield & OS_LISTEN_REGEX_NAME) != OS_LISTEN_REGEX_NAME && !li.GetName().Equals(name)) ||
+ ((li.RegexBitfield & OS_LISTEN_REGEX_NAME) == OS_LISTEN_REGEX_NAME && !Regex.IsMatch(name, li.GetName()))
))
{
continue;
@@ -722,8 +722,8 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
continue;
}
if (li.GetMessage().Length > 0 && (
- ((li.GetRegexBitfield() & OS_LISTEN_REGEX_MESSAGE) != OS_LISTEN_REGEX_MESSAGE && !li.GetMessage().Equals(msg)) ||
- ((li.GetRegexBitfield() & OS_LISTEN_REGEX_MESSAGE) == OS_LISTEN_REGEX_MESSAGE && !Regex.IsMatch(msg, li.GetMessage()))
+ ((li.RegexBitfield & OS_LISTEN_REGEX_MESSAGE) != OS_LISTEN_REGEX_MESSAGE && !li.GetMessage().Equals(msg)) ||
+ ((li.RegexBitfield & OS_LISTEN_REGEX_MESSAGE) == OS_LISTEN_REGEX_MESSAGE && !Regex.IsMatch(msg, li.GetMessage()))
))
{
continue;
@@ -791,7 +791,6 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
private UUID m_id; // ID to filter messages from
private string m_name; // Object name to filter messages from
private string m_message; // The message
- private int m_regexBitfield; // The regex bitfield
public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message)
{
@@ -828,7 +827,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
m_name = name;
m_id = id;
m_message = message;
- m_regexBitfield = regexBitfield;
+ RegexBitfield = regexBitfield;
}
public Object[] GetSerializationData()
@@ -841,7 +840,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
data[3] = m_name;
data[4] = m_id;
data[5] = m_message;
- data[6] = m_regexBitfield;
+ data[6] = RegexBitfield;
return data;
}
@@ -852,7 +851,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
linfo.m_active = (bool)data[0];
if (data.Length >= 7)
{
- linfo.m_regexBitfield = (int)data[6];
+ linfo.RegexBitfield = (int)data[6];
}
return linfo;
@@ -913,9 +912,6 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
return m_id;
}
- public int GetRegexBitfield()
- {
- return m_regexBitfield;
- }
+ public int RegexBitfield { get; private set; }
}
}
diff --git a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
index 66b3f3a..d76a0d7 100644
--- a/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
+++ b/OpenSim/Region/Framework/Interfaces/IWorldComm.cs
@@ -51,8 +51,7 @@ namespace OpenSim.Region.Framework.Interfaces
/// 1 corresponds to IWorldCommListenerInfo::GetName()
/// 2 corresponds to IWorldCommListenerInfo::GetMessage()
/// </summary>
- /// <returns></returns>
- int GetRegexBitfield();
+ int RegexBitfield { get; }
}
public interface IWorldComm
--
1.7.11.msysgit.1
| ||||||||
Notes |
|
|
(0021897) dahlia (manager) 2012-07-26 00:25 |
interesting idea, but I wonder if there is some way this could be done with something more generic, perhaps an osRegex()? that way it could be used in other areas of a script besides listen filtering. |
|
(0021898) SignpostMarv (reporter) 2012-07-26 09:06 |
implementing a function that wraps to Regex.IsMatch() is relatively trivial in comparison and for the use-case this was designed for it would be called *after* listen() has fired, whereas osListenRegex() prevents listen() from firing when you know you don't want it to. Currently trying to fix a bug this patch introduces, so if I can't get it fixed I'll get to integer osRegexIsMatch(string input, string pattern) :) |
|
(0021899) SignpostMarv (reporter) 2012-07-26 10:15 edited on: 2012-07-26 10:26 |
Changed the example script to what I'm actually using it for. Turns out I needed osRegexIsMatch as well :D The third patch includes a fix that broke existing script states and fixes copypasta. It seems we can't delete our own attachments on the mantis : |
|
(0021903) justincc (administrator) 2012-07-26 23:09 edited on: 2012-07-26 23:10 |
Without having looked through this super-thoroughly, I think this is a reasonable function - I can imagine it would be good to be able to listen for certain matching messages or things without the overhead of generating listen events. A couple of points * Please don't use magic numbers. '1' and '2' must have meaningfully named constants that can be used by scripts. The same is true of internal code. Possibly internal code should use bools rather than packing things into a single field, though I know a lot of other code uses such fields. I know some parts of OpenSimulator are using magic numbers but this is a bad thing and should not be perpetuated. * I don't think it's worth castings ints around to bytes. This just litters the code with casts for very little gain. Please use ints throughout. |
|
(0021904) SignpostMarv (reporter) 2012-07-26 23:15 |
* re: magic nubmers: I'm using magic numbers because I'm unsure how to add constants to the script engine. * re: ints & btes: I started off using bytes throughout and found that didn't work. It's easy enough to change though, so I'll get that done if I have time tomorrow :) |
|
(0021905) justincc (administrator) 2012-07-26 23:17 |
* You can see examples of constants accessible by scripts in the ScriptBaseClass. If internal code is to use constants these will have to be duplicated elsewhere. Ultimately this should change but it may be a good thing since internal constants shouldn't really by tied to externally interfaces, though I know OpenSimulator is shot through with this kind of thing. |
|
(0021912) SignpostMarv (reporter) 2012-07-27 13:46 |
re: magic numbers & constants, it looks like I'm going to have to add a reference in OpenSim.Region.CoreModules so WorldCommModule can use the constants I've added. Is that going to be an issue ? |
|
(0021925) justincc (administrator) 2012-07-27 23:28 |
Well, WorldCommModule is in OpenSim.Region.CoreModules already. We want to avoid other packages referencing OpenSim.Region.CoreModules directly. If you want to share constants (or preferable a flags enum) then the easiest place would be OpenSim.Framework even if that's not very modular. |
|
(0021933) SignpostMarv (reporter) 2012-07-30 08:16 |
Forgot to upload the patch last week that had the constants in use. |
|
(0021943) justincc (administrator) 2012-07-31 23:20 |
Hi Signpost. Patch does not apply, probably because of the addition of osMin to IOSSLApi, etc. Please could you rebase against current master. Also, it's hard to tell from the patch but it looks like we're still using magic numbers in WorldCommModule? |
|
(0021944) SignpostMarv (reporter) 2012-07-31 23:29 |
The patch was made before the magic numbers discussion (it's why I enquired about adding a reference). Can constants reference other constants ? A constant needs to be set so they can be used in the LSL script editor... |
|
(0021945) justincc (administrator) 2012-07-31 23:30 |
The simplest thing right now would be to dupe the constants in WorldCommModule. |
|
(0021947) SignpostMarv (reporter) 2012-08-01 08:37 |
duplicating constants with identical purposes seems almost as bad magic numbers :s Will get it done :) |
|
(0021950) SignpostMarv (reporter) 2012-08-01 08:50 |
rebased patch uploaded :) |
|
(0021952) SignpostMarv (reporter) 2012-08-01 09:42 |
Realised I had forgotten to duplicate the constants :P |
|
(0022900) SignpostMarv (reporter) 2012-10-23 15:09 |
Made a new patch as the old one wouldn't apply. New patch also refactors the additional method into a field. |
|
(0022933) justincc (administrator) 2012-10-26 01:24 |
Applied as commits 80dcc13a..18b1ee6 on git master. Thanks Marv! |
|
(0022935) justincc (administrator) 2012-10-26 02:07 |
Oh yes, could you document these new methods in the OpenSimulator wiki now? Thanks. |
Issue History |
|||
| Date Modified | Username | Field | Change |
| 2012-07-25 14:17 | SignpostMarv | New Issue | |
| 2012-07-25 14:17 | SignpostMarv | File Added: osListenRegex.patch | |
| 2012-07-25 14:17 | SignpostMarv | Status | new => patch included |
| 2012-07-26 00:25 | dahlia | Note Added: 0021897 | |
| 2012-07-26 09:06 | SignpostMarv | Note Added: 0021898 | |
| 2012-07-26 10:14 | SignpostMarv | File Added: osListenRegex-with-osRegexIsMatch.patch | |
| 2012-07-26 10:15 | SignpostMarv | Note Added: 0021899 | |
| 2012-07-26 10:15 | SignpostMarv | Steps to Reproduce Updated | View Revisions |
| 2012-07-26 10:16 | SignpostMarv | Note Edited: 0021899 | View Revisions |
| 2012-07-26 10:25 | SignpostMarv | File Added: osListenRegex-with-osRegexIsMatch-copypasta.patch | |
| 2012-07-26 10:26 | SignpostMarv | Note Edited: 0021899 | View Revisions |
| 2012-07-26 23:09 | justincc | Note Added: 0021903 | |
| 2012-07-26 23:09 | justincc | Assigned To | => justincc |
| 2012-07-26 23:09 | justincc | Status | patch included => patch feedback |
| 2012-07-26 23:10 | justincc | Note Edited: 0021903 | View Revisions |
| 2012-07-26 23:15 | SignpostMarv | Note Added: 0021904 | |
| 2012-07-26 23:17 | justincc | Note Added: 0021905 | |
| 2012-07-27 13:46 | SignpostMarv | Note Added: 0021912 | |
| 2012-07-27 23:28 | justincc | Note Added: 0021925 | |
| 2012-07-28 22:29 | SignpostMarv | File Deleted: osListenRegex-with-osRegexIsMatch.patch | |
| 2012-07-30 08:16 | SignpostMarv | File Added: osListenRegex-with-constants.patch | |
| 2012-07-30 08:16 | SignpostMarv | Note Added: 0021933 | |
| 2012-07-31 23:20 | justincc | Note Added: 0021943 | |
| 2012-07-31 23:29 | SignpostMarv | Note Added: 0021944 | |
| 2012-07-31 23:30 | justincc | Note Added: 0021945 | |
| 2012-08-01 08:37 | SignpostMarv | Note Added: 0021947 | |
| 2012-08-01 08:50 | SignpostMarv | File Added: osListenRegex-rebase.patch | |
| 2012-08-01 08:50 | SignpostMarv | Note Added: 0021950 | |
| 2012-08-01 09:41 | SignpostMarv | File Added: osListenRegex-duplicated-constants.patch | |
| 2012-08-01 09:42 | SignpostMarv | Note Added: 0021952 | |
| 2012-10-23 15:09 | SignpostMarv | File Added: osListenRegex-rewritten-refactored.patch | |
| 2012-10-23 15:09 | SignpostMarv | Note Added: 0022900 | |
| 2012-10-23 15:09 | SignpostMarv | Status | patch feedback => patch included |
| 2012-10-26 01:24 | justincc | Note Added: 0022933 | |
| 2012-10-26 01:24 | justincc | Status | patch included => resolved |
| 2012-10-26 01:24 | justincc | Resolution | open => fixed |
| 2012-10-26 02:07 | justincc | Note Added: 0022935 | |
| Copyright © 2000 - 2012 MantisBT Group |




