aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--OpenSim/Region/CoreModules/Scripting/WorldComm/WorldCommModule.cs129
-rw-r--r--OpenSim/Region/Framework/Interfaces/IWorldComm.cs25
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs63
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Interface/IOSSL_Api.cs24
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/LSL_Constants.cs10
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Runtime/OSSL_Stub.cs10
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 @@
28using System; 28using System;
29using System.Collections; 29using System.Collections;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text.RegularExpressions;
31using Nini.Config; 32using Nini.Config;
32using OpenMetaverse; 33using OpenMetaverse;
33using OpenSim.Framework; 34using OpenSim.Framework;
@@ -170,12 +171,42 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
170 /// <param name="hostID">UUID of the SceneObjectPart</param> 171 /// <param name="hostID">UUID of the SceneObjectPart</param>
171 /// <param name="channel">channel to listen on</param> 172 /// <param name="channel">channel to listen on</param>
172 /// <param name="name">name to filter on</param> 173 /// <param name="name">name to filter on</param>
173 /// <param name="id">key to filter on (user given, could be totally faked)</param> 174 /// <param name="id">
175 /// key to filter on (user given, could be totally faked)
176 /// </param>
174 /// <param name="msg">msg to filter on</param> 177 /// <param name="msg">msg to filter on</param>
175 /// <returns>number of the scripts handle</returns> 178 /// <returns>number of the scripts handle</returns>
176 public int Listen(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg) 179 public int Listen(uint localID, UUID itemID, UUID hostID, int channel,
180 string name, UUID id, string msg)
177 { 181 {
178 return m_listenerManager.AddListener(localID, itemID, hostID, channel, name, id, msg); 182 return m_listenerManager.AddListener(localID, itemID, hostID,
183 channel, name, id, msg);
184 }
185
186 /// <summary>
187 /// Create a listen event callback with the specified filters.
188 /// The parameters localID,itemID are needed to uniquely identify
189 /// the script during 'peek' time. Parameter hostID is needed to
190 /// determine the position of the script.
191 /// </summary>
192 /// <param name="localID">localID of the script engine</param>
193 /// <param name="itemID">UUID of the script engine</param>
194 /// <param name="hostID">UUID of the SceneObjectPart</param>
195 /// <param name="channel">channel to listen on</param>
196 /// <param name="name">name to filter on</param>
197 /// <param name="id">
198 /// key to filter on (user given, could be totally faked)
199 /// </param>
200 /// <param name="msg">msg to filter on</param>
201 /// <param name="regexBitfield">
202 /// Bitfield indicating which strings should be processed as regex.
203 /// </param>
204 /// <returns>number of the scripts handle</returns>
205 public int Listen(uint localID, UUID itemID, UUID hostID, int channel,
206 string name, UUID id, string msg, int regexBitfield)
207 {
208 return m_listenerManager.AddListener(localID, itemID, hostID,
209 channel, name, id, msg, regexBitfield);
179 } 210 }
180 211
181 /// <summary> 212 /// <summary>
@@ -465,10 +496,20 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
465 m_curlisteners = 0; 496 m_curlisteners = 0;
466 } 497 }
467 498
468 public int AddListener(uint localID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg) 499 public int AddListener(uint localID, UUID itemID, UUID hostID,
500 int channel, string name, UUID id, string msg)
501 {
502 return AddListener(localID, itemID, hostID, channel, name, id,
503 msg, 0);
504 }
505
506 public int AddListener(uint localID, UUID itemID, UUID hostID,
507 int channel, string name, UUID id, string msg,
508 int regexBitfield)
469 { 509 {
470 // do we already have a match on this particular filter event? 510 // do we already have a match on this particular filter event?
471 List<ListenerInfo> coll = GetListeners(itemID, channel, name, id, msg); 511 List<ListenerInfo> coll = GetListeners(itemID, channel, name, id,
512 msg);
472 513
473 if (coll.Count > 0) 514 if (coll.Count > 0)
474 { 515 {
@@ -485,7 +526,9 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
485 526
486 if (newHandle > 0) 527 if (newHandle > 0)
487 { 528 {
488 ListenerInfo li = new ListenerInfo(newHandle, localID, itemID, hostID, channel, name, id, msg); 529 ListenerInfo li = new ListenerInfo(newHandle, localID,
530 itemID, hostID, channel, name, id, msg,
531 regexBitfield);
489 532
490 List<ListenerInfo> listeners; 533 List<ListenerInfo> listeners;
491 if (!m_listeners.TryGetValue(channel,out listeners)) 534 if (!m_listeners.TryGetValue(channel,out listeners))
@@ -626,6 +669,22 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
626 return -1; 669 return -1;
627 } 670 }
628 671
672 /// These are duplicated from ScriptBaseClass
673 /// http://opensimulator.org/mantis/view.php?id=6106#c21945
674 #region Constants for the bitfield parameter of osListenRegex
675
676 /// <summary>
677 /// process name parameter as regex
678 /// </summary>
679 public const int OS_LISTEN_REGEX_NAME = 0x1;
680
681 /// <summary>
682 /// process message parameter as regex
683 /// </summary>
684 public const int OS_LISTEN_REGEX_MESSAGE = 0x2;
685
686 #endregion
687
629 // Theres probably a more clever and efficient way to 688 // Theres probably a more clever and efficient way to
630 // do this, maybe with regex. 689 // do this, maybe with regex.
631 // PM2008: Ha, one could even be smart and define a specialized Enumerator. 690 // PM2008: Ha, one could even be smart and define a specialized Enumerator.
@@ -651,7 +710,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
651 { 710 {
652 continue; 711 continue;
653 } 712 }
654 if (li.GetName().Length > 0 && !li.GetName().Equals(name)) 713 if (li.GetName().Length > 0 && (
714 ((li.GetRegexBitfield() & OS_LISTEN_REGEX_NAME) != OS_LISTEN_REGEX_NAME && !li.GetName().Equals(name)) ||
715 ((li.GetRegexBitfield() & OS_LISTEN_REGEX_NAME) == OS_LISTEN_REGEX_NAME && !Regex.IsMatch(name, li.GetName()))
716 ))
655 { 717 {
656 continue; 718 continue;
657 } 719 }
@@ -659,7 +721,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
659 { 721 {
660 continue; 722 continue;
661 } 723 }
662 if (li.GetMessage().Length > 0 && !li.GetMessage().Equals(msg)) 724 if (li.GetMessage().Length > 0 && (
725 ((li.GetRegexBitfield() & OS_LISTEN_REGEX_MESSAGE) != OS_LISTEN_REGEX_MESSAGE && !li.GetMessage().Equals(msg)) ||
726 ((li.GetRegexBitfield() & OS_LISTEN_REGEX_MESSAGE) == OS_LISTEN_REGEX_MESSAGE && !Regex.IsMatch(msg, li.GetMessage()))
727 ))
663 { 728 {
664 continue; 729 continue;
665 } 730 }
@@ -692,10 +757,13 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
692 { 757 {
693 int idx = 0; 758 int idx = 0;
694 Object[] item = new Object[6]; 759 Object[] item = new Object[6];
760 int dataItemLength = 6;
695 761
696 while (idx < data.Length) 762 while (idx < data.Length)
697 { 763 {
698 Array.Copy(data, idx, item, 0, 6); 764 dataItemLength = (idx + 7 == data.Length || (idx + 7 < data.Length && data[idx + 7] is bool)) ? 7 : 6;
765 item = new Object[dataItemLength];
766 Array.Copy(data, idx, item, 0, dataItemLength);
699 767
700 ListenerInfo info = 768 ListenerInfo info =
701 ListenerInfo.FromData(localID, itemID, hostID, item); 769 ListenerInfo.FromData(localID, itemID, hostID, item);
@@ -707,7 +775,7 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
707 m_listeners[(int)item[2]].Add(info); 775 m_listeners[(int)item[2]].Add(info);
708 } 776 }
709 777
710 idx+=6; 778 idx+=dataItemLength;
711 } 779 }
712 } 780 }
713 } 781 }
@@ -723,19 +791,33 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
723 private UUID m_id; // ID to filter messages from 791 private UUID m_id; // ID to filter messages from
724 private string m_name; // Object name to filter messages from 792 private string m_name; // Object name to filter messages from
725 private string m_message; // The message 793 private string m_message; // The message
794 private int m_regexBitfield; // The regex bitfield
726 795
727 public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message) 796 public ListenerInfo(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message)
728 { 797 {
729 Initialise(handle, localID, ItemID, hostID, channel, name, id, message); 798 Initialise(handle, localID, ItemID, hostID, channel, name, id,
799 message, 0);
800 }
801
802 public ListenerInfo(int handle, uint localID, UUID ItemID,
803 UUID hostID, int channel, string name, UUID id,
804 string message, int regexBitfield)
805 {
806 Initialise(handle, localID, ItemID, hostID, channel, name, id,
807 message, regexBitfield);
730 } 808 }
731 809
732 public ListenerInfo(ListenerInfo li, string name, UUID id, string message) 810 public ListenerInfo(ListenerInfo li, string name, UUID id, string message)
733 { 811 {
734 Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message); 812 Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, 0);
813 }
814
815 public ListenerInfo(ListenerInfo li, string name, UUID id, string message, int regexBitfield)
816 {
817 Initialise(li.m_handle, li.m_localID, li.m_itemID, li.m_hostID, li.m_channel, name, id, message, regexBitfield);
735 } 818 }
736 819
737 private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, 820 private void Initialise(int handle, uint localID, UUID ItemID, UUID hostID, int channel, string name, UUID id, string message, int regexBitfield)
738 UUID id, string message)
739 { 821 {
740 m_active = true; 822 m_active = true;
741 m_handle = handle; 823 m_handle = handle;
@@ -746,11 +828,12 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
746 m_name = name; 828 m_name = name;
747 m_id = id; 829 m_id = id;
748 m_message = message; 830 m_message = message;
831 m_regexBitfield = regexBitfield;
749 } 832 }
750 833
751 public Object[] GetSerializationData() 834 public Object[] GetSerializationData()
752 { 835 {
753 Object[] data = new Object[6]; 836 Object[] data = new Object[7];
754 837
755 data[0] = m_active; 838 data[0] = m_active;
756 data[1] = m_handle; 839 data[1] = m_handle;
@@ -758,16 +841,19 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
758 data[3] = m_name; 841 data[3] = m_name;
759 data[4] = m_id; 842 data[4] = m_id;
760 data[5] = m_message; 843 data[5] = m_message;
844 data[6] = m_regexBitfield;
761 845
762 return data; 846 return data;
763 } 847 }
764 848
765 public static ListenerInfo FromData(uint localID, UUID ItemID, UUID hostID, Object[] data) 849 public static ListenerInfo FromData(uint localID, UUID ItemID, UUID hostID, Object[] data)
766 { 850 {
767 ListenerInfo linfo = new ListenerInfo((int)data[1], localID, 851 ListenerInfo linfo = new ListenerInfo((int)data[1], localID, ItemID, hostID, (int)data[2], (string)data[3], (UUID)data[4], (string)data[5]);
768 ItemID, hostID, (int)data[2], (string)data[3], 852 linfo.m_active = (bool)data[0];
769 (UUID)data[4], (string)data[5]); 853 if (data.Length >= 7)
770 linfo.m_active=(bool)data[0]; 854 {
855 linfo.m_regexBitfield = (int)data[6];
856 }
771 857
772 return linfo; 858 return linfo;
773 } 859 }
@@ -826,5 +912,10 @@ namespace OpenSim.Region.CoreModules.Scripting.WorldComm
826 { 912 {
827 return m_id; 913 return m_id;
828 } 914 }
915
916 public int GetRegexBitfield()
917 {
918 return m_regexBitfield;
919 }
829 } 920 }
830} 921}
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
45 void Deactivate(); 45 void Deactivate();
46 void Activate(); 46 void Activate();
47 UUID GetID(); 47 UUID GetID();
48
49 /// <summary>
50 /// Bitfield indicating which strings should be processed as regex.
51 /// 1 corresponds to IWorldCommListenerInfo::GetName()
52 /// 2 corresponds to IWorldCommListenerInfo::GetMessage()
53 /// </summary>
54 /// <returns></returns>
55 int GetRegexBitfield();
48 } 56 }
49 57
50 public interface IWorldComm 58 public interface IWorldComm
@@ -70,6 +78,23 @@ namespace OpenSim.Region.Framework.Interfaces
70 /// <returns>number of the scripts handle</returns> 78 /// <returns>number of the scripts handle</returns>
71 int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg); 79 int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg);
72 80
81 /// <summary>
82 /// Create a listen event callback with the specified filters.
83 /// The parameters localID,itemID are needed to uniquely identify
84 /// the script during 'peek' time. Parameter hostID is needed to
85 /// determine the position of the script.
86 /// </summary>
87 /// <param name="LocalID">localID of the script engine</param>
88 /// <param name="itemID">UUID of the script engine</param>
89 /// <param name="hostID">UUID of the SceneObjectPart</param>
90 /// <param name="channel">channel to listen on</param>
91 /// <param name="name">name to filter on</param>
92 /// <param name="id">key to filter on (user given, could be totally faked)</param>
93 /// <param name="msg">msg to filter on</param>
94 /// <param name="regexBitfield">Bitfield indicating which strings should be processed as regex.</param>
95 /// <returns>number of the scripts handle</returns>
96 int Listen(uint LocalID, UUID itemID, UUID hostID, int channel, string name, UUID id, string msg, int regexBitfield);
97
73 /// <summary> 98 /// <summary>
74 /// This method scans over the objects which registered an interest in listen callbacks. 99 /// This method scans over the objects which registered an interest in listen callbacks.
75 /// For everyone it finds, it checks if it fits the given filter. If it does, then 100 /// 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 0650b90..828288d 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/OSSL_Api.cs
@@ -3647,5 +3647,68 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
3647 3647
3648 DropAttachmentAt(false, pos, rot); 3648 DropAttachmentAt(false, pos, rot);
3649 } 3649 }
3650
3651 public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
3652 {
3653 CheckThreatLevel(ThreatLevel.Low, "osListenRegex");
3654 m_host.AddScriptLPS(1);
3655 UUID keyID;
3656 UUID.TryParse(ID, out keyID);
3657
3658 // if we want the name to be used as a regular expression, ensure it is valid first.
3659 if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_NAME) == ScriptBaseClass.OS_LISTEN_REGEX_NAME)
3660 {
3661 try
3662 {
3663 Regex.IsMatch("", name);
3664 }
3665 catch (Exception)
3666 {
3667 OSSLShoutError("Name regex is invalid.");
3668 return -1;
3669 }
3670 }
3671
3672 // if we want the msg to be used as a regular expression, ensure it is valid first.
3673 if ((regexBitfield & ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE) == ScriptBaseClass.OS_LISTEN_REGEX_MESSAGE)
3674 {
3675 try
3676 {
3677 Regex.IsMatch("", msg);
3678 }
3679 catch (Exception)
3680 {
3681 OSSLShoutError("Message regex is invalid.");
3682 return -1;
3683 }
3684 }
3685
3686 IWorldComm wComm = m_ScriptEngine.World.RequestModuleInterface<IWorldComm>();
3687 return (wComm == null) ? -1 : wComm.Listen(
3688 m_host.LocalId,
3689 m_item.ItemID,
3690 m_host.UUID,
3691 channelID,
3692 name,
3693 keyID,
3694 msg,
3695 regexBitfield
3696 );
3697 }
3698
3699 public LSL_Integer osRegexIsMatch(string input, string pattern)
3700 {
3701 CheckThreatLevel(ThreatLevel.Low, "osRegexIsMatch");
3702 m_host.AddScriptLPS(1);
3703 try
3704 {
3705 return Regex.IsMatch(input, pattern) ? 1 : 0;
3706 }
3707 catch (Exception)
3708 {
3709 OSSLShoutError("Possible invalid regular expression detected.");
3710 return 0;
3711 }
3712 }
3650 } 3713 }
3651} 3714}
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
418 /// <param name="pos"></param> 418 /// <param name="pos"></param>
419 /// <param name="rot"></param> 419 /// <param name="rot"></param>
420 void osForceDropAttachmentAt(vector pos, rotation rot); 420 void osForceDropAttachmentAt(vector pos, rotation rot);
421
422 /// <summary>
423 /// Identical to llListen except for a bitfield which indicates which
424 /// string parameters should be parsed as regex patterns.
425 /// </summary>
426 /// <param name="channelID"></param>
427 /// <param name="name"></param>
428 /// <param name="ID"></param>
429 /// <param name="msg"></param>
430 /// <param name="regexBitfield">
431 /// OS_LISTEN_REGEX_NAME
432 /// OS_LISTEN_REGEX_MESSAGE
433 /// </param>
434 /// <returns></returns>
435 LSL_Integer osListenRegex(int channelID, string name, string ID,
436 string msg, int regexBitfield);
437
438 /// <summary>
439 /// Wraps to bool Regex.IsMatch(string input, string pattern)
440 /// </summary>
441 /// <param name="input">string to test for match</param>
442 /// <param name="regex">string to use as pattern</param>
443 /// <returns>boolean</returns>
444 LSL_Integer osRegexIsMatch(string input, string pattern);
421 } 445 }
422} 446}
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
716 public static readonly LSLInteger RCERR_UNKNOWN = -1; 716 public static readonly LSLInteger RCERR_UNKNOWN = -1;
717 public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2; 717 public static readonly LSLInteger RCERR_SIM_PERF_LOW = -2;
718 public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3; 718 public static readonly LSLInteger RCERR_CAST_TIME_EXCEEDED = 3;
719
720 /// <summary>
721 /// process name parameter as regex
722 /// </summary>
723 public const int OS_LISTEN_REGEX_NAME = 0x1;
724
725 /// <summary>
726 /// process message parameter as regex
727 /// </summary>
728 public const int OS_LISTEN_REGEX_MESSAGE = 0x2;
719 } 729 }
720} 730}
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
992 { 992 {
993 m_OSSL_Functions.osForceDropAttachmentAt(pos, rot); 993 m_OSSL_Functions.osForceDropAttachmentAt(pos, rot);
994 } 994 }
995
996 public LSL_Integer osListenRegex(int channelID, string name, string ID, string msg, int regexBitfield)
997 {
998 return m_OSSL_Functions.osListenRegex(channelID, name, ID, msg, regexBitfield);
999 }
1000
1001 public LSL_Integer osRegexIsMatch(string input, string pattern)
1002 {
1003 return m_OSSL_Functions.osRegexIsMatch(input, pattern);
1004 }
995 } 1005 }
996} 1006}