diff options
author | onefang | 2019-09-11 16:36:50 +1000 |
---|---|---|
committer | onefang | 2019-09-11 16:36:50 +1000 |
commit | 50cd1ffd32f69228e566f2b0b89f86ea0d9fe489 (patch) | |
tree | 52f2ab0c04f1a5d7d6ac5dc872981b4b156447e7 /OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs | |
parent | Renamed branch to SledjChisl. (diff) | |
parent | Bump to release flavour, build 0. (diff) | |
download | opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.zip opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.gz opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.bz2 opensim-SC_OLD-50cd1ffd32f69228e566f2b0b89f86ea0d9fe489.tar.xz |
Merge branch 'SledjChisl'
Diffstat (limited to 'OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs | 102 |
1 files changed, 2 insertions, 100 deletions
diff --git a/OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs b/OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs index 2661522..2c2042d 100644 --- a/OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs +++ b/OpenSim/Region/OptionalModules/ViewerSupport/SimulatorFeaturesHelper.cs | |||
@@ -49,90 +49,15 @@ using TeleportFlags = OpenSim.Framework.Constants.TeleportFlags; | |||
49 | 49 | ||
50 | namespace OpenSim.Region.OptionalModules.ViewerSupport | 50 | namespace OpenSim.Region.OptionalModules.ViewerSupport |
51 | { | 51 | { |
52 | public class SimulatorFeaturesHelper | 52 | public class SimulatorFeaturesHelper |
53 | { | 53 | { |
54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 54 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
55 | 55 | ||
56 | private IEntityTransferModule m_TransferModule; | ||
57 | private Scene m_scene; | 56 | private Scene m_scene; |
58 | 57 | ||
59 | private struct RegionSend { | 58 | public SimulatorFeaturesHelper(Scene scene) |
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 | { | 59 | { |
72 | m_scene = scene; | 60 | 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 | } | 61 | } |
137 | 62 | ||
138 | public int UserLevel(UUID agentID) | 63 | public int UserLevel(UUID agentID) |
@@ -144,28 +69,5 @@ namespace OpenSim.Region.OptionalModules.ViewerSupport | |||
144 | 69 | ||
145 | return level; | 70 | return level; |
146 | } | 71 | } |
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 | } | 72 | } |
170 | |||
171 | } | 73 | } |