diff options
author | Melanie Thielker | 2014-08-12 01:04:29 +0200 |
---|---|---|
committer | Melanie Thielker | 2014-08-12 01:04:29 +0200 |
commit | 37921c66e53c4b6a38e1ee1279cf85ace35d4a3a (patch) | |
tree | 86305e416941ff0b92824e8758a70ec4b3ea2634 /OpenSim/Region | |
parent | Move the inventory request lock introduced in git master a58152bd to HGInvent... (diff) | |
download | opensim-SC-37921c66e53c4b6a38e1ee1279cf85ace35d4a3a.zip opensim-SC-37921c66e53c4b6a38e1ee1279cf85ace35d4a3a.tar.gz opensim-SC-37921c66e53c4b6a38e1ee1279cf85ace35d4a3a.tar.bz2 opensim-SC-37921c66e53c4b6a38e1ee1279cf85ace35d4a3a.tar.xz |
Avination's Dynamic Floater Module. This works with Singularity viewer only.
It's WIP in that a dialog builder is on it's way. For now, the XML needs to
be handmade.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r-- | OpenSim/Region/Framework/Interfaces/IDynamicFloaterModule.cs | 52 | ||||
-rw-r--r-- | OpenSim/Region/OptionalModules/ViewerSupport/DynamicFloaterModule.cs | 238 |
2 files changed, 290 insertions, 0 deletions
diff --git a/OpenSim/Region/Framework/Interfaces/IDynamicFloaterModule.cs b/OpenSim/Region/Framework/Interfaces/IDynamicFloaterModule.cs new file mode 100644 index 0000000..7684ce3 --- /dev/null +++ b/OpenSim/Region/Framework/Interfaces/IDynamicFloaterModule.cs | |||
@@ -0,0 +1,52 @@ | |||
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.Collections.Generic; | ||
29 | using OpenMetaverse; | ||
30 | using OpenSim.Framework; | ||
31 | using OpenSim.Region.Framework.Scenes; | ||
32 | |||
33 | namespace OpenSim.Region.Framework.Interfaces | ||
34 | { | ||
35 | public delegate bool HandlerDelegate(IClientAPI client, FloaterData data, string[] msg); | ||
36 | |||
37 | public abstract class FloaterData | ||
38 | { | ||
39 | public abstract int Channel { get; } | ||
40 | public abstract string FloaterName { get; set; } | ||
41 | public virtual string XmlName { get; set; } | ||
42 | public virtual string XmlText { get; set; } | ||
43 | public virtual HandlerDelegate Handler { get; set; } | ||
44 | } | ||
45 | |||
46 | |||
47 | public interface IDynamicFloaterModule | ||
48 | { | ||
49 | void DoUserFloater(UUID agentID, FloaterData dialogData, string configuration); | ||
50 | void FloaterControl(ScenePresence sp, FloaterData d, string msg); | ||
51 | } | ||
52 | } | ||
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 | } | ||