diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Region/OptionalModules/ViewerSupport | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Region/OptionalModules/ViewerSupport')
6 files changed, 1198 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/ViewerSupport/CameraOnlyModeModule.cs b/OpenSim/Region/OptionalModules/ViewerSupport/CameraOnlyModeModule.cs new file mode 100644 index 0000000..7ae4223 --- /dev/null +++ b/OpenSim/Region/OptionalModules/ViewerSupport/CameraOnlyModeModule.cs | |||
@@ -0,0 +1,176 @@ | |||
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.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Collections.Generic; | ||
33 | using System.Threading; | ||
34 | |||
35 | using OpenMetaverse; | ||
36 | using OpenMetaverse.StructuredData; | ||
37 | using OpenSim; | ||
38 | using OpenSim.Region; | ||
39 | using OpenSim.Region.Framework; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Framework; | ||
43 | //using OpenSim.Framework.Capabilities; | ||
44 | using OpenSim.Framework.Servers; | ||
45 | using OpenSim.Framework.Servers.HttpServer; | ||
46 | using Nini.Config; | ||
47 | using log4net; | ||
48 | using Mono.Addins; | ||
49 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
50 | using TeleportFlags = OpenSim.Framework.Constants.TeleportFlags; | ||
51 | |||
52 | namespace OpenSim.Region.OptionalModules.ViewerSupport | ||
53 | { | ||
54 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "CameraOnlyMode")] | ||
55 | public class CameraOnlyModeModule : INonSharedRegionModule | ||
56 | { | ||
57 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
58 | |||
59 | private Scene m_scene; | ||
60 | private SimulatorFeaturesHelper m_Helper; | ||
61 | private bool m_Enabled; | ||
62 | private int m_UserLevel; | ||
63 | |||
64 | public string Name | ||
65 | { | ||
66 | get { return "CameraOnlyModeModule"; } | ||
67 | } | ||
68 | |||
69 | public Type ReplaceableInterface | ||
70 | { | ||
71 | get { return null; } | ||
72 | } | ||
73 | |||
74 | public void Initialise(IConfigSource config) | ||
75 | { | ||
76 | IConfig moduleConfig = config.Configs["CameraOnlyModeModule"]; | ||
77 | if (moduleConfig != null) | ||
78 | { | ||
79 | m_Enabled = moduleConfig.GetBoolean("enabled", false); | ||
80 | if (m_Enabled) | ||
81 | { | ||
82 | m_UserLevel = moduleConfig.GetInt("UserLevel", 0); | ||
83 | m_log.Info("[CAMERA-ONLY MODE]: CameraOnlyModeModule enabled"); | ||
84 | } | ||
85 | |||
86 | } | ||
87 | } | ||
88 | |||
89 | public void Close() | ||
90 | { | ||
91 | } | ||
92 | |||
93 | public void AddRegion(Scene scene) | ||
94 | { | ||
95 | if (m_Enabled) | ||
96 | { | ||
97 | m_scene = scene; | ||
98 | //m_scene.EventManager.OnMakeRootAgent += (OnMakeRootAgent); | ||
99 | } | ||
100 | } | ||
101 | |||
102 | //private void OnMakeRootAgent(ScenePresence obj) | ||
103 | //{ | ||
104 | // throw new NotImplementedException(); | ||
105 | //} | ||
106 | |||
107 | public void RegionLoaded(Scene scene) | ||
108 | { | ||
109 | if (m_Enabled) | ||
110 | { | ||
111 | IEntityTransferModule et = m_scene.RequestModuleInterface<IEntityTransferModule>(); | ||
112 | m_Helper = new SimulatorFeaturesHelper(scene, et); | ||
113 | |||
114 | ISimulatorFeaturesModule featuresModule = m_scene.RequestModuleInterface<ISimulatorFeaturesModule>(); | ||
115 | if (featuresModule != null) | ||
116 | featuresModule.OnSimulatorFeaturesRequest += OnSimulatorFeaturesRequest; | ||
117 | } | ||
118 | } | ||
119 | |||
120 | public void RemoveRegion(Scene scene) | ||
121 | { | ||
122 | } | ||
123 | |||
124 | private void OnSimulatorFeaturesRequest(UUID agentID, ref OSDMap features) | ||
125 | { | ||
126 | m_log.DebugFormat("[CAMERA-ONLY MODE]: OnSimulatorFeaturesRequest in {0}", m_scene.RegionInfo.RegionName); | ||
127 | if (m_Helper.ShouldSend(agentID) && m_Helper.UserLevel(agentID) <= m_UserLevel) | ||
128 | { | ||
129 | OSDMap extrasMap; | ||
130 | if (features.ContainsKey("OpenSimExtras")) | ||
131 | { | ||
132 | extrasMap = (OSDMap)features["OpenSimExtras"]; | ||
133 | } | ||
134 | else | ||
135 | { | ||
136 | extrasMap = new OSDMap(); | ||
137 | features["OpenSimExtras"] = extrasMap; | ||
138 | } | ||
139 | extrasMap["camera-only-mode"] = OSDMap.FromString("true"); | ||
140 | m_log.DebugFormat("[CAMERA-ONLY MODE]: Sent in {0}", m_scene.RegionInfo.RegionName); | ||
141 | |||
142 | // Detaching attachments doesn't work for HG visitors, | ||
143 | // so I'm giving that up. | ||
144 | //Util.FireAndForget(delegate { DetachAttachments(agentID); }); | ||
145 | } | ||
146 | else | ||
147 | m_log.DebugFormat("[CAMERA-ONLY MODE]: NOT Sending camera-only-mode in {0}", m_scene.RegionInfo.RegionName); | ||
148 | } | ||
149 | |||
150 | private void DetachAttachments(UUID agentID) | ||
151 | { | ||
152 | ScenePresence sp = m_scene.GetScenePresence(agentID); | ||
153 | if ((sp.TeleportFlags & TeleportFlags.ViaLogin) != 0) | ||
154 | // Wait a little, cos there's weird stuff going on at login related to | ||
155 | // the Current Outfit Folder | ||
156 | Thread.Sleep(8000); | ||
157 | |||
158 | if (sp != null && m_scene.AttachmentsModule != null) | ||
159 | { | ||
160 | List<SceneObjectGroup> attachs = sp.GetAttachments(); | ||
161 | if (attachs != null && attachs.Count > 0) | ||
162 | { | ||
163 | foreach (SceneObjectGroup sog in attachs) | ||
164 | { | ||
165 | m_log.DebugFormat("[CAMERA-ONLY MODE]: Forcibly detaching attach {0} from {1} in {2}", | ||
166 | sog.Name, sp.Name, m_scene.RegionInfo.RegionName); | ||
167 | |||
168 | m_scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, sog); | ||
169 | } | ||
170 | } | ||
171 | } | ||
172 | } | ||
173 | |||
174 | } | ||
175 | |||
176 | } | ||
diff --git a/OpenSim/Region/OptionalModules/ViewerSupport/DynamicFloaterModule.cs b/OpenSim/Region/OptionalModules/ViewerSupport/DynamicFloaterModule.cs new file mode 100644 index 0000000..e76e8f2 --- /dev/null +++ b/OpenSim/Region/OptionalModules/ViewerSupport/DynamicFloaterModule.cs | |||
@@ -0,0 +1,238 @@ | |||
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.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Collections.Generic; | ||
33 | using OpenMetaverse; | ||
34 | using OpenMetaverse.StructuredData; | ||
35 | using OpenSim; | ||
36 | using OpenSim.Region; | ||
37 | using OpenSim.Region.Framework; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Framework; | ||
41 | using OpenSim.Framework.Servers; | ||
42 | using OpenSim.Framework.Servers.HttpServer; | ||
43 | using Nini.Config; | ||
44 | using log4net; | ||
45 | using Mono.Addins; | ||
46 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
47 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
48 | |||
49 | namespace OpenSim.Region.OptionalModules.ViewerSupport | ||
50 | { | ||
51 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "DynamicFloater")] | ||
52 | public class DynamicFloaterModule : INonSharedRegionModule, IDynamicFloaterModule | ||
53 | { | ||
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | |||
56 | private Scene m_scene; | ||
57 | |||
58 | private Dictionary<UUID, Dictionary<int, FloaterData>> m_floaters = new Dictionary<UUID, Dictionary<int, FloaterData>>(); | ||
59 | |||
60 | public string Name | ||
61 | { | ||
62 | get { return "DynamicFloaterModule"; } | ||
63 | } | ||
64 | |||
65 | public Type ReplaceableInterface | ||
66 | { | ||
67 | get { return null; } | ||
68 | } | ||
69 | |||
70 | public void Initialise(IConfigSource config) | ||
71 | { | ||
72 | } | ||
73 | |||
74 | public void Close() | ||
75 | { | ||
76 | } | ||
77 | |||
78 | public void AddRegion(Scene scene) | ||
79 | { | ||
80 | m_scene = scene; | ||
81 | scene.EventManager.OnNewClient += OnNewClient; | ||
82 | scene.EventManager.OnClientClosed += OnClientClosed; | ||
83 | m_scene.RegisterModuleInterface<IDynamicFloaterModule>(this); | ||
84 | } | ||
85 | |||
86 | public void RegionLoaded(Scene scene) | ||
87 | { | ||
88 | } | ||
89 | |||
90 | public void RemoveRegion(Scene scene) | ||
91 | { | ||
92 | } | ||
93 | |||
94 | private void OnNewClient(IClientAPI client) | ||
95 | { | ||
96 | client.OnChatFromClient += OnChatFromClient; | ||
97 | } | ||
98 | |||
99 | private void OnClientClosed(UUID agentID, Scene scene) | ||
100 | { | ||
101 | m_floaters.Remove(agentID); | ||
102 | } | ||
103 | |||
104 | private void SendToClient(ScenePresence sp, string msg) | ||
105 | { | ||
106 | sp.ControllingClient.SendChatMessage(msg, | ||
107 | (byte)ChatTypeEnum.Owner, | ||
108 | sp.AbsolutePosition, | ||
109 | "Server", | ||
110 | UUID.Zero, | ||
111 | UUID.Zero, | ||
112 | (byte)ChatSourceType.Object, | ||
113 | (byte)ChatAudibleLevel.Fully); | ||
114 | } | ||
115 | |||
116 | public void DoUserFloater(UUID agentID, FloaterData dialogData, string configuration) | ||
117 | { | ||
118 | ScenePresence sp = m_scene.GetScenePresence(agentID); | ||
119 | if (sp == null || sp.IsChildAgent) | ||
120 | return; | ||
121 | |||
122 | if (!m_floaters.ContainsKey(agentID)) | ||
123 | m_floaters[agentID] = new Dictionary<int, FloaterData>(); | ||
124 | |||
125 | if (m_floaters[agentID].ContainsKey(dialogData.Channel)) | ||
126 | return; | ||
127 | |||
128 | m_floaters[agentID].Add(dialogData.Channel, dialogData); | ||
129 | |||
130 | string xml; | ||
131 | if (dialogData.XmlText != null && dialogData.XmlText != String.Empty) | ||
132 | { | ||
133 | xml = dialogData.XmlText; | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | using (FileStream fs = File.Open(dialogData.XmlName + ".xml", FileMode.Open)) | ||
138 | { | ||
139 | using (StreamReader sr = new StreamReader(fs)) | ||
140 | xml = sr.ReadToEnd().Replace("\n", ""); | ||
141 | } | ||
142 | } | ||
143 | |||
144 | List<string> xparts = new List<string>(); | ||
145 | |||
146 | while (xml.Length > 0) | ||
147 | { | ||
148 | string x = xml; | ||
149 | if (x.Length > 600) | ||
150 | { | ||
151 | x = x.Substring(0, 600); | ||
152 | xml = xml.Substring(600); | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | xml = String.Empty; | ||
157 | } | ||
158 | |||
159 | xparts.Add(x); | ||
160 | } | ||
161 | |||
162 | for (int i = 0 ; i < xparts.Count ; i++) | ||
163 | SendToClient(sp, String.Format("># floater {2} create {0}/{1} " + xparts[i], i + 1, xparts.Count, dialogData.FloaterName)); | ||
164 | |||
165 | SendToClient(sp, String.Format("># floater {0} {{notify:1}} {{channel: {1}}} {{node:cancel {{notify:1}}}} {{node:ok {{notify:1}}}} {2}", dialogData.FloaterName, (uint)dialogData.Channel, configuration)); | ||
166 | } | ||
167 | |||
168 | private void OnChatFromClient(object sender, OSChatMessage msg) | ||
169 | { | ||
170 | if (msg.Sender == null) | ||
171 | return; | ||
172 | |||
173 | //m_log.DebugFormat("chan {0} msg {1}", msg.Channel, msg.Message); | ||
174 | |||
175 | IClientAPI client = msg.Sender; | ||
176 | |||
177 | if (!m_floaters.ContainsKey(client.AgentId)) | ||
178 | return; | ||
179 | |||
180 | string[] parts = msg.Message.Split(new char[] {':'}); | ||
181 | if (parts.Length == 0) | ||
182 | return; | ||
183 | |||
184 | ScenePresence sp = m_scene.GetScenePresence(client.AgentId); | ||
185 | if (sp == null || sp.IsChildAgent) | ||
186 | return; | ||
187 | |||
188 | Dictionary<int, FloaterData> d = m_floaters[client.AgentId]; | ||
189 | |||
190 | // Work around a viewer bug - VALUE from any | ||
191 | // dialog can appear on this channel and needs to | ||
192 | // be dispatched to ALL open dialogs for the user | ||
193 | if (msg.Channel == 427169570) | ||
194 | { | ||
195 | if (parts[0] == "VALUE") | ||
196 | { | ||
197 | foreach (FloaterData dd in d.Values) | ||
198 | { | ||
199 | if(dd.Handler(client, dd, parts)) | ||
200 | { | ||
201 | m_floaters[client.AgentId].Remove(dd.Channel); | ||
202 | SendToClient(sp, String.Format("># floater {0} destroy", dd.FloaterName)); | ||
203 | break; | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | return; | ||
208 | } | ||
209 | |||
210 | if (!d.ContainsKey(msg.Channel)) | ||
211 | return; | ||
212 | |||
213 | FloaterData data = d[msg.Channel]; | ||
214 | |||
215 | if (parts[0] == "NOTIFY") | ||
216 | { | ||
217 | if (parts[1] == "cancel" || parts[1] == data.FloaterName) | ||
218 | { | ||
219 | m_floaters[client.AgentId].Remove(data.Channel); | ||
220 | SendToClient(sp, String.Format("># floater {0} destroy", data.FloaterName)); | ||
221 | } | ||
222 | } | ||
223 | |||
224 | if (data.Handler != null && data.Handler(client, data, parts)) | ||
225 | { | ||
226 | m_floaters[client.AgentId].Remove(data.Channel); | ||
227 | SendToClient(sp, String.Format("># floater {0} destroy", data.FloaterName)); | ||
228 | } | ||
229 | } | ||
230 | |||
231 | public void FloaterControl(ScenePresence sp, FloaterData d, string msg) | ||
232 | { | ||
233 | string sendData = String.Format("># floater {0} {1}", d.FloaterName, msg); | ||
234 | SendToClient(sp, sendData); | ||
235 | |||
236 | } | ||
237 | } | ||
238 | } | ||
diff --git a/OpenSim/Region/OptionalModules/ViewerSupport/DynamicMenuModule.cs b/OpenSim/Region/OptionalModules/ViewerSupport/DynamicMenuModule.cs new file mode 100644 index 0000000..d37369c --- /dev/null +++ b/OpenSim/Region/OptionalModules/ViewerSupport/DynamicMenuModule.cs | |||
@@ -0,0 +1,304 @@ | |||
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.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Collections.Generic; | ||
33 | using OpenMetaverse; | ||
34 | using OpenMetaverse.StructuredData; | ||
35 | using OpenSim; | ||
36 | using OpenSim.Region; | ||
37 | using OpenSim.Region.Framework; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using OpenSim.Region.Framework.Interfaces; | ||
40 | using OpenSim.Framework; | ||
41 | //using OpenSim.Framework.Capabilities; | ||
42 | using OpenSim.Framework.Servers; | ||
43 | using OpenSim.Framework.Servers.HttpServer; | ||
44 | using Nini.Config; | ||
45 | using log4net; | ||
46 | using Mono.Addins; | ||
47 | using Caps = OpenSim.Framework.Capabilities.Caps; | ||
48 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
49 | |||
50 | namespace OpenSim.Region.OptionalModules.ViewerSupport | ||
51 | { | ||
52 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "DynamicMenu")] | ||
53 | public class DynamicMenuModule : INonSharedRegionModule, IDynamicMenuModule | ||
54 | { | ||
55 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
56 | |||
57 | private class MenuItemData | ||
58 | { | ||
59 | public string Title; | ||
60 | public UUID AgentID; | ||
61 | public InsertLocation Location; | ||
62 | public UserMode Mode; | ||
63 | public CustomMenuHandler Handler; | ||
64 | } | ||
65 | |||
66 | private Dictionary<UUID, List<MenuItemData>> m_menuItems = | ||
67 | new Dictionary<UUID, List<MenuItemData>>(); | ||
68 | |||
69 | private Scene m_scene; | ||
70 | |||
71 | public string Name | ||
72 | { | ||
73 | get { return "DynamicMenuModule"; } | ||
74 | } | ||
75 | |||
76 | public Type ReplaceableInterface | ||
77 | { | ||
78 | get { return null; } | ||
79 | } | ||
80 | |||
81 | public void Initialise(IConfigSource config) | ||
82 | { | ||
83 | } | ||
84 | |||
85 | public void Close() | ||
86 | { | ||
87 | } | ||
88 | |||
89 | public void AddRegion(Scene scene) | ||
90 | { | ||
91 | m_scene = scene; | ||
92 | scene.EventManager.OnRegisterCaps += OnRegisterCaps; | ||
93 | m_scene.RegisterModuleInterface<IDynamicMenuModule>(this); | ||
94 | } | ||
95 | |||
96 | public void RegionLoaded(Scene scene) | ||
97 | { | ||
98 | ISimulatorFeaturesModule featuresModule = m_scene.RequestModuleInterface<ISimulatorFeaturesModule>(); | ||
99 | |||
100 | if (featuresModule != null) | ||
101 | featuresModule.OnSimulatorFeaturesRequest += OnSimulatorFeaturesRequest; | ||
102 | } | ||
103 | |||
104 | public void RemoveRegion(Scene scene) | ||
105 | { | ||
106 | } | ||
107 | |||
108 | private void OnSimulatorFeaturesRequest(UUID agentID, ref OSDMap features) | ||
109 | { | ||
110 | OSD menus = new OSDMap(); | ||
111 | if (features.ContainsKey("menus")) | ||
112 | menus = features["menus"]; | ||
113 | |||
114 | OSDMap agent = new OSDMap(); | ||
115 | OSDMap world = new OSDMap(); | ||
116 | OSDMap tools = new OSDMap(); | ||
117 | OSDMap advanced = new OSDMap(); | ||
118 | OSDMap admin = new OSDMap(); | ||
119 | if (((OSDMap)menus).ContainsKey("agent")) | ||
120 | agent = (OSDMap)((OSDMap)menus)["agent"]; | ||
121 | if (((OSDMap)menus).ContainsKey("world")) | ||
122 | world = (OSDMap)((OSDMap)menus)["world"]; | ||
123 | if (((OSDMap)menus).ContainsKey("tools")) | ||
124 | tools = (OSDMap)((OSDMap)menus)["tools"]; | ||
125 | if (((OSDMap)menus).ContainsKey("advanced")) | ||
126 | advanced = (OSDMap)((OSDMap)menus)["advanced"]; | ||
127 | if (((OSDMap)menus).ContainsKey("admin")) | ||
128 | admin = (OSDMap)((OSDMap)menus)["admin"]; | ||
129 | |||
130 | if (m_menuItems.ContainsKey(UUID.Zero)) | ||
131 | { | ||
132 | foreach (MenuItemData d in m_menuItems[UUID.Zero]) | ||
133 | { | ||
134 | if (d.Mode == UserMode.God && (!m_scene.Permissions.IsGod(agentID))) | ||
135 | continue; | ||
136 | |||
137 | OSDMap loc = null; | ||
138 | switch (d.Location) | ||
139 | { | ||
140 | case InsertLocation.Agent: | ||
141 | loc = agent; | ||
142 | break; | ||
143 | case InsertLocation.World: | ||
144 | loc = world; | ||
145 | break; | ||
146 | case InsertLocation.Tools: | ||
147 | loc = tools; | ||
148 | break; | ||
149 | case InsertLocation.Advanced: | ||
150 | loc = advanced; | ||
151 | break; | ||
152 | case InsertLocation.Admin: | ||
153 | loc = admin; | ||
154 | break; | ||
155 | } | ||
156 | |||
157 | if (loc == null) | ||
158 | continue; | ||
159 | |||
160 | loc[d.Title] = OSD.FromString(d.Title); | ||
161 | } | ||
162 | } | ||
163 | |||
164 | if (m_menuItems.ContainsKey(agentID)) | ||
165 | { | ||
166 | foreach (MenuItemData d in m_menuItems[agentID]) | ||
167 | { | ||
168 | if (d.Mode == UserMode.God && (!m_scene.Permissions.IsGod(agentID))) | ||
169 | continue; | ||
170 | |||
171 | OSDMap loc = null; | ||
172 | switch (d.Location) | ||
173 | { | ||
174 | case InsertLocation.Agent: | ||
175 | loc = agent; | ||
176 | break; | ||
177 | case InsertLocation.World: | ||
178 | loc = world; | ||
179 | break; | ||
180 | case InsertLocation.Tools: | ||
181 | loc = tools; | ||
182 | break; | ||
183 | case InsertLocation.Advanced: | ||
184 | loc = advanced; | ||
185 | break; | ||
186 | case InsertLocation.Admin: | ||
187 | loc = admin; | ||
188 | break; | ||
189 | } | ||
190 | |||
191 | if (loc == null) | ||
192 | continue; | ||
193 | |||
194 | loc[d.Title] = OSD.FromString(d.Title); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | |||
199 | ((OSDMap)menus)["agent"] = agent; | ||
200 | ((OSDMap)menus)["world"] = world; | ||
201 | ((OSDMap)menus)["tools"] = tools; | ||
202 | ((OSDMap)menus)["advanced"] = advanced; | ||
203 | ((OSDMap)menus)["admin"] = admin; | ||
204 | |||
205 | features["menus"] = menus; | ||
206 | } | ||
207 | |||
208 | private void OnRegisterCaps(UUID agentID, Caps caps) | ||
209 | { | ||
210 | string capUrl = "/CAPS/" + UUID.Random() + "/"; | ||
211 | |||
212 | capUrl = "/CAPS/" + UUID.Random() + "/"; | ||
213 | caps.RegisterHandler("CustomMenuAction", new MenuActionHandler(capUrl, "CustomMenuAction", agentID, this, m_scene)); | ||
214 | } | ||
215 | |||
216 | internal void HandleMenuSelection(string action, UUID agentID, List<uint> selection) | ||
217 | { | ||
218 | if (m_menuItems.ContainsKey(agentID)) | ||
219 | { | ||
220 | foreach (MenuItemData d in m_menuItems[agentID]) | ||
221 | { | ||
222 | if (d.Title == action) | ||
223 | d.Handler(action, agentID, selection); | ||
224 | } | ||
225 | } | ||
226 | |||
227 | if (m_menuItems.ContainsKey(UUID.Zero)) | ||
228 | { | ||
229 | foreach (MenuItemData d in m_menuItems[UUID.Zero]) | ||
230 | { | ||
231 | if (d.Title == action) | ||
232 | d.Handler(action, agentID, selection); | ||
233 | } | ||
234 | } | ||
235 | } | ||
236 | |||
237 | public void AddMenuItem(string title, InsertLocation location, UserMode mode, CustomMenuHandler handler) | ||
238 | { | ||
239 | AddMenuItem(UUID.Zero, title, location, mode, handler); | ||
240 | } | ||
241 | |||
242 | public void AddMenuItem(UUID agentID, string title, InsertLocation location, UserMode mode, CustomMenuHandler handler) | ||
243 | { | ||
244 | if (!m_menuItems.ContainsKey(agentID)) | ||
245 | m_menuItems[agentID] = new List<MenuItemData>(); | ||
246 | |||
247 | m_menuItems[agentID].Add(new MenuItemData() { Title = title, AgentID = agentID, Location = location, Mode = mode, Handler = handler }); | ||
248 | } | ||
249 | |||
250 | public void RemoveMenuItem(string action) | ||
251 | { | ||
252 | foreach (KeyValuePair<UUID,List< MenuItemData>> kvp in m_menuItems) | ||
253 | { | ||
254 | List<MenuItemData> pendingDeletes = new List<MenuItemData>(); | ||
255 | foreach (MenuItemData d in kvp.Value) | ||
256 | { | ||
257 | if (d.Title == action) | ||
258 | pendingDeletes.Add(d); | ||
259 | } | ||
260 | |||
261 | foreach (MenuItemData d in pendingDeletes) | ||
262 | kvp.Value.Remove(d); | ||
263 | } | ||
264 | } | ||
265 | } | ||
266 | |||
267 | public class MenuActionHandler : BaseStreamHandler | ||
268 | { | ||
269 | private static readonly ILog m_log = | ||
270 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
271 | |||
272 | private UUID m_agentID; | ||
273 | private Scene m_scene; | ||
274 | private DynamicMenuModule m_module; | ||
275 | |||
276 | public MenuActionHandler(string path, string name, UUID agentID, DynamicMenuModule module, Scene scene) | ||
277 | :base("POST", path, name, agentID.ToString()) | ||
278 | { | ||
279 | m_agentID = agentID; | ||
280 | m_scene = scene; | ||
281 | m_module = module; | ||
282 | } | ||
283 | |||
284 | protected override byte[] ProcessRequest(string path, Stream request, IOSHttpRequest httpRequest, IOSHttpResponse httpResponse) | ||
285 | { | ||
286 | StreamReader reader = new StreamReader(request); | ||
287 | string requestBody = reader.ReadToEnd(); | ||
288 | |||
289 | OSD osd = OSDParser.DeserializeLLSDXml(requestBody); | ||
290 | |||
291 | string action = ((OSDMap)osd)["action"].AsString(); | ||
292 | OSDArray selection = (OSDArray)((OSDMap)osd)["selection"]; | ||
293 | List<uint> sel = new List<uint>(); | ||
294 | for (int i = 0 ; i < selection.Count ; i++) | ||
295 | sel.Add(selection[i].AsUInteger()); | ||
296 | |||
297 | Util.FireAndForget( | ||
298 | x => { m_module.HandleMenuSelection(action, m_agentID, sel); }, null, "DynamicMenuModule.HandleMenuSelection"); | ||
299 | |||
300 | Encoding encoding = Encoding.UTF8; | ||
301 | return encoding.GetBytes(OSDParser.SerializeLLSDXmlString(new OSD())); | ||
302 | } | ||
303 | } | ||
304 | } | ||
diff --git a/OpenSim/Region/OptionalModules/ViewerSupport/GodNamesModule.cs b/OpenSim/Region/OptionalModules/ViewerSupport/GodNamesModule.cs new file mode 100644 index 0000000..e0537a4 --- /dev/null +++ b/OpenSim/Region/OptionalModules/ViewerSupport/GodNamesModule.cs | |||
@@ -0,0 +1,144 @@ | |||
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.Reflection; | ||
31 | using log4net; | ||
32 | using Mono.Addins; | ||
33 | using Nini.Config; | ||
34 | using OpenMetaverse; | ||
35 | using OpenMetaverse.StructuredData; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | |||
40 | namespace OpenSim.Region.OptionalModules.ViewerSupport | ||
41 | { | ||
42 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "GodNamesModule")] | ||
43 | public class GodNamesModule : ISharedRegionModule | ||
44 | { | ||
45 | // Infrastructure | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | // Configuration | ||
49 | private static bool m_enabled = false; | ||
50 | private static List<String> m_lastNames = new List<String>(); | ||
51 | private static List<String> m_fullNames = new List<String>(); | ||
52 | |||
53 | public void Initialise(IConfigSource config) | ||
54 | { | ||
55 | IConfig moduleConfig = config.Configs["GodNames"]; | ||
56 | |||
57 | if (moduleConfig == null) { | ||
58 | return; | ||
59 | } | ||
60 | |||
61 | if (!moduleConfig.GetBoolean("Enabled", false)) { | ||
62 | m_log.Info("[GODNAMES]: Addon is disabled"); | ||
63 | return; | ||
64 | } | ||
65 | |||
66 | m_log.Info("[GODNAMES]: Enabled"); | ||
67 | m_enabled = true; | ||
68 | string conf_str = moduleConfig.GetString("FullNames", String.Empty); | ||
69 | foreach (string strl in conf_str.Split(',')) { | ||
70 | string strlan = strl.Trim(" \t".ToCharArray()); | ||
71 | m_log.DebugFormat("[GODNAMES]: Adding {0} as a God name", strlan); | ||
72 | m_fullNames.Add(strlan); | ||
73 | } | ||
74 | |||
75 | conf_str = moduleConfig.GetString("Surnames", String.Empty); | ||
76 | foreach (string strl in conf_str.Split(',')) { | ||
77 | string strlan = strl.Trim(" \t".ToCharArray()); | ||
78 | m_log.DebugFormat("[GODNAMES]: Adding {0} as a God last name", strlan); | ||
79 | m_lastNames.Add(strlan); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | public void AddRegion(Scene scene) { | ||
84 | /*no op*/ | ||
85 | } | ||
86 | |||
87 | public void RemoveRegion(Scene scene) { | ||
88 | /*no op*/ | ||
89 | } | ||
90 | |||
91 | public void PostInitialise() { | ||
92 | /*no op*/ | ||
93 | } | ||
94 | |||
95 | public void Close() { | ||
96 | /*no op*/ | ||
97 | } | ||
98 | |||
99 | public Type ReplaceableInterface { | ||
100 | get { return null; } | ||
101 | } | ||
102 | |||
103 | public string Name { | ||
104 | get { return "Godnames"; } | ||
105 | } | ||
106 | |||
107 | public bool IsSharedModule { | ||
108 | get { return true; } | ||
109 | } | ||
110 | |||
111 | public virtual void RegionLoaded(Scene scene) | ||
112 | { | ||
113 | if (!m_enabled) | ||
114 | return; | ||
115 | |||
116 | ISimulatorFeaturesModule featuresModule = scene.RequestModuleInterface<ISimulatorFeaturesModule>(); | ||
117 | |||
118 | if (featuresModule != null) | ||
119 | featuresModule.OnSimulatorFeaturesRequest += OnSimulatorFeaturesRequest; | ||
120 | |||
121 | } | ||
122 | |||
123 | private void OnSimulatorFeaturesRequest(UUID agentID, ref OSDMap features) | ||
124 | { | ||
125 | OSD namesmap = new OSDMap(); | ||
126 | if (features.ContainsKey("god_names")) | ||
127 | namesmap = features["god_names"]; | ||
128 | else | ||
129 | features["god_names"] = namesmap; | ||
130 | |||
131 | OSDArray fnames = new OSDArray(); | ||
132 | foreach (string name in m_fullNames) { | ||
133 | fnames.Add(name); | ||
134 | } | ||
135 | ((OSDMap)namesmap)["full_names"] = fnames; | ||
136 | |||
137 | OSDArray lnames = new OSDArray(); | ||
138 | foreach (string name in m_lastNames) { | ||
139 | lnames.Add(name); | ||
140 | } | ||
141 | ((OSDMap)namesmap)["last_names"] = lnames; | ||
142 | } | ||
143 | } | ||
144 | } | ||
diff --git a/OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs b/OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs new file mode 100644 index 0000000..2661522 --- /dev/null +++ b/OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs | |||
@@ -0,0 +1,171 @@ | |||
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.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Collections.Generic; | ||
33 | using System.Threading; | ||
34 | |||
35 | using OpenMetaverse; | ||
36 | using OpenMetaverse.StructuredData; | ||
37 | using OpenSim; | ||
38 | using OpenSim.Region; | ||
39 | using OpenSim.Region.Framework; | ||
40 | using OpenSim.Region.Framework.Scenes; | ||
41 | using OpenSim.Region.Framework.Interfaces; | ||
42 | using OpenSim.Framework; | ||
43 | using OpenSim.Services.Interfaces; | ||
44 | //using OpenSim.Framework.Capabilities; | ||
45 | using Nini.Config; | ||
46 | using log4net; | ||
47 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
48 | using TeleportFlags = OpenSim.Framework.Constants.TeleportFlags; | ||
49 | |||
50 | namespace OpenSim.Region.OptionalModules.ViewerSupport | ||
51 | { | ||
52 | public class SimulatorFeaturesHelper | ||
53 | { | ||
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
55 | |||
56 | private IEntityTransferModule m_TransferModule; | ||
57 | private Scene m_scene; | ||
58 | |||
59 | private struct RegionSend { | ||
60 | public UUID region; | ||
61 | public bool send; | ||
62 | }; | ||
63 | // Using a static cache so that we don't have to perform the time-consuming tests | ||
64 | // in ShouldSend on Extra SimFeatures that go on the same response but come from | ||
65 | // different modules. | ||
66 | // This cached is indexed on the agentID and maps to a list of regions | ||
67 | private static ExpiringCache<UUID, List<RegionSend>> m_Cache = new ExpiringCache<UUID, List<RegionSend>>(); | ||
68 | private const double TIMEOUT = 1.0; // time in cache | ||
69 | |||
70 | public SimulatorFeaturesHelper(Scene scene, IEntityTransferModule et) | ||
71 | { | ||
72 | m_scene = scene; | ||
73 | m_TransferModule = et; | ||
74 | } | ||
75 | |||
76 | public bool ShouldSend(UUID agentID) | ||
77 | { | ||
78 | List<RegionSend> rsendlist; | ||
79 | RegionSend rsend; | ||
80 | if (m_Cache.TryGetValue(agentID, out rsendlist)) | ||
81 | { | ||
82 | rsend = rsendlist.Find(r => r.region == m_scene.RegionInfo.RegionID); | ||
83 | if (rsend.region != UUID.Zero) // Found it | ||
84 | { | ||
85 | return rsend.send; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | // Relatively complex logic for deciding whether to send the extra SimFeature or not. | ||
90 | // This is because the viewer calls this cap to all sims that it knows about, | ||
91 | // including the departing sims and non-neighbors (those that are cached). | ||
92 | rsend.region = m_scene.RegionInfo.RegionID; | ||
93 | rsend.send = false; | ||
94 | IClientAPI client = null; | ||
95 | int counter = 200; | ||
96 | |||
97 | // Let's wait a little to see if we get a client here | ||
98 | while (!m_scene.TryGetClient(agentID, out client) && counter-- > 0) | ||
99 | Thread.Sleep(50); | ||
100 | |||
101 | if (client != null) | ||
102 | { | ||
103 | ScenePresence sp = WaitGetScenePresence(agentID); | ||
104 | |||
105 | if (sp != null) | ||
106 | { | ||
107 | // On the receiving region, the call to this cap may arrive before | ||
108 | // the agent is root. Make sure we only proceed from here when the agent | ||
109 | // has been made root | ||
110 | counter = 200; | ||
111 | while ((sp.IsInTransit || sp.IsChildAgent) && counter-- > 0) | ||
112 | { | ||
113 | Thread.Sleep(50); | ||
114 | } | ||
115 | |||
116 | // The viewer calls this cap on the departing sims too. Make sure | ||
117 | // that we only proceed after the agent is not in transit anymore. | ||
118 | // The agent must be root and not going anywhere | ||
119 | if (!sp.IsChildAgent && !m_TransferModule.IsInTransit(agentID)) | ||
120 | rsend.send = true; | ||
121 | |||
122 | } | ||
123 | } | ||
124 | //else | ||
125 | // m_log.DebugFormat("[XXX]: client is null"); | ||
126 | |||
127 | |||
128 | if (rsendlist == null) | ||
129 | { | ||
130 | rsendlist = new List<RegionSend>(); | ||
131 | m_Cache.AddOrUpdate(agentID, rsendlist, TIMEOUT); | ||
132 | } | ||
133 | rsendlist.Add(rsend); | ||
134 | |||
135 | return rsend.send; | ||
136 | } | ||
137 | |||
138 | public int UserLevel(UUID agentID) | ||
139 | { | ||
140 | int level = 0; | ||
141 | UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, agentID); | ||
142 | if (account != null) | ||
143 | level = account.UserLevel; | ||
144 | |||
145 | return level; | ||
146 | } | ||
147 | |||
148 | protected virtual ScenePresence WaitGetScenePresence(UUID agentID) | ||
149 | { | ||
150 | int ntimes = 20; | ||
151 | ScenePresence sp = null; | ||
152 | while ((sp = m_scene.GetScenePresence(agentID)) == null && (ntimes-- > 0)) | ||
153 | Thread.Sleep(1000); | ||
154 | |||
155 | if (sp == null) | ||
156 | m_log.WarnFormat( | ||
157 | "[XXX]: Did not find presence with id {0} in {1} before timeout", | ||
158 | agentID, m_scene.RegionInfo.RegionName); | ||
159 | else | ||
160 | { | ||
161 | ntimes = 10; | ||
162 | while (sp.IsInTransit && (ntimes-- > 0)) | ||
163 | Thread.Sleep(1000); | ||
164 | } | ||
165 | |||
166 | return sp; | ||
167 | } | ||
168 | |||
169 | } | ||
170 | |||
171 | } | ||
diff --git a/OpenSim/Region/OptionalModules/ViewerSupport/SpecialUIModule.cs b/OpenSim/Region/OptionalModules/ViewerSupport/SpecialUIModule.cs new file mode 100644 index 0000000..3fe922d --- /dev/null +++ b/OpenSim/Region/OptionalModules/ViewerSupport/SpecialUIModule.cs | |||
@@ -0,0 +1,165 @@ | |||
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.IO; | ||
30 | using System.Reflection; | ||
31 | using System.Text; | ||
32 | using System.Collections.Generic; | ||
33 | using System.Threading; | ||
34 | using OpenMetaverse; | ||
35 | using OpenMetaverse.StructuredData; | ||
36 | using OpenSim; | ||
37 | using OpenSim.Region; | ||
38 | using OpenSim.Region.Framework; | ||
39 | using OpenSim.Region.Framework.Scenes; | ||
40 | using OpenSim.Region.Framework.Interfaces; | ||
41 | using OpenSim.Framework; | ||
42 | //using OpenSim.Framework.Capabilities; | ||
43 | using OpenSim.Framework.Servers; | ||
44 | using OpenSim.Framework.Servers.HttpServer; | ||
45 | using Nini.Config; | ||
46 | using log4net; | ||
47 | using Mono.Addins; | ||
48 | using OSDMap = OpenMetaverse.StructuredData.OSDMap; | ||
49 | using TeleportFlags = OpenSim.Framework.Constants.TeleportFlags; | ||
50 | |||
51 | namespace OpenSim.Region.OptionalModules.ViewerSupport | ||
52 | { | ||
53 | [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "SpecialUI")] | ||
54 | public class SpecialUIModule : INonSharedRegionModule | ||
55 | { | ||
56 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
57 | private const string VIEWER_SUPPORT_DIR = "ViewerSupport"; | ||
58 | |||
59 | private Scene m_scene; | ||
60 | private SimulatorFeaturesHelper m_Helper; | ||
61 | private bool m_Enabled; | ||
62 | private int m_UserLevel; | ||
63 | |||
64 | public string Name | ||
65 | { | ||
66 | get { return "SpecialUIModule"; } | ||
67 | } | ||
68 | |||
69 | public Type ReplaceableInterface | ||
70 | { | ||
71 | get { return null; } | ||
72 | } | ||
73 | |||
74 | public void Initialise(IConfigSource config) | ||
75 | { | ||
76 | IConfig moduleConfig = config.Configs["SpecialUIModule"]; | ||
77 | if (moduleConfig != null) | ||
78 | { | ||
79 | m_Enabled = moduleConfig.GetBoolean("enabled", false); | ||
80 | if (m_Enabled) | ||
81 | { | ||
82 | m_UserLevel = moduleConfig.GetInt("UserLevel", 0); | ||
83 | m_log.Info("[SPECIAL UI]: SpecialUIModule enabled"); | ||
84 | } | ||
85 | |||
86 | } | ||
87 | } | ||
88 | |||
89 | public void Close() | ||
90 | { | ||
91 | } | ||
92 | |||
93 | public void AddRegion(Scene scene) | ||
94 | { | ||
95 | if (m_Enabled) | ||
96 | { | ||
97 | m_scene = scene; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | public void RegionLoaded(Scene scene) | ||
102 | { | ||
103 | if (m_Enabled) | ||
104 | { | ||
105 | IEntityTransferModule et = m_scene.RequestModuleInterface<IEntityTransferModule>(); | ||
106 | m_Helper = new SimulatorFeaturesHelper(scene, et); | ||
107 | |||
108 | ISimulatorFeaturesModule featuresModule = m_scene.RequestModuleInterface<ISimulatorFeaturesModule>(); | ||
109 | if (featuresModule != null) | ||
110 | featuresModule.OnSimulatorFeaturesRequest += OnSimulatorFeaturesRequest; | ||
111 | } | ||
112 | } | ||
113 | |||
114 | public void RemoveRegion(Scene scene) | ||
115 | { | ||
116 | } | ||
117 | |||
118 | private void OnSimulatorFeaturesRequest(UUID agentID, ref OSDMap features) | ||
119 | { | ||
120 | m_log.DebugFormat("[SPECIAL UI]: OnSimulatorFeaturesRequest in {0}", m_scene.RegionInfo.RegionName); | ||
121 | if (m_Helper.ShouldSend(agentID) && m_Helper.UserLevel(agentID) <= m_UserLevel) | ||
122 | { | ||
123 | OSDMap extrasMap; | ||
124 | OSDMap specialUI = new OSDMap(); | ||
125 | using (StreamReader s = new StreamReader(Path.Combine(VIEWER_SUPPORT_DIR, "panel_toolbar.xml"))) | ||
126 | { | ||
127 | if (features.ContainsKey("OpenSimExtras")) | ||
128 | extrasMap = (OSDMap)features["OpenSimExtras"]; | ||
129 | else | ||
130 | { | ||
131 | extrasMap = new OSDMap(); | ||
132 | features["OpenSimExtras"] = extrasMap; | ||
133 | } | ||
134 | |||
135 | specialUI["toolbar"] = OSDMap.FromString(s.ReadToEnd()); | ||
136 | extrasMap["special-ui"] = specialUI; | ||
137 | } | ||
138 | m_log.DebugFormat("[SPECIAL UI]: Sending panel_toolbar.xml in {0}", m_scene.RegionInfo.RegionName); | ||
139 | |||
140 | if (Directory.Exists(Path.Combine(VIEWER_SUPPORT_DIR, "Floaters"))) | ||
141 | { | ||
142 | OSDMap floaters = new OSDMap(); | ||
143 | uint n = 0; | ||
144 | foreach (String name in Directory.GetFiles(Path.Combine(VIEWER_SUPPORT_DIR, "Floaters"), "*.xml")) | ||
145 | { | ||
146 | using (StreamReader s = new StreamReader(name)) | ||
147 | { | ||
148 | string simple_name = Path.GetFileNameWithoutExtension(name); | ||
149 | OSDMap floater = new OSDMap(); | ||
150 | floaters[simple_name] = OSDMap.FromString(s.ReadToEnd()); | ||
151 | n++; | ||
152 | } | ||
153 | } | ||
154 | specialUI["floaters"] = floaters; | ||
155 | m_log.DebugFormat("[SPECIAL UI]: Sending {0} floaters", n); | ||
156 | } | ||
157 | } | ||
158 | else | ||
159 | m_log.DebugFormat("[SPECIAL UI]: NOT Sending panel_toolbar.xml in {0}", m_scene.RegionInfo.RegionName); | ||
160 | |||
161 | } | ||
162 | |||
163 | } | ||
164 | |||
165 | } | ||