diff options
Diffstat (limited to '')
14 files changed, 1764 insertions, 79 deletions
diff --git a/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs b/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs new file mode 100644 index 0000000..a95514c --- /dev/null +++ b/OpenSim/Region/OptionalModules/Avatar/Attachments/AttachmentsCommandModule.cs | |||
@@ -0,0 +1,195 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Linq; | ||
31 | using System.Reflection; | ||
32 | using System.Text; | ||
33 | using log4net; | ||
34 | using Mono.Addins; | ||
35 | using Nini.Config; | ||
36 | using OpenMetaverse; | ||
37 | using OpenSim.Framework; | ||
38 | using OpenSim.Framework.Console; | ||
39 | using OpenSim.Framework.Statistics; | ||
40 | using OpenSim.Region.ClientStack.LindenUDP; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Region.Framework.Scenes; | ||
43 | |||
44 | namespace OpenSim.Region.OptionalModules.Avatar.Attachments | ||
45 | { | ||
46 | /// <summary> | ||
47 | /// A module that just holds commands for inspecting avatar appearance. | ||
48 | /// </summary> | ||
49 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "AttachmentsCommandModule")] | ||
50 | public class AttachmentsCommandModule : ISharedRegionModule | ||
51 | { | ||
52 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | |||
54 | private List<Scene> m_scenes = new List<Scene>(); | ||
55 | // private IAvatarFactoryModule m_avatarFactory; | ||
56 | |||
57 | public string Name { get { return "Attachments Command Module"; } } | ||
58 | |||
59 | public Type ReplaceableInterface { get { return null; } } | ||
60 | |||
61 | public void Initialise(IConfigSource source) | ||
62 | { | ||
63 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: INITIALIZED MODULE"); | ||
64 | } | ||
65 | |||
66 | public void PostInitialise() | ||
67 | { | ||
68 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: POST INITIALIZED MODULE"); | ||
69 | } | ||
70 | |||
71 | public void Close() | ||
72 | { | ||
73 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: CLOSED MODULE"); | ||
74 | } | ||
75 | |||
76 | public void AddRegion(Scene scene) | ||
77 | { | ||
78 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} ADDED", scene.RegionInfo.RegionName); | ||
79 | } | ||
80 | |||
81 | public void RemoveRegion(Scene scene) | ||
82 | { | ||
83 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} REMOVED", scene.RegionInfo.RegionName); | ||
84 | |||
85 | lock (m_scenes) | ||
86 | m_scenes.Remove(scene); | ||
87 | } | ||
88 | |||
89 | public void RegionLoaded(Scene scene) | ||
90 | { | ||
91 | // m_log.DebugFormat("[ATTACHMENTS COMMAND MODULE]: REGION {0} LOADED", scene.RegionInfo.RegionName); | ||
92 | |||
93 | lock (m_scenes) | ||
94 | m_scenes.Add(scene); | ||
95 | |||
96 | scene.AddCommand( | ||
97 | "Users", this, "attachments show", | ||
98 | "attachments show [<first-name> <last-name>]", | ||
99 | "Show attachment information for avatars in this simulator.", | ||
100 | HandleShowAttachmentsCommand); | ||
101 | } | ||
102 | |||
103 | protected void HandleShowAttachmentsCommand(string module, string[] cmd) | ||
104 | { | ||
105 | if (cmd.Length != 2 && cmd.Length < 4) | ||
106 | { | ||
107 | MainConsole.Instance.OutputFormat("Usage: attachments show [<first-name> <last-name>]"); | ||
108 | return; | ||
109 | } | ||
110 | |||
111 | bool targetNameSupplied = false; | ||
112 | string optionalTargetFirstName = null; | ||
113 | string optionalTargetLastName = null; | ||
114 | |||
115 | if (cmd.Length >= 4) | ||
116 | { | ||
117 | targetNameSupplied = true; | ||
118 | optionalTargetFirstName = cmd[2]; | ||
119 | optionalTargetLastName = cmd[3]; | ||
120 | } | ||
121 | |||
122 | StringBuilder sb = new StringBuilder(); | ||
123 | |||
124 | lock (m_scenes) | ||
125 | { | ||
126 | foreach (Scene scene in m_scenes) | ||
127 | { | ||
128 | if (targetNameSupplied) | ||
129 | { | ||
130 | ScenePresence sp = scene.GetScenePresence(optionalTargetFirstName, optionalTargetLastName); | ||
131 | if (sp != null && !sp.IsChildAgent) | ||
132 | GetAttachmentsReport(sp, sb); | ||
133 | } | ||
134 | else | ||
135 | { | ||
136 | scene.ForEachRootScenePresence(sp => GetAttachmentsReport(sp, sb)); | ||
137 | } | ||
138 | } | ||
139 | } | ||
140 | |||
141 | MainConsole.Instance.Output(sb.ToString()); | ||
142 | } | ||
143 | |||
144 | private void GetAttachmentsReport(ScenePresence sp, StringBuilder sb) | ||
145 | { | ||
146 | sb.AppendFormat("Attachments for {0}\n", sp.Name); | ||
147 | |||
148 | ConsoleTable ct = new ConsoleTable() { Indent = 2 }; | ||
149 | ct.Columns.Add(new ConsoleTableColumn("Attachment Name", 36)); | ||
150 | ct.Columns.Add(new ConsoleTableColumn("Local ID", 10)); | ||
151 | ct.Columns.Add(new ConsoleTableColumn("Item ID", 36)); | ||
152 | ct.Columns.Add(new ConsoleTableColumn("Attach Point", 14)); | ||
153 | ct.Columns.Add(new ConsoleTableColumn("Position", 15)); | ||
154 | |||
155 | // sb.AppendFormat( | ||
156 | // " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n", | ||
157 | // "Attachment Name", "Local ID", "Item ID", "Attach Point", "Position"); | ||
158 | |||
159 | List<SceneObjectGroup> attachmentObjects = sp.GetAttachments(); | ||
160 | foreach (SceneObjectGroup attachmentObject in attachmentObjects) | ||
161 | { | ||
162 | // InventoryItemBase attachmentItem | ||
163 | // = m_scenes[0].InventoryService.GetItem(new InventoryItemBase(attachmentObject.FromItemID)); | ||
164 | |||
165 | // if (attachmentItem == null) | ||
166 | // { | ||
167 | // sb.AppendFormat( | ||
168 | // "WARNING: Couldn't find attachment for item {0} at point {1}\n", | ||
169 | // attachmentData.ItemID, (AttachmentPoint)attachmentData.AttachPoint); | ||
170 | // continue; | ||
171 | // } | ||
172 | // else | ||
173 | // { | ||
174 | // sb.AppendFormat( | ||
175 | // " {0,-36} {1,-10} {2,-36} {3,-14} {4,-15}\n", | ||
176 | // attachmentObject.Name, attachmentObject.LocalId, attachmentObject.FromItemID, | ||
177 | // (AttachmentPoint)attachmentObject.AttachmentPoint, attachmentObject.RootPart.AttachedPos); | ||
178 | ct.Rows.Add( | ||
179 | new ConsoleTableRow( | ||
180 | new List<string>() | ||
181 | { | ||
182 | attachmentObject.Name, | ||
183 | attachmentObject.LocalId.ToString(), | ||
184 | attachmentObject.FromItemID.ToString(), | ||
185 | ((AttachmentPoint)attachmentObject.AttachmentPoint).ToString(), | ||
186 | attachmentObject.RootPart.AttachedPos.ToString() | ||
187 | })); | ||
188 | // } | ||
189 | } | ||
190 | |||
191 | ct.AddToStringBuilder(sb); | ||
192 | sb.Append("\n"); | ||
193 | } | ||
194 | } | ||
195 | } \ No newline at end of file | ||
diff --git a/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs b/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs index e68f9d0..2602050 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Friends/FriendsCommandsModule.cs | |||
@@ -58,6 +58,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends | |||
58 | private Scene m_scene; | 58 | private Scene m_scene; |
59 | private IFriendsModule m_friendsModule; | 59 | private IFriendsModule m_friendsModule; |
60 | private IUserManagement m_userManagementModule; | 60 | private IUserManagement m_userManagementModule; |
61 | private IPresenceService m_presenceService; | ||
61 | 62 | ||
62 | // private IAvatarFactoryModule m_avatarFactory; | 63 | // private IAvatarFactoryModule m_avatarFactory; |
63 | 64 | ||
@@ -99,8 +100,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends | |||
99 | 100 | ||
100 | m_friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); | 101 | m_friendsModule = m_scene.RequestModuleInterface<IFriendsModule>(); |
101 | m_userManagementModule = m_scene.RequestModuleInterface<IUserManagement>(); | 102 | m_userManagementModule = m_scene.RequestModuleInterface<IUserManagement>(); |
103 | m_presenceService = m_scene.RequestModuleInterface<IPresenceService>(); | ||
102 | 104 | ||
103 | if (m_friendsModule != null && m_userManagementModule != null) | 105 | if (m_friendsModule != null && m_userManagementModule != null && m_presenceService != null) |
104 | { | 106 | { |
105 | m_scene.AddCommand( | 107 | m_scene.AddCommand( |
106 | "Friends", this, "friends show", | 108 | "Friends", this, "friends show", |
@@ -162,7 +164,8 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends | |||
162 | 164 | ||
163 | MainConsole.Instance.OutputFormat("Friends for {0} {1} {2}:", firstName, lastName, userId); | 165 | MainConsole.Instance.OutputFormat("Friends for {0} {1} {2}:", firstName, lastName, userId); |
164 | 166 | ||
165 | MainConsole.Instance.OutputFormat("UUID, Name, MyFlags, TheirFlags"); | 167 | MainConsole.Instance.OutputFormat( |
168 | "{0,-36} {1,-36} {2,-7} {3,7} {4,10}", "UUID", "Name", "Status", "MyFlags", "TheirFlags"); | ||
166 | 169 | ||
167 | foreach (FriendInfo friend in friends) | 170 | foreach (FriendInfo friend in friends) |
168 | { | 171 | { |
@@ -175,14 +178,22 @@ namespace OpenSim.Region.OptionalModules.Avatar.Friends | |||
175 | 178 | ||
176 | UUID friendId; | 179 | UUID friendId; |
177 | string friendName; | 180 | string friendName; |
181 | string onlineText; | ||
178 | 182 | ||
179 | if (UUID.TryParse(friend.Friend, out friendId)) | 183 | if (UUID.TryParse(friend.Friend, out friendId)) |
180 | friendName = m_userManagementModule.GetUserName(friendId); | 184 | friendName = m_userManagementModule.GetUserName(friendId); |
181 | else | 185 | else |
182 | friendName = friend.Friend; | 186 | friendName = friend.Friend; |
183 | 187 | ||
188 | OpenSim.Services.Interfaces.PresenceInfo[] pi = m_presenceService.GetAgents(new string[] { friend.Friend }); | ||
189 | if (pi.Length > 0) | ||
190 | onlineText = "online"; | ||
191 | else | ||
192 | onlineText = "offline"; | ||
193 | |||
184 | MainConsole.Instance.OutputFormat( | 194 | MainConsole.Instance.OutputFormat( |
185 | "{0} {1} {2} {3}", friend.Friend, friendName, friend.MyFlags, friend.TheirFlags); | 195 | "{0,-36} {1,-36} {2,-7} {3,-7} {4,-10}", |
196 | friend.Friend, friendName, onlineText, friend.MyFlags, friend.TheirFlags); | ||
186 | } | 197 | } |
187 | } | 198 | } |
188 | } | 199 | } |
diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs index 8af3652..6c53d95 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Voice/FreeSwitchVoice/FreeSwitchVoiceModule.cs | |||
@@ -306,30 +306,35 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.FreeSwitchVoice | |||
306 | agentID, caps, scene.RegionInfo.RegionName); | 306 | agentID, caps, scene.RegionInfo.RegionName); |
307 | 307 | ||
308 | string capsBase = "/CAPS/" + caps.CapsObjectPath; | 308 | string capsBase = "/CAPS/" + caps.CapsObjectPath; |
309 | caps.RegisterHandler("ProvisionVoiceAccountRequest", | 309 | caps.RegisterHandler( |
310 | new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath, | 310 | "ProvisionVoiceAccountRequest", |
311 | delegate(string request, string path, string param, | 311 | new RestStreamHandler( |
312 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 312 | "POST", |
313 | { | 313 | capsBase + m_provisionVoiceAccountRequestPath, |
314 | return ProvisionVoiceAccountRequest(scene, request, path, param, | 314 | (request, path, param, httpRequest, httpResponse) |
315 | agentID, caps); | 315 | => ProvisionVoiceAccountRequest(scene, request, path, param, agentID, caps), |
316 | })); | 316 | "ProvisionVoiceAccountRequest", |
317 | caps.RegisterHandler("ParcelVoiceInfoRequest", | 317 | agentID.ToString())); |
318 | new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath, | 318 | |
319 | delegate(string request, string path, string param, | 319 | caps.RegisterHandler( |
320 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 320 | "ParcelVoiceInfoRequest", |
321 | { | 321 | new RestStreamHandler( |
322 | return ParcelVoiceInfoRequest(scene, request, path, param, | 322 | "POST", |
323 | agentID, caps); | 323 | capsBase + m_parcelVoiceInfoRequestPath, |
324 | })); | 324 | (request, path, param, httpRequest, httpResponse) |
325 | caps.RegisterHandler("ChatSessionRequest", | 325 | => ParcelVoiceInfoRequest(scene, request, path, param, agentID, caps), |
326 | new RestStreamHandler("POST", capsBase + m_chatSessionRequestPath, | 326 | "ParcelVoiceInfoRequest", |
327 | delegate(string request, string path, string param, | 327 | agentID.ToString())); |
328 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 328 | |
329 | { | 329 | caps.RegisterHandler( |
330 | return ChatSessionRequest(scene, request, path, param, | 330 | "ChatSessionRequest", |
331 | agentID, caps); | 331 | new RestStreamHandler( |
332 | })); | 332 | "POST", |
333 | capsBase + m_chatSessionRequestPath, | ||
334 | (request, path, param, httpRequest, httpResponse) | ||
335 | => ChatSessionRequest(scene, request, path, param, agentID, caps), | ||
336 | "ChatSessionRequest", | ||
337 | agentID.ToString())); | ||
333 | } | 338 | } |
334 | 339 | ||
335 | /// <summary> | 340 | /// <summary> |
diff --git a/OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs b/OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs index 4dbac1d..396d4c5 100644 --- a/OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/Voice/VivoxVoice/VivoxVoiceModule.cs | |||
@@ -406,30 +406,36 @@ namespace OpenSim.Region.OptionalModules.Avatar.Voice.VivoxVoice | |||
406 | m_log.DebugFormat("[VivoxVoice] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); | 406 | m_log.DebugFormat("[VivoxVoice] OnRegisterCaps: agentID {0} caps {1}", agentID, caps); |
407 | 407 | ||
408 | string capsBase = "/CAPS/" + caps.CapsObjectPath; | 408 | string capsBase = "/CAPS/" + caps.CapsObjectPath; |
409 | caps.RegisterHandler("ProvisionVoiceAccountRequest", | 409 | |
410 | new RestStreamHandler("POST", capsBase + m_provisionVoiceAccountRequestPath, | 410 | caps.RegisterHandler( |
411 | delegate(string request, string path, string param, | 411 | "ProvisionVoiceAccountRequest", |
412 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 412 | new RestStreamHandler( |
413 | { | 413 | "POST", |
414 | return ProvisionVoiceAccountRequest(scene, request, path, param, | 414 | capsBase + m_provisionVoiceAccountRequestPath, |
415 | agentID, caps); | 415 | (request, path, param, httpRequest, httpResponse) |
416 | })); | 416 | => ProvisionVoiceAccountRequest(scene, request, path, param, agentID, caps), |
417 | caps.RegisterHandler("ParcelVoiceInfoRequest", | 417 | "ProvisionVoiceAccountRequest", |
418 | new RestStreamHandler("POST", capsBase + m_parcelVoiceInfoRequestPath, | 418 | agentID.ToString())); |
419 | delegate(string request, string path, string param, | 419 | |
420 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 420 | caps.RegisterHandler( |
421 | { | 421 | "ParcelVoiceInfoRequest", |
422 | return ParcelVoiceInfoRequest(scene, request, path, param, | 422 | new RestStreamHandler( |
423 | agentID, caps); | 423 | "POST", |
424 | })); | 424 | capsBase + m_parcelVoiceInfoRequestPath, |
425 | caps.RegisterHandler("ChatSessionRequest", | 425 | (request, path, param, httpRequest, httpResponse) |
426 | new RestStreamHandler("POST", capsBase + m_chatSessionRequestPath, | 426 | => ParcelVoiceInfoRequest(scene, request, path, param, agentID, caps), |
427 | delegate(string request, string path, string param, | 427 | "ParcelVoiceInfoRequest", |
428 | IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | 428 | agentID.ToString())); |
429 | { | 429 | |
430 | return ChatSessionRequest(scene, request, path, param, | 430 | caps.RegisterHandler( |
431 | agentID, caps); | 431 | "ChatSessionRequest", |
432 | })); | 432 | new RestStreamHandler( |
433 | "POST", | ||
434 | capsBase + m_chatSessionRequestPath, | ||
435 | (request, path, param, httpRequest, httpResponse) | ||
436 | => ChatSessionRequest(scene, request, path, param, agentID, caps), | ||
437 | "ChatSessionRequest", | ||
438 | agentID.ToString())); | ||
433 | } | 439 | } |
434 | 440 | ||
435 | /// <summary> | 441 | /// <summary> |
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs index 130513d..5d57f70 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/SimianGroupsServicesConnectorModule.cs | |||
@@ -1401,9 +1401,9 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups | |||
1401 | { | 1401 | { |
1402 | response = WebUtil.PostToService(m_groupsServerURI, requestArgs); | 1402 | response = WebUtil.PostToService(m_groupsServerURI, requestArgs); |
1403 | } | 1403 | } |
1404 | catch (Exception e) | 1404 | catch (Exception) |
1405 | { | 1405 | { |
1406 | m_log.InfoFormat("[SIMIAN GROUPS CONNECTOR] request failed {0}",CacheKey); | 1406 | m_log.ErrorFormat("[SIMIAN GROUPS CONNECTOR]: request failed {0}", CacheKey); |
1407 | } | 1407 | } |
1408 | 1408 | ||
1409 | // and cache the response | 1409 | // and cache the response |
diff --git a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs index d2f6327..ac638f1 100644 --- a/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs +++ b/OpenSim/Region/OptionalModules/Avatar/XmlRpcGroups/Tests/GroupsModuleTests.cs | |||
@@ -50,7 +50,7 @@ namespace OpenSim.Region.OptionalModules.Avatar.XmlRpcGroups.Tests | |||
50 | TestHelpers.InMethod(); | 50 | TestHelpers.InMethod(); |
51 | // log4net.Config.XmlConfigurator.Configure(); | 51 | // log4net.Config.XmlConfigurator.Configure(); |
52 | 52 | ||
53 | TestScene scene = SceneHelpers.SetupScene(); | 53 | TestScene scene = new SceneHelpers().SetupScene(); |
54 | IConfigSource configSource = new IniConfigSource(); | 54 | IConfigSource configSource = new IniConfigSource(); |
55 | IConfig config = configSource.AddConfig("Groups"); | 55 | IConfig config = configSource.AddConfig("Groups"); |
56 | config.Set("Enabled", true); | 56 | config.Set("Enabled", true); |
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs new file mode 100644 index 0000000..34894ba --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStore.cs | |||
@@ -0,0 +1,500 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using Mono.Addins; | ||
28 | |||
29 | using System; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using System.Text; | ||
33 | using System.Net; | ||
34 | using System.Net.Sockets; | ||
35 | using log4net; | ||
36 | using Nini.Config; | ||
37 | using OpenMetaverse; | ||
38 | using OpenMetaverse.StructuredData; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Region.Framework.Interfaces; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | using System.Collections.Generic; | ||
43 | using System.Text.RegularExpressions; | ||
44 | |||
45 | namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | ||
46 | { | ||
47 | public class JsonStore | ||
48 | { | ||
49 | private static readonly ILog m_log = | ||
50 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
51 | |||
52 | private OSD m_ValueStore; | ||
53 | |||
54 | protected class TakeValueCallbackClass | ||
55 | { | ||
56 | public string Path { get; set; } | ||
57 | public bool UseJson { get; set; } | ||
58 | public TakeValueCallback Callback { get; set; } | ||
59 | |||
60 | public TakeValueCallbackClass(string spath, bool usejson, TakeValueCallback cback) | ||
61 | { | ||
62 | Path = spath; | ||
63 | UseJson = usejson; | ||
64 | Callback = cback; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | protected List<TakeValueCallbackClass> m_TakeStore; | ||
69 | protected List<TakeValueCallbackClass> m_ReadStore; | ||
70 | |||
71 | |||
72 | // ----------------------------------------------------------------- | ||
73 | /// <summary> | ||
74 | /// | ||
75 | /// </summary> | ||
76 | // ----------------------------------------------------------------- | ||
77 | public JsonStore() : this("") {} | ||
78 | |||
79 | public JsonStore(string value) | ||
80 | { | ||
81 | m_TakeStore = new List<TakeValueCallbackClass>(); | ||
82 | m_ReadStore = new List<TakeValueCallbackClass>(); | ||
83 | |||
84 | if (String.IsNullOrEmpty(value)) | ||
85 | m_ValueStore = new OSDMap(); | ||
86 | else | ||
87 | m_ValueStore = OSDParser.DeserializeJson(value); | ||
88 | } | ||
89 | |||
90 | // ----------------------------------------------------------------- | ||
91 | /// <summary> | ||
92 | /// | ||
93 | /// </summary> | ||
94 | // ----------------------------------------------------------------- | ||
95 | public bool TestPath(string expr, bool useJson) | ||
96 | { | ||
97 | Stack<string> path = ParsePathExpression(expr); | ||
98 | OSD result = ProcessPathExpression(m_ValueStore,path); | ||
99 | |||
100 | if (result == null) | ||
101 | return false; | ||
102 | |||
103 | if (useJson || result.Type == OSDType.String) | ||
104 | return true; | ||
105 | |||
106 | return false; | ||
107 | } | ||
108 | |||
109 | // ----------------------------------------------------------------- | ||
110 | /// <summary> | ||
111 | /// | ||
112 | /// </summary> | ||
113 | // ----------------------------------------------------------------- | ||
114 | public bool GetValue(string expr, out string value, bool useJson) | ||
115 | { | ||
116 | Stack<string> path = ParsePathExpression(expr); | ||
117 | OSD result = ProcessPathExpression(m_ValueStore,path); | ||
118 | return ConvertOutputValue(result,out value,useJson); | ||
119 | } | ||
120 | |||
121 | |||
122 | // ----------------------------------------------------------------- | ||
123 | /// <summary> | ||
124 | /// | ||
125 | /// </summary> | ||
126 | // ----------------------------------------------------------------- | ||
127 | public bool RemoveValue(string expr) | ||
128 | { | ||
129 | return SetValueFromExpression(expr,null); | ||
130 | } | ||
131 | |||
132 | // ----------------------------------------------------------------- | ||
133 | /// <summary> | ||
134 | /// | ||
135 | /// </summary> | ||
136 | // ----------------------------------------------------------------- | ||
137 | public bool SetValue(string expr, string value, bool useJson) | ||
138 | { | ||
139 | OSD ovalue = useJson ? OSDParser.DeserializeJson(value) : new OSDString(value); | ||
140 | return SetValueFromExpression(expr,ovalue); | ||
141 | } | ||
142 | |||
143 | // ----------------------------------------------------------------- | ||
144 | /// <summary> | ||
145 | /// | ||
146 | /// </summary> | ||
147 | // ----------------------------------------------------------------- | ||
148 | public bool TakeValue(string expr, bool useJson, TakeValueCallback cback) | ||
149 | { | ||
150 | Stack<string> path = ParsePathExpression(expr); | ||
151 | string pexpr = PathExpressionToKey(path); | ||
152 | |||
153 | OSD result = ProcessPathExpression(m_ValueStore,path); | ||
154 | if (result == null) | ||
155 | { | ||
156 | m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); | ||
157 | return false; | ||
158 | } | ||
159 | |||
160 | string value = String.Empty; | ||
161 | if (! ConvertOutputValue(result,out value,useJson)) | ||
162 | { | ||
163 | // the structure does not match the request so i guess we'll wait | ||
164 | m_TakeStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); | ||
165 | return false; | ||
166 | } | ||
167 | |||
168 | SetValueFromExpression(expr,null); | ||
169 | cback(value); | ||
170 | |||
171 | return true; | ||
172 | } | ||
173 | |||
174 | // ----------------------------------------------------------------- | ||
175 | /// <summary> | ||
176 | /// | ||
177 | /// </summary> | ||
178 | // ----------------------------------------------------------------- | ||
179 | public bool ReadValue(string expr, bool useJson, TakeValueCallback cback) | ||
180 | { | ||
181 | Stack<string> path = ParsePathExpression(expr); | ||
182 | string pexpr = PathExpressionToKey(path); | ||
183 | |||
184 | OSD result = ProcessPathExpression(m_ValueStore,path); | ||
185 | if (result == null) | ||
186 | { | ||
187 | m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); | ||
188 | return false; | ||
189 | } | ||
190 | |||
191 | string value = String.Empty; | ||
192 | if (! ConvertOutputValue(result,out value,useJson)) | ||
193 | { | ||
194 | // the structure does not match the request so i guess we'll wait | ||
195 | m_ReadStore.Add(new TakeValueCallbackClass(pexpr,useJson,cback)); | ||
196 | return false; | ||
197 | } | ||
198 | |||
199 | cback(value); | ||
200 | |||
201 | return true; | ||
202 | } | ||
203 | |||
204 | // ----------------------------------------------------------------- | ||
205 | /// <summary> | ||
206 | /// | ||
207 | /// </summary> | ||
208 | // ----------------------------------------------------------------- | ||
209 | protected bool SetValueFromExpression(string expr, OSD ovalue) | ||
210 | { | ||
211 | Stack<string> path = ParsePathExpression(expr); | ||
212 | if (path.Count == 0) | ||
213 | { | ||
214 | m_ValueStore = ovalue; | ||
215 | return true; | ||
216 | } | ||
217 | |||
218 | string pkey = path.Pop(); | ||
219 | string pexpr = PathExpressionToKey(path); | ||
220 | if (pexpr != "") | ||
221 | pexpr += "."; | ||
222 | |||
223 | OSD result = ProcessPathExpression(m_ValueStore,path); | ||
224 | if (result == null) | ||
225 | return false; | ||
226 | |||
227 | Regex aPattern = new Regex("\\[([0-9]+|\\+)\\]"); | ||
228 | MatchCollection amatches = aPattern.Matches(pkey,0); | ||
229 | |||
230 | if (amatches.Count > 0) | ||
231 | { | ||
232 | if (result.Type != OSDType.Array) | ||
233 | return false; | ||
234 | |||
235 | OSDArray amap = result as OSDArray; | ||
236 | |||
237 | Match match = amatches[0]; | ||
238 | GroupCollection groups = match.Groups; | ||
239 | string akey = groups[1].Value; | ||
240 | |||
241 | if (akey == "+") | ||
242 | { | ||
243 | string npkey = String.Format("[{0}]",amap.Count); | ||
244 | |||
245 | amap.Add(ovalue); | ||
246 | InvokeNextCallback(pexpr + npkey); | ||
247 | return true; | ||
248 | } | ||
249 | |||
250 | int aval = Convert.ToInt32(akey); | ||
251 | if (0 <= aval && aval < amap.Count) | ||
252 | { | ||
253 | if (ovalue == null) | ||
254 | amap.RemoveAt(aval); | ||
255 | else | ||
256 | { | ||
257 | amap[aval] = ovalue; | ||
258 | InvokeNextCallback(pexpr + pkey); | ||
259 | } | ||
260 | return true; | ||
261 | } | ||
262 | |||
263 | return false; | ||
264 | } | ||
265 | |||
266 | Regex hPattern = new Regex("{([^}]+)}"); | ||
267 | MatchCollection hmatches = hPattern.Matches(pkey,0); | ||
268 | |||
269 | if (hmatches.Count > 0) | ||
270 | { | ||
271 | Match match = hmatches[0]; | ||
272 | GroupCollection groups = match.Groups; | ||
273 | string hkey = groups[1].Value; | ||
274 | |||
275 | if (result is OSDMap) | ||
276 | { | ||
277 | OSDMap hmap = result as OSDMap; | ||
278 | if (ovalue != null) | ||
279 | { | ||
280 | hmap[hkey] = ovalue; | ||
281 | InvokeNextCallback(pexpr + pkey); | ||
282 | } | ||
283 | else if (hmap.ContainsKey(hkey)) | ||
284 | hmap.Remove(hkey); | ||
285 | |||
286 | return true; | ||
287 | } | ||
288 | |||
289 | return false; | ||
290 | } | ||
291 | |||
292 | // Shouldn't get here if the path was checked correctly | ||
293 | m_log.WarnFormat("[JsonStore] invalid path expression"); | ||
294 | return false; | ||
295 | } | ||
296 | |||
297 | // ----------------------------------------------------------------- | ||
298 | /// <summary> | ||
299 | /// | ||
300 | /// </summary> | ||
301 | // ----------------------------------------------------------------- | ||
302 | protected bool InvokeNextCallback(string pexpr) | ||
303 | { | ||
304 | // Process all of the reads that match the expression first | ||
305 | List<TakeValueCallbackClass> reads = | ||
306 | m_ReadStore.FindAll(delegate(TakeValueCallbackClass tb) { return pexpr.StartsWith(tb.Path); }); | ||
307 | |||
308 | foreach (TakeValueCallbackClass readcb in reads) | ||
309 | { | ||
310 | m_ReadStore.Remove(readcb); | ||
311 | ReadValue(readcb.Path,readcb.UseJson,readcb.Callback); | ||
312 | } | ||
313 | |||
314 | // Process one take next | ||
315 | TakeValueCallbackClass takecb = | ||
316 | m_TakeStore.Find(delegate(TakeValueCallbackClass tb) { return pexpr.StartsWith(tb.Path); }); | ||
317 | |||
318 | if (takecb != null) | ||
319 | { | ||
320 | m_TakeStore.Remove(takecb); | ||
321 | TakeValue(takecb.Path,takecb.UseJson,takecb.Callback); | ||
322 | |||
323 | return true; | ||
324 | } | ||
325 | |||
326 | return false; | ||
327 | } | ||
328 | |||
329 | // ----------------------------------------------------------------- | ||
330 | /// <summary> | ||
331 | /// Parse the path expression and put the components into a stack. We | ||
332 | /// use a stack because we process the path in inverse order later | ||
333 | /// </summary> | ||
334 | // ----------------------------------------------------------------- | ||
335 | protected static Stack<string> ParsePathExpression(string path) | ||
336 | { | ||
337 | Stack<string> m_path = new Stack<string>(); | ||
338 | |||
339 | // add front and rear separators | ||
340 | path = "." + path + "."; | ||
341 | |||
342 | // add separators for quoted paths | ||
343 | Regex pass1 = new Regex("{[^}]+}"); | ||
344 | path = pass1.Replace(path,".$0.",-1,0); | ||
345 | |||
346 | // add separators for array references | ||
347 | Regex pass2 = new Regex("(\\[[0-9]+\\]|\\[\\+\\])"); | ||
348 | path = pass2.Replace(path,".$0.",-1,0); | ||
349 | |||
350 | // add quotes to bare identifier | ||
351 | Regex pass3 = new Regex("\\.([a-zA-Z]+)"); | ||
352 | path = pass3.Replace(path,".{$1}",-1,0); | ||
353 | |||
354 | // remove extra separators | ||
355 | Regex pass4 = new Regex("\\.+"); | ||
356 | path = pass4.Replace(path,".",-1,0); | ||
357 | |||
358 | Regex validate = new Regex("^\\.(({[^}]+}|\\[[0-9]+\\]|\\[\\+\\])\\.)+$"); | ||
359 | if (validate.IsMatch(path)) | ||
360 | { | ||
361 | Regex parser = new Regex("\\.({[^}]+}|\\[[0-9]+\\]|\\[\\+\\]+)"); | ||
362 | MatchCollection matches = parser.Matches(path,0); | ||
363 | foreach (Match match in matches) | ||
364 | m_path.Push(match.Groups[1].Value); | ||
365 | } | ||
366 | |||
367 | return m_path; | ||
368 | } | ||
369 | |||
370 | // ----------------------------------------------------------------- | ||
371 | /// <summary> | ||
372 | /// | ||
373 | /// </summary> | ||
374 | /// <param>path is a stack where the top level of the path is at the bottom of the stack</param> | ||
375 | // ----------------------------------------------------------------- | ||
376 | protected static OSD ProcessPathExpression(OSD map, Stack<string> path) | ||
377 | { | ||
378 | if (path.Count == 0) | ||
379 | return map; | ||
380 | |||
381 | string pkey = path.Pop(); | ||
382 | |||
383 | OSD rmap = ProcessPathExpression(map,path); | ||
384 | if (rmap == null) | ||
385 | return null; | ||
386 | |||
387 | // ---------- Check for an array index ---------- | ||
388 | Regex aPattern = new Regex("\\[([0-9]+)\\]"); | ||
389 | MatchCollection amatches = aPattern.Matches(pkey,0); | ||
390 | |||
391 | if (amatches.Count > 0) | ||
392 | { | ||
393 | if (rmap.Type != OSDType.Array) | ||
394 | { | ||
395 | m_log.WarnFormat("[JsonStore] wrong type for key {2}, expecting {0}, got {1}",OSDType.Array,rmap.Type,pkey); | ||
396 | return null; | ||
397 | } | ||
398 | |||
399 | OSDArray amap = rmap as OSDArray; | ||
400 | |||
401 | Match match = amatches[0]; | ||
402 | GroupCollection groups = match.Groups; | ||
403 | string akey = groups[1].Value; | ||
404 | int aval = Convert.ToInt32(akey); | ||
405 | |||
406 | if (aval < amap.Count) | ||
407 | return (OSD) amap[aval]; | ||
408 | |||
409 | return null; | ||
410 | } | ||
411 | |||
412 | // ---------- Check for a hash index ---------- | ||
413 | Regex hPattern = new Regex("{([^}]+)}"); | ||
414 | MatchCollection hmatches = hPattern.Matches(pkey,0); | ||
415 | |||
416 | if (hmatches.Count > 0) | ||
417 | { | ||
418 | if (rmap.Type != OSDType.Map) | ||
419 | { | ||
420 | m_log.WarnFormat("[JsonStore] wrong type for key {2}, expecting {0}, got {1}",OSDType.Map,rmap.Type,pkey); | ||
421 | return null; | ||
422 | } | ||
423 | |||
424 | OSDMap hmap = rmap as OSDMap; | ||
425 | |||
426 | Match match = hmatches[0]; | ||
427 | GroupCollection groups = match.Groups; | ||
428 | string hkey = groups[1].Value; | ||
429 | |||
430 | if (hmap.ContainsKey(hkey)) | ||
431 | return (OSD) hmap[hkey]; | ||
432 | |||
433 | return null; | ||
434 | } | ||
435 | |||
436 | // Shouldn't get here if the path was checked correctly | ||
437 | m_log.WarnFormat("[JsonStore] Path type (unknown) does not match the structure"); | ||
438 | return null; | ||
439 | } | ||
440 | |||
441 | // ----------------------------------------------------------------- | ||
442 | /// <summary> | ||
443 | /// | ||
444 | /// </summary> | ||
445 | // ----------------------------------------------------------------- | ||
446 | protected static bool ConvertOutputValue(OSD result, out string value, bool useJson) | ||
447 | { | ||
448 | value = String.Empty; | ||
449 | |||
450 | // If we couldn't process the path | ||
451 | if (result == null) | ||
452 | return false; | ||
453 | |||
454 | if (useJson) | ||
455 | { | ||
456 | // The path pointed to an intermediate hash structure | ||
457 | if (result.Type == OSDType.Map) | ||
458 | { | ||
459 | value = OSDParser.SerializeJsonString(result as OSDMap); | ||
460 | return true; | ||
461 | } | ||
462 | |||
463 | // The path pointed to an intermediate hash structure | ||
464 | if (result.Type == OSDType.Array) | ||
465 | { | ||
466 | value = OSDParser.SerializeJsonString(result as OSDArray); | ||
467 | return true; | ||
468 | } | ||
469 | |||
470 | value = "'" + result.AsString() + "'"; | ||
471 | return true; | ||
472 | } | ||
473 | |||
474 | if (result.Type == OSDType.String) | ||
475 | { | ||
476 | value = result.AsString(); | ||
477 | return true; | ||
478 | } | ||
479 | |||
480 | return false; | ||
481 | } | ||
482 | |||
483 | // ----------------------------------------------------------------- | ||
484 | /// <summary> | ||
485 | /// | ||
486 | /// </summary> | ||
487 | // ----------------------------------------------------------------- | ||
488 | protected static string PathExpressionToKey(Stack<string> path) | ||
489 | { | ||
490 | if (path.Count == 0) | ||
491 | return ""; | ||
492 | |||
493 | string pkey = ""; | ||
494 | foreach (string k in path) | ||
495 | pkey = (pkey == "") ? k : (k + "." + pkey); | ||
496 | |||
497 | return pkey; | ||
498 | } | ||
499 | } | ||
500 | } | ||
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs new file mode 100644 index 0000000..311531c --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreModule.cs | |||
@@ -0,0 +1,430 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using Mono.Addins; | ||
28 | |||
29 | using System; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using System.Text; | ||
33 | using System.Net; | ||
34 | using System.Net.Sockets; | ||
35 | using log4net; | ||
36 | using Nini.Config; | ||
37 | using OpenMetaverse; | ||
38 | using OpenMetaverse.StructuredData; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Region.Framework.Interfaces; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | using System.Collections.Generic; | ||
43 | using System.Text.RegularExpressions; | ||
44 | |||
45 | |||
46 | namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | ||
47 | { | ||
48 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreModule")] | ||
49 | |||
50 | public class JsonStoreModule : INonSharedRegionModule, IJsonStoreModule | ||
51 | { | ||
52 | private static readonly ILog m_log = | ||
53 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | |||
55 | private IConfig m_config = null; | ||
56 | private bool m_enabled = false; | ||
57 | private Scene m_scene = null; | ||
58 | |||
59 | private Dictionary<UUID,JsonStore> m_JsonValueStore; | ||
60 | private UUID m_sharedStore; | ||
61 | |||
62 | #region IRegionModule Members | ||
63 | |||
64 | // ----------------------------------------------------------------- | ||
65 | /// <summary> | ||
66 | /// Name of this shared module is it's class name | ||
67 | /// </summary> | ||
68 | // ----------------------------------------------------------------- | ||
69 | public string Name | ||
70 | { | ||
71 | get { return this.GetType().Name; } | ||
72 | } | ||
73 | |||
74 | // ----------------------------------------------------------------- | ||
75 | /// <summary> | ||
76 | /// Initialise this shared module | ||
77 | /// </summary> | ||
78 | /// <param name="scene">this region is getting initialised</param> | ||
79 | /// <param name="source">nini config, we are not using this</param> | ||
80 | // ----------------------------------------------------------------- | ||
81 | public void Initialise(IConfigSource config) | ||
82 | { | ||
83 | try | ||
84 | { | ||
85 | if ((m_config = config.Configs["JsonStore"]) == null) | ||
86 | { | ||
87 | // There is no configuration, the module is disabled | ||
88 | // m_log.InfoFormat("[JsonStore] no configuration info"); | ||
89 | return; | ||
90 | } | ||
91 | |||
92 | m_enabled = m_config.GetBoolean("Enabled", m_enabled); | ||
93 | } | ||
94 | catch (Exception e) | ||
95 | { | ||
96 | m_log.ErrorFormat("[JsonStore] initialization error: {0}",e.Message); | ||
97 | return; | ||
98 | } | ||
99 | |||
100 | if (m_enabled) | ||
101 | m_log.DebugFormat("[JsonStore] module is enabled"); | ||
102 | } | ||
103 | |||
104 | // ----------------------------------------------------------------- | ||
105 | /// <summary> | ||
106 | /// everything is loaded, perform post load configuration | ||
107 | /// </summary> | ||
108 | // ----------------------------------------------------------------- | ||
109 | public void PostInitialise() | ||
110 | { | ||
111 | } | ||
112 | |||
113 | // ----------------------------------------------------------------- | ||
114 | /// <summary> | ||
115 | /// Nothing to do on close | ||
116 | /// </summary> | ||
117 | // ----------------------------------------------------------------- | ||
118 | public void Close() | ||
119 | { | ||
120 | } | ||
121 | |||
122 | // ----------------------------------------------------------------- | ||
123 | /// <summary> | ||
124 | /// </summary> | ||
125 | // ----------------------------------------------------------------- | ||
126 | public void AddRegion(Scene scene) | ||
127 | { | ||
128 | if (m_enabled) | ||
129 | { | ||
130 | m_scene = scene; | ||
131 | m_scene.RegisterModuleInterface<IJsonStoreModule>(this); | ||
132 | |||
133 | m_sharedStore = UUID.Zero; | ||
134 | m_JsonValueStore = new Dictionary<UUID,JsonStore>(); | ||
135 | m_JsonValueStore.Add(m_sharedStore,new JsonStore("")); | ||
136 | } | ||
137 | } | ||
138 | |||
139 | // ----------------------------------------------------------------- | ||
140 | /// <summary> | ||
141 | /// </summary> | ||
142 | // ----------------------------------------------------------------- | ||
143 | public void RemoveRegion(Scene scene) | ||
144 | { | ||
145 | // need to remove all references to the scene in the subscription | ||
146 | // list to enable full garbage collection of the scene object | ||
147 | } | ||
148 | |||
149 | // ----------------------------------------------------------------- | ||
150 | /// <summary> | ||
151 | /// Called when all modules have been added for a region. This is | ||
152 | /// where we hook up events | ||
153 | /// </summary> | ||
154 | // ----------------------------------------------------------------- | ||
155 | public void RegionLoaded(Scene scene) | ||
156 | { | ||
157 | if (m_enabled) {} | ||
158 | } | ||
159 | |||
160 | /// ----------------------------------------------------------------- | ||
161 | /// <summary> | ||
162 | /// </summary> | ||
163 | // ----------------------------------------------------------------- | ||
164 | public Type ReplaceableInterface | ||
165 | { | ||
166 | get { return null; } | ||
167 | } | ||
168 | |||
169 | #endregion | ||
170 | |||
171 | #region ScriptInvocationInteface | ||
172 | |||
173 | // ----------------------------------------------------------------- | ||
174 | /// <summary> | ||
175 | /// | ||
176 | /// </summary> | ||
177 | // ----------------------------------------------------------------- | ||
178 | public bool CreateStore(string value, out UUID result) | ||
179 | { | ||
180 | result = UUID.Zero; | ||
181 | |||
182 | if (! m_enabled) return false; | ||
183 | |||
184 | UUID uuid = UUID.Random(); | ||
185 | JsonStore map = null; | ||
186 | |||
187 | try | ||
188 | { | ||
189 | map = new JsonStore(value); | ||
190 | } | ||
191 | catch (Exception e) | ||
192 | { | ||
193 | m_log.InfoFormat("[JsonStore] Unable to initialize store from {0}; {1}",value,e.Message); | ||
194 | return false; | ||
195 | } | ||
196 | |||
197 | lock (m_JsonValueStore) | ||
198 | m_JsonValueStore.Add(uuid,map); | ||
199 | |||
200 | result = uuid; | ||
201 | return true; | ||
202 | } | ||
203 | |||
204 | // ----------------------------------------------------------------- | ||
205 | /// <summary> | ||
206 | /// | ||
207 | /// </summary> | ||
208 | // ----------------------------------------------------------------- | ||
209 | public bool DestroyStore(UUID storeID) | ||
210 | { | ||
211 | if (! m_enabled) return false; | ||
212 | |||
213 | lock (m_JsonValueStore) | ||
214 | m_JsonValueStore.Remove(storeID); | ||
215 | |||
216 | return true; | ||
217 | } | ||
218 | |||
219 | // ----------------------------------------------------------------- | ||
220 | /// <summary> | ||
221 | /// | ||
222 | /// </summary> | ||
223 | // ----------------------------------------------------------------- | ||
224 | public bool TestPath(UUID storeID, string path, bool useJson) | ||
225 | { | ||
226 | if (! m_enabled) return false; | ||
227 | |||
228 | JsonStore map = null; | ||
229 | lock (m_JsonValueStore) | ||
230 | { | ||
231 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) | ||
232 | { | ||
233 | m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); | ||
234 | return true; | ||
235 | } | ||
236 | } | ||
237 | |||
238 | try | ||
239 | { | ||
240 | lock (map) | ||
241 | return map.TestPath(path,useJson); | ||
242 | } | ||
243 | catch (Exception e) | ||
244 | { | ||
245 | m_log.InfoFormat("[JsonStore] Path test failed for {0} in {1}; {2}",path,storeID,e.Message); | ||
246 | } | ||
247 | |||
248 | return false; | ||
249 | } | ||
250 | |||
251 | // ----------------------------------------------------------------- | ||
252 | /// <summary> | ||
253 | /// | ||
254 | /// </summary> | ||
255 | // ----------------------------------------------------------------- | ||
256 | public bool SetValue(UUID storeID, string path, string value, bool useJson) | ||
257 | { | ||
258 | if (! m_enabled) return false; | ||
259 | |||
260 | JsonStore map = null; | ||
261 | lock (m_JsonValueStore) | ||
262 | { | ||
263 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) | ||
264 | { | ||
265 | m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); | ||
266 | return false; | ||
267 | } | ||
268 | } | ||
269 | |||
270 | try | ||
271 | { | ||
272 | lock (map) | ||
273 | if (map.SetValue(path,value,useJson)) | ||
274 | return true; | ||
275 | } | ||
276 | catch (Exception e) | ||
277 | { | ||
278 | m_log.InfoFormat("[JsonStore] Unable to assign {0} to {1} in {2}; {3}",value,path,storeID,e.Message); | ||
279 | } | ||
280 | |||
281 | return false; | ||
282 | } | ||
283 | |||
284 | // ----------------------------------------------------------------- | ||
285 | /// <summary> | ||
286 | /// | ||
287 | /// </summary> | ||
288 | // ----------------------------------------------------------------- | ||
289 | public bool RemoveValue(UUID storeID, string path) | ||
290 | { | ||
291 | if (! m_enabled) return false; | ||
292 | |||
293 | JsonStore map = null; | ||
294 | lock (m_JsonValueStore) | ||
295 | { | ||
296 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) | ||
297 | { | ||
298 | m_log.InfoFormat("[JsonStore] Missing store {0}",storeID); | ||
299 | return false; | ||
300 | } | ||
301 | } | ||
302 | |||
303 | try | ||
304 | { | ||
305 | lock (map) | ||
306 | if (map.RemoveValue(path)) | ||
307 | return true; | ||
308 | } | ||
309 | catch (Exception e) | ||
310 | { | ||
311 | m_log.InfoFormat("[JsonStore] Unable to remove {0} in {1}; {2}",path,storeID,e.Message); | ||
312 | } | ||
313 | |||
314 | return false; | ||
315 | } | ||
316 | |||
317 | // ----------------------------------------------------------------- | ||
318 | /// <summary> | ||
319 | /// | ||
320 | /// </summary> | ||
321 | // ----------------------------------------------------------------- | ||
322 | public bool GetValue(UUID storeID, string path, bool useJson, out string value) | ||
323 | { | ||
324 | value = String.Empty; | ||
325 | |||
326 | if (! m_enabled) return false; | ||
327 | |||
328 | JsonStore map = null; | ||
329 | lock (m_JsonValueStore) | ||
330 | { | ||
331 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) | ||
332 | return false; | ||
333 | } | ||
334 | |||
335 | try | ||
336 | { | ||
337 | lock (map) | ||
338 | { | ||
339 | return map.GetValue(path, out value, useJson); | ||
340 | } | ||
341 | } | ||
342 | catch (Exception e) | ||
343 | { | ||
344 | m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.Message); | ||
345 | } | ||
346 | |||
347 | return false; | ||
348 | } | ||
349 | |||
350 | // ----------------------------------------------------------------- | ||
351 | /// <summary> | ||
352 | /// | ||
353 | /// </summary> | ||
354 | // ----------------------------------------------------------------- | ||
355 | public void TakeValue(UUID storeID, string path, bool useJson, TakeValueCallback cback) | ||
356 | { | ||
357 | if (! m_enabled) | ||
358 | { | ||
359 | cback(String.Empty); | ||
360 | return; | ||
361 | } | ||
362 | |||
363 | JsonStore map = null; | ||
364 | lock (m_JsonValueStore) | ||
365 | { | ||
366 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) | ||
367 | { | ||
368 | cback(String.Empty); | ||
369 | return; | ||
370 | } | ||
371 | } | ||
372 | |||
373 | try | ||
374 | { | ||
375 | lock (map) | ||
376 | { | ||
377 | map.TakeValue(path, useJson, cback); | ||
378 | return; | ||
379 | } | ||
380 | } | ||
381 | catch (Exception e) | ||
382 | { | ||
383 | m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString()); | ||
384 | } | ||
385 | |||
386 | cback(String.Empty); | ||
387 | } | ||
388 | |||
389 | // ----------------------------------------------------------------- | ||
390 | /// <summary> | ||
391 | /// | ||
392 | /// </summary> | ||
393 | // ----------------------------------------------------------------- | ||
394 | public void ReadValue(UUID storeID, string path, bool useJson, TakeValueCallback cback) | ||
395 | { | ||
396 | if (! m_enabled) | ||
397 | { | ||
398 | cback(String.Empty); | ||
399 | return; | ||
400 | } | ||
401 | |||
402 | JsonStore map = null; | ||
403 | lock (m_JsonValueStore) | ||
404 | { | ||
405 | if (! m_JsonValueStore.TryGetValue(storeID,out map)) | ||
406 | { | ||
407 | cback(String.Empty); | ||
408 | return; | ||
409 | } | ||
410 | } | ||
411 | |||
412 | try | ||
413 | { | ||
414 | lock (map) | ||
415 | { | ||
416 | map.ReadValue(path, useJson, cback); | ||
417 | return; | ||
418 | } | ||
419 | } | ||
420 | catch (Exception e) | ||
421 | { | ||
422 | m_log.InfoFormat("[JsonStore] unable to retrieve value; {0}",e.ToString()); | ||
423 | } | ||
424 | |||
425 | cback(String.Empty); | ||
426 | } | ||
427 | |||
428 | #endregion | ||
429 | } | ||
430 | } | ||
diff --git a/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs new file mode 100644 index 0000000..4949097 --- /dev/null +++ b/OpenSim/Region/OptionalModules/Scripting/JsonStore/JsonStoreScriptModule.cs | |||
@@ -0,0 +1,499 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSim Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | using Mono.Addins; | ||
28 | |||
29 | using System; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using System.Text; | ||
33 | using System.Net; | ||
34 | using System.Net.Sockets; | ||
35 | using log4net; | ||
36 | using Nini.Config; | ||
37 | using OpenMetaverse; | ||
38 | using OpenMetaverse.StructuredData; | ||
39 | using OpenSim.Framework; | ||
40 | using OpenSim.Region.Framework.Interfaces; | ||
41 | using OpenSim.Region.Framework.Scenes; | ||
42 | using System.Collections.Generic; | ||
43 | using System.Text.RegularExpressions; | ||
44 | |||
45 | namespace OpenSim.Region.OptionalModules.Scripting.JsonStore | ||
46 | { | ||
47 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "JsonStoreScriptModule")] | ||
48 | |||
49 | public class JsonStoreScriptModule : INonSharedRegionModule | ||
50 | { | ||
51 | private static readonly ILog m_log = | ||
52 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | |||
54 | private IConfig m_config = null; | ||
55 | private bool m_enabled = false; | ||
56 | private Scene m_scene = null; | ||
57 | |||
58 | private IScriptModuleComms m_comms; | ||
59 | private IJsonStoreModule m_store; | ||
60 | |||
61 | #region IRegionModule Members | ||
62 | |||
63 | // ----------------------------------------------------------------- | ||
64 | /// <summary> | ||
65 | /// Name of this shared module is it's class name | ||
66 | /// </summary> | ||
67 | // ----------------------------------------------------------------- | ||
68 | public string Name | ||
69 | { | ||
70 | get { return this.GetType().Name; } | ||
71 | } | ||
72 | |||
73 | // ----------------------------------------------------------------- | ||
74 | /// <summary> | ||
75 | /// Initialise this shared module | ||
76 | /// </summary> | ||
77 | /// <param name="scene">this region is getting initialised</param> | ||
78 | /// <param name="source">nini config, we are not using this</param> | ||
79 | // ----------------------------------------------------------------- | ||
80 | public void Initialise(IConfigSource config) | ||
81 | { | ||
82 | try | ||
83 | { | ||
84 | if ((m_config = config.Configs["JsonStore"]) == null) | ||
85 | { | ||
86 | // There is no configuration, the module is disabled | ||
87 | // m_log.InfoFormat("[JsonStoreScripts] no configuration info"); | ||
88 | return; | ||
89 | } | ||
90 | |||
91 | m_enabled = m_config.GetBoolean("Enabled", m_enabled); | ||
92 | } | ||
93 | catch (Exception e) | ||
94 | { | ||
95 | m_log.ErrorFormat("[JsonStoreScripts] initialization error: {0}",e.Message); | ||
96 | return; | ||
97 | } | ||
98 | |||
99 | if (m_enabled) | ||
100 | m_log.DebugFormat("[JsonStoreScripts] module is enabled"); | ||
101 | } | ||
102 | |||
103 | // ----------------------------------------------------------------- | ||
104 | /// <summary> | ||
105 | /// everything is loaded, perform post load configuration | ||
106 | /// </summary> | ||
107 | // ----------------------------------------------------------------- | ||
108 | public void PostInitialise() | ||
109 | { | ||
110 | } | ||
111 | |||
112 | // ----------------------------------------------------------------- | ||
113 | /// <summary> | ||
114 | /// Nothing to do on close | ||
115 | /// </summary> | ||
116 | // ----------------------------------------------------------------- | ||
117 | public void Close() | ||
118 | { | ||
119 | } | ||
120 | |||
121 | // ----------------------------------------------------------------- | ||
122 | /// <summary> | ||
123 | /// </summary> | ||
124 | // ----------------------------------------------------------------- | ||
125 | public void AddRegion(Scene scene) | ||
126 | { | ||
127 | } | ||
128 | |||
129 | // ----------------------------------------------------------------- | ||
130 | /// <summary> | ||
131 | /// </summary> | ||
132 | // ----------------------------------------------------------------- | ||
133 | public void RemoveRegion(Scene scene) | ||
134 | { | ||
135 | // need to remove all references to the scene in the subscription | ||
136 | // list to enable full garbage collection of the scene object | ||
137 | } | ||
138 | |||
139 | // ----------------------------------------------------------------- | ||
140 | /// <summary> | ||
141 | /// Called when all modules have been added for a region. This is | ||
142 | /// where we hook up events | ||
143 | /// </summary> | ||
144 | // ----------------------------------------------------------------- | ||
145 | public void RegionLoaded(Scene scene) | ||
146 | { | ||
147 | if (m_enabled) | ||
148 | { | ||
149 | m_scene = scene; | ||
150 | m_comms = m_scene.RequestModuleInterface<IScriptModuleComms>(); | ||
151 | if (m_comms == null) | ||
152 | { | ||
153 | m_log.ErrorFormat("[JsonStoreScripts] ScriptModuleComms interface not defined"); | ||
154 | m_enabled = false; | ||
155 | return; | ||
156 | } | ||
157 | |||
158 | m_store = m_scene.RequestModuleInterface<IJsonStoreModule>(); | ||
159 | if (m_store == null) | ||
160 | { | ||
161 | m_log.ErrorFormat("[JsonStoreScripts] JsonModule interface not defined"); | ||
162 | m_enabled = false; | ||
163 | return; | ||
164 | } | ||
165 | |||
166 | try | ||
167 | { | ||
168 | m_comms.RegisterScriptInvocation(this,"JsonCreateStore"); | ||
169 | m_comms.RegisterScriptInvocation(this,"JsonDestroyStore"); | ||
170 | |||
171 | m_comms.RegisterScriptInvocation(this,"JsonReadNotecard"); | ||
172 | m_comms.RegisterScriptInvocation(this,"JsonWriteNotecard"); | ||
173 | |||
174 | m_comms.RegisterScriptInvocation(this,"JsonTestPath"); | ||
175 | m_comms.RegisterScriptInvocation(this,"JsonTestPathJson"); | ||
176 | |||
177 | m_comms.RegisterScriptInvocation(this,"JsonGetValue"); | ||
178 | m_comms.RegisterScriptInvocation(this,"JsonGetValueJson"); | ||
179 | |||
180 | m_comms.RegisterScriptInvocation(this,"JsonTakeValue"); | ||
181 | m_comms.RegisterScriptInvocation(this,"JsonTakeValueJson"); | ||
182 | |||
183 | m_comms.RegisterScriptInvocation(this,"JsonReadValue"); | ||
184 | m_comms.RegisterScriptInvocation(this,"JsonReadValueJson"); | ||
185 | |||
186 | m_comms.RegisterScriptInvocation(this,"JsonSetValue"); | ||
187 | m_comms.RegisterScriptInvocation(this,"JsonSetValueJson"); | ||
188 | |||
189 | m_comms.RegisterScriptInvocation(this,"JsonRemoveValue"); | ||
190 | } | ||
191 | catch (Exception e) | ||
192 | { | ||
193 | // See http://opensimulator.org/mantis/view.php?id=5971 for more information | ||
194 | m_log.WarnFormat("[JsonStroreScripts] script method registration failed; {0}",e.Message); | ||
195 | m_enabled = false; | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | |||
200 | /// ----------------------------------------------------------------- | ||
201 | /// <summary> | ||
202 | /// </summary> | ||
203 | // ----------------------------------------------------------------- | ||
204 | public Type ReplaceableInterface | ||
205 | { | ||
206 | get { return null; } | ||
207 | } | ||
208 | |||
209 | #endregion | ||
210 | |||
211 | #region ScriptInvocationInteface | ||
212 | // ----------------------------------------------------------------- | ||
213 | /// <summary> | ||
214 | /// | ||
215 | /// </summary> | ||
216 | // ----------------------------------------------------------------- | ||
217 | protected void GenerateRuntimeError(string msg) | ||
218 | { | ||
219 | throw new Exception("JsonStore Runtime Error: " + msg); | ||
220 | } | ||
221 | |||
222 | // ----------------------------------------------------------------- | ||
223 | /// <summary> | ||
224 | /// | ||
225 | /// </summary> | ||
226 | // ----------------------------------------------------------------- | ||
227 | protected UUID JsonCreateStore(UUID hostID, UUID scriptID, string value) | ||
228 | { | ||
229 | UUID uuid = UUID.Zero; | ||
230 | if (! m_store.CreateStore(value, out uuid)) | ||
231 | GenerateRuntimeError("Failed to create Json store"); | ||
232 | |||
233 | return uuid; | ||
234 | } | ||
235 | |||
236 | // ----------------------------------------------------------------- | ||
237 | /// <summary> | ||
238 | /// | ||
239 | /// </summary> | ||
240 | // ----------------------------------------------------------------- | ||
241 | protected int JsonDestroyStore(UUID hostID, UUID scriptID, UUID storeID) | ||
242 | { | ||
243 | return m_store.DestroyStore(storeID) ? 1 : 0; | ||
244 | } | ||
245 | |||
246 | // ----------------------------------------------------------------- | ||
247 | /// <summary> | ||
248 | /// | ||
249 | /// </summary> | ||
250 | // ----------------------------------------------------------------- | ||
251 | protected UUID JsonReadNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) | ||
252 | { | ||
253 | UUID reqID = UUID.Random(); | ||
254 | Util.FireAndForget(delegate(object o) { DoJsonReadNotecard(reqID,hostID,scriptID,storeID,path,assetID); }); | ||
255 | return reqID; | ||
256 | } | ||
257 | |||
258 | // ----------------------------------------------------------------- | ||
259 | /// <summary> | ||
260 | /// | ||
261 | /// </summary> | ||
262 | // ----------------------------------------------------------------- | ||
263 | protected UUID JsonWriteNotecard(UUID hostID, UUID scriptID, UUID storeID, string path, string name) | ||
264 | { | ||
265 | UUID reqID = UUID.Random(); | ||
266 | Util.FireAndForget(delegate(object o) { DoJsonWriteNotecard(reqID,hostID,scriptID,storeID,path,name); }); | ||
267 | return reqID; | ||
268 | } | ||
269 | |||
270 | // ----------------------------------------------------------------- | ||
271 | /// <summary> | ||
272 | /// | ||
273 | /// </summary> | ||
274 | // ----------------------------------------------------------------- | ||
275 | protected int JsonTestPath(UUID hostID, UUID scriptID, UUID storeID, string path) | ||
276 | { | ||
277 | return m_store.TestPath(storeID,path,false) ? 1 : 0; | ||
278 | } | ||
279 | |||
280 | protected int JsonTestPathJson(UUID hostID, UUID scriptID, UUID storeID, string path) | ||
281 | { | ||
282 | return m_store.TestPath(storeID,path,true) ? 1 : 0; | ||
283 | } | ||
284 | |||
285 | // ----------------------------------------------------------------- | ||
286 | /// <summary> | ||
287 | /// | ||
288 | /// </summary> | ||
289 | // ----------------------------------------------------------------- | ||
290 | protected int JsonSetValue(UUID hostID, UUID scriptID, UUID storeID, string path, string value) | ||
291 | { | ||
292 | return m_store.SetValue(storeID,path,value,false) ? 1 : 0; | ||
293 | } | ||
294 | |||
295 | protected int JsonSetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path, string value) | ||
296 | { | ||
297 | return m_store.SetValue(storeID,path,value,true) ? 1 : 0; | ||
298 | } | ||
299 | |||
300 | // ----------------------------------------------------------------- | ||
301 | /// <summary> | ||
302 | /// | ||
303 | /// </summary> | ||
304 | // ----------------------------------------------------------------- | ||
305 | protected int JsonRemoveValue(UUID hostID, UUID scriptID, UUID storeID, string path) | ||
306 | { | ||
307 | return m_store.RemoveValue(storeID,path) ? 1 : 0; | ||
308 | } | ||
309 | |||
310 | // ----------------------------------------------------------------- | ||
311 | /// <summary> | ||
312 | /// | ||
313 | /// </summary> | ||
314 | // ----------------------------------------------------------------- | ||
315 | protected string JsonGetValue(UUID hostID, UUID scriptID, UUID storeID, string path) | ||
316 | { | ||
317 | string value = String.Empty; | ||
318 | m_store.GetValue(storeID,path,false,out value); | ||
319 | return value; | ||
320 | } | ||
321 | |||
322 | protected string JsonGetValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) | ||
323 | { | ||
324 | string value = String.Empty; | ||
325 | m_store.GetValue(storeID,path,true, out value); | ||
326 | return value; | ||
327 | } | ||
328 | |||
329 | // ----------------------------------------------------------------- | ||
330 | /// <summary> | ||
331 | /// | ||
332 | /// </summary> | ||
333 | // ----------------------------------------------------------------- | ||
334 | protected UUID JsonTakeValue(UUID hostID, UUID scriptID, UUID storeID, string path) | ||
335 | { | ||
336 | UUID reqID = UUID.Random(); | ||
337 | Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,false); }); | ||
338 | return reqID; | ||
339 | } | ||
340 | |||
341 | protected UUID JsonTakeValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) | ||
342 | { | ||
343 | UUID reqID = UUID.Random(); | ||
344 | Util.FireAndForget(delegate(object o) { DoJsonTakeValue(scriptID,reqID,storeID,path,true); }); | ||
345 | return reqID; | ||
346 | } | ||
347 | |||
348 | private void DoJsonTakeValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson) | ||
349 | { | ||
350 | try | ||
351 | { | ||
352 | m_store.TakeValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); }); | ||
353 | return; | ||
354 | } | ||
355 | catch (Exception e) | ||
356 | { | ||
357 | m_log.InfoFormat("[JsonStoreScripts] unable to retrieve value; {0}",e.ToString()); | ||
358 | } | ||
359 | |||
360 | DispatchValue(scriptID,reqID,String.Empty); | ||
361 | } | ||
362 | |||
363 | |||
364 | // ----------------------------------------------------------------- | ||
365 | /// <summary> | ||
366 | /// | ||
367 | /// </summary> | ||
368 | // ----------------------------------------------------------------- | ||
369 | protected UUID JsonReadValue(UUID hostID, UUID scriptID, UUID storeID, string path) | ||
370 | { | ||
371 | UUID reqID = UUID.Random(); | ||
372 | Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,false); }); | ||
373 | return reqID; | ||
374 | } | ||
375 | |||
376 | protected UUID JsonReadValueJson(UUID hostID, UUID scriptID, UUID storeID, string path) | ||
377 | { | ||
378 | UUID reqID = UUID.Random(); | ||
379 | Util.FireAndForget(delegate(object o) { DoJsonReadValue(scriptID,reqID,storeID,path,true); }); | ||
380 | return reqID; | ||
381 | } | ||
382 | |||
383 | private void DoJsonReadValue(UUID scriptID, UUID reqID, UUID storeID, string path, bool useJson) | ||
384 | { | ||
385 | try | ||
386 | { | ||
387 | m_store.ReadValue(storeID,path,useJson,delegate(string value) { DispatchValue(scriptID,reqID,value); }); | ||
388 | return; | ||
389 | } | ||
390 | catch (Exception e) | ||
391 | { | ||
392 | m_log.InfoFormat("[JsonStoreScripts] unable to retrieve value; {0}",e.ToString()); | ||
393 | } | ||
394 | |||
395 | DispatchValue(scriptID,reqID,String.Empty); | ||
396 | } | ||
397 | |||
398 | #endregion | ||
399 | |||
400 | // ----------------------------------------------------------------- | ||
401 | /// <summary> | ||
402 | /// | ||
403 | /// </summary> | ||
404 | // ----------------------------------------------------------------- | ||
405 | protected void DispatchValue(UUID scriptID, UUID reqID, string value) | ||
406 | { | ||
407 | m_comms.DispatchReply(scriptID,1,value,reqID.ToString()); | ||
408 | } | ||
409 | |||
410 | // ----------------------------------------------------------------- | ||
411 | /// <summary> | ||
412 | /// | ||
413 | /// </summary> | ||
414 | // ----------------------------------------------------------------- | ||
415 | private void DoJsonReadNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, UUID assetID) | ||
416 | { | ||
417 | AssetBase a = m_scene.AssetService.Get(assetID.ToString()); | ||
418 | if (a == null) | ||
419 | GenerateRuntimeError(String.Format("Unable to find notecard asset {0}",assetID)); | ||
420 | |||
421 | if (a.Type != (sbyte)AssetType.Notecard) | ||
422 | GenerateRuntimeError(String.Format("Invalid notecard asset {0}",assetID)); | ||
423 | |||
424 | m_log.DebugFormat("[JsonStoreScripts] read notecard in context {0}",storeID); | ||
425 | |||
426 | try | ||
427 | { | ||
428 | System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); | ||
429 | string jsondata = SLUtil.ParseNotecardToString(enc.GetString(a.Data)); | ||
430 | int result = m_store.SetValue(storeID,path,jsondata,true) ? 1 : 0; | ||
431 | m_comms.DispatchReply(scriptID,result,"",reqID.ToString()); | ||
432 | return; | ||
433 | } | ||
434 | catch (Exception e) | ||
435 | { | ||
436 | m_log.WarnFormat("[JsonStoreScripts] Json parsing failed; {0}",e.Message); | ||
437 | } | ||
438 | |||
439 | GenerateRuntimeError(String.Format("Json parsing failed for {0}",assetID.ToString())); | ||
440 | m_comms.DispatchReply(scriptID,0,"",reqID.ToString()); | ||
441 | } | ||
442 | |||
443 | // ----------------------------------------------------------------- | ||
444 | /// <summary> | ||
445 | /// | ||
446 | /// </summary> | ||
447 | // ----------------------------------------------------------------- | ||
448 | private void DoJsonWriteNotecard(UUID reqID, UUID hostID, UUID scriptID, UUID storeID, string path, string name) | ||
449 | { | ||
450 | string data; | ||
451 | if (! m_store.GetValue(storeID,path,true, out data)) | ||
452 | { | ||
453 | m_comms.DispatchReply(scriptID,0,UUID.Zero.ToString(),reqID.ToString()); | ||
454 | return; | ||
455 | } | ||
456 | |||
457 | SceneObjectPart host = m_scene.GetSceneObjectPart(hostID); | ||
458 | |||
459 | // Create new asset | ||
460 | UUID assetID = UUID.Random(); | ||
461 | AssetBase asset = new AssetBase(assetID, name, (sbyte)AssetType.Notecard, host.OwnerID.ToString()); | ||
462 | asset.Description = "Json store"; | ||
463 | |||
464 | int textLength = data.Length; | ||
465 | data = "Linden text version 2\n{\nLLEmbeddedItems version 1\n{\ncount 0\n}\nText length " | ||
466 | + textLength.ToString() + "\n" + data + "}\n"; | ||
467 | |||
468 | asset.Data = Util.UTF8.GetBytes(data); | ||
469 | m_scene.AssetService.Store(asset); | ||
470 | |||
471 | // Create Task Entry | ||
472 | TaskInventoryItem taskItem = new TaskInventoryItem(); | ||
473 | |||
474 | taskItem.ResetIDs(host.UUID); | ||
475 | taskItem.ParentID = host.UUID; | ||
476 | taskItem.CreationDate = (uint)Util.UnixTimeSinceEpoch(); | ||
477 | taskItem.Name = asset.Name; | ||
478 | taskItem.Description = asset.Description; | ||
479 | taskItem.Type = (int)AssetType.Notecard; | ||
480 | taskItem.InvType = (int)InventoryType.Notecard; | ||
481 | taskItem.OwnerID = host.OwnerID; | ||
482 | taskItem.CreatorID = host.OwnerID; | ||
483 | taskItem.BasePermissions = (uint)PermissionMask.All; | ||
484 | taskItem.CurrentPermissions = (uint)PermissionMask.All; | ||
485 | taskItem.EveryonePermissions = 0; | ||
486 | taskItem.NextPermissions = (uint)PermissionMask.All; | ||
487 | taskItem.GroupID = host.GroupID; | ||
488 | taskItem.GroupPermissions = 0; | ||
489 | taskItem.Flags = 0; | ||
490 | taskItem.PermsGranter = UUID.Zero; | ||
491 | taskItem.PermsMask = 0; | ||
492 | taskItem.AssetID = asset.FullID; | ||
493 | |||
494 | host.Inventory.AddInventoryItem(taskItem, false); | ||
495 | |||
496 | m_comms.DispatchReply(scriptID,1,assetID.ToString(),reqID.ToString()); | ||
497 | } | ||
498 | } | ||
499 | } | ||
diff --git a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs index 922eaaf..d192309 100644 --- a/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs +++ b/OpenSim/Region/OptionalModules/Scripting/Minimodule/SPAvatar.cs | |||
@@ -68,7 +68,7 @@ namespace OpenSim.Region.OptionalModules.Scripting.Minimodule | |||
68 | public Vector3 WorldPosition | 68 | public Vector3 WorldPosition |
69 | { | 69 | { |
70 | get { return GetSP().AbsolutePosition; } | 70 | get { return GetSP().AbsolutePosition; } |
71 | set { GetSP().TeleportWithMomentum(value); } | 71 | set { GetSP().Teleport(value); } |
72 | } | 72 | } |
73 | 73 | ||
74 | public bool IsChildAgent | 74 | public bool IsChildAgent |
diff --git a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs index cab30de..74a85e2 100644 --- a/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs +++ b/OpenSim/Region/OptionalModules/Scripting/ScriptModuleComms/ScriptModuleCommsModule.cs | |||
@@ -38,7 +38,7 @@ using OpenMetaverse; | |||
38 | using System.Linq; | 38 | using System.Linq; |
39 | using System.Linq.Expressions; | 39 | using System.Linq.Expressions; |
40 | 40 | ||
41 | namespace OpenSim.Region.CoreModules.Scripting.ScriptModuleComms | 41 | namespace OpenSim.Region.OptionalModules.Scripting.ScriptModuleComms |
42 | { | 42 | { |
43 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ScriptModuleCommsModule")] | 43 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "ScriptModuleCommsModule")] |
44 | class ScriptModuleCommsModule : INonSharedRegionModule, IScriptModuleComms | 44 | class ScriptModuleCommsModule : INonSharedRegionModule, IScriptModuleComms |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs index 8996865..e798382 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCAvatar.cs | |||
@@ -76,22 +76,27 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
76 | 76 | ||
77 | public void Say(string message) | 77 | public void Say(string message) |
78 | { | 78 | { |
79 | SendOnChatFromClient(message, ChatTypeEnum.Say); | 79 | SendOnChatFromClient(0, message, ChatTypeEnum.Say); |
80 | } | 80 | } |
81 | 81 | ||
82 | public void Shout(string message) | 82 | public void Say(int channel, string message) |
83 | { | 83 | { |
84 | SendOnChatFromClient(message, ChatTypeEnum.Shout); | 84 | SendOnChatFromClient(channel, message, ChatTypeEnum.Say); |
85 | } | 85 | } |
86 | 86 | ||
87 | public void Whisper(string message) | 87 | public void Shout(int channel, string message) |
88 | { | 88 | { |
89 | SendOnChatFromClient(message, ChatTypeEnum.Whisper); | 89 | SendOnChatFromClient(channel, message, ChatTypeEnum.Shout); |
90 | } | ||
91 | |||
92 | public void Whisper(int channel, string message) | ||
93 | { | ||
94 | SendOnChatFromClient(channel, message, ChatTypeEnum.Whisper); | ||
90 | } | 95 | } |
91 | 96 | ||
92 | public void Broadcast(string message) | 97 | public void Broadcast(string message) |
93 | { | 98 | { |
94 | SendOnChatFromClient(message, ChatTypeEnum.Broadcast); | 99 | SendOnChatFromClient(0, message, ChatTypeEnum.Broadcast); |
95 | } | 100 | } |
96 | 101 | ||
97 | public void GiveMoney(UUID target, int amount) | 102 | public void GiveMoney(UUID target, int amount) |
@@ -146,10 +151,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
146 | 151 | ||
147 | #region Internal Functions | 152 | #region Internal Functions |
148 | 153 | ||
149 | private void SendOnChatFromClient(string message, ChatTypeEnum chatType) | 154 | private void SendOnChatFromClient(int channel, string message, ChatTypeEnum chatType) |
150 | { | 155 | { |
151 | OSChatMessage chatFromClient = new OSChatMessage(); | 156 | OSChatMessage chatFromClient = new OSChatMessage(); |
152 | chatFromClient.Channel = 0; | 157 | chatFromClient.Channel = channel; |
153 | chatFromClient.From = Name; | 158 | chatFromClient.From = Name; |
154 | chatFromClient.Message = message; | 159 | chatFromClient.Message = message; |
155 | chatFromClient.Position = StartPos; | 160 | chatFromClient.Position = StartPos; |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index ebf5e84..a32ab2a 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs | |||
@@ -155,18 +155,10 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
155 | ScenePresence sp; | 155 | ScenePresence sp; |
156 | if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) | 156 | if (scene.TryGetScenePresence(npcAvatar.AgentId, out sp)) |
157 | { | 157 | { |
158 | m_log.DebugFormat( | ||
159 | "[NPC MODULE]: Successfully retrieved scene presence for NPC {0} {1}", sp.Name, sp.UUID); | ||
160 | |||
161 | sp.CompleteMovement(npcAvatar, false); | 158 | sp.CompleteMovement(npcAvatar, false); |
162 | m_avatars.Add(npcAvatar.AgentId, npcAvatar); | 159 | m_avatars.Add(npcAvatar.AgentId, npcAvatar); |
160 | m_log.DebugFormat("[NPC MODULE]: Created NPC {0} {1}", npcAvatar.AgentId, sp.Name); | ||
163 | } | 161 | } |
164 | else | ||
165 | { | ||
166 | m_log.WarnFormat("[NPC MODULE]: Could not find scene presence for NPC {0} {1}", sp.Name, sp.UUID); | ||
167 | npcAvatar.AgentId = UUID.Zero; | ||
168 | } | ||
169 | |||
170 | } | 162 | } |
171 | ev.Set(); | 163 | ev.Set(); |
172 | }); | 164 | }); |
@@ -178,7 +170,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
178 | return npcAvatar.AgentId; | 170 | return npcAvatar.AgentId; |
179 | } | 171 | } |
180 | 172 | ||
181 | public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget) | 173 | public bool MoveToTarget(UUID agentID, Scene scene, Vector3 pos, bool noFly, bool landAtTarget, bool running) |
182 | { | 174 | { |
183 | lock (m_avatars) | 175 | lock (m_avatars) |
184 | { | 176 | { |
@@ -192,6 +184,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
192 | sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); | 184 | sp.Name, pos, scene.RegionInfo.RegionName, noFly, landAtTarget); |
193 | 185 | ||
194 | sp.MoveToTarget(pos, noFly, landAtTarget); | 186 | sp.MoveToTarget(pos, noFly, landAtTarget); |
187 | sp.SetAlwaysRun = running; | ||
195 | 188 | ||
196 | return true; | 189 | return true; |
197 | } | 190 | } |
@@ -221,6 +214,11 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
221 | 214 | ||
222 | public bool Say(UUID agentID, Scene scene, string text) | 215 | public bool Say(UUID agentID, Scene scene, string text) |
223 | { | 216 | { |
217 | return Say(agentID, scene, text, 0); | ||
218 | } | ||
219 | |||
220 | public bool Say(UUID agentID, Scene scene, string text, int channel) | ||
221 | { | ||
224 | lock (m_avatars) | 222 | lock (m_avatars) |
225 | { | 223 | { |
226 | if (m_avatars.ContainsKey(agentID)) | 224 | if (m_avatars.ContainsKey(agentID)) |
@@ -228,7 +226,25 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
228 | ScenePresence sp; | 226 | ScenePresence sp; |
229 | scene.TryGetScenePresence(agentID, out sp); | 227 | scene.TryGetScenePresence(agentID, out sp); |
230 | 228 | ||
231 | m_avatars[agentID].Say(text); | 229 | m_avatars[agentID].Say(channel, text); |
230 | |||
231 | return true; | ||
232 | } | ||
233 | } | ||
234 | |||
235 | return false; | ||
236 | } | ||
237 | |||
238 | public bool Shout(UUID agentID, Scene scene, string text, int channel) | ||
239 | { | ||
240 | lock (m_avatars) | ||
241 | { | ||
242 | if (m_avatars.ContainsKey(agentID)) | ||
243 | { | ||
244 | ScenePresence sp; | ||
245 | scene.TryGetScenePresence(agentID, out sp); | ||
246 | |||
247 | m_avatars[agentID].Shout(channel, text); | ||
232 | 248 | ||
233 | return true; | 249 | return true; |
234 | } | 250 | } |
@@ -255,6 +271,24 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
255 | return false; | 271 | return false; |
256 | } | 272 | } |
257 | 273 | ||
274 | public bool Whisper(UUID agentID, Scene scene, string text, int channel) | ||
275 | { | ||
276 | lock (m_avatars) | ||
277 | { | ||
278 | if (m_avatars.ContainsKey(agentID)) | ||
279 | { | ||
280 | ScenePresence sp; | ||
281 | scene.TryGetScenePresence(agentID, out sp); | ||
282 | |||
283 | m_avatars[agentID].Whisper(channel, text); | ||
284 | |||
285 | return true; | ||
286 | } | ||
287 | } | ||
288 | |||
289 | return false; | ||
290 | } | ||
291 | |||
258 | public bool Stand(UUID agentID, Scene scene) | 292 | public bool Stand(UUID agentID, Scene scene) |
259 | { | 293 | { |
260 | lock (m_avatars) | 294 | lock (m_avatars) |
@@ -308,7 +342,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC | |||
308 | scene.RemoveClient(agentID, false); | 342 | scene.RemoveClient(agentID, false); |
309 | m_avatars.Remove(agentID); | 343 | m_avatars.Remove(agentID); |
310 | 344 | ||
311 | // m_log.DebugFormat("[NPC MODULE]: Removed {0} {1}", agentID, av.Name); | 345 | m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", agentID, av.Name); |
312 | return true; | 346 | return true; |
313 | } | 347 | } |
314 | } | 348 | } |
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs index eea0b2e..65dad2d 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs | |||
@@ -85,7 +85,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
85 | m_attMod = new AttachmentsModule(); | 85 | m_attMod = new AttachmentsModule(); |
86 | m_npcMod = new NPCModule(); | 86 | m_npcMod = new NPCModule(); |
87 | 87 | ||
88 | m_scene = SceneHelpers.SetupScene(); | 88 | m_scene = new SceneHelpers().SetupScene(); |
89 | SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule()); | 89 | SceneHelpers.SetupSceneModules(m_scene, config, m_afMod, m_umMod, m_attMod, m_npcMod, new BasicInventoryAccessModule()); |
90 | } | 90 | } |
91 | 91 | ||
@@ -242,7 +242,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
242 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); | 242 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
243 | 243 | ||
244 | Vector3 targetPos = startPos + new Vector3(0, 10, 0); | 244 | Vector3 targetPos = startPos + new Vector3(0, 10, 0); |
245 | m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false); | 245 | m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false); |
246 | 246 | ||
247 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); | 247 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
248 | //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f))); | 248 | //Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0.7071068f, 0.7071068f))); |
@@ -267,7 +267,7 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests | |||
267 | // Try a second movement | 267 | // Try a second movement |
268 | startPos = npc.AbsolutePosition; | 268 | startPos = npc.AbsolutePosition; |
269 | targetPos = startPos + new Vector3(10, 0, 0); | 269 | targetPos = startPos + new Vector3(10, 0, 0); |
270 | m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false); | 270 | m_npcMod.MoveToTarget(npc.UUID, m_scene, targetPos, false, false, false); |
271 | 271 | ||
272 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); | 272 | Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos)); |
273 | // Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0, 1))); | 273 | // Assert.That(npc.Rotation, Is.EqualTo(new Quaternion(0, 0, 0, 1))); |