diff options
author | Justin Clark-Casey (justincc) | 2014-04-11 00:20:05 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2014-04-11 00:29:06 +0100 |
commit | 530c86335d637ed72411c1161c89ece166160586 (patch) | |
tree | 13b8db0239ebdd5d070b4777aefb083857505540 /OpenSim | |
parent | BulletSim: small tweek to avatar height reduce feet embedded into prims. (diff) | |
download | opensim-SC-530c86335d637ed72411c1161c89ece166160586.zip opensim-SC-530c86335d637ed72411c1161c89ece166160586.tar.gz opensim-SC-530c86335d637ed72411c1161c89ece166160586.tar.bz2 opensim-SC-530c86335d637ed72411c1161c89ece166160586.tar.xz |
Fix the presence info caching used in llRequestAgentData(), which was completely inoperative.
This means the presence info may be out of date by up to 20 seconds, but this avoids scripts potentially triggering constants requests to user accout and presence info services.
Relates to http://opensimulator.org/mantis/view.php?id=7088 though I fixed in a different way.
Adds regression test for this case.
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Data/Null/NullPresenceData.cs | 2 | ||||
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 143 | ||||
-rw-r--r-- | OpenSim/Tests/Common/Helpers/SceneHelpers.cs | 6 |
3 files changed, 92 insertions, 59 deletions
diff --git a/OpenSim/Data/Null/NullPresenceData.cs b/OpenSim/Data/Null/NullPresenceData.cs index b85b95e..aff0b0b 100644 --- a/OpenSim/Data/Null/NullPresenceData.cs +++ b/OpenSim/Data/Null/NullPresenceData.cs | |||
@@ -40,7 +40,7 @@ namespace OpenSim.Data.Null | |||
40 | { | 40 | { |
41 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 41 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
42 | 42 | ||
43 | private static NullPresenceData Instance; | 43 | public static NullPresenceData Instance; |
44 | 44 | ||
45 | Dictionary<UUID, PresenceData> m_presenceData = new Dictionary<UUID, PresenceData>(); | 45 | Dictionary<UUID, PresenceData> m_presenceData = new Dictionary<UUID, PresenceData>(); |
46 | 46 | ||
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index e38394a..a9f5541 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -87,6 +87,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
87 | { | 87 | { |
88 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 88 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
89 | 89 | ||
90 | public int LlRequestAgentDataCacheTimeoutMs { get; set; } | ||
91 | |||
90 | protected IScriptEngine m_ScriptEngine; | 92 | protected IScriptEngine m_ScriptEngine; |
91 | protected SceneObjectPart m_host; | 93 | protected SceneObjectPart m_host; |
92 | 94 | ||
@@ -160,30 +162,44 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
160 | /// </summary> | 162 | /// </summary> |
161 | private void LoadConfig() | 163 | private void LoadConfig() |
162 | { | 164 | { |
163 | m_ScriptDelayFactor = | 165 | LlRequestAgentDataCacheTimeoutMs = 20000; |
164 | m_ScriptEngine.Config.GetFloat("ScriptDelayFactor", 1.0f); | 166 | |
165 | m_ScriptDistanceFactor = | 167 | IConfig seConfig = m_ScriptEngine.Config; |
166 | m_ScriptEngine.Config.GetFloat("ScriptDistanceLimitFactor", 1.0f); | 168 | |
167 | m_MinTimerInterval = | 169 | if (seConfig != null) |
168 | m_ScriptEngine.Config.GetFloat("MinTimerInterval", 0.5f); | 170 | { |
169 | m_automaticLinkPermission = | 171 | m_ScriptDelayFactor = |
170 | m_ScriptEngine.Config.GetBoolean("AutomaticLinkPermission", false); | 172 | seConfig.GetFloat("ScriptDelayFactor", m_ScriptDelayFactor); |
171 | m_notecardLineReadCharsMax = | 173 | m_ScriptDistanceFactor = |
172 | m_ScriptEngine.Config.GetInt("NotecardLineReadCharsMax", 255); | 174 | seConfig.GetFloat("ScriptDistanceLimitFactor", m_ScriptDistanceFactor); |
175 | m_MinTimerInterval = | ||
176 | seConfig.GetFloat("MinTimerInterval", m_MinTimerInterval); | ||
177 | m_automaticLinkPermission = | ||
178 | seConfig.GetBoolean("AutomaticLinkPermission", m_automaticLinkPermission); | ||
179 | m_notecardLineReadCharsMax = | ||
180 | seConfig.GetInt("NotecardLineReadCharsMax", m_notecardLineReadCharsMax); | ||
181 | |||
182 | // Rezzing an object with a velocity can create recoil. This feature seems to have been | ||
183 | // removed from recent versions of SL. The code computes recoil (vel*mass) and scales | ||
184 | // it by this factor. May be zero to turn off recoil all together. | ||
185 | m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor); | ||
186 | } | ||
187 | |||
173 | if (m_notecardLineReadCharsMax > 65535) | 188 | if (m_notecardLineReadCharsMax > 65535) |
174 | m_notecardLineReadCharsMax = 65535; | 189 | m_notecardLineReadCharsMax = 65535; |
175 | 190 | ||
176 | // load limits for particular subsystems. | 191 | // load limits for particular subsystems. |
177 | IConfig SMTPConfig; | 192 | IConfigSource seConfigSource = m_ScriptEngine.ConfigSource; |
178 | if ((SMTPConfig = m_ScriptEngine.ConfigSource.Configs["SMTP"]) != null) { | ||
179 | // there's an smtp config, so load in the snooze time. | ||
180 | EMAIL_PAUSE_TIME = SMTPConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME); | ||
181 | } | ||
182 | 193 | ||
183 | // Rezzing an object with a velocity can create recoil. This feature seems to have been | 194 | if (seConfigSource != null) |
184 | // removed from recent versions of SL. The code computes recoil (vel*mass) and scales | 195 | { |
185 | // it by this factor. May be zero to turn off recoil all together. | 196 | IConfig smtpConfig = seConfigSource.Configs["SMTP"]; |
186 | m_recoilScaleFactor = m_ScriptEngine.Config.GetFloat("RecoilScaleFactor", m_recoilScaleFactor); | 197 | if (smtpConfig != null) |
198 | { | ||
199 | // there's an smtp config, so load in the snooze time. | ||
200 | EMAIL_PAUSE_TIME = smtpConfig.GetInt("email_pause_time", EMAIL_PAUSE_TIME); | ||
201 | } | ||
202 | } | ||
187 | } | 203 | } |
188 | 204 | ||
189 | public override Object InitializeLifetimeService() | 205 | public override Object InitializeLifetimeService() |
@@ -4196,60 +4212,71 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
4196 | UserAccount account; | 4212 | UserAccount account; |
4197 | 4213 | ||
4198 | UserInfoCacheEntry ce; | 4214 | UserInfoCacheEntry ce; |
4199 | if (!m_userInfoCache.TryGetValue(uuid, out ce)) | 4215 | |
4216 | lock (m_userInfoCache) | ||
4200 | { | 4217 | { |
4201 | account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); | 4218 | if (!m_userInfoCache.TryGetValue(uuid, out ce)) |
4202 | if (account == null) | ||
4203 | { | 4219 | { |
4204 | m_userInfoCache[uuid] = null; // Cache negative | 4220 | account = World.UserAccountService.GetUserAccount(World.RegionInfo.ScopeID, uuid); |
4205 | return UUID.Zero.ToString(); | 4221 | if (account == null) |
4206 | } | 4222 | { |
4207 | 4223 | m_userInfoCache[uuid] = null; // Cache negative | |
4224 | return UUID.Zero.ToString(); | ||
4225 | } | ||
4208 | 4226 | ||
4209 | PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); | 4227 | PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); |
4210 | if (pinfos != null && pinfos.Length > 0) | 4228 | if (pinfos != null && pinfos.Length > 0) |
4211 | { | ||
4212 | foreach (PresenceInfo p in pinfos) | ||
4213 | { | 4229 | { |
4214 | if (p.RegionID != UUID.Zero) | 4230 | foreach (PresenceInfo p in pinfos) |
4215 | { | 4231 | { |
4216 | pinfo = p; | 4232 | if (p.RegionID != UUID.Zero) |
4233 | { | ||
4234 | pinfo = p; | ||
4235 | } | ||
4217 | } | 4236 | } |
4218 | } | 4237 | } |
4219 | } | ||
4220 | 4238 | ||
4221 | ce = new UserInfoCacheEntry(); | 4239 | ce = new UserInfoCacheEntry(); |
4222 | ce.time = Util.EnvironmentTickCount(); | 4240 | ce.time = Util.EnvironmentTickCount(); |
4223 | ce.account = account; | 4241 | ce.account = account; |
4224 | ce.pinfo = pinfo; | 4242 | ce.pinfo = pinfo; |
4225 | } | ||
4226 | else | ||
4227 | { | ||
4228 | if (ce == null) | ||
4229 | return UUID.Zero.ToString(); | ||
4230 | |||
4231 | account = ce.account; | ||
4232 | pinfo = ce.pinfo; | ||
4233 | } | ||
4234 | 4243 | ||
4235 | if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) >= 20000) | 4244 | m_userInfoCache[uuid] = ce; |
4236 | { | 4245 | } |
4237 | PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); | 4246 | else |
4238 | if (pinfos != null && pinfos.Length > 0) | ||
4239 | { | 4247 | { |
4240 | foreach (PresenceInfo p in pinfos) | 4248 | if (ce == null) |
4249 | return UUID.Zero.ToString(); | ||
4250 | |||
4251 | account = ce.account; | ||
4252 | |||
4253 | if (Util.EnvironmentTickCount() < ce.time || (Util.EnvironmentTickCount() - ce.time) | ||
4254 | >= LlRequestAgentDataCacheTimeoutMs) | ||
4241 | { | 4255 | { |
4242 | if (p.RegionID != UUID.Zero) | 4256 | PresenceInfo[] pinfos = World.PresenceService.GetAgents(new string[] { uuid.ToString() }); |
4257 | if (pinfos != null && pinfos.Length > 0) | ||
4258 | { | ||
4259 | foreach (PresenceInfo p in pinfos) | ||
4260 | { | ||
4261 | if (p.RegionID != UUID.Zero) | ||
4262 | { | ||
4263 | pinfo = p; | ||
4264 | } | ||
4265 | } | ||
4266 | } | ||
4267 | else | ||
4243 | { | 4268 | { |
4244 | pinfo = p; | 4269 | pinfo = null; |
4245 | } | 4270 | } |
4271 | |||
4272 | ce.time = Util.EnvironmentTickCount(); | ||
4273 | ce.pinfo = pinfo; | ||
4274 | } | ||
4275 | else | ||
4276 | { | ||
4277 | pinfo = ce.pinfo; | ||
4246 | } | 4278 | } |
4247 | } | 4279 | } |
4248 | else | ||
4249 | pinfo = null; | ||
4250 | |||
4251 | ce.time = Util.EnvironmentTickCount(); | ||
4252 | ce.pinfo = pinfo; | ||
4253 | } | 4280 | } |
4254 | 4281 | ||
4255 | string reply = String.Empty; | 4282 | string reply = String.Empty; |
diff --git a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs index 8f44555..eb8078d 100644 --- a/OpenSim/Tests/Common/Helpers/SceneHelpers.cs +++ b/OpenSim/Tests/Common/Helpers/SceneHelpers.cs | |||
@@ -30,6 +30,7 @@ using System.Net; | |||
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using Nini.Config; | 31 | using Nini.Config; |
32 | using OpenMetaverse; | 32 | using OpenMetaverse; |
33 | using OpenSim.Data.Null; | ||
33 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
34 | using OpenSim.Framework.Communications; | 35 | using OpenSim.Framework.Communications; |
35 | using OpenSim.Framework.Console; | 36 | using OpenSim.Framework.Console; |
@@ -301,6 +302,11 @@ namespace OpenSim.Tests.Common | |||
301 | /// <param name="testScene"></param> | 302 | /// <param name="testScene"></param> |
302 | private static LocalPresenceServicesConnector StartPresenceService() | 303 | private static LocalPresenceServicesConnector StartPresenceService() |
303 | { | 304 | { |
305 | // Unfortunately, some services share data via statics, so we need to null every time to stop interference | ||
306 | // between tests. | ||
307 | // This is a massive non-obvious pita. | ||
308 | NullPresenceData.Instance = null; | ||
309 | |||
304 | IConfigSource config = new IniConfigSource(); | 310 | IConfigSource config = new IniConfigSource(); |
305 | config.AddConfig("Modules"); | 311 | config.AddConfig("Modules"); |
306 | config.AddConfig("PresenceService"); | 312 | config.AddConfig("PresenceService"); |