aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs
diff options
context:
space:
mode:
authorDiva Canto2014-11-10 19:03:06 -0800
committerDiva Canto2014-11-10 19:03:06 -0800
commit5e34727b7e2796e6eb621cdc3ede48ab796c198e (patch)
tree4a47c34bc3a80e7d020de4a89984b18ab9a9f258 /OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC-5e34727b7e2796e6eb621cdc3ede48ab796c198e.zip
opensim-SC-5e34727b7e2796e6eb621cdc3ede48ab796c198e.tar.gz
opensim-SC-5e34727b7e2796e6eb621cdc3ede48ab796c198e.tar.bz2
opensim-SC-5e34727b7e2796e6eb621cdc3ede48ab796c198e.tar.xz
Add additional viewer support modules that allow certain viewers to modify their UI on the fly.
Diffstat (limited to 'OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs')
-rw-r--r--OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs174
1 files changed, 174 insertions, 0 deletions
diff --git a/OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs b/OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs
new file mode 100644
index 0000000..1900f31
--- /dev/null
+++ b/OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs
@@ -0,0 +1,174 @@
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
28using System;
29using System.IO;
30using System.Reflection;
31using System.Text;
32using System.Collections.Generic;
33using System.Threading;
34
35using OpenMetaverse;
36using OpenMetaverse.StructuredData;
37using OpenSim;
38using OpenSim.Region;
39using OpenSim.Region.Framework;
40using OpenSim.Region.Framework.Scenes;
41using OpenSim.Region.Framework.Interfaces;
42using OpenSim.Framework;
43using OpenSim.Services.Interfaces;
44//using OpenSim.Framework.Capabilities;
45using Nini.Config;
46using log4net;
47using OSDMap = OpenMetaverse.StructuredData.OSDMap;
48using TeleportFlags = OpenSim.Framework.Constants.TeleportFlags;
49
50namespace 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 if (sp == null) // Client is connected but SP still doesn't exist: this may happen on login
105 {
106 m_log.DebugFormat("[XXX]: SP is null");
107 }
108 else
109 {
110 // On the receiving region, the call to this cap may arrive before
111 // the agent is root. Make sure we only proceed from here when the agent
112 // has been made root
113 counter = 200;
114 while ((sp.IsInTransit || sp.IsChildAgent) && counter-- > 0)
115 {
116 Thread.Sleep(50);
117 }
118
119 // The viewer calls this cap on the departing sims too. Make sure
120 // that we only proceed after the agent is not in transit anymore.
121 // The agent must be root and not going anywhere
122 if (!sp.IsChildAgent && !m_TransferModule.IsInTransit(agentID))
123 rsend.send = true;
124 else
125 m_log.DebugFormat("[XXX]: Child or in transit");
126 }
127 }
128 else
129 m_log.DebugFormat("[XXX]: client is null");
130
131 if (rsendlist == null)
132 {
133 rsendlist = new List<RegionSend>();
134 m_Cache.AddOrUpdate(agentID, rsendlist, TIMEOUT);
135 }
136 rsendlist.Add(rsend);
137
138 return rsend.send;
139 }
140
141 public int UserLevel(UUID agentID)
142 {
143 int level = 0;
144 UserAccount account = m_scene.UserAccountService.GetUserAccount(m_scene.RegionInfo.ScopeID, agentID);
145 if (account != null)
146 level = account.UserLevel;
147
148 return level;
149 }
150
151 protected virtual ScenePresence WaitGetScenePresence(UUID agentID)
152 {
153 int ntimes = 20;
154 ScenePresence sp = null;
155 while ((sp = m_scene.GetScenePresence(agentID)) == null && (ntimes-- > 0))
156 Thread.Sleep(1000);
157
158 if (sp == null)
159 m_log.WarnFormat(
160 "[XXX]: Did not find presence with id {0} in {1} before timeout",
161 agentID, m_scene.RegionInfo.RegionName);
162 else
163 {
164 ntimes = 10;
165 while (sp.IsInTransit && (ntimes-- > 0))
166 Thread.Sleep(1000);
167 }
168
169 return sp;
170 }
171
172 }
173
174}