aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/ServiceConnectorsOut
diff options
context:
space:
mode:
authoronefang2019-09-11 16:36:50 +1000
committeronefang2019-09-11 16:36:50 +1000
commit50cd1ffd32f69228e566f2b0b89f86ea0d9fe489 (patch)
tree52f2ab0c04f1a5d7d6ac5dc872981b4b156447e7 /OpenSim/Region/CoreModules/ServiceConnectorsOut
parentRenamed branch to SledjChisl. (diff)
parentBump to release flavour, build 0. (diff)
downloadopensim-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/CoreModules/ServiceConnectorsOut')
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs2
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs6
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs73
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs44
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RemoteAssetServiceConnector.cs6
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs11
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/RemoteAuthenticationServiceConnector.cs2
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs11
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/LocalAuthorizationServiceConnector.cs9
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs20
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs8
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/RemoteAvatarServiceConnector.cs2
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs164
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs102
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs965
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs154
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs6
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs35
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs70
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs13
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs18
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs16
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Land/LocalLandServiceConnector.cs25
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Land/RemoteLandServiceConnector.cs2
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs52
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs188
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/RemoteMuteListServiceConnector.cs143
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/NeighbourServiceOutConnector.cs (renamed from OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/LocalNeighbourServiceConnector.cs)83
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/RemoteNeighourServiceConnector.cs157
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/BasePresenceServiceConnector.cs5
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs18
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs2
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs10
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs17
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs55
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs61
-rw-r--r--OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs103
37 files changed, 1910 insertions, 748 deletions
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs
index 41ae53f..5cd68d9 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/LocalAgentPreferencesServiceConnector.cs
@@ -50,7 +50,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.AgentPreferences
50 50
51 #region ISharedRegionModule 51 #region ISharedRegionModule
52 52
53 public Type ReplaceableInterface 53 public Type ReplaceableInterface
54 { 54 {
55 get { return null; } 55 get { return null; }
56 } 56 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs
index ad9544a..d60236a 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/AgentPreferences/RemoteAgentPreferencesServiceConnector.cs
@@ -44,14 +44,14 @@ using Nini.Config;
44namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.AgentPreferences 44namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.AgentPreferences
45{ 45{
46 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteAgentPreferencesServicesConnector")] 46 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteAgentPreferencesServicesConnector")]
47 public class RemoteAgentPreferencesServicesConnector : AgentPreferencesServicesConnector, 47 public class RemoteAgentPreferencesServicesConnector : AgentPreferencesServicesConnector,
48 ISharedRegionModule, IAgentPreferencesService 48 ISharedRegionModule, IAgentPreferencesService
49 { 49 {
50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 50 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
51 51
52 private bool m_Enabled = false; 52 private bool m_Enabled = false;
53 53
54 public Type ReplaceableInterface 54 public Type ReplaceableInterface
55 { 55 {
56 get { return null; } 56 get { return null; }
57 } 57 }
@@ -61,7 +61,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.AgentPreferences
61 get { return "RemoteAgentPreferencesServicesConnector"; } 61 get { return "RemoteAgentPreferencesServicesConnector"; }
62 } 62 }
63 63
64 public override void Initialise(IConfigSource source) 64 public new void Initialise(IConfigSource source)
65 { 65 {
66 IConfig moduleConfig = source.Configs["Modules"]; 66 IConfig moduleConfig = source.Configs["Modules"];
67 if (moduleConfig != null) 67 if (moduleConfig != null)
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs
index 7fcfc74..92ae36f 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/HGAssetBroker.cs
@@ -48,7 +48,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
48 LogManager.GetLogger( 48 LogManager.GetLogger(
49 MethodBase.GetCurrentMethod().DeclaringType); 49 MethodBase.GetCurrentMethod().DeclaringType);
50 50
51 private IImprovedAssetCache m_Cache = null; 51 private IAssetCache m_Cache = null;
52 private IAssetService m_GridService; 52 private IAssetService m_GridService;
53 private IAssetService m_HGService; 53 private IAssetService m_HGService;
54 54
@@ -59,7 +59,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
59 59
60 private AssetPermissions m_AssetPerms; 60 private AssetPermissions m_AssetPerms;
61 61
62 public Type ReplaceableInterface 62 public Type ReplaceableInterface
63 { 63 {
64 get { return null; } 64 get { return null; }
65 } 65 }
@@ -159,7 +159,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
159 { 159 {
160 if (!m_Enabled) 160 if (!m_Enabled)
161 return; 161 return;
162 162
163 m_aScene = scene; 163 m_aScene = scene;
164 164
165 m_aScene.RegisterModuleInterface<IAssetService>(this); 165 m_aScene.RegisterModuleInterface<IAssetService>(this);
@@ -176,10 +176,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
176 176
177 if (m_Cache == null) 177 if (m_Cache == null)
178 { 178 {
179 m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>(); 179 m_Cache = scene.RequestModuleInterface<IAssetCache>();
180 180
181 if (!(m_Cache is ISharedRegionModule)) 181 if (!(m_Cache is ISharedRegionModule))
182 m_Cache = null; 182 m_Cache = null;
183
183 } 184 }
184 185
185 m_log.InfoFormat("[HG ASSET CONNECTOR]: Enabled hypergrid asset broker for region {0}", scene.RegionInfo.RegionName); 186 m_log.InfoFormat("[HG ASSET CONNECTOR]: Enabled hypergrid asset broker for region {0}", scene.RegionInfo.RegionName);
@@ -205,10 +206,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
205 { 206 {
206 //m_log.DebugFormat("[HG ASSET CONNECTOR]: Get {0}", id); 207 //m_log.DebugFormat("[HG ASSET CONNECTOR]: Get {0}", id);
207 AssetBase asset = null; 208 AssetBase asset = null;
208 209
209 if (m_Cache != null) 210 if (m_Cache != null)
210 { 211 {
211 asset = m_Cache.Get(id); 212 if (!m_Cache.Get(id, out asset))
213 return null;
212 214
213 if (asset != null) 215 if (asset != null)
214 return asset; 216 return asset;
@@ -237,20 +239,21 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
237 239
238 public AssetBase GetCached(string id) 240 public AssetBase GetCached(string id)
239 { 241 {
242 AssetBase asset = null;
240 if (m_Cache != null) 243 if (m_Cache != null)
241 return m_Cache.Get(id); 244 m_Cache.Get(id, out asset);
242 245
243 return null; 246 return asset;
244 } 247 }
245 248
246 public AssetMetadata GetMetadata(string id) 249 public AssetMetadata GetMetadata(string id)
247 { 250 {
248 AssetBase asset = null; 251 AssetBase asset = null;
249 252
250 if (m_Cache != null) 253 if (m_Cache != null)
251 { 254 {
252 if (m_Cache != null) 255 if (!m_Cache.Get(id, out asset))
253 m_Cache.Get(id); 256 return null;
254 257
255 if (asset != null) 258 if (asset != null)
256 return asset.Metadata; 259 return asset.Metadata;
@@ -269,11 +272,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
269 public byte[] GetData(string id) 272 public byte[] GetData(string id)
270 { 273 {
271 AssetBase asset = null; 274 AssetBase asset = null;
272 275
273 if (m_Cache != null) 276 if (m_Cache != null)
274 { 277 {
275 if (m_Cache != null) 278 if (!m_Cache.Get(id, out asset))
276 m_Cache.Get(id); 279 return null;
277 280
278 if (asset != null) 281 if (asset != null)
279 return asset.Data; 282 return asset.Data;
@@ -289,9 +292,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
289 public bool Get(string id, Object sender, AssetRetrieved handler) 292 public bool Get(string id, Object sender, AssetRetrieved handler)
290 { 293 {
291 AssetBase asset = null; 294 AssetBase asset = null;
292 295
293 if (m_Cache != null) 296 if (m_Cache != null)
294 asset = m_Cache.Get(id); 297 {
298 if (!m_Cache.Get(id, out asset))
299 return false;
300 }
295 301
296 if (asset != null) 302 if (asset != null)
297 { 303 {
@@ -338,23 +344,22 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
338 344
339 public string Store(AssetBase asset) 345 public string Store(AssetBase asset)
340 { 346 {
341 bool isHG = IsHG(asset.ID); 347 if (asset.Local || asset.Temporary)
342
343 if ((m_Cache != null) && !isHG)
344 // Don't store it in the cache if the asset is to
345 // be sent to the other grid, because this is already
346 // a copy of the local asset.
347 m_Cache.Cache(asset);
348
349 if (asset.Local)
350 { 348 {
351 if (m_Cache != null) 349 if (m_Cache != null)
352 m_Cache.Cache(asset); 350 m_Cache.Cache(asset);
353 return asset.ID; 351 return asset.ID;
354 } 352 }
355 353
354 bool isHG = IsHG(asset.ID);
355 if ((m_Cache != null) && !isHG)
356 // Don't store it in the cache if the asset is to
357 // be sent to the other grid, because this is already
358 // a copy of the local asset.
359 m_Cache.Cache(asset);
360
356 string id; 361 string id;
357 if (IsHG(asset.ID)) 362 if (isHG)
358 { 363 {
359 if (m_AssetPerms.AllowedExport(asset.Type)) 364 if (m_AssetPerms.AllowedExport(asset.Type))
360 id = m_HGService.Store(asset); 365 id = m_HGService.Store(asset);
@@ -366,21 +371,23 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
366 371
367 if (String.IsNullOrEmpty(id)) 372 if (String.IsNullOrEmpty(id))
368 return string.Empty; 373 return string.Empty;
369
370 asset.ID = id;
371 374
372 if (m_Cache != null) 375 if(asset.ID != id)
373 m_Cache.Cache(asset); 376 {
377 asset.ID = id;
378 if (m_Cache != null)
379 m_Cache.Cache(asset);
380 }
374 381
375 return id; 382 return id;
376 } 383 }
377 384
378 public bool UpdateContent(string id, byte[] data) 385 public bool UpdateContent(string id, byte[] data)
379 { 386 {
380 AssetBase asset = null; 387 AssetBase asset = null;
381 388
382 if (m_Cache != null) 389 if (m_Cache != null)
383 asset = m_Cache.Get(id); 390 m_Cache.Get(id, out asset);
384 391
385 if (asset != null) 392 if (asset != null)
386 { 393 {
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs
index 5f34450..37a48bb 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/LocalAssetServiceConnector.cs
@@ -44,13 +44,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
44 { 44 {
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 private IImprovedAssetCache m_Cache = null; 47 private IAssetCache m_Cache = null;
48 48
49 private IAssetService m_AssetService; 49 private IAssetService m_AssetService;
50 50
51 private bool m_Enabled = false; 51 private bool m_Enabled = false;
52 52
53 public Type ReplaceableInterface 53 public Type ReplaceableInterface
54 { 54 {
55 get { return null; } 55 get { return null; }
56 } 56 }
@@ -128,7 +128,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
128 128
129 if (m_Cache == null) 129 if (m_Cache == null)
130 { 130 {
131 m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>(); 131 m_Cache = scene.RequestModuleInterface<IAssetCache>();
132 132
133 if (!(m_Cache is ISharedRegionModule)) 133 if (!(m_Cache is ISharedRegionModule))
134 m_Cache = null; 134 m_Cache = null;
@@ -155,10 +155,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
155 public AssetBase Get(string id) 155 public AssetBase Get(string id)
156 { 156 {
157// m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Synchronously requesting asset {0}", id); 157// m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Synchronously requesting asset {0}", id);
158 158
159 AssetBase asset = null; 159 AssetBase asset = null;
160 if (m_Cache != null) 160 if (m_Cache != null)
161 asset = m_Cache.Get(id); 161 {
162 if (!m_Cache.Get(id, out asset))
163 return null;
164 }
162 165
163 if (asset == null) 166 if (asset == null)
164 { 167 {
@@ -169,7 +172,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
169// if (null == asset) 172// if (null == asset)
170// m_log.WarnFormat("[LOCAL ASSET SERVICES CONNECTOR]: Could not synchronously find asset with id {0}", id); 173// m_log.WarnFormat("[LOCAL ASSET SERVICES CONNECTOR]: Could not synchronously find asset with id {0}", id);
171 } 174 }
172 175
173 return asset; 176 return asset;
174 } 177 }
175 178
@@ -177,23 +180,27 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
177 { 180 {
178// m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Cache request for {0}", id); 181// m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Cache request for {0}", id);
179 182
183 AssetBase asset = null;
180 if (m_Cache != null) 184 if (m_Cache != null)
181 return m_Cache.Get(id); 185 m_Cache.Get(id, out asset);
182 186
183 return null; 187 return asset;
184 } 188 }
185 189
186 public AssetMetadata GetMetadata(string id) 190 public AssetMetadata GetMetadata(string id)
187 { 191 {
188 AssetBase asset = null; 192 AssetBase asset = null;
189 if (m_Cache != null) 193 if (m_Cache != null)
190 asset = m_Cache.Get(id); 194 {
195 if (!m_Cache.Get(id, out asset))
196 return null;
197 }
191 198
192 if (asset != null) 199 if (asset != null)
193 return asset.Metadata; 200 return asset.Metadata;
194 201
195 asset = m_AssetService.Get(id); 202 asset = m_AssetService.Get(id);
196 if (asset != null) 203 if (asset != null)
197 { 204 {
198 if (m_Cache != null) 205 if (m_Cache != null)
199 m_Cache.Cache(asset); 206 m_Cache.Cache(asset);
@@ -210,7 +217,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
210 AssetBase asset = null; 217 AssetBase asset = null;
211 218
212 if (m_Cache != null) 219 if (m_Cache != null)
213 asset = m_Cache.Get(id); 220 {
221 if (!m_Cache.Get(id, out asset))
222 return null;
223 }
214 224
215 if (asset != null) 225 if (asset != null)
216 return asset.Data; 226 return asset.Data;
@@ -229,10 +239,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
229 public bool Get(string id, Object sender, AssetRetrieved handler) 239 public bool Get(string id, Object sender, AssetRetrieved handler)
230 { 240 {
231// m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Asynchronously requesting asset {0}", id); 241// m_log.DebugFormat("[LOCAL ASSET SERVICES CONNECTOR]: Asynchronously requesting asset {0}", id);
232 242
233 if (m_Cache != null) 243 if (m_Cache != null)
234 { 244 {
235 AssetBase asset = m_Cache.Get(id); 245 AssetBase asset;
246 if (!m_Cache.Get(id, out asset))
247 return false;
236 248
237 if (asset != null) 249 if (asset != null)
238 { 250 {
@@ -264,7 +276,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
264 { 276 {
265 if (m_Cache != null) 277 if (m_Cache != null)
266 m_Cache.Cache(asset); 278 m_Cache.Cache(asset);
267 279
268 if (asset.Local) 280 if (asset.Local)
269 { 281 {
270// m_log.DebugFormat( 282// m_log.DebugFormat(
@@ -278,7 +290,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
278// m_log.DebugFormat( 290// m_log.DebugFormat(
279// "[LOCAL ASSET SERVICE CONNECTOR]: Passing {0} {1} on to asset service for storage, status Temporary = {2}, Local = {3}", 291// "[LOCAL ASSET SERVICE CONNECTOR]: Passing {0} {1} on to asset service for storage, status Temporary = {2}, Local = {3}",
280// asset.Name, asset.ID, asset.Temporary, asset.Local); 292// asset.Name, asset.ID, asset.Temporary, asset.Local);
281 293
282 return m_AssetService.Store(asset); 294 return m_AssetService.Store(asset);
283 } 295 }
284 } 296 }
@@ -287,7 +299,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
287 { 299 {
288 AssetBase asset = null; 300 AssetBase asset = null;
289 if (m_Cache != null) 301 if (m_Cache != null)
290 m_Cache.Get(id); 302 m_Cache.Get(id, out asset);
291 if (asset != null) 303 if (asset != null)
292 { 304 {
293 asset.Data = data; 305 asset.Data = data;
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RemoteAssetServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RemoteAssetServiceConnector.cs
index e6eeacf..1225ab5 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RemoteAssetServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Asset/RemoteAssetServiceConnector.cs
@@ -48,9 +48,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
48 MethodBase.GetCurrentMethod().DeclaringType); 48 MethodBase.GetCurrentMethod().DeclaringType);
49 49
50 private bool m_Enabled = false; 50 private bool m_Enabled = false;
51 private IImprovedAssetCache m_Cache; 51 private IAssetCache m_Cache;
52 52
53 public Type ReplaceableInterface 53 public Type ReplaceableInterface
54 { 54 {
55 get { return null; } 55 get { return null; }
56 } 56 }
@@ -111,7 +111,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Asset
111 111
112 if (m_Cache == null) 112 if (m_Cache == null)
113 { 113 {
114 m_Cache = scene.RequestModuleInterface<IImprovedAssetCache>(); 114 m_Cache = scene.RequestModuleInterface<IAssetCache>();
115 115
116 // Since we are a shared module and scene data is not 116 // Since we are a shared module and scene data is not
117 // available for every method, the cache must be shared, too 117 // available for every method, the cache must be shared, too
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs
index 16f42a7..8017245 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/LocalAuthenticationServiceConnector.cs
@@ -53,7 +53,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication
53 53
54 #region ISharedRegionModule 54 #region ISharedRegionModule
55 55
56 public Type ReplaceableInterface 56 public Type ReplaceableInterface
57 { 57 {
58 get { return null; } 58 get { return null; }
59 } 59 }
@@ -139,10 +139,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication
139 139
140 #region IAuthenticationService 140 #region IAuthenticationService
141 141
142 public string Authenticate(UUID principalID, string password, int lifetime, out UUID realID)
143 {
144 // Not implemented at the regions
145 realID = UUID.Zero;
146 return string.Empty;
147 }
148
142 public string Authenticate(UUID principalID, string password, int lifetime) 149 public string Authenticate(UUID principalID, string password, int lifetime)
143 { 150 {
144 // Not implemented at the regions 151 // Not implemented at the regions
145 return string.Empty; 152 return string.Empty;
146 } 153 }
147 154
148 public bool Verify(UUID principalID, string token, int lifetime) 155 public bool Verify(UUID principalID, string token, int lifetime)
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/RemoteAuthenticationServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/RemoteAuthenticationServiceConnector.cs
index 7cb8b22..fd1d802 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/RemoteAuthenticationServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authentication/RemoteAuthenticationServiceConnector.cs
@@ -47,7 +47,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authentication
47 47
48 private bool m_Enabled = false; 48 private bool m_Enabled = false;
49 49
50 public Type ReplaceableInterface 50 public Type ReplaceableInterface
51 { 51 {
52 get { return null; } 52 get { return null; }
53 } 53 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs
index 93dff1f..c910422 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/AuthorizationService.cs
@@ -69,7 +69,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
69 69
70 if (config != null) 70 if (config != null)
71 { 71 {
72 string accessStr = config.GetString("Region_" + scene.RegionInfo.RegionName.Replace(' ', '_'), String.Empty); 72 string defaultAccess = config.GetString("DefaultRegionAccess", "None");
73 string accessStr = config.GetString("Region_" + scene.RegionInfo.RegionName.Replace(' ', '_'), defaultAccess);
73 if (accessStr != string.Empty) 74 if (accessStr != string.Empty)
74 { 75 {
75 try 76 try
@@ -87,8 +88,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
87 } 88 }
88 89
89 public bool IsAuthorizedForRegion( 90 public bool IsAuthorizedForRegion(
90 string user, string firstName, string lastName, string regionID, out string message) 91 string user, string firstName, string lastName, string regionID, out string message, out bool isLocal)
91 { 92 {
93 UUID userID = new UUID(user);
94 isLocal = m_UserManagement.IsLocalGridUser(userID);
95
92 // This should not happen 96 // This should not happen
93 if (m_Scene.RegionInfo.RegionID.ToString() != regionID) 97 if (m_Scene.RegionInfo.RegionID.ToString() != regionID)
94 { 98 {
@@ -104,11 +108,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
104 return true; 108 return true;
105 } 109 }
106 110
107 UUID userID = new UUID(user);
108 111
109 if ((m_accessValue & AccessFlags.DisallowForeigners) != 0) 112 if ((m_accessValue & AccessFlags.DisallowForeigners) != 0)
110 { 113 {
111 if (!m_UserManagement.IsLocalGridUser(userID)) 114 if (!isLocal)
112 { 115 {
113 message = "No foreign users allowed in this region"; 116 message = "No foreign users allowed in this region";
114 return false; 117 return false;
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/LocalAuthorizationServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/LocalAuthorizationServiceConnector.cs
index 1acb695..b2be907 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/LocalAuthorizationServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/LocalAuthorizationServiceConnector.cs
@@ -53,7 +53,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
53 53
54 private bool m_Enabled = false; 54 private bool m_Enabled = false;
55 55
56 public Type ReplaceableInterface 56 public Type ReplaceableInterface
57 { 57 {
58 get { return null; } 58 get { return null; }
59 } 59 }
@@ -66,7 +66,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
66 public void Initialise(IConfigSource source) 66 public void Initialise(IConfigSource source)
67 { 67 {
68 m_log.Info("[AUTHORIZATION CONNECTOR]: Initialise"); 68 m_log.Info("[AUTHORIZATION CONNECTOR]: Initialise");
69 69
70 IConfig moduleConfig = source.Configs["Modules"]; 70 IConfig moduleConfig = source.Configs["Modules"];
71 if (moduleConfig != null) 71 if (moduleConfig != null)
72 { 72 {
@@ -114,13 +114,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
114 } 114 }
115 115
116 public bool IsAuthorizedForRegion( 116 public bool IsAuthorizedForRegion(
117 string userID, string firstName, string lastName, string regionID, out string message) 117 string userID, string firstName, string lastName, string regionID, out string message, out bool isLocal)
118 { 118 {
119 message = ""; 119 message = "";
120 isLocal = false;
120 if (!m_Enabled) 121 if (!m_Enabled)
121 return true; 122 return true;
122 123
123 return m_AuthorizationService.IsAuthorizedForRegion(userID, firstName, lastName, regionID, out message); 124 return m_AuthorizationService.IsAuthorizedForRegion(userID, firstName, lastName, regionID, out message, out isLocal);
124 } 125 }
125 } 126 }
126} \ No newline at end of file 127} \ No newline at end of file
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs
index b8d409d..3df3288 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Authorization/RemoteAuthorizationServiceConnector.cs
@@ -51,7 +51,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
51 private bool m_Enabled = false; 51 private bool m_Enabled = false;
52 private List<Scene> m_scenes = new List<Scene>(); 52 private List<Scene> m_scenes = new List<Scene>();
53 53
54 public Type ReplaceableInterface 54 public Type ReplaceableInterface
55 { 55 {
56 get { return null; } 56 get { return null; }
57 } 57 }
@@ -103,7 +103,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
103 m_scenes.Add(scene); 103 m_scenes.Add(scene);
104 scene.RegisterModuleInterface<IAuthorizationService>(this); 104 scene.RegisterModuleInterface<IAuthorizationService>(this);
105 } 105 }
106 106
107 } 107 }
108 108
109 public void RemoveRegion(Scene scene) 109 public void RemoveRegion(Scene scene)
@@ -118,16 +118,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
118 m_log.InfoFormat("[REMOTE AUTHORIZATION CONNECTOR]: Enabled remote authorization for region {0}", scene.RegionInfo.RegionName); 118 m_log.InfoFormat("[REMOTE AUTHORIZATION CONNECTOR]: Enabled remote authorization for region {0}", scene.RegionInfo.RegionName);
119 119
120 } 120 }
121 121
122 public bool IsAuthorizedForRegion( 122 public bool IsAuthorizedForRegion(
123 string userID, string firstName, string lastName, string regionID, out string message) 123 string userID, string firstName, string lastName, string regionID, out string message, out bool isLocal)
124 { 124 {
125 m_log.InfoFormat( 125 m_log.InfoFormat(
126 "[REMOTE AUTHORIZATION CONNECTOR]: IsAuthorizedForRegion checking {0} for region {1}", userID, regionID); 126 "[REMOTE AUTHORIZATION CONNECTOR]: IsAuthorizedForRegion checking {0} for region {1}", userID, regionID);
127 127
128 bool isAuthorized = true; 128 bool isAuthorized = true;
129 message = String.Empty; 129 message = String.Empty;
130 130
131 // get the scene this call is being made for 131 // get the scene this call is being made for
132 Scene scene = null; 132 Scene scene = null;
133 lock (m_scenes) 133 lock (m_scenes)
@@ -140,11 +140,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
140 } 140 }
141 } 141 }
142 } 142 }
143 143
144 isLocal = false;
144 if (scene != null) 145 if (scene != null)
145 { 146 {
146 string mail = String.Empty; 147 string mail = String.Empty;
147 148
148 UserAccount account = scene.UserAccountService.GetUserAccount(UUID.Zero, new UUID(userID)); 149 UserAccount account = scene.UserAccountService.GetUserAccount(UUID.Zero, new UUID(userID));
149 150
150 //if account not found, we assume its a foreign visitor from HG, else use account data... 151 //if account not found, we assume its a foreign visitor from HG, else use account data...
@@ -153,6 +154,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
153 mail = account.Email; 154 mail = account.Email;
154 firstName = account.FirstName; 155 firstName = account.FirstName;
155 lastName = account.LastName; 156 lastName = account.LastName;
157 isLocal = true;
156 } 158 }
157 159
158 isAuthorized 160 isAuthorized
@@ -165,7 +167,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Authorization
165 "[REMOTE AUTHORIZATION CONNECTOR] IsAuthorizedForRegion, can't find scene to match region id of {0}", 167 "[REMOTE AUTHORIZATION CONNECTOR] IsAuthorizedForRegion, can't find scene to match region id of {0}",
166 regionID); 168 regionID);
167 } 169 }
168 170
169 return isAuthorized; 171 return isAuthorized;
170 } 172 }
171 } 173 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs
index c3ef588..42f6c3f 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/LocalAvatarServiceConnector.cs
@@ -54,7 +54,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar
54 54
55 #region ISharedRegionModule 55 #region ISharedRegionModule
56 56
57 public Type ReplaceableInterface 57 public Type ReplaceableInterface
58 { 58 {
59 get { return null; } 59 get { return null; }
60 } 60 }
@@ -144,12 +144,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar
144 { 144 {
145 return m_AvatarService.GetAppearance(userID); 145 return m_AvatarService.GetAppearance(userID);
146 } 146 }
147 147
148 public bool SetAppearance(UUID userID, AvatarAppearance appearance) 148 public bool SetAppearance(UUID userID, AvatarAppearance appearance)
149 { 149 {
150 return m_AvatarService.SetAppearance(userID,appearance); 150 return m_AvatarService.SetAppearance(userID,appearance);
151 } 151 }
152 152
153 public AvatarData GetAvatar(UUID userID) 153 public AvatarData GetAvatar(UUID userID)
154 { 154 {
155 return m_AvatarService.GetAvatar(userID); 155 return m_AvatarService.GetAvatar(userID);
@@ -174,7 +174,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar
174 { 174 {
175 return m_AvatarService.RemoveItems(userID, names); 175 return m_AvatarService.RemoveItems(userID, names);
176 } 176 }
177 177
178 #endregion 178 #endregion
179 179
180 } 180 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/RemoteAvatarServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/RemoteAvatarServiceConnector.cs
index a087aea..37cfbbc 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/RemoteAvatarServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Avatar/RemoteAvatarServiceConnector.cs
@@ -47,7 +47,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar
47 47
48 private bool m_Enabled = false; 48 private bool m_Enabled = false;
49 49
50 public Type ReplaceableInterface 50 public Type ReplaceableInterface
51 { 51 {
52 get { return null; } 52 get { return null; }
53 } 53 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
index 1f782f5..d220568 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/LocalGridServiceConnector.cs
@@ -51,7 +51,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
51 private static string LogHeader = "[LOCAL GRID SERVICE CONNECTOR]"; 51 private static string LogHeader = "[LOCAL GRID SERVICE CONNECTOR]";
52 52
53 private IGridService m_GridService; 53 private IGridService m_GridService;
54 private Dictionary<UUID, RegionCache> m_LocalCache = new Dictionary<UUID, RegionCache>(); 54 private RegionInfoCache m_RegionInfoCache;
55 private HashSet<Scene> m_scenes = new HashSet<Scene>();
55 56
56 private bool m_Enabled; 57 private bool m_Enabled;
57 58
@@ -63,12 +64,18 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
63 public LocalGridServicesConnector(IConfigSource source) 64 public LocalGridServicesConnector(IConfigSource source)
64 { 65 {
65 m_log.DebugFormat("{0} LocalGridServicesConnector instantiated directly.", LogHeader); 66 m_log.DebugFormat("{0} LocalGridServicesConnector instantiated directly.", LogHeader);
66 InitialiseService(source); 67 InitialiseService(source, null);
68 }
69
70 public LocalGridServicesConnector(IConfigSource source, RegionInfoCache regionInfoCache)
71 {
72 m_log.DebugFormat("{0} LocalGridServicesConnector instantiated directly with cache.", LogHeader);
73 InitialiseService(source, regionInfoCache);
67 } 74 }
68 75
69 #region ISharedRegionModule 76 #region ISharedRegionModule
70 77
71 public Type ReplaceableInterface 78 public Type ReplaceableInterface
72 { 79 {
73 get { return null; } 80 get { return null; }
74 } 81 }
@@ -86,19 +93,24 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
86 string name = moduleConfig.GetString("GridServices", ""); 93 string name = moduleConfig.GetString("GridServices", "");
87 if (name == Name) 94 if (name == Name)
88 { 95 {
89 InitialiseService(source); 96 if(InitialiseService(source, null))
90 m_log.Info("[LOCAL GRID SERVICE CONNECTOR]: Local grid connector enabled"); 97 m_log.Info("[LOCAL GRID SERVICE CONNECTOR]: Local grid connector enabled");
91 } 98 }
92 } 99 }
93 } 100 }
94 101
95 private void InitialiseService(IConfigSource source) 102 private bool InitialiseService(IConfigSource source, RegionInfoCache ric)
96 { 103 {
104 if(ric == null && m_RegionInfoCache == null)
105 m_RegionInfoCache = new RegionInfoCache();
106 else
107 m_RegionInfoCache = ric;
108
97 IConfig config = source.Configs["GridService"]; 109 IConfig config = source.Configs["GridService"];
98 if (config == null) 110 if (config == null)
99 { 111 {
100 m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: GridService missing from OpenSim.ini"); 112 m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: GridService missing from OpenSim.ini");
101 return; 113 return false;
102 } 114 }
103 115
104 string serviceDll = config.GetString("LocalServiceModule", String.Empty); 116 string serviceDll = config.GetString("LocalServiceModule", String.Empty);
@@ -106,7 +118,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
106 if (serviceDll == String.Empty) 118 if (serviceDll == String.Empty)
107 { 119 {
108 m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: No LocalServiceModule named in section GridService"); 120 m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: No LocalServiceModule named in section GridService");
109 return; 121 return false;
110 } 122 }
111 123
112 Object[] args = new Object[] { source }; 124 Object[] args = new Object[] { source };
@@ -117,19 +129,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
117 if (m_GridService == null) 129 if (m_GridService == null)
118 { 130 {
119 m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: Can't load grid service"); 131 m_log.Error("[LOCAL GRID SERVICE CONNECTOR]: Can't load grid service");
120 return; 132 return false;
121 } 133 }
122 134
123 m_Enabled = true; 135 m_Enabled = true;
136 return true;
124 } 137 }
125 138
126 public void PostInitialise() 139 public void PostInitialise()
127 { 140 {
128 // FIXME: We will still add this command even if we aren't enabled since RemoteGridServiceConnector
129 // will have instantiated us directly.
130 MainConsole.Instance.Commands.AddCommand("Regions", false, "show neighbours",
131 "show neighbours",
132 "Shows the local regions' neighbours", HandleShowNeighboursCommand);
133 } 141 }
134 142
135 public void Close() 143 public void Close()
@@ -141,15 +149,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
141 if (!m_Enabled) 149 if (!m_Enabled)
142 return; 150 return;
143 151
144 scene.RegisterModuleInterface<IGridService>(this); 152 lock(m_scenes)
145
146 lock (m_LocalCache)
147 { 153 {
148 if (m_LocalCache.ContainsKey(scene.RegionInfo.RegionID)) 154 if(!m_scenes.Contains(scene))
149 m_log.ErrorFormat("[LOCAL GRID SERVICE CONNECTOR]: simulator seems to have more than one region with the same UUID. Please correct this!"); 155 m_scenes.Add(scene);
150 else
151 m_LocalCache.Add(scene.RegionInfo.RegionID, new RegionCache(scene));
152 } 156 }
157 scene.RegisterModuleInterface<IGridService>(this);
158
159 GridRegion r = new GridRegion(scene.RegionInfo);
160 m_RegionInfoCache.CacheLocal(r);
161
162 scene.EventManager.OnRegionUp += OnRegionUp;
153 } 163 }
154 164
155 public void RemoveRegion(Scene scene) 165 public void RemoveRegion(Scene scene)
@@ -157,11 +167,14 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
157 if (!m_Enabled) 167 if (!m_Enabled)
158 return; 168 return;
159 169
160 lock (m_LocalCache) 170 lock(m_scenes)
161 { 171 {
162 m_LocalCache[scene.RegionInfo.RegionID].Clear(); 172 if(m_scenes.Contains(scene))
163 m_LocalCache.Remove(scene.RegionInfo.RegionID); 173 m_scenes.Remove(scene);
164 } 174 }
175
176 m_RegionInfoCache.Remove(scene.RegionInfo.ScopeID, scene.RegionInfo.RegionHandle);
177 scene.EventManager.OnRegionUp -= OnRegionUp;
165 } 178 }
166 179
167 public void RegionLoaded(Scene scene) 180 public void RegionLoaded(Scene scene)
@@ -172,6 +185,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
172 185
173 #region IGridService 186 #region IGridService
174 187
188 private void OnRegionUp(GridRegion region)
189 {
190 // This shouldn't happen
191 if (region == null)
192 return;
193
194 m_RegionInfoCache.CacheNearNeighbour(region.ScopeID, region);
195 }
196
175 public string RegisterRegion(UUID scopeID, GridRegion regionInfo) 197 public string RegisterRegion(UUID scopeID, GridRegion regionInfo)
176 { 198 {
177 return m_GridService.RegisterRegion(scopeID, regionInfo); 199 return m_GridService.RegisterRegion(scopeID, regionInfo);
@@ -184,12 +206,20 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
184 206
185 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID) 207 public List<GridRegion> GetNeighbours(UUID scopeID, UUID regionID)
186 { 208 {
187 return m_GridService.GetNeighbours(scopeID, regionID); 209 return m_GridService.GetNeighbours(scopeID, regionID);
188 } 210 }
189 211
190 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) 212 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
191 { 213 {
192 return m_GridService.GetRegionByUUID(scopeID, regionID); 214 bool inCache = false;
215 GridRegion rinfo = m_RegionInfoCache.Get(scopeID,regionID,out inCache);
216 if (inCache)
217 return rinfo;
218
219 rinfo = m_GridService.GetRegionByUUID(scopeID, regionID);
220 if(rinfo != null)
221 m_RegionInfoCache.Cache(scopeID, rinfo);
222 return rinfo;
193 } 223 }
194 224
195 // Get a region given its base coordinates. 225 // Get a region given its base coordinates.
@@ -197,59 +227,30 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
197 // be the base coordinate of the region. 227 // be the base coordinate of the region.
198 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) 228 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
199 { 229 {
200 GridRegion region = null;
201 uint regionX = Util.WorldToRegionLoc((uint)x);
202 uint regionY = Util.WorldToRegionLoc((uint)y);
203 230
204 // Sanity check 231 bool inCache = false;
205 if ((Util.RegionToWorldLoc(regionX) != (uint)x) || (Util.RegionToWorldLoc(regionY) != (uint)y)) 232 GridRegion rinfo = m_RegionInfoCache.Get(scopeID, (uint)x, (uint)y, out inCache);
206 { 233 if (inCache)
207 m_log.WarnFormat("{0} GetRegionByPosition. Bad position requested: not the base of the region. Requested Pos=<{1},{2}>, Should Be=<{3},{4}>", 234 return rinfo;
208 LogHeader, x, y, Util.RegionToWorldLoc(regionX), Util.RegionToWorldLoc(regionY));
209 }
210
211 // First see if it's a neighbour, even if it isn't on this sim.
212 // Neighbour data is cached in memory, so this is fast
213
214 lock (m_LocalCache)
215 {
216 foreach (RegionCache rcache in m_LocalCache.Values)
217 {
218 region = rcache.GetRegionByPosition(x, y);
219 if (region != null)
220 {
221 m_log.DebugFormat("{0} GetRegionByPosition. Found region {1} in cache (of region {2}). Pos=<{3},{4}>",
222 LogHeader, region.RegionName, rcache.RegionName,
223 Util.WorldToRegionLoc((uint)region.RegionLocX), Util.WorldToRegionLoc((uint)region.RegionLocY));
224 break;
225 }
226 }
227 }
228 235
229 // Then try on this sim (may be a lookup in DB if this is using MySql). 236 // Then try on this sim (may be a lookup in DB if this is using MySql).
230 if (region == null) 237 rinfo = m_GridService.GetRegionByPosition(scopeID, x, y);
231 { 238 if(rinfo != null)
232 region = m_GridService.GetRegionByPosition(scopeID, x, y); 239 m_RegionInfoCache.Cache(scopeID, rinfo);
233 240 return rinfo;
234 if (region == null)
235 {
236 m_log.DebugFormat("{0} GetRegionByPosition. Region not found by grid service. Pos=<{1},{2}>",
237 LogHeader, regionX, regionY);
238 }
239 else
240 {
241 m_log.DebugFormat("{0} GetRegionByPosition. Got region {1} from grid service. Pos=<{2},{3}>",
242 LogHeader, region.RegionName,
243 Util.WorldToRegionLoc((uint)region.RegionLocX), Util.WorldToRegionLoc((uint)region.RegionLocY));
244 }
245 }
246
247 return region;
248 } 241 }
249 242
250 public GridRegion GetRegionByName(UUID scopeID, string regionName) 243 public GridRegion GetRegionByName(UUID scopeID, string regionName)
251 { 244 {
252 return m_GridService.GetRegionByName(scopeID, regionName); 245 bool inCache = false;
246 GridRegion rinfo = m_RegionInfoCache.Get(scopeID, regionName, out inCache);
247 if (inCache)
248 return rinfo;
249
250 rinfo = m_GridService.GetRegionByName(scopeID, regionName);
251 if(rinfo != null)
252 m_RegionInfoCache.Cache(scopeID, rinfo);
253 return rinfo;
253 } 254 }
254 255
255 public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber) 256 public List<GridRegion> GetRegionsByName(UUID scopeID, string name, int maxNumber)
@@ -281,7 +282,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
281 { 282 {
282 return m_GridService.GetHyperlinks(scopeID); 283 return m_GridService.GetHyperlinks(scopeID);
283 } 284 }
284 285
285 public int GetRegionFlags(UUID scopeID, UUID regionID) 286 public int GetRegionFlags(UUID scopeID, UUID regionID)
286 { 287 {
287 return m_GridService.GetRegionFlags(scopeID, regionID); 288 return m_GridService.GetRegionFlags(scopeID, regionID);
@@ -294,22 +295,5 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
294 295
295 #endregion 296 #endregion
296 297
297 public void HandleShowNeighboursCommand(string module, string[] cmdparams)
298 {
299 System.Text.StringBuilder caps = new System.Text.StringBuilder();
300
301 lock (m_LocalCache)
302 {
303 foreach (KeyValuePair<UUID, RegionCache> kvp in m_LocalCache)
304 {
305 caps.AppendFormat("*** Neighbours of {0} ({1}) ***\n", kvp.Value.RegionName, kvp.Key);
306 List<GridRegion> regions = kvp.Value.GetNeighbours();
307 foreach (GridRegion r in regions)
308 caps.AppendFormat(" {0} @ {1}-{2}\n", r.RegionName, Util.WorldToRegionLoc((uint)r.RegionLocX), Util.WorldToRegionLoc((uint)r.RegionLocY));
309 }
310 }
311
312 MainConsole.Instance.Output(caps.ToString());
313 }
314 } 298 }
315} 299}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs
deleted file mode 100644
index ae76288..0000000
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionCache.cs
+++ /dev/null
@@ -1,102 +0,0 @@
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.Collections.Generic;
30using System.Reflection;
31
32using OpenSim.Framework;
33using OpenSim.Region.Framework.Scenes;
34using OpenSim.Services.Interfaces;
35using GridRegion = OpenSim.Services.Interfaces.GridRegion;
36
37using OpenMetaverse;
38using log4net;
39
40namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
41{
42 public class RegionCache
43 {
44 private static readonly ILog m_log =
45 LogManager.GetLogger(
46 MethodBase.GetCurrentMethod().DeclaringType);
47
48 private Scene m_scene;
49 private Dictionary<ulong, GridRegion> m_neighbours = new Dictionary<ulong, GridRegion>();
50
51 public string RegionName
52 {
53 get { return m_scene.RegionInfo.RegionName; }
54 }
55
56 public RegionCache(Scene s)
57 {
58 m_scene = s;
59 m_scene.EventManager.OnRegionUp += OnRegionUp;
60 }
61
62 private void OnRegionUp(GridRegion otherRegion)
63 {
64 // This shouldn't happen
65 if (otherRegion == null)
66 return;
67
68 m_log.DebugFormat("[REGION CACHE]: (on region {0}) Region {1} is up @ {2}-{3}",
69 m_scene.RegionInfo.RegionName, otherRegion.RegionName, Util.WorldToRegionLoc((uint)otherRegion.RegionLocX), Util.WorldToRegionLoc((uint)otherRegion.RegionLocY));
70
71 m_neighbours[otherRegion.RegionHandle] = otherRegion;
72 }
73
74 public void Clear()
75 {
76 m_scene.EventManager.OnRegionUp -= OnRegionUp;
77 m_neighbours.Clear();
78 }
79
80 public List<GridRegion> GetNeighbours()
81 {
82 return new List<GridRegion>(m_neighbours.Values);
83 }
84
85 // Get a region given its base coordinates (in meters).
86 // NOTE: this is NOT 'get a region by some point in the region'. The coordinate MUST
87 // be the base coordinate of the region.
88 // The snapping is technically unnecessary but is harmless because regions are always
89 // multiples of the legacy region size (256).
90 public GridRegion GetRegionByPosition(int x, int y)
91 {
92 uint xsnap = (uint)(x / Constants.RegionSize) * Constants.RegionSize;
93 uint ysnap = (uint)(y / Constants.RegionSize) * Constants.RegionSize;
94 ulong handle = Util.RegionWorldLocToHandle(xsnap, ysnap);
95
96 if (m_neighbours.ContainsKey(handle))
97 return m_neighbours[handle];
98
99 return null;
100 }
101 }
102}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs
index be8a9a2..f6fff58 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RegionInfoCache.cs
@@ -26,6 +26,8 @@
26 */ 26 */
27using System; 27using System;
28using System.Reflection; 28using System.Reflection;
29using System.Threading;
30using System.Runtime.InteropServices;
29using System.Collections.Generic; 31using System.Collections.Generic;
30using OpenSim.Framework; 32using OpenSim.Framework;
31using OpenSim.Services.Interfaces; 33using OpenSim.Services.Interfaces;
@@ -37,82 +39,68 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
37{ 39{
38 public class RegionInfoCache 40 public class RegionInfoCache
39 { 41 {
40 private const double CACHE_EXPIRATION_SECONDS = 300.0; // 5 minutes 42 private const float CACHE_EXPIRATION_SECONDS = 120; // 2 minutes opensim regions change a lot
41 43
42// private static readonly ILog m_log = 44// private static readonly ILog m_log =
43// LogManager.GetLogger( 45// LogManager.GetLogger(
44// MethodBase.GetCurrentMethod().DeclaringType); 46// MethodBase.GetCurrentMethod().DeclaringType);
45 47
46 internal struct ScopedRegionUUID 48 private static RegionsExpiringCache m_Cache;
49 private int numberInstances;
50
51 public RegionInfoCache()
47 { 52 {
48 public UUID m_scopeID; 53 if(m_Cache == null)
49 public UUID m_regionID; 54 m_Cache = new RegionsExpiringCache();
50 public ScopedRegionUUID(UUID scopeID, UUID regionID) 55 numberInstances++;
51 {
52 m_scopeID = scopeID;
53 m_regionID = regionID;
54 }
55 } 56 }
56 57
57 internal struct ScopedRegionName 58 public void Cache(GridRegion rinfo)
58 { 59 {
59 public UUID m_scopeID; 60 if (rinfo != null)
60 public string m_name; 61 this.Cache(rinfo.ScopeID, rinfo);
61 public ScopedRegionName(UUID scopeID, string name)
62 {
63 m_scopeID = scopeID;
64 m_name = name;
65 }
66 } 62 }
67 63
68 internal struct ScopedRegionPosition 64 public void Cache(UUID scopeID, GridRegion rinfo)
69 { 65 {
70 public UUID m_scopeID; 66 if (rinfo == null)
71 public ulong m_regionHandle; 67 return;
72 public ScopedRegionPosition(UUID scopeID, ulong handle)
73 {
74 m_scopeID = scopeID;
75 m_regionHandle = handle;
76 }
77 }
78 68
79 private ExpiringCache<ScopedRegionUUID, GridRegion> m_UUIDCache; 69 m_Cache.AddOrUpdate(scopeID, rinfo, CACHE_EXPIRATION_SECONDS);
80 private ExpiringCache<ScopedRegionName, ScopedRegionUUID> m_NameCache; 70 }
81 private ExpiringCache<ScopedRegionPosition, GridRegion> m_PositionCache;
82 71
83 public RegionInfoCache() 72 public void CacheLocal(GridRegion rinfo)
84 { 73 {
85 m_UUIDCache = new ExpiringCache<ScopedRegionUUID, GridRegion>(); 74 if (rinfo == null)
86 m_NameCache = new ExpiringCache<ScopedRegionName, ScopedRegionUUID>(); 75 return;
87 m_PositionCache = new ExpiringCache<ScopedRegionPosition, GridRegion>(); 76
77 m_Cache.AddOrUpdate(rinfo.ScopeID, rinfo, 1e7f);
88 } 78 }
89 79
90 public void Cache(GridRegion rinfo) 80 public void CacheNearNeighbour(UUID scopeID, GridRegion rinfo)
91 { 81 {
92 if (rinfo != null) 82 if (rinfo == null)
93 this.Cache(rinfo.ScopeID,rinfo.RegionID,rinfo); 83 return;
84
85 m_Cache.AddOrUpdate(scopeID, rinfo, CACHE_EXPIRATION_SECONDS);
94 } 86 }
95 87
96 public void Cache(UUID scopeID, UUID regionID, GridRegion rinfo) 88 public void Cache(UUID scopeID, GridRegion rinfo, float expireSeconds)
97 { 89 {
98 // for now, do not cache negative results; this is because
99 // we need to figure out how to handle regions coming online
100 // in a timely way
101 if (rinfo == null) 90 if (rinfo == null)
102 return; 91 return;
103
104 ScopedRegionUUID id = new ScopedRegionUUID(scopeID,regionID);
105
106 // Cache even null accounts
107 m_UUIDCache.AddOrUpdate(id, rinfo, CACHE_EXPIRATION_SECONDS);
108 if (rinfo != null)
109 {
110 ScopedRegionName name = new ScopedRegionName(scopeID,rinfo.RegionName);
111 m_NameCache.AddOrUpdate(name, id, CACHE_EXPIRATION_SECONDS);
112 92
113 ScopedRegionPosition pos = new ScopedRegionPosition(scopeID, rinfo.RegionHandle); 93 m_Cache.AddOrUpdate(scopeID, rinfo, expireSeconds);
114 m_PositionCache.AddOrUpdate(pos, rinfo, CACHE_EXPIRATION_SECONDS); 94 }
115 } 95
96 public void Remove(UUID scopeID, GridRegion rinfo)
97 {
98 m_Cache.Remove(scopeID, rinfo);
99 }
100
101 public void Remove(UUID scopeID, ulong regionHandle)
102 {
103 m_Cache.Remove(scopeID, regionHandle);
116 } 104 }
117 105
118 public GridRegion Get(UUID scopeID, UUID regionID, out bool inCache) 106 public GridRegion Get(UUID scopeID, UUID regionID, out bool inCache)
@@ -120,8 +108,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
120 inCache = false; 108 inCache = false;
121 109
122 GridRegion rinfo = null; 110 GridRegion rinfo = null;
123 ScopedRegionUUID id = new ScopedRegionUUID(scopeID,regionID); 111 if (m_Cache.TryGetValue(scopeID, regionID, out rinfo))
124 if (m_UUIDCache.TryGetValue(id, out rinfo))
125 { 112 {
126 inCache = true; 113 inCache = true;
127 return rinfo; 114 return rinfo;
@@ -135,8 +122,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
135 inCache = false; 122 inCache = false;
136 123
137 GridRegion rinfo = null; 124 GridRegion rinfo = null;
138 ScopedRegionPosition pos = new ScopedRegionPosition(scopeID, handle); 125 if (m_Cache.TryGetValue(scopeID, handle, out rinfo))
139 if (m_PositionCache.TryGetValue(pos, out rinfo))
140 { 126 {
141 inCache = true; 127 inCache = true;
142 return rinfo; 128 return rinfo;
@@ -145,25 +131,868 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
145 return null; 131 return null;
146 } 132 }
147 133
148
149 public GridRegion Get(UUID scopeID, string name, out bool inCache) 134 public GridRegion Get(UUID scopeID, string name, out bool inCache)
150 { 135 {
151 inCache = false; 136 inCache = false;
152 137
153 ScopedRegionName sname = new ScopedRegionName(scopeID,name); 138 GridRegion rinfo = null;
139 if (m_Cache.TryGetValue(scopeID, name, out rinfo))
140 {
141 inCache = true;
142 return rinfo;
143 }
144
145 return null;
146 }
147
148 public GridRegion Get(UUID scopeID, uint x, uint y, out bool inCache)
149 {
150 inCache = false;
151
152 GridRegion rinfo = null;
153 if (m_Cache.TryGetValue(scopeID, x, y, out rinfo))
154 {
155 inCache = true;
156 return rinfo;
157 }
158
159 return null;
160 }
161 }
162
163 // dont care about endianess
164 [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 8)]
165 public class fastRegionHandle
166 {
167 [FieldOffset(0)] public ulong handle;
168 [FieldOffset(0)] public uint y;
169 [FieldOffset(4)] public uint x;
170
171 public fastRegionHandle(ulong h)
172 {
173 handle = h;
174 }
175
176 public fastRegionHandle(uint px, uint py)
177 {
178 y = py & 0xffffff00;
179 x = px & 0xffffff00;
180 }
181 // actually do care
182 public ulong toHandle()
183 {
184 if(BitConverter.IsLittleEndian)
185 return handle;
186 return (ulong) x << 32 | (ulong)y ;
187 }
188
189 public static bool operator ==(fastRegionHandle value1, fastRegionHandle value2)
190 {
191 return value1.handle == value2.handle;
192 }
193 public static bool operator !=(fastRegionHandle value1, fastRegionHandle value2)
194 {
195 return value1.handle != value2.handle;
196 }
197 public override int GetHashCode()
198 {
199 return handle.GetHashCode();
200 }
201 public override bool Equals(Object obj)
202 {
203 if(obj == null)
204 return false;
205 fastRegionHandle p = obj as fastRegionHandle;
206 return p.handle == handle;
207 }
208 }
209
210/*
211 [StructLayout(LayoutKind.Explicit, Size = 8, Pack = 8)]
212 public class regionHandle
213 {
214 [FieldOffset(0)] private ulong handle;
215 [FieldOffset(0)] public uint a;
216 [FieldOffset(4)] public uint b;
217
218 public regionHandle(ulong h)
219 {
220 handle = h;
221 }
222
223 public regionHandle(uint px, uint py)
224 {
225 if(BitConverter.IsLittleEndian)
226 {
227 a = py & 0xffffff00;
228 b = px & 0xffffff00;
229 }
230 else
231 {
232 a = px & 0xffffff00;
233 b = py & 0xffffff00;
234 }
235 }
236
237 public uint x
238 {
239 get
240 {
241 if(BitConverter.IsLittleEndian)
242 return b;
243 return a;
244 }
245 set
246 {
247 if(BitConverter.IsLittleEndian)
248 b = value & 0xffffff00;
249 else
250 a = value & 0xffffff00;
251 }
252 }
253
254 public uint y
255 {
256 get
257 {
258 if(BitConverter.IsLittleEndian)
259 return a;
260 return b;
261 }
262 set
263 {
264 if(BitConverter.IsLittleEndian)
265 a = value;
266 else
267 b = value;
268 }
269 }
270
271 public static bool operator ==(regionHandle value1, regionHandle value2)
272 {
273 return value1.handle == value2.handle;
274 }
275 public static bool operator !=(regionHandle value1, regionHandle value2)
276 {
277 return value1.handle != value2.handle;
278 }
279 public override int GetHashCode()
280 {
281 return handle.GetHashCode();
282 }
283 public override bool Equals(Object obj)
284 {
285 if(obj == null)
286 return false;
287 regionHandle p = obj as regionHandle;
288 return p.handle == handle;
289 }
290 }
291*/
292
293 public class RegionInfoForScope
294 {
295 public const ulong HANDLEMASK = 0xffffff00ffffff00ul;
296 public const ulong HANDLECOORDMASK = 0xffffff00ul;
297
298 private Dictionary<ulong, GridRegion> storage;
299 private Dictionary<ulong, DateTime> expires;
300 private Dictionary<string, ulong> byname;
301 private Dictionary<UUID, ulong> byuuid;
302 // includes handles to the inside of large regions
303 private Dictionary<ulong, ulong> innerHandles = new Dictionary<ulong, ulong>();
304
305 public RegionInfoForScope()
306 {
307 storage = new Dictionary<ulong, GridRegion>();
308 expires = new Dictionary<ulong, DateTime>();
309 byname = new Dictionary<string, ulong>();
310 byuuid = new Dictionary<UUID, ulong>();
311 }
312
313 public RegionInfoForScope(GridRegion region, DateTime expire)
314 {
315 storage = new Dictionary<ulong, GridRegion>();
316 expires = new Dictionary<ulong, DateTime>();
317 byname = new Dictionary<string, ulong>();
318 byuuid = new Dictionary<UUID, ulong>();
319
320 ulong handle = region.RegionHandle & HANDLEMASK;
321 storage[handle] = region;
322 expires[handle] = expire;
323 byname[region.RegionName] = handle;
324 byuuid[region.RegionID] = handle;
325 addToInner(region);
326 }
327
328 public void Add(GridRegion region, DateTime expire)
329 {
330 ulong handle = region.RegionHandle & HANDLEMASK;
331
332 if(storage != null && storage.ContainsKey(handle))
333 return;
334
335 if(storage == null)
336 storage = new Dictionary<ulong, GridRegion>();
337 if(expires == null)
338 expires = new Dictionary<ulong, DateTime>();
339 if(byname == null)
340 byname = new Dictionary<string, ulong>();
341 if(byuuid == null)
342 byuuid = new Dictionary<UUID, ulong>();
343
344 storage[handle] = region;
345 expires[handle] = expire;
346 byname[region.RegionName] = handle;
347 byuuid[region.RegionID] = handle;
348
349 addToInner(region);
350 }
351
352 public void AddUpdate(GridRegion region, DateTime expire)
353 {
354 if(storage == null)
355 storage = new Dictionary<ulong, GridRegion>();
356 if(expires == null)
357 expires = new Dictionary<ulong, DateTime>();
358 if(byname == null)
359 byname = new Dictionary<string, ulong>();
360 if(byuuid == null)
361 byuuid = new Dictionary<UUID, ulong>();
362
363 ulong handle = region.RegionHandle & HANDLEMASK;
154 364
155 ScopedRegionUUID id; 365 if(expires.ContainsKey(handle))
156 if (m_NameCache.TryGetValue(sname, out id))
157 { 366 {
158 GridRegion rinfo = null; 367 if(expires[handle] < expire)
159 if (m_UUIDCache.TryGetValue(id, out rinfo)) 368 expires[handle] = expire;
369 if(storage.ContainsKey(handle))
160 { 370 {
161 inCache = true; 371 GridRegion oldr = storage[handle];
162 return rinfo; 372 if (oldr.RegionSizeX != region.RegionSizeX
373 || oldr.RegionSizeY != region.RegionSizeY)
374 {
375 removeFromInner(oldr);
376 addToInner(region);
377 }
163 } 378 }
164 } 379 }
165 380 else
381 {
382 expires[handle] = expire;
383 addToInner(region);
384 }
385 storage[handle] = region;
386 byname[region.RegionName] = handle;
387 byuuid[region.RegionID] = handle;
388 }
389
390 public void Remove(GridRegion region)
391 {
392 if(region == null)
393 return;
394
395 if(byname != null)
396 byname.Remove(region.RegionName);
397 if(byuuid != null)
398 byuuid.Remove(region.RegionID);
399
400 ulong handle = region.RegionHandle & HANDLEMASK;
401 if(storage != null)
402 {
403 if(storage.ContainsKey(handle))
404 {
405 storage[handle] = null;
406 storage.Remove(handle);
407 }
408 }
409 removeFromInner(region);
410 if(expires != null)
411 {
412 expires.Remove(handle);
413 if(expires.Count == 0)
414 Clear();
415 }
416 }
417
418 public void Remove(ulong handle)
419 {
420 handle &= HANDLEMASK;
421
422 if(storage != null)
423 {
424 if(storage.ContainsKey(handle))
425 {
426 GridRegion r = storage[handle];
427 if(byname != null)
428 byname.Remove(r.RegionName);
429 if(byuuid != null)
430 byuuid.Remove(r.RegionID);
431 removeFromInner(r);
432 storage[handle] = null;
433 }
434 storage.Remove(handle);
435 }
436 if(expires != null)
437 {
438 expires.Remove(handle);
439 if(expires.Count == 0)
440 Clear();
441 }
442 }
443
444 public void Clear()
445 {
446 if(expires != null)
447 expires.Clear();
448 if(storage != null)
449 storage.Clear();
450 if(byname != null)
451 byname.Clear();
452 if(byuuid != null)
453 byuuid.Clear();
454 byname = null;
455 byuuid = null;
456 storage = null;
457 expires = null;
458 innerHandles.Clear();
459 }
460
461 public bool Contains(GridRegion region)
462 {
463 if(storage == null)
464 return false;
465 if(region == null)
466 return false;
467
468 ulong handle = region.RegionHandle & HANDLEMASK;
469 return storage.ContainsKey(handle);
470 }
471
472 public bool Contains(ulong handle)
473 {
474 if(storage == null)
475 return false;
476
477 handle &= HANDLEMASK;
478 return storage.ContainsKey(handle);
479 }
480
481 public GridRegion get(ulong handle)
482 {
483 if(storage == null)
484 return null;
485
486 handle &= HANDLEMASK;
487 if(storage.ContainsKey(handle))
488 return storage[handle];
489
490 if(!innerHandles.ContainsKey(handle))
491 return null;
492
493 ulong rhandle = innerHandles[handle];
494 if(storage.ContainsKey(rhandle))
495 return storage[rhandle];
496
166 return null; 497 return null;
167 } 498 }
499
500 public GridRegion get(string name)
501 {
502 if(byname == null || !byname.ContainsKey(name))
503 return null;
504
505 ulong handle = byname[name];
506 if(storage.ContainsKey(handle))
507 return storage[handle];
508 return null;
509 }
510
511 public GridRegion get(UUID id)
512 {
513 if(byuuid == null || !byuuid.ContainsKey(id))
514 return null;
515
516 ulong handle = byuuid[id];
517 if(storage.ContainsKey(handle))
518 return storage[handle];
519 return null;
520 }
521
522 public GridRegion get(uint x, uint y)
523 {
524 if(storage == null)
525 return null;
526
527 // look for a handle first this should find normal size regions
528 ulong handle = (ulong)x & HANDLECOORDMASK;
529 handle <<= 32;
530 handle |= ((ulong)y & HANDLECOORDMASK);
531
532 if(storage.ContainsKey(handle))
533 return storage[handle];
534
535 if(!innerHandles.ContainsKey(handle))
536 return null;
537
538 ulong rhandle = innerHandles[handle];
539 if(!storage.ContainsKey(rhandle))
540 return null;
541
542 GridRegion r = storage[rhandle];
543 if(r == null)
544 return null;
545
546 // extra check, possible redundant
547
548 int test = r.RegionLocX;
549 if(x < test)
550 return null;
551 test += r.RegionSizeX;
552 if(x >= test)
553 return null;
554 test = r.RegionLocY;
555 if (y < test)
556 return null;
557 test += r.RegionSizeY;
558 if (y < test)
559 return r;
560
561/*
562 // next do the harder work
563 foreach(KeyValuePair<ulong, GridRegion> kvp in storage)
564 {
565 GridRegion r = kvp.Value;
566 if(r == null) // ??
567 continue;
568
569 int test = r.RegionLocX;
570 if(x < test)
571 continue;
572 test += r.RegionSizeX;
573 if(x >= test)
574 continue;
575 test = r.RegionLocY;
576 if (y < test)
577 continue;
578 test += r.RegionSizeY;
579 if (y < test)
580 return r;
581 }
582*/
583 return null;
584 }
585
586 public int expire(DateTime now )
587 {
588 if(expires == null || expires.Count == 0)
589 return 0;
590
591 int expiresCount = expires.Count;
592 List<ulong> toexpire = new List<ulong>();
593
594 foreach(KeyValuePair<ulong, DateTime> kvp in expires)
595 {
596 if(kvp.Value < now)
597 toexpire.Add(kvp.Key);
598 }
599
600 int toexpireCount = toexpire.Count;
601 if(toexpireCount == 0)
602 return expiresCount;
603
604 if(toexpireCount == expiresCount)
605 {
606 Clear();
607 return 0;
608 }
609
610 if(storage != null)
611 {
612 ulong h;
613 for(int i = 0; i < toexpireCount; i++)
614 {
615 h = toexpire[i];
616 if(storage.ContainsKey(h))
617 {
618 GridRegion r = storage[h];
619 if(byname != null)
620 byname.Remove(r.RegionName);
621 if(byuuid != null)
622 byuuid.Remove(r.RegionID);
623 removeFromInner(r);
624
625 storage[h] = null;
626 storage.Remove(h);
627 }
628 if(expires != null)
629 expires.Remove(h);
630 }
631 }
632 else
633 {
634 Clear();
635 return 0;
636 }
637
638 expiresCount = expires.Count;
639 if(expiresCount == 0)
640 {
641 byname = null;
642 byuuid = null;
643 storage = null;
644 expires = null;
645 return 0;
646 }
647
648 return expiresCount;
649 }
650
651 public int Count()
652 {
653 if(byname == null)
654 return 0;
655 else
656 return byname.Count;
657 }
658
659 private void addToInner(GridRegion region)
660 {
661 int rsx = region.RegionSizeX;
662 int rsy = region.RegionSizeY;
663
664 if(rsx < 512 && rsy < 512)
665 return;
666
667 rsx >>= 8;
668 rsy >>= 8;
669
670 ulong handle = region.RegionHandle & HANDLEMASK;
671 fastRegionHandle fh = new fastRegionHandle(handle);
672 uint startY = fh.y;
673 for(int i = 0; i < rsx; i++)
674 {
675 for(int j = 0; j < rsy ; j++)
676 {
677 innerHandles[fh.toHandle()] = handle;
678 fh.y += 256;
679 }
680
681 fh.y = startY;
682 fh.x += 256;
683 }
684 }
685
686 private void removeFromInner(GridRegion region)
687 {
688 int rsx = region.RegionSizeX;
689 int rsy = region.RegionSizeY;
690
691 if(rsx < 512 && rsy < 512)
692 return;
693
694 rsx >>= 8;
695 rsy >>= 8;
696 ulong handle = region.RegionHandle & HANDLEMASK;
697 fastRegionHandle fh = new fastRegionHandle(handle);
698 uint startY = fh.y;
699 for(int i = 0; i < rsx; i++)
700 {
701 for(int j = 0; j < rsy ; j++)
702 {
703 innerHandles.Remove(fh.toHandle());
704 fh.y += 256;
705 }
706
707 fh.y = startY;
708 fh.x += 256;
709 }
710 }
711 }
712
713 public class RegionsExpiringCache
714 {
715 const double CACHE_PURGE_TIME = 60000; // milliseconds
716 const int MAX_LOCK_WAIT = 10000; // milliseconds
717
718 /// <summary>For thread safety</summary>
719 object syncRoot = new object();
720 /// <summary>For thread safety</summary>
721 object isPurging = new object();
722
723 Dictionary<UUID, RegionInfoForScope> InfobyScope = new Dictionary<UUID, RegionInfoForScope>();
724 private System.Timers.Timer timer = new System.Timers.Timer(CACHE_PURGE_TIME);
725
726 public RegionsExpiringCache()
727 {
728 timer.Elapsed += PurgeCache;
729 timer.Start();
730 }
731
732 public bool AddOrUpdate(UUID scope, GridRegion region, float expirationSeconds)
733 {
734 if(region == null)
735 return false;
736
737 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
738 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
739
740 try
741 {
742 DateTime expire = DateTime.UtcNow + TimeSpan.FromSeconds(expirationSeconds);
743
744 RegionInfoForScope ris = null;
745 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
746 {
747 ris = new RegionInfoForScope(region, expire);
748 InfobyScope[scope] = ris;
749 }
750 else
751 ris.AddUpdate(region, expire);
752
753 return true;
754 }
755 finally { Monitor.Exit(syncRoot); }
756 }
757
758 public void Clear()
759 {
760 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
761 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
762 try
763 {
764 foreach(RegionInfoForScope ris in InfobyScope.Values)
765 ris.Clear();
766 InfobyScope.Clear();
767 }
768 finally { Monitor.Exit(syncRoot); }
769 }
770
771 public bool Contains(UUID scope, GridRegion region)
772 {
773 if(region == null)
774 return false;
775
776 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
777 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
778
779 try
780 {
781 RegionInfoForScope ris = null;
782 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
783 return false;
784
785 return ris.Contains(region);
786 }
787 finally { Monitor.Exit(syncRoot); }
788 }
789
790 public bool Contains(UUID scope, ulong handle)
791 {
792 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
793 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
794
795 try
796 {
797 RegionInfoForScope ris = null;
798 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
799 return false;
800
801 return ris.Contains(handle);
802 }
803 finally { Monitor.Exit(syncRoot); }
804 }
805
806 public int Count()
807 {
808 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
809 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
810
811 try
812 {
813 int count = 0;
814 foreach(RegionInfoForScope ris in InfobyScope.Values)
815 count += ris.Count();
816 return count;
817 }
818 finally { Monitor.Exit(syncRoot); }
819 }
820
821 public bool Remove(UUID scope, ulong handle)
822 {
823 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
824 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
825 try
826 {
827 RegionInfoForScope ris = null;
828 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
829 return false;
830
831 ris.Remove(handle);
832 if(ris.Count() == 0)
833 InfobyScope.Remove(scope);
834 return true;
835 }
836 finally { Monitor.Exit(syncRoot); }
837 }
838
839 public bool Remove(UUID scope, GridRegion region)
840 {
841 if(region == null)
842 return false;
843
844 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
845 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
846 try
847 {
848 RegionInfoForScope ris = null;
849 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
850 return false;
851
852 ris.Remove(region);
853 if(ris.Count() == 0)
854 InfobyScope.Remove(scope);
855 return true;
856 }
857 finally { Monitor.Exit(syncRoot); }
858 }
859
860 public bool TryGetValue(UUID scope, ulong handle, out GridRegion value)
861 {
862 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
863 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
864
865 value = null;
866 try
867 {
868 RegionInfoForScope ris = null;
869 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
870 return false;
871 value = ris.get(handle);
872 }
873 finally { Monitor.Exit(syncRoot); }
874
875 return value != null;
876 }
877
878 public bool TryGetValue(UUID scope, string name, out GridRegion value)
879 {
880 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
881 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
882
883 value = null;
884 try
885 {
886 RegionInfoForScope ris = null;
887 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
888 return false;
889 value = ris.get(name);
890 }
891 finally { Monitor.Exit(syncRoot); }
892
893 return value != null;
894 }
895
896 public bool TryGetValue(UUID scope, UUID id, out GridRegion value)
897 {
898 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
899 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
900
901 value = null;
902 try
903 {
904 RegionInfoForScope ris = null;
905 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
906 return false;
907 value = ris.get(id);
908 }
909 finally { Monitor.Exit(syncRoot); }
910
911 return value != null;
912 }
913
914 // gets a region that contains world position (x,y)
915 // hopefull will not take ages
916 public bool TryGetValue(UUID scope, uint x, uint y, out GridRegion value)
917 {
918 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
919 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
920
921 value = null;
922 try
923 {
924 RegionInfoForScope ris = null;
925 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
926 return false;
927
928 value = ris.get(x, y);
929 }
930 finally { Monitor.Exit(syncRoot); }
931
932 return value != null;
933 }
934
935 public bool Update(UUID scope, GridRegion region, double expirationSeconds)
936 {
937 if(region == null)
938 return false;
939
940 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
941 throw new ApplicationException("Lock could not be acquired after " + MAX_LOCK_WAIT + "ms");
942
943 try
944 {
945 RegionInfoForScope ris = null;
946 if(!InfobyScope.TryGetValue(scope, out ris) || ris == null)
947 return false;
948
949 DateTime expire = DateTime.UtcNow + TimeSpan.FromSeconds(expirationSeconds);
950 ris.AddUpdate(region,expire);
951 return true;
952 }
953 finally { Monitor.Exit(syncRoot); }
954 }
955
956 /// <summary>
957 /// Purges expired objects from the cache. Called automatically by the purge timer.
958 /// </summary>
959 private void PurgeCache(object sender, System.Timers.ElapsedEventArgs e)
960 {
961 // Only let one thread purge at once - a buildup could cause a crash
962 // This could cause the purge to be delayed while there are lots of read/write ops
963 // happening on the cache
964 if (!Monitor.TryEnter(isPurging))
965 return;
966
967 DateTime now = DateTime.UtcNow;
968
969 try
970 {
971 // If we fail to acquire a lock on the synchronization root after MAX_LOCK_WAIT, skip this purge cycle
972 if (!Monitor.TryEnter(syncRoot, MAX_LOCK_WAIT))
973 return;
974 try
975 {
976 List<UUID> expiredscopes = new List<UUID>();
977
978 foreach (KeyValuePair<UUID, RegionInfoForScope> kvp in InfobyScope)
979 {
980 if (kvp.Value.expire(now) == 0)
981 expiredscopes.Add(kvp.Key);
982 }
983
984 if (expiredscopes.Count > 0)
985 {
986 foreach (UUID sid in expiredscopes)
987 {
988 InfobyScope[sid] = null;
989 InfobyScope.Remove(sid);
990 }
991 }
992 }
993 finally { Monitor.Exit(syncRoot); }
994 }
995 finally { Monitor.Exit(isPurging); }
996 }
168 } 997 }
169} 998}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
index 85073fc..0efe99d 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/RemoteGridServiceConnector.cs
@@ -52,12 +52,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
52 MethodBase.GetCurrentMethod().DeclaringType); 52 MethodBase.GetCurrentMethod().DeclaringType);
53 53
54 private bool m_Enabled = false; 54 private bool m_Enabled = false;
55 private string m_ThisGatekeeper = string.Empty;
55 56
56 private IGridService m_LocalGridService; 57 private IGridService m_LocalGridService;
57 private IGridService m_RemoteGridService; 58 private IGridService m_RemoteGridService;
58 59
59 private RegionInfoCache m_RegionInfoCache = new RegionInfoCache(); 60 private RegionInfoCache m_RegionInfoCache;
60 61
61 public RemoteGridServicesConnector() 62 public RemoteGridServicesConnector()
62 { 63 {
63 } 64 }
@@ -69,7 +70,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
69 70
70 #region ISharedRegionmodule 71 #region ISharedRegionmodule
71 72
72 public Type ReplaceableInterface 73 public Type ReplaceableInterface
73 { 74 {
74 get { return null; } 75 get { return null; }
75 } 76 }
@@ -87,38 +88,57 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
87 string name = moduleConfig.GetString("GridServices", ""); 88 string name = moduleConfig.GetString("GridServices", "");
88 if (name == Name) 89 if (name == Name)
89 { 90 {
90 InitialiseServices(source); 91 if(InitialiseServices(source))
91 m_Enabled = true; 92 {
92 m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled"); 93 m_Enabled = true;
94 m_log.Info("[REMOTE GRID CONNECTOR]: Remote grid enabled");
95 }
93 } 96 }
94 } 97 }
95 } 98 }
96 99
97 private void InitialiseServices(IConfigSource source) 100 private bool InitialiseServices(IConfigSource source)
98 { 101 {
99 IConfig gridConfig = source.Configs["GridService"]; 102 IConfig gridConfig = source.Configs["GridService"];
100 if (gridConfig == null) 103 if (gridConfig == null)
101 { 104 {
102 m_log.Error("[REMOTE GRID CONNECTOR]: GridService missing from OpenSim.ini"); 105 m_log.Error("[REMOTE GRID CONNECTOR]: GridService missing from OpenSim.ini");
103 return; 106 return false;
104 } 107 }
105 108
106 string networkConnector = gridConfig.GetString("NetworkConnector", string.Empty); 109 string networkConnector = gridConfig.GetString("NetworkConnector", string.Empty);
107 if (networkConnector == string.Empty) 110 if (networkConnector == string.Empty)
108 { 111 {
109 m_log.Error("[REMOTE GRID CONNECTOR]: Please specify a network connector under [GridService]"); 112 m_log.Error("[REMOTE GRID CONNECTOR]: Please specify a network connector under [GridService]");
110 return; 113 return false;
111 } 114 }
112 115
113 Object[] args = new Object[] { source }; 116 Object[] args = new Object[] { source };
114 m_RemoteGridService = ServerUtils.LoadPlugin<IGridService>(networkConnector, args); 117 m_RemoteGridService = ServerUtils.LoadPlugin<IGridService>(networkConnector, args);
115 118
116 m_LocalGridService = new LocalGridServicesConnector(source); 119 m_LocalGridService = new LocalGridServicesConnector(source, m_RegionInfoCache);
117 } 120 if (m_LocalGridService == null)
121 {
122 m_log.Error("[REMOTE GRID CONNECTOR]: failed to load local connector");
123 return false;
124 }
125
126 if(m_RegionInfoCache == null)
127 m_RegionInfoCache = new RegionInfoCache();
128
129 m_ThisGatekeeper = Util.GetConfigVarFromSections<string>(source, "GatekeeperURI",
130 new string[] { "Startup", "Hypergrid", "GridService" }, String.Empty);
131 // Legacy. Remove soon!
132//// m_ThisGatekeeper = gridConfig.GetString("Gatekeeper", m_ThisGatekeeper);
133
134 Util.checkServiceURI(m_ThisGatekeeper, out m_ThisGatekeeper);
135
136 return true;
137 }
118 138
119 public void PostInitialise() 139 public void PostInitialise()
120 { 140 {
121 if (m_LocalGridService != null) 141 if (m_Enabled)
122 ((ISharedRegionModule)m_LocalGridService).PostInitialise(); 142 ((ISharedRegionModule)m_LocalGridService).PostInitialise();
123 } 143 }
124 144
@@ -129,15 +149,15 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
129 public void AddRegion(Scene scene) 149 public void AddRegion(Scene scene)
130 { 150 {
131 if (m_Enabled) 151 if (m_Enabled)
152 {
132 scene.RegisterModuleInterface<IGridService>(this); 153 scene.RegisterModuleInterface<IGridService>(this);
133
134 if (m_LocalGridService != null)
135 ((ISharedRegionModule)m_LocalGridService).AddRegion(scene); 154 ((ISharedRegionModule)m_LocalGridService).AddRegion(scene);
155 }
136 } 156 }
137 157
138 public void RemoveRegion(Scene scene) 158 public void RemoveRegion(Scene scene)
139 { 159 {
140 if (m_LocalGridService != null) 160 if (m_Enabled)
141 ((ISharedRegionModule)m_LocalGridService).RemoveRegion(scene); 161 ((ISharedRegionModule)m_LocalGridService).RemoveRegion(scene);
142 } 162 }
143 163
@@ -174,16 +194,12 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
174 194
175 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID) 195 public GridRegion GetRegionByUUID(UUID scopeID, UUID regionID)
176 { 196 {
177 bool inCache = false; 197 GridRegion rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID);
178 GridRegion rinfo = m_RegionInfoCache.Get(scopeID,regionID,out inCache); 198 if (rinfo != null)
179 if (inCache)
180 return rinfo; 199 return rinfo;
181
182 rinfo = m_LocalGridService.GetRegionByUUID(scopeID, regionID);
183 if (rinfo == null)
184 rinfo = m_RemoteGridService.GetRegionByUUID(scopeID, regionID);
185 200
186 m_RegionInfoCache.Cache(scopeID,regionID,rinfo); 201 rinfo = m_RemoteGridService.GetRegionByUUID(scopeID, regionID);
202 m_RegionInfoCache.Cache(scopeID, rinfo);
187 return rinfo; 203 return rinfo;
188 } 204 }
189 205
@@ -193,51 +209,56 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
193 // The coordinates are world coords (meters), NOT region units. 209 // The coordinates are world coords (meters), NOT region units.
194 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y) 210 public GridRegion GetRegionByPosition(UUID scopeID, int x, int y)
195 { 211 {
196 ulong regionHandle = Util.RegionWorldLocToHandle((uint)x, (uint)y); 212 GridRegion rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y);
197 uint regionX = Util.WorldToRegionLoc((uint)x); 213 if (rinfo != null)
198 uint regionY = Util.WorldToRegionLoc((uint)y);
199
200 // Sanity check
201 if ((Util.RegionToWorldLoc(regionX) != (uint)x) || (Util.RegionToWorldLoc(regionY) != (uint)y))
202 { 214 {
203 m_log.WarnFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Bad position requested: not the base of the region. Requested Pos=<{0},{1}>, Should Be=<{2},{3}>", 215// m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Found region {0} on local. Pos=<{1},{2}>, RegionHandle={3}",
204 x, y, Util.RegionToWorldLoc(regionX), Util.RegionToWorldLoc(regionY)); 216// rinfo.RegionName, rinfo.RegionCoordX, rinfo.RegionCoordY, rinfo.RegionHandle);
205 }
206
207 bool inCache = false;
208 GridRegion rinfo = m_RegionInfoCache.Get(scopeID, regionHandle, out inCache);
209 if (inCache)
210 {
211 //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Found region {0} in cache. Pos=<{1},{2}>, RegionHandle={3}",
212 // (rinfo == null) ? "<missing>" : rinfo.RegionName, regionX, regionY, (rinfo == null) ? regionHandle : rinfo.RegionHandle);
213 return rinfo; 217 return rinfo;
214 } 218 }
215 219
216 rinfo = m_LocalGridService.GetRegionByPosition(scopeID, x, y); 220 rinfo = m_RemoteGridService.GetRegionByPosition(scopeID, x, y);
217 if (rinfo == null)
218 rinfo = m_RemoteGridService.GetRegionByPosition(scopeID, x, y);
219 221
220 m_RegionInfoCache.Cache(rinfo); 222 if (rinfo == null)
221 223 {
222 //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Added region {0} to the cache. Pos=<{1},{2}>, RegionHandle={3}", 224// uint regionX = Util.WorldToRegionLoc((uint)x);
223 // (rinfo == null) ? "<missing>" : rinfo.RegionName, regionX, regionY, (rinfo == null) ? regionHandle : rinfo.RegionHandle); 225// uint regionY = Util.WorldToRegionLoc((uint)y);
226// m_log.WarnFormat("[REMOTE GRID CONNECTOR]: Requested region {0}-{1} not found", regionX, regionY);
227 }
228 else
229 {
230 m_RegionInfoCache.Cache(scopeID, rinfo);
224 231
232// m_log.DebugFormat("[REMOTE GRID CONNECTOR]: GetRegionByPosition. Added region {0} to the cache. Pos=<{1},{2}>, RegionHandle={3}",
233// rinfo.RegionName, rinfo.RegionCoordX, rinfo.RegionCoordY, rinfo.RegionHandle);
234 }
225 return rinfo; 235 return rinfo;
226 } 236 }
227 237
228 public GridRegion GetRegionByName(UUID scopeID, string regionName) 238 public GridRegion GetRegionByName(UUID scopeID, string name)
229 { 239 {
230 bool inCache = false; 240 GridRegion rinfo = m_LocalGridService.GetRegionByName(scopeID, name);
231 GridRegion rinfo = m_RegionInfoCache.Get(scopeID,regionName, out inCache); 241 if (rinfo != null)
232 if (inCache)
233 return rinfo; 242 return rinfo;
234
235 rinfo = m_LocalGridService.GetRegionByName(scopeID, regionName);
236 if (rinfo == null)
237 rinfo = m_RemoteGridService.GetRegionByName(scopeID, regionName);
238 243
239 // can't cache negative results for name lookups 244 // HG urls should not get here, strip them
240 m_RegionInfoCache.Cache(rinfo); 245 // side effect is that local regions with same name as HG may also be found
246 // this mb good or bad
247 string regionName = name;
248 if(name.Contains("."))
249 {
250 if(string.IsNullOrWhiteSpace(m_ThisGatekeeper))
251 return rinfo; // no HG
252
253 string regionURI = "";
254 if(!Util.buildHGRegionURI(name, out regionURI, out regionName) || string.IsNullOrWhiteSpace(regionName))
255 return rinfo; // invalid
256 if(m_ThisGatekeeper != regionURI)
257 return rinfo; // not local grid
258 }
259
260 rinfo = m_RemoteGridService.GetRegionByName(scopeID, regionName);
261 m_RegionInfoCache.Cache(scopeID, rinfo);
241 return rinfo; 262 return rinfo;
242 } 263 }
243 264
@@ -245,7 +266,24 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid
245 { 266 {
246 List<GridRegion> rinfo = m_LocalGridService.GetRegionsByName(scopeID, name, maxNumber); 267 List<GridRegion> rinfo = m_LocalGridService.GetRegionsByName(scopeID, name, maxNumber);
247 //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetRegionsByName {0} found {1} regions", name, rinfo.Count); 268 //m_log.DebugFormat("[REMOTE GRID CONNECTOR]: Local GetRegionsByName {0} found {1} regions", name, rinfo.Count);
248 List<GridRegion> grinfo = m_RemoteGridService.GetRegionsByName(scopeID, name, maxNumber); 269
270 // HG urls should not get here, strip them
271 // side effect is that local regions with same name as HG may also be found
272 // this mb good or bad
273 string regionName = name;
274 if(name.Contains("."))
275 {
276 if(string.IsNullOrWhiteSpace(m_ThisGatekeeper))
277 return rinfo; // no HG
278
279 string regionURI = "";
280 if(!Util.buildHGRegionURI(name, out regionURI, out regionName) || string.IsNullOrWhiteSpace(regionName))
281 return rinfo; // invalid
282 if(m_ThisGatekeeper != regionURI)
283 return rinfo; // not local grid
284 }
285
286 List<GridRegion> grinfo = m_RemoteGridService.GetRegionsByName(scopeID, regionName, maxNumber);
249 287
250 if (grinfo != null) 288 if (grinfo != null)
251 { 289 {
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs
index 25ae689..1378368 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Grid/Tests/GridConnectorsTests.cs
@@ -64,7 +64,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
64 config.Configs["GridService"].Set("Region_Test_Region_3", "FallbackRegion"); 64 config.Configs["GridService"].Set("Region_Test_Region_3", "FallbackRegion");
65 config.Configs["GridService"].Set("Region_Other_Region_4", "FallbackRegion"); 65 config.Configs["GridService"].Set("Region_Other_Region_4", "FallbackRegion");
66 66
67 m_LocalConnector = new LocalGridServicesConnector(config); 67 m_LocalConnector = new LocalGridServicesConnector(config, null);
68 } 68 }
69 69
70 /// <summary> 70 /// <summary>
@@ -88,7 +88,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
88 Scene s = new Scene(new RegionInfo()); 88 Scene s = new Scene(new RegionInfo());
89 s.RegionInfo.RegionID = r1.RegionID; 89 s.RegionInfo.RegionID = r1.RegionID;
90 m_LocalConnector.AddRegion(s); 90 m_LocalConnector.AddRegion(s);
91 91
92 GridRegion r2 = new GridRegion(); 92 GridRegion r2 = new GridRegion();
93 r2.RegionName = "Test Region 2"; 93 r2.RegionName = "Test Region 2";
94 r2.RegionID = new UUID(2); 94 r2.RegionID = new UUID(2);
@@ -198,4 +198,4 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
198 Assert.That(results.Count, Is.EqualTo(0), "Retrieved linked regions collection is not the number expected"); 198 Assert.That(results.Count, Is.EqualTo(0), "Retrieved linked regions collection is not the number expected");
199 } 199 }
200 } 200 }
201} \ No newline at end of file 201}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs
index 2238c90..1529fc2 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/GridUser/ActivityDetector.cs
@@ -37,7 +37,7 @@ using log4net;
37 37
38namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser 38namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
39{ 39{
40 public class ActivityDetector 40 public class ActivityDetector
41 { 41 {
42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 42 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
43 43
@@ -63,18 +63,31 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.GridUser
63 scene.EventManager.OnNewClient -= OnNewClient; 63 scene.EventManager.OnNewClient -= OnNewClient;
64 } 64 }
65 65
66 public void OnMakeRootAgent(ScenePresence sp) 66 public void OnMakeRootAgent(ScenePresence sp)
67 { 67 {
68 if (sp.PresenceType != PresenceType.Npc) 68 if (sp.IsNPC)
69 return;
70
71 if(sp.gotCrossUpdate)
69 { 72 {
70 string userid; 73 Util.FireAndForget(delegate
71 //m_log.DebugFormat("[ACTIVITY DETECTOR]: Detected root presence {0} in {1}", userid, sp.Scene.RegionInfo.RegionName);
72 if (sp.Scene.UserManagementModule.GetUserUUI(sp.UUID, out userid))
73 { 74 {
74 /* we only setposition on known agents that have a valid lookup */ 75 DoOnMakeRootAgent(sp);
75 m_GridUserService.SetLastPosition( 76 }, null, "ActivityDetector_MakeRoot");
76 userid, UUID.Zero, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat); 77 }
77 } 78 else
79 DoOnMakeRootAgent(sp);
80 }
81
82 public void DoOnMakeRootAgent(ScenePresence sp)
83 {
84 string userid;
85 //m_log.DebugFormat("[ACTIVITY DETECTOR]: Detected root presence {0} in {1}", userid, sp.Scene.RegionInfo.RegionName);
86 if (sp.Scene.UserManagementModule.GetUserUUI(sp.UUID, out userid))
87 {
88 /* we only setposition on known agents that have a valid lookup */
89 m_GridUserService.SetLastPosition(
90 userid, UUID.Zero, sp.Scene.RegionInfo.RegionID, sp.AbsolutePosition, sp.Lookat);
78 } 91 }
79 } 92 }
80 93
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
index 48f228a..7a4f981 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/HGInventoryBroker.cs
@@ -86,7 +86,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
86 } 86 }
87 } 87 }
88 88
89 public Type ReplaceableInterface 89 public Type ReplaceableInterface
90 { 90 {
91 get { return null; } 91 get { return null; }
92 } 92 }
@@ -203,21 +203,22 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
203 203
204 void OnClientClosed(UUID clientID, Scene scene) 204 void OnClientClosed(UUID clientID, Scene scene)
205 { 205 {
206 if (m_InventoryURLs.ContainsKey(clientID)) // if it's in cache 206 ScenePresence sp = null;
207 foreach (Scene s in m_Scenes)
207 { 208 {
208 ScenePresence sp = null; 209 s.TryGetScenePresence(clientID, out sp);
209 foreach (Scene s in m_Scenes) 210 if ((sp != null) && !sp.IsChildAgent && (s != scene))
210 { 211 {
211 s.TryGetScenePresence(clientID, out sp); 212 m_log.DebugFormat("[INVENTORY CACHE]: OnClientClosed in {0}, but user {1} still in sim. Keeping inventoryURL in cache",
212 if ((sp != null) && !sp.IsChildAgent && (s != scene))
213 {
214 m_log.DebugFormat("[INVENTORY CACHE]: OnClientClosed in {0}, but user {1} still in sim. Keeping inventoryURL in cache",
215 scene.RegionInfo.RegionName, clientID); 213 scene.RegionInfo.RegionName, clientID);
216 return; 214 return;
217 }
218 } 215 }
219 DropInventoryServiceURL(clientID);
220 } 216 }
217
218 if (m_InventoryURLs.ContainsKey(clientID)) // if it's in cache
219 DropInventoryServiceURL(clientID);
220
221 m_Cache.RemoveAll(clientID);
221 } 222 }
222 223
223 /// <summary> 224 /// <summary>
@@ -249,7 +250,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
249 if (inventoryURL != null && inventoryURL != string.Empty) 250 if (inventoryURL != null && inventoryURL != string.Empty)
250 { 251 {
251 inventoryURL = inventoryURL.Trim(new char[] { '/' }); 252 inventoryURL = inventoryURL.Trim(new char[] { '/' });
252 m_InventoryURLs[userID] = inventoryURL; 253 lock (m_InventoryURLs)
254 m_InventoryURLs[userID] = inventoryURL;
253 m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Added {0} to the cache of inventory URLs", inventoryURL); 255 m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Added {0} to the cache of inventory URLs", inventoryURL);
254 return; 256 return;
255 } 257 }
@@ -267,38 +269,45 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
267 if (!string.IsNullOrEmpty(inventoryURL)) 269 if (!string.IsNullOrEmpty(inventoryURL))
268 { 270 {
269 inventoryURL = inventoryURL.Trim(new char[] { '/' }); 271 inventoryURL = inventoryURL.Trim(new char[] { '/' });
270 m_InventoryURLs.Add(userID, inventoryURL); 272 lock (m_InventoryURLs)
273 m_InventoryURLs[userID] = inventoryURL;
271 m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Added {0} to the cache of inventory URLs", inventoryURL); 274 m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Added {0} to the cache of inventory URLs", inventoryURL);
272 } 275 }
273
274 } 276 }
275
276 } 277 }
277 } 278 }
278 279
279 private void DropInventoryServiceURL(UUID userID) 280 private void DropInventoryServiceURL(UUID userID)
280 { 281 {
281 lock (m_InventoryURLs) 282 lock (m_InventoryURLs)
283 {
282 if (m_InventoryURLs.ContainsKey(userID)) 284 if (m_InventoryURLs.ContainsKey(userID))
283 { 285 {
284 string url = m_InventoryURLs[userID]; 286 string url = m_InventoryURLs[userID];
285 m_InventoryURLs.Remove(userID); 287 m_InventoryURLs.Remove(userID);
286 m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Removed {0} from the cache of inventory URLs", url); 288 m_log.DebugFormat("[HG INVENTORY CONNECTOR]: Removed {0} from the cache of inventory URLs", url);
287 } 289 }
290 }
288 } 291 }
289 292
290 public string GetInventoryServiceURL(UUID userID) 293 public string GetInventoryServiceURL(UUID userID)
291 { 294 {
292 if (m_InventoryURLs.ContainsKey(userID)) 295 lock (m_InventoryURLs)
293 return m_InventoryURLs[userID]; 296 {
297 if (m_InventoryURLs.ContainsKey(userID))
298 return m_InventoryURLs[userID];
299 }
294 300
295 CacheInventoryServiceURL(userID); 301 CacheInventoryServiceURL(userID);
296 302
297 if (m_InventoryURLs.ContainsKey(userID)) 303 lock (m_InventoryURLs)
298 return m_InventoryURLs[userID]; 304 {
305 if (m_InventoryURLs.ContainsKey(userID))
306 return m_InventoryURLs[userID];
307 }
299 308
300 return null; //it means that the methods should forward to local grid's inventory 309 return null; //it means that the methods should forward to local grid's inventory
301 310
302 } 311 }
303 #endregion 312 #endregion
304 313
@@ -598,21 +607,19 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
598 return connector.DeleteItems(ownerID, itemIDs); 607 return connector.DeleteItems(ownerID, itemIDs);
599 } 608 }
600 609
601 public InventoryItemBase GetItem(InventoryItemBase item) 610 public InventoryItemBase GetItem(UUID principalID, UUID itemID)
602 { 611 {
603 if (item == null)
604 return null;
605 //m_log.Debug("[HG INVENTORY CONNECTOR]: GetItem " + item.ID); 612 //m_log.Debug("[HG INVENTORY CONNECTOR]: GetItem " + item.ID);
606 613
607 string invURL = GetInventoryServiceURL(item.Owner); 614 string invURL = GetInventoryServiceURL(principalID);
608 615
609 if (invURL == null) // not there, forward to local inventory connector to resolve 616 if (invURL == null) // not there, forward to local inventory connector to resolve
610 lock (m_Lock) 617 lock (m_Lock)
611 return m_LocalGridInventoryService.GetItem(item); 618 return m_LocalGridInventoryService.GetItem(principalID, itemID);
612 619
613 IInventoryService connector = GetConnector(invURL); 620 IInventoryService connector = GetConnector(invURL);
614 621
615 return connector.GetItem(item); 622 return connector.GetItem(principalID, itemID);
616 } 623 }
617 624
618 public InventoryItemBase[] GetMultipleItems(UUID userID, UUID[] itemIDs) 625 public InventoryItemBase[] GetMultipleItems(UUID userID, UUID[] itemIDs)
@@ -632,22 +639,19 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
632 return connector.GetMultipleItems(userID, itemIDs); 639 return connector.GetMultipleItems(userID, itemIDs);
633 } 640 }
634 641
635 public InventoryFolderBase GetFolder(InventoryFolderBase folder) 642 public InventoryFolderBase GetFolder(UUID principalID, UUID folderID)
636 { 643 {
637 if (folder == null)
638 return null;
639
640 //m_log.Debug("[HG INVENTORY CONNECTOR]: GetFolder " + folder.ID); 644 //m_log.Debug("[HG INVENTORY CONNECTOR]: GetFolder " + folder.ID);
641 645
642 string invURL = GetInventoryServiceURL(folder.Owner); 646 string invURL = GetInventoryServiceURL(principalID);
643 647
644 if (invURL == null) // not there, forward to local inventory connector to resolve 648 if (invURL == null) // not there, forward to local inventory connector to resolve
645 lock (m_Lock) 649 lock (m_Lock)
646 return m_LocalGridInventoryService.GetFolder(folder); 650 return m_LocalGridInventoryService.GetFolder(principalID, folderID);
647 651
648 IInventoryService connector = GetConnector(invURL); 652 IInventoryService connector = GetConnector(invURL);
649 653
650 return connector.GetFolder(folder); 654 return connector.GetFolder(principalID, folderID);
651 } 655 }
652 656
653 public bool HasInventoryForUser(UUID userID) 657 public bool HasInventoryForUser(UUID userID)
@@ -710,4 +714,4 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
710 return connector; 714 return connector;
711 } 715 }
712 } 716 }
713} \ No newline at end of file 717}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs
index 3195e6b..f7ef2ea 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/InventoryCache.cs
@@ -38,12 +38,23 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
38 /// </summary> 38 /// </summary>
39 public class InventoryCache 39 public class InventoryCache
40 { 40 {
41 private const double CACHE_EXPIRATION_SECONDS = 3600.0; // 1 hour 41 private const double CACHE_EXPIRATION_SECONDS = 60.0; // 1 minute
42 42
43 private static ExpiringCache<UUID, InventoryFolderBase> m_RootFolders = new ExpiringCache<UUID, InventoryFolderBase>(); 43 private static ExpiringCache<UUID, InventoryFolderBase> m_RootFolders = new ExpiringCache<UUID, InventoryFolderBase>();
44 private static ExpiringCache<UUID, Dictionary<FolderType, InventoryFolderBase>> m_FolderTypes = new ExpiringCache<UUID, Dictionary<FolderType, InventoryFolderBase>>(); 44 private static ExpiringCache<UUID, Dictionary<FolderType, InventoryFolderBase>> m_FolderTypes = new ExpiringCache<UUID, Dictionary<FolderType, InventoryFolderBase>>();
45 private static ExpiringCache<UUID, InventoryCollection> m_Inventories = new ExpiringCache<UUID, InventoryCollection>(); 45 private static ExpiringCache<UUID, InventoryCollection> m_Inventories = new ExpiringCache<UUID, InventoryCollection>();
46 46
47
48 public void RemoveAll(UUID userID)
49 {
50 if(m_RootFolders.Contains(userID))
51 m_RootFolders.Remove(userID);
52 if(m_FolderTypes.Contains(userID))
53 m_FolderTypes.Remove(userID);
54 if(m_Inventories.Contains(userID))
55 m_Inventories.Remove(userID);
56 }
57
47 public void Cache(UUID userID, InventoryFolderBase root) 58 public void Cache(UUID userID, InventoryFolderBase root)
48 { 59 {
49 m_RootFolders.AddOrUpdate(userID, root, CACHE_EXPIRATION_SECONDS); 60 m_RootFolders.AddOrUpdate(userID, root, CACHE_EXPIRATION_SECONDS);
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs
index 20d4e02..fa36b66 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/LocalInventoryServiceConnector.cs
@@ -72,7 +72,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
72 72
73 private bool m_Enabled = false; 73 private bool m_Enabled = false;
74 74
75 public Type ReplaceableInterface 75 public Type ReplaceableInterface
76 { 76 {
77 get { return null; } 77 get { return null; }
78 } 78 }
@@ -134,7 +134,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
134 { 134 {
135 if (!m_Enabled) 135 if (!m_Enabled)
136 return; 136 return;
137 137
138 scene.RegisterModuleInterface<IInventoryService>(this); 138 scene.RegisterModuleInterface<IInventoryService>(this);
139 139
140 if (Scene == null) 140 if (Scene == null)
@@ -261,9 +261,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
261 public bool AddItem(InventoryItemBase item) 261 public bool AddItem(InventoryItemBase item)
262 { 262 {
263// m_log.DebugFormat( 263// m_log.DebugFormat(
264// "[LOCAL INVENTORY SERVICES CONNECTOR]: Adding inventory item {0} to user {1} folder {2}", 264// "[LOCAL INVENTORY SERVICES CONNECTOR]: Adding inventory item {0} to user {1} folder {2}",
265// item.Name, item.Owner, item.Folder); 265// item.Name, item.Owner, item.Folder);
266 266
267 return m_InventoryService.AddItem(item); 267 return m_InventoryService.AddItem(item);
268 } 268 }
269 269
@@ -292,13 +292,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
292 return m_InventoryService.DeleteItems(ownerID, itemIDs); 292 return m_InventoryService.DeleteItems(ownerID, itemIDs);
293 } 293 }
294 294
295 public InventoryItemBase GetItem(InventoryItemBase item) 295 public InventoryItemBase GetItem(UUID principalID, UUID itemID)
296 { 296 {
297// m_log.DebugFormat("[LOCAL INVENTORY SERVICES CONNECTOR]: Requesting inventory item {0}", item.ID); 297// m_log.DebugFormat("[LOCAL INVENTORY SERVICES CONNECTOR]: Requesting inventory item {0}", item.ID);
298 298
299// UUID requestedItemId = item.ID; 299// UUID requestedItemId = item.ID;
300 300
301 item = m_InventoryService.GetItem(item); 301 InventoryItemBase item = m_InventoryService.GetItem(principalID, itemID);
302 302
303// if (null == item) 303// if (null == item)
304// m_log.ErrorFormat( 304// m_log.ErrorFormat(
@@ -312,9 +312,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
312 return m_InventoryService.GetMultipleItems(userID, itemIDs); 312 return m_InventoryService.GetMultipleItems(userID, itemIDs);
313 } 313 }
314 314
315 public InventoryFolderBase GetFolder(InventoryFolderBase folder) 315 public InventoryFolderBase GetFolder(UUID principalID, UUID folderID)
316 { 316 {
317 return m_InventoryService.GetFolder(folder); 317 return m_InventoryService.GetFolder(principalID, folderID);
318 } 318 }
319 319
320 /// <summary> 320 /// <summary>
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs
index 978b9d9..d8ae2c4 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Inventory/RemoteXInventoryServiceConnector.cs
@@ -74,7 +74,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
74 } 74 }
75 } 75 }
76 76
77 public Type ReplaceableInterface 77 public Type ReplaceableInterface
78 { 78 {
79 get { return null; } 79 get { return null; }
80 } 80 }
@@ -292,15 +292,13 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
292 return m_RemoteConnector.DeleteItems(ownerID, itemIDs); 292 return m_RemoteConnector.DeleteItems(ownerID, itemIDs);
293 } 293 }
294 294
295 public InventoryItemBase GetItem(InventoryItemBase item) 295 public InventoryItemBase GetItem(UUID userID, UUID itemID)
296 { 296 {
297 //m_log.DebugFormat("[XINVENTORY CONNECTOR]: GetItem {0}", item.ID); 297 //m_log.DebugFormat("[XINVENTORY CONNECTOR]: GetItem {0}", item.ID);
298 if (item == null)
299 return null;
300 298
301 if (m_RemoteConnector == null) 299 if (m_RemoteConnector == null)
302 m_log.DebugFormat("[XINVENTORY CONNECTOR]: connector stub is null!!!"); 300 m_log.DebugFormat("[XINVENTORY CONNECTOR]: connector stub is null!!!");
303 return m_RemoteConnector.GetItem(item); 301 return m_RemoteConnector.GetItem(userID, itemID);
304 } 302 }
305 303
306 public InventoryItemBase[] GetMultipleItems(UUID userID, UUID[] itemIDs) 304 public InventoryItemBase[] GetMultipleItems(UUID userID, UUID[] itemIDs)
@@ -311,13 +309,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
311 return m_RemoteConnector.GetMultipleItems(userID, itemIDs); 309 return m_RemoteConnector.GetMultipleItems(userID, itemIDs);
312 } 310 }
313 311
314 public InventoryFolderBase GetFolder(InventoryFolderBase folder) 312 public InventoryFolderBase GetFolder(UUID userID, UUID folderID)
315 { 313 {
316 //m_log.DebugFormat("[XINVENTORY CONNECTOR]: GetFolder {0}", folder.ID); 314 //m_log.DebugFormat("[XINVENTORY CONNECTOR]: GetFolder {0}", folder.ID);
317 if (folder == null)
318 return null;
319 315
320 return m_RemoteConnector.GetFolder(folder); 316 return m_RemoteConnector.GetFolder(userID, folderID);
321 } 317 }
322 318
323 public bool HasInventoryForUser(UUID userID) 319 public bool HasInventoryForUser(UUID userID)
@@ -337,4 +333,4 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Inventory
337 333
338 #endregion 334 #endregion
339 } 335 }
340} \ No newline at end of file 336}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Land/LocalLandServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Land/LocalLandServiceConnector.cs
index 5329933..8baf41a 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Land/LocalLandServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Land/LocalLandServiceConnector.cs
@@ -62,7 +62,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Land
62 62
63 #region ISharedRegionModule 63 #region ISharedRegionModule
64 64
65 public Type ReplaceableInterface 65 public Type ReplaceableInterface
66 { 66 {
67 get { return null; } 67 get { return null; }
68 } 68 }
@@ -121,15 +121,32 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Land
121 public LandData GetLandData(UUID scopeID, ulong regionHandle, uint x, uint y, out byte regionAccess) 121 public LandData GetLandData(UUID scopeID, ulong regionHandle, uint x, uint y, out byte regionAccess)
122 { 122 {
123 regionAccess = 2; 123 regionAccess = 2;
124 m_log.DebugFormat("[LAND CONNECTOR]: request for land data in {0} at {1}, {2}", 124// m_log.DebugFormat("[LAND CONNECTOR]: request for land data in {0} at {1}, {2}",
125 regionHandle, x, y); 125// regionHandle, x, y);
126
127 uint rx = 0, ry = 0;
128 Util.RegionHandleToWorldLoc(regionHandle, out rx, out ry);
126 129
127 foreach (Scene s in m_Scenes) 130 foreach (Scene s in m_Scenes)
128 { 131 {
129 if (s.RegionInfo.RegionHandle == regionHandle) 132 uint t = s.RegionInfo.WorldLocX;
133 if( rx < t)
134 continue;
135 t += s.RegionInfo.RegionSizeX;
136 if( rx >= t)
137 continue;
138 t = s.RegionInfo.WorldLocY;
139 if( ry < t)
140 continue;
141 t += s.RegionInfo.RegionSizeY;
142 if( ry < t)
130 { 143 {
131 LandData land = s.GetLandData(x, y); 144 LandData land = s.GetLandData(x, y);
132 regionAccess = s.RegionInfo.AccessLevel; 145 regionAccess = s.RegionInfo.AccessLevel;
146 IDwellModule dwellModule = s.RequestModuleInterface<IDwellModule>();
147 if (dwellModule != null)
148 land.Dwell = dwellModule.GetDwell(land);
149
133 return land; 150 return land;
134 } 151 }
135 } 152 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Land/RemoteLandServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Land/RemoteLandServiceConnector.cs
index 77dfa4a..68c5b64 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Land/RemoteLandServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Land/RemoteLandServiceConnector.cs
@@ -53,7 +53,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Land
53 private bool m_Enabled = false; 53 private bool m_Enabled = false;
54 private LocalLandServicesConnector m_LocalService; 54 private LocalLandServicesConnector m_LocalService;
55 55
56 public Type ReplaceableInterface 56 public Type ReplaceableInterface
57 { 57 {
58 get { return null; } 58 get { return null; }
59 } 59 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
index 08d6bdd..9888c3b 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MapImage/MapImageServiceModule.cs
@@ -53,6 +53,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
53 /// </remarks> 53 /// </remarks>
54 54
55 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MapImageServiceModule")] 55 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "MapImageServiceModule")]
56
56 public class MapImageServiceModule : IMapImageUploadModule, ISharedRegionModule 57 public class MapImageServiceModule : IMapImageUploadModule, ISharedRegionModule
57 { 58 {
58 private static readonly ILog m_log = 59 private static readonly ILog m_log =
@@ -67,11 +68,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
67 private int m_refreshtime = 0; 68 private int m_refreshtime = 0;
68 private int m_lastrefresh = 0; 69 private int m_lastrefresh = 0;
69 private System.Timers.Timer m_refreshTimer; 70 private System.Timers.Timer m_refreshTimer;
70 71
71 #region ISharedRegionModule 72 #region ISharedRegionModule
72 73
73 public Type ReplaceableInterface { get { return null; } } 74 public Type ReplaceableInterface { get { return null; } }
74 public string Name { get { return "MapImageServiceModule"; } } 75 public string Name { get { return "MapImageServiceModule"; } }
75 public void RegionLoaded(Scene scene) { } 76 public void RegionLoaded(Scene scene) { }
76 public void Close() { } 77 public void Close() { }
77 public void PostInitialise() { } 78 public void PostInitialise() { }
@@ -94,8 +95,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
94 return; 95 return;
95 96
96 int refreshminutes = Convert.ToInt32(config.GetString("RefreshTime")); 97 int refreshminutes = Convert.ToInt32(config.GetString("RefreshTime"));
97
98 // if refresh is less than zero, disable the module
99 if (refreshminutes < 0) 98 if (refreshminutes < 0)
100 { 99 {
101 m_log.WarnFormat("[MAP IMAGE SERVICE MODULE]: Negative refresh time given in config. Module disabled."); 100 m_log.WarnFormat("[MAP IMAGE SERVICE MODULE]: Negative refresh time given in config. Module disabled.");
@@ -116,22 +115,23 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
116 m_log.WarnFormat("[MAP IMAGE SERVICE MODULE]: Unable to load LocalServiceModule from {0}. MapService module disabled. Please fix the configuration.", service); 115 m_log.WarnFormat("[MAP IMAGE SERVICE MODULE]: Unable to load LocalServiceModule from {0}. MapService module disabled. Please fix the configuration.", service);
117 return; 116 return;
118 } 117 }
119 118
120 // we don't want the timer if the interval is zero, but we still want this module enables 119 // we don't want the timer if the interval is zero, but we still want this module enables
121 if(refreshminutes > 0) 120 if(refreshminutes > 0)
122 { 121 {
123 m_refreshtime = refreshminutes * 60 * 1000; // convert from minutes to ms 122 m_refreshtime = refreshminutes * 60 * 1000; // convert from minutes to ms
124 123
125 m_refreshTimer = new System.Timers.Timer(); 124 m_refreshTimer = new System.Timers.Timer();
126 m_refreshTimer.Enabled = true; 125 m_refreshTimer.Enabled = true;
127 m_refreshTimer.AutoReset = true; 126 m_refreshTimer.AutoReset = true;
128 m_refreshTimer.Interval = m_refreshtime; 127 m_refreshTimer.Interval = m_refreshtime;
129 m_refreshTimer.Elapsed += new ElapsedEventHandler(HandleMaptileRefresh); 128 m_refreshTimer.Elapsed += new ElapsedEventHandler(HandleMaptileRefresh);
130 129
130
131 m_log.InfoFormat("[MAP IMAGE SERVICE MODULE]: enabled with refresh time {0} min and service object {1}", 131 m_log.InfoFormat("[MAP IMAGE SERVICE MODULE]: enabled with refresh time {0} min and service object {1}",
132 refreshminutes, service); 132 refreshminutes, service);
133 } 133 }
134 else 134 else
135 { 135 {
136 m_log.InfoFormat("[MAP IMAGE SERVICE MODULE]: enabled with no refresh and service object {0}", service); 136 m_log.InfoFormat("[MAP IMAGE SERVICE MODULE]: enabled with no refresh and service object {0}", service);
137 } 137 }
@@ -171,7 +171,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
171 } 171 }
172 172
173 #endregion ISharedRegionModule 173 #endregion ISharedRegionModule
174 174
175 ///<summary> 175 ///<summary>
176 /// 176 ///
177 ///</summary> 177 ///</summary>
@@ -210,7 +210,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
210 return; 210 return;
211 } 211 }
212 212
213 m_log.DebugFormat("{0} Upload maptile for {1}", LogHeader, scene.Name);
214 213
215 // mapTile.Save( // DEBUG DEBUG 214 // mapTile.Save( // DEBUG DEBUG
216 // String.Format("maptiles/raw-{0}-{1}-{2}.jpg", regionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY), 215 // String.Format("maptiles/raw-{0}-{1}-{2}.jpg", regionName, scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY),
@@ -218,12 +217,17 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
218 // If the region/maptile is legacy sized, just upload the one tile like it has always been done 217 // If the region/maptile is legacy sized, just upload the one tile like it has always been done
219 if (mapTile.Width == Constants.RegionSize && mapTile.Height == Constants.RegionSize) 218 if (mapTile.Width == Constants.RegionSize && mapTile.Height == Constants.RegionSize)
220 { 219 {
221 ConvertAndUploadMaptile(mapTile, 220 m_log.DebugFormat("{0} Upload maptile for {1}", LogHeader, scene.Name);
221 ConvertAndUploadMaptile(scene, mapTile,
222 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY, 222 scene.RegionInfo.RegionLocX, scene.RegionInfo.RegionLocY,
223 scene.RegionInfo.RegionName); 223 scene.RegionInfo.RegionName);
224 } 224 }
225 else 225 else
226 { 226 {
227 m_log.DebugFormat("{0} Upload {1} maptiles for {2}", LogHeader,
228 (mapTile.Width * mapTile.Height) / (Constants.RegionSize * Constants.RegionSize),
229 scene.Name);
230
227 // For larger regions (varregion) we must cut the region image into legacy sized 231 // For larger regions (varregion) we must cut the region image into legacy sized
228 // pieces since that is how the maptile system works. 232 // pieces since that is how the maptile system works.
229 // Note the assumption that varregions are always a multiple of legacy size. 233 // Note the assumption that varregions are always a multiple of legacy size.
@@ -240,7 +244,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
240 (int)Constants.RegionSize, (int)Constants.RegionSize); 244 (int)Constants.RegionSize, (int)Constants.RegionSize);
241 using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat)) 245 using (Bitmap subMapTile = mapTile.Clone(rect, mapTile.PixelFormat))
242 { 246 {
243 ConvertAndUploadMaptile(subMapTile, 247 ConvertAndUploadMaptile(scene, subMapTile,
244 scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize), 248 scene.RegionInfo.RegionLocX + (xx / Constants.RegionSize),
245 scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize), 249 scene.RegionInfo.RegionLocY + (yy / Constants.RegionSize),
246 scene.Name); 250 scene.Name);
@@ -253,8 +257,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
253 ///<summary> 257 ///<summary>
254 /// 258 ///
255 ///</summary> 259 ///</summary>
256 private void UploadMapTile(IScene scene) 260 public void UploadMapTile(IScene scene)
257 { 261 {
262 m_log.DebugFormat("{0}: upload maptile for {1}", LogHeader, scene.RegionInfo.RegionName);
263
258 // Create a JPG map tile and upload it to the AddMapTile API 264 // Create a JPG map tile and upload it to the AddMapTile API
259 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>(); 265 IMapImageGenerator tileGenerator = scene.RequestModuleInterface<IMapImageGenerator>();
260 if (tileGenerator == null) 266 if (tileGenerator == null)
@@ -265,18 +271,16 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
265 271
266 using (Bitmap mapTile = tileGenerator.CreateMapTile()) 272 using (Bitmap mapTile = tileGenerator.CreateMapTile())
267 { 273 {
268 if (mapTile != null) 274 // XXX: The MapImageModule will return a null if the user has chosen not to create map tiles and there
269 { 275 // is no static map tile.
270 UploadMapTile(scene, mapTile); 276 if (mapTile == null)
271 } 277 return;
272 else 278
273 { 279 UploadMapTile(scene, mapTile);
274 m_log.WarnFormat("{0} Tile image generation failed", LogHeader);
275 }
276 } 280 }
277 } 281 }
278 282
279 private void ConvertAndUploadMaptile(Image tileImage, uint locX, uint locY, string regionName) 283 private void ConvertAndUploadMaptile(IScene scene, Image tileImage, uint locX, uint locY, string regionName)
280 { 284 {
281 byte[] jpgData = Utils.EmptyBytes; 285 byte[] jpgData = Utils.EmptyBytes;
282 286
@@ -288,7 +292,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
288 if (jpgData != Utils.EmptyBytes) 292 if (jpgData != Utils.EmptyBytes)
289 { 293 {
290 string reason = string.Empty; 294 string reason = string.Empty;
291 if (!m_MapService.AddMapTile((int)locX, (int)locY, jpgData, out reason)) 295 if (!m_MapService.AddMapTile((int)locX, (int)locY, jpgData, scene.RegionInfo.ScopeID, out reason))
292 { 296 {
293 m_log.DebugFormat("{0} Unable to upload tile image for {1} at {2}-{3}: {4}", LogHeader, 297 m_log.DebugFormat("{0} Unable to upload tile image for {1} at {2}-{3}: {4}", LogHeader,
294 regionName, locX, locY, reason); 298 regionName, locX, locY, reason);
@@ -300,4 +304,4 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MapImage
300 } 304 }
301 } 305 }
302 } 306 }
303} \ No newline at end of file 307}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs
new file mode 100644
index 0000000..37b30aa
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/LocalMuteListServiceConnector.cs
@@ -0,0 +1,188 @@
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 log4net;
29using Mono.Addins;
30using Nini.Config;
31using System;
32using System.Collections.Generic;
33using System.Reflection;
34using OpenSim.Framework;
35using OpenSim.Server.Base;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Services.Interfaces;
39using OpenMetaverse;
40
41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MuteList
42{
43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalMuteListServicesConnector")]
44 public class LocalMuteListServicesConnector : ISharedRegionModule, IMuteListService
45 {
46 private static readonly ILog m_log =
47 LogManager.GetLogger(
48 MethodBase.GetCurrentMethod().DeclaringType);
49
50 private List<Scene> m_Scenes = new List<Scene>();
51 protected IMuteListService m_service = null;
52
53 private bool m_Enabled = false;
54
55 #region ISharedRegionModule
56
57 public Type ReplaceableInterface
58 {
59 get { return null; }
60 }
61
62 public string Name
63 {
64 get { return "LocalMuteListServicesConnector"; }
65 }
66
67 public void Initialise(IConfigSource source)
68 {
69 // only active for core mute lists module
70 IConfig moduleConfig = source.Configs["Messaging"];
71 if (moduleConfig == null)
72 return;
73
74 if (moduleConfig.GetString("MuteListModule", "None") != "MuteListModuleTst")
75 return;
76
77 moduleConfig = source.Configs["Modules"];
78
79 if (moduleConfig == null)
80 return;
81
82 string name = moduleConfig.GetString("MuteListService", "");
83 if(name != Name)
84 return;
85
86 IConfig userConfig = source.Configs["MuteListService"];
87 if (userConfig == null)
88 {
89 m_log.Error("[MuteList LOCALCONNECTOR]: MuteListService missing from configuration");
90 return;
91 }
92
93 string serviceDll = userConfig.GetString("LocalServiceModule",
94 String.Empty);
95
96 if (serviceDll == String.Empty)
97 {
98 m_log.Error("[MuteList LOCALCONNECTOR]: No LocalServiceModule named in section MuteListService");
99 return;
100 }
101
102 Object[] args = new Object[] { source };
103 try
104 {
105 m_service = ServerUtils.LoadPlugin<IMuteListService>(serviceDll, args);
106 }
107 catch
108 {
109 m_log.Error("[MuteList LOCALCONNECTOR]: Failed to load mute service");
110 return;
111 }
112
113 if (m_service == null)
114 {
115 m_log.Error("[MuteList LOCALCONNECTOR]: Can't load MuteList service");
116 return;
117 }
118
119 m_Enabled = true;
120 m_log.Info("[MuteList LOCALCONNECTOR]: enabled");
121 }
122
123 public void Close()
124 {
125 }
126
127 public void AddRegion(Scene scene)
128 {
129 if (!m_Enabled)
130 return;
131
132 lock(m_Scenes)
133 {
134 m_Scenes.Add(scene);
135 scene.RegisterModuleInterface<IMuteListService>(this);
136 }
137 }
138
139 public void RegionLoaded(Scene scene)
140 {
141 }
142
143 public void PostInitialise()
144 {
145 }
146
147 public void RemoveRegion(Scene scene)
148 {
149 if (!m_Enabled)
150 return;
151
152 lock(m_Scenes)
153 {
154 if (m_Scenes.Contains(scene))
155 {
156 m_Scenes.Remove(scene);
157 scene.UnregisterModuleInterface<IMuteListService>(this);
158 }
159 }
160 }
161
162 #endregion ISharedRegionModule
163
164 #region IMuteListService
165 public Byte[] MuteListRequest(UUID agentID, uint crc)
166 {
167 if (!m_Enabled)
168 return null;
169 return m_service.MuteListRequest(agentID, crc);
170 }
171
172 public bool UpdateMute(MuteData mute)
173 {
174 if (!m_Enabled)
175 return false;
176 return m_service.UpdateMute(mute);
177 }
178
179 public bool RemoveMute(UUID agentID, UUID muteID, string muteName)
180 {
181 if (!m_Enabled)
182 return false;
183 return m_service.RemoveMute(agentID, muteID, muteName);
184 }
185
186 #endregion IMuteListService
187 }
188}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/RemoteMuteListServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/RemoteMuteListServiceConnector.cs
new file mode 100644
index 0000000..a5dec64
--- /dev/null
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/MuteList/RemoteMuteListServiceConnector.cs
@@ -0,0 +1,143 @@
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 */
27using System;
28using System.Collections.Generic;
29using System.Reflection;
30using OpenSim.Framework;
31using OpenSim.Region.Framework.Interfaces;
32using OpenSim.Region.Framework.Scenes;
33using OpenSim.Server.Base;
34using OpenSim.Services.Interfaces;
35using OpenSim.Services.Connectors;
36
37using OpenMetaverse;
38using log4net;
39using Mono.Addins;
40using Nini.Config;
41
42namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.MuteList
43{
44 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteMuteListServicesConnector")]
45 public class RemoteMuteListServicesConnector : ISharedRegionModule, IMuteListService
46 {
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
48
49 #region ISharedRegionModule
50
51 private bool m_Enabled = false;
52
53 private IMuteListService m_remoteConnector;
54
55 public Type ReplaceableInterface
56 {
57 get { return null; }
58 }
59
60 public string Name
61 {
62 get { return "RemoteMuteListServicesConnector"; }
63 }
64
65 public void Initialise(IConfigSource source)
66 {
67 // only active for core mute lists module
68 IConfig moduleConfig = source.Configs["Messaging"];
69 if (moduleConfig == null)
70 return;
71
72 if (moduleConfig.GetString("MuteListModule", "None") != "MuteListModuleTst")
73 return;
74
75 moduleConfig = source.Configs["Modules"];
76 if (moduleConfig != null)
77 {
78 string name = moduleConfig.GetString("MuteListService", "");
79 if (name == Name)
80 {
81 m_remoteConnector = new MuteListServicesConnector(source);
82 m_Enabled = true;
83 }
84 }
85 }
86
87 public void PostInitialise()
88 {
89 }
90
91 public void Close()
92 {
93 }
94
95 public void AddRegion(Scene scene)
96 {
97 if (!m_Enabled)
98 return;
99
100 scene.RegisterModuleInterface<IMuteListService>(this);
101 m_log.InfoFormat("[MUTELIST CONNECTOR]: Enabled for region {0}", scene.RegionInfo.RegionName);
102 }
103
104 public void RemoveRegion(Scene scene)
105 {
106 if (!m_Enabled)
107 return;
108 }
109
110 public void RegionLoaded(Scene scene)
111 {
112 if (!m_Enabled)
113 return;
114 }
115
116 #endregion
117
118 #region IMuteListService
119 public Byte[] MuteListRequest(UUID agentID, uint crc)
120 {
121 if (!m_Enabled)
122 return null;
123 return m_remoteConnector.MuteListRequest(agentID, crc);
124 }
125
126 public bool UpdateMute(MuteData mute)
127 {
128 if (!m_Enabled)
129 return false;
130 return m_remoteConnector.UpdateMute(mute);
131 }
132
133 public bool RemoveMute(UUID agentID, UUID muteID, string muteName)
134 {
135 if (!m_Enabled)
136 return false;
137 return m_remoteConnector.RemoveMute(agentID, muteID, muteName);
138 }
139
140 #endregion IMuteListService
141
142 }
143}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/LocalNeighbourServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/NeighbourServiceOutConnector.cs
index bda354f..60addec 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/LocalNeighbourServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/NeighbourServiceOutConnector.cs
@@ -25,52 +25,40 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System;
29using System.Collections.Generic;
30using System.Reflection;
31using log4net; 28using log4net;
32using Mono.Addins; 29using Mono.Addins;
30using System;
31using System.Reflection;
32using System.Collections.Generic;
33using Nini.Config; 33using Nini.Config;
34using OpenMetaverse;
35using OpenSim.Framework; 34using OpenSim.Framework;
36using OpenSim.Server.Base; 35using OpenSim.Services.Connectors;
37using OpenSim.Region.Framework.Interfaces; 36using OpenSim.Region.Framework.Interfaces;
38using OpenSim.Region.Framework.Scenes; 37using OpenSim.Region.Framework.Scenes;
39using OpenSim.Services.Interfaces; 38using OpenSim.Services.Interfaces;
40 39
40
41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Neighbour 41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Neighbour
42{ 42{
43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "LocalNeighbourServicesConnector")] 43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "NeighbourServicesOutConnector")]
44 public class LocalNeighbourServicesConnector : 44 public class NeighbourServicesOutConnector :
45 ISharedRegionModule, INeighbourService 45 NeighbourServicesConnector, ISharedRegionModule, INeighbourService
46 { 46 {
47 private static readonly ILog m_log = 47 private static readonly ILog m_log =
48 LogManager.GetLogger( 48 LogManager.GetLogger(
49 MethodBase.GetCurrentMethod().DeclaringType); 49 MethodBase.GetCurrentMethod().DeclaringType);
50 50
51 private List<Scene> m_Scenes = new List<Scene>(); 51 private List<Scene> m_Scenes = new List<Scene>();
52
53 private bool m_Enabled = false; 52 private bool m_Enabled = false;
54 53
55 public LocalNeighbourServicesConnector() 54 public Type ReplaceableInterface
56 {
57 }
58
59 public LocalNeighbourServicesConnector(List<Scene> scenes)
60 {
61 m_Scenes = scenes;
62 }
63
64 #region ISharedRegionModule
65
66 public Type ReplaceableInterface
67 { 55 {
68 get { return null; } 56 get { return null; }
69 } 57 }
70 58
71 public string Name 59 public string Name
72 { 60 {
73 get { return "LocalNeighbourServicesConnector"; } 61 get { return "NeighbourServicesOutConnector"; }
74 } 62 }
75 63
76 public void Initialise(IConfigSource source) 64 public void Initialise(IConfigSource source)
@@ -78,68 +66,69 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Neighbour
78 IConfig moduleConfig = source.Configs["Modules"]; 66 IConfig moduleConfig = source.Configs["Modules"];
79 if (moduleConfig != null) 67 if (moduleConfig != null)
80 { 68 {
81 string name = moduleConfig.GetString("NeighbourServices", this.Name); 69 string name = moduleConfig.GetString("NeighbourServices");
82 if (name == Name) 70 if (name == Name)
83 { 71 {
84 // m_Enabled rules whether this module registers as INeighbourService or not
85 m_Enabled = true; 72 m_Enabled = true;
86 m_log.Info("[NEIGHBOUR CONNECTOR]: Local neighbour connector enabled"); 73 m_log.Info("[NEIGHBOUR CONNECTOR]: Neighbour out connector enabled");
87 } 74 }
88 } 75 }
89 } 76 }
90 77
78 public void PostInitialise()
79 {
80 }
81
91 public void Close() 82 public void Close()
92 { 83 {
93 } 84 }
94 85
95 public void AddRegion(Scene scene) 86 public void AddRegion(Scene scene)
96 { 87 {
97 m_Scenes.Add(scene);
98
99 if (!m_Enabled) 88 if (!m_Enabled)
100 return; 89 return;
101 90
91 m_Scenes.Add(scene);
102 scene.RegisterModuleInterface<INeighbourService>(this); 92 scene.RegisterModuleInterface<INeighbourService>(this);
103 } 93 }
104 94
105 public void RegionLoaded(Scene scene)
106 {
107 m_log.Info("[NEIGHBOUR CONNECTOR]: Local neighbour connector enabled for region " + scene.RegionInfo.RegionName);
108 }
109
110 public void PostInitialise()
111 {
112 }
113
114 public void RemoveRegion(Scene scene) 95 public void RemoveRegion(Scene scene)
115 { 96 {
116 // Always remove 97 // Always remove
117 if (m_Scenes.Contains(scene)) 98 if (m_Scenes.Contains(scene))
118 m_Scenes.Remove(scene); 99 m_Scenes.Remove(scene);
119 } 100 }
120 101
121 #endregion ISharedRegionModule 102 public void RegionLoaded(Scene scene)
103 {
104 if (!m_Enabled)
105 return;
106
107 m_GridService = scene.GridService;
108 m_log.InfoFormat("[NEIGHBOUR CONNECTOR]: Enabled out neighbours for region {0}", scene.RegionInfo.RegionName);
109
110 }
122 111
123 #region INeighbourService 112 #region INeighbourService
124 113
125 public OpenSim.Services.Interfaces.GridRegion HelloNeighbour(ulong regionHandle, RegionInfo thisRegion) 114 public override GridRegion HelloNeighbour(ulong regionHandle, RegionInfo thisRegion)
126 { 115 {
127 uint x, y; 116 if (!m_Enabled)
128 Util.RegionHandleToRegionLoc(regionHandle, out x, out y); 117 return null;
129 118
130 foreach (Scene s in m_Scenes) 119 foreach (Scene s in m_Scenes)
131 { 120 {
132 if (s.RegionInfo.RegionHandle == regionHandle) 121 if (s.RegionInfo.RegionHandle == regionHandle)
133 { 122 {
134 m_log.DebugFormat("[LOCAL NEIGHBOUR SERVICE CONNECTOR]: HelloNeighbour from region {0} to neighbour {1} at {2}-{3}", 123// uint x, y;
135 thisRegion.RegionName, s.Name, x, y ); 124// Util.RegionHandleToRegionLoc(regionHandle, out x, out y);
136 125// m_log.DebugFormat("[NEIGHBOUR SERVICE OUT CONNECTOR]: HelloNeighbour from region {0} to neighbour {1} at {2}-{3}",
137 //m_log.Debug("[NEIGHBOUR CONNECTOR]: Found region to SendHelloNeighbour"); 126// thisRegion.RegionName, s.Name, x, y );
138 return s.IncomingHelloNeighbour(thisRegion); 127 return s.IncomingHelloNeighbour(thisRegion);
139 } 128 }
140 } 129 }
141 //m_log.DebugFormat("[NEIGHBOUR CONNECTOR]: region handle {0} not found", regionHandle); 130
142 return null; 131 return base.HelloNeighbour(regionHandle, thisRegion);
143 } 132 }
144 133
145 #endregion INeighbourService 134 #endregion INeighbourService
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/RemoteNeighourServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/RemoteNeighourServiceConnector.cs
deleted file mode 100644
index e6772f3..0000000
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Neighbour/RemoteNeighourServiceConnector.cs
+++ /dev/null
@@ -1,157 +0,0 @@
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 log4net;
29using Mono.Addins;
30using System;
31using System.Collections.Generic;
32using System.Reflection;
33using Nini.Config;
34using OpenSim.Framework;
35using OpenSim.Services.Connectors;
36using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes;
38using OpenSim.Services.Interfaces;
39using OpenSim.Server.Base;
40
41namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Neighbour
42{
43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "RemoteNeighbourServicesConnector")]
44 public class RemoteNeighbourServicesConnector :
45 NeighbourServicesConnector, ISharedRegionModule, INeighbourService
46 {
47 private static readonly ILog m_log =
48 LogManager.GetLogger(
49 MethodBase.GetCurrentMethod().DeclaringType);
50
51 private bool m_Enabled = false;
52 private LocalNeighbourServicesConnector m_LocalService;
53 //private string serviceDll;
54 //private List<Scene> m_Scenes = new List<Scene>();
55
56 public Type ReplaceableInterface
57 {
58 get { return null; }
59 }
60
61 public string Name
62 {
63 get { return "RemoteNeighbourServicesConnector"; }
64 }
65
66 public void Initialise(IConfigSource source)
67 {
68 IConfig moduleConfig = source.Configs["Modules"];
69 if (moduleConfig != null)
70 {
71 string name = moduleConfig.GetString("NeighbourServices");
72 if (name == Name)
73 {
74 m_LocalService = new LocalNeighbourServicesConnector();
75
76 //IConfig neighbourConfig = source.Configs["NeighbourService"];
77 //if (neighbourConfig == null)
78 //{
79 // m_log.Error("[NEIGHBOUR CONNECTOR]: NeighbourService missing from OpenSim.ini");
80 // return;
81 //}
82 //serviceDll = neighbourConfig.GetString("LocalServiceModule", String.Empty);
83 //if (serviceDll == String.Empty)
84 //{
85 // m_log.Error("[NEIGHBOUR CONNECTOR]: No LocalServiceModule named in section NeighbourService");
86 // return;
87 //}
88
89 m_Enabled = true;
90
91 m_log.Info("[NEIGHBOUR CONNECTOR]: Remote Neighbour connector enabled");
92 }
93 }
94 }
95
96 public void PostInitialise()
97 {
98 //if (m_Enabled)
99 //{
100 // Object[] args = new Object[] { m_Scenes };
101 // m_LocalService =
102 // ServerUtils.LoadPlugin<INeighbourService>(serviceDll,
103 // args);
104
105 // if (m_LocalService == null)
106 // {
107 // m_log.Error("[NEIGHBOUR CONNECTOR]: Can't load neighbour service");
108 // Unregister();
109 // return;
110 // }
111 //}
112 }
113
114 public void Close()
115 {
116 }
117
118 public void AddRegion(Scene scene)
119 {
120 if (!m_Enabled)
121 return;
122
123 m_LocalService.AddRegion(scene);
124 scene.RegisterModuleInterface<INeighbourService>(this);
125 }
126
127 public void RemoveRegion(Scene scene)
128 {
129 if (m_Enabled)
130 m_LocalService.RemoveRegion(scene);
131 }
132
133 public void RegionLoaded(Scene scene)
134 {
135 if (!m_Enabled)
136 return;
137
138 m_GridService = scene.GridService;
139
140 m_log.InfoFormat("[NEIGHBOUR CONNECTOR]: Enabled remote neighbours for region {0}", scene.RegionInfo.RegionName);
141
142 }
143
144 #region INeighbourService
145
146 public override GridRegion HelloNeighbour(ulong regionHandle, RegionInfo thisRegion)
147 {
148 GridRegion region = m_LocalService.HelloNeighbour(regionHandle, thisRegion);
149 if (region != null)
150 return region;
151
152 return base.HelloNeighbour(regionHandle, thisRegion);
153 }
154
155 #endregion INeighbourService
156 }
157}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/BasePresenceServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/BasePresenceServiceConnector.cs
index fdbe10a..e014a57 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/BasePresenceServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/BasePresenceServiceConnector.cs
@@ -123,6 +123,11 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
123 return m_PresenceService.GetAgent(sessionID); 123 return m_PresenceService.GetAgent(sessionID);
124 } 124 }
125 125
126 public PresenceInfo GetAgentByUser(UUID userID)
127 {
128 return m_PresenceService.GetAgentByUser(userID);
129 }
130
126 public PresenceInfo[] GetAgents(string[] userIDs) 131 public PresenceInfo[] GetAgents(string[] userIDs)
127 { 132 {
128 // Don't bother potentially making a useless network call if we not going to ask for any users anyway. 133 // Don't bother potentially making a useless network call if we not going to ask for any users anyway.
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs
index 50c252c..a7e62eb 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/PresenceDetector.cs
@@ -35,7 +35,7 @@ using OpenSim.Services.Interfaces;
35 35
36namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence 36namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
37{ 37{
38 public class PresenceDetector 38 public class PresenceDetector
39 { 39 {
40// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 40// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
41 41
@@ -68,6 +68,22 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence
68 68
69 public void OnMakeRootAgent(ScenePresence sp) 69 public void OnMakeRootAgent(ScenePresence sp)
70 { 70 {
71 if (sp.IsNPC)
72 return;
73
74 if(sp.gotCrossUpdate)
75 {
76 Util.FireAndForget(delegate
77 {
78 DoOnMakeRootAgent(sp);
79 }, null, "PresenceDetector_MakeRoot");
80 }
81 else
82 DoOnMakeRootAgent(sp);
83 }
84
85 public void DoOnMakeRootAgent(ScenePresence sp)
86 {
71// m_log.DebugFormat("[PRESENCE DETECTOR]: Detected root presence {0} in {1}", sp.UUID, sp.Scene.RegionInfo.RegionName); 87// m_log.DebugFormat("[PRESENCE DETECTOR]: Detected root presence {0} in {1}", sp.UUID, sp.Scene.RegionInfo.RegionName);
72 if (sp.PresenceType != PresenceType.Npc) 88 if (sp.PresenceType != PresenceType.Npc)
73 m_PresenceService.ReportAgent(sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID); 89 m_PresenceService.ReportAgent(sp.ControllingClient.SessionId, sp.Scene.RegionInfo.RegionID);
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs
index 69bac82..7838d12 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Presence/Tests/PresenceConnectorsTests.cs
@@ -72,7 +72,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Presence.Tests
72 public void TestPresenceV0_1() 72 public void TestPresenceV0_1()
73 { 73 {
74 SetUp(); 74 SetUp();
75 75
76 // Let's stick in a test presence 76 // Let's stick in a test presence
77 /* 77 /*
78 PresenceData p = new PresenceData(); 78 PresenceData p = new PresenceData();
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
index cc8203e..57aba05 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/LocalSimulationConnector.cs
@@ -185,7 +185,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
185 * Agent-related communications 185 * Agent-related communications
186 */ 186 */
187 187
188 public bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) 188 public bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, EntityTransferContext ctx, out string reason)
189 { 189 {
190 if (destination == null) 190 if (destination == null)
191 { 191 {
@@ -204,7 +204,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
204 return false; 204 return false;
205 } 205 }
206 206
207 public bool UpdateAgent(GridRegion destination, AgentData cAgentData) 207 public bool UpdateAgent(GridRegion destination, AgentData cAgentData, EntityTransferContext ctx)
208 { 208 {
209 if (destination == null) 209 if (destination == null)
210 return false; 210 return false;
@@ -219,7 +219,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
219 } 219 }
220 220
221// m_log.DebugFormat( 221// m_log.DebugFormat(
222// "[LOCAL COMMS]: Did not find region {0} {1} for ChildAgentUpdate", 222// "[LOCAL COMMS]: Did not find region {0} {1} for ChildAgentUpdate",
223// destination.RegionName, destination.RegionID); 223// destination.RegionName, destination.RegionID);
224 224
225 return false; 225 return false;
@@ -265,9 +265,10 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
265 reason = "Destination is a variable-sized region, and source is an old simulator. Consider upgrading."; 265 reason = "Destination is a variable-sized region, and source is an old simulator. Consider upgrading.";
266 m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: Request to access this variable-sized region from older simulator was denied"); 266 m_log.DebugFormat("[LOCAL SIMULATION CONNECTOR]: Request to access this variable-sized region from older simulator was denied");
267 return false; 267 return false;
268 268
269 } 269 }
270 270
271
271 return m_scenes[destination.RegionID].QueryAccess(agentID, agentHomeURI, viaTeleport, position, features, out reason); 272 return m_scenes[destination.RegionID].QueryAccess(agentID, agentHomeURI, viaTeleport, position, features, out reason);
272 } 273 }
273 274
@@ -305,7 +306,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
305 m_scenes[destination.RegionID].CloseAgent(id, false, auth_token); 306 m_scenes[destination.RegionID].CloseAgent(id, false, auth_token);
306 return true; 307 return true;
307 } 308 }
308
309 //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent"); 309 //m_log.Debug("[LOCAL COMMS]: region not found in SendCloseAgent");
310 return false; 310 return false;
311 } 311 }
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
index 1e095ca..b402d2a 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/Simulation/RemoteSimulationConnector.cs
@@ -137,7 +137,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
137 } 137 }
138 138
139 protected virtual void InitOnce(Scene scene) 139 protected virtual void InitOnce(Scene scene)
140 { 140 {
141 m_aScene = scene; 141 m_aScene = scene;
142 //m_regionClient = new RegionToRegionClient(m_aScene, m_hyperlinkService); 142 //m_regionClient = new RegionToRegionClient(m_aScene, m_hyperlinkService);
143 } 143 }
@@ -160,7 +160,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
160 * Agent-related communications 160 * Agent-related communications
161 */ 161 */
162 162
163 public bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, out string reason) 163 public bool CreateAgent(GridRegion source, GridRegion destination, AgentCircuitData aCircuit, uint teleportFlags, EntityTransferContext ctx, out string reason)
164 { 164 {
165 if (destination == null) 165 if (destination == null)
166 { 166 {
@@ -170,27 +170,27 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
170 } 170 }
171 171
172 // Try local first 172 // Try local first
173 if (m_localBackend.CreateAgent(source, destination, aCircuit, teleportFlags, out reason)) 173 if (m_localBackend.CreateAgent(source, destination, aCircuit, teleportFlags, ctx, out reason))
174 return true; 174 return true;
175 175
176 // else do the remote thing 176 // else do the remote thing
177 if (!m_localBackend.IsLocalRegion(destination.RegionID)) 177 if (!m_localBackend.IsLocalRegion(destination.RegionID))
178 { 178 {
179 return m_remoteConnector.CreateAgent(source, destination, aCircuit, teleportFlags, out reason); 179 return m_remoteConnector.CreateAgent(source, destination, aCircuit, teleportFlags, ctx, out reason);
180 } 180 }
181 return false; 181 return false;
182 } 182 }
183 183
184 public bool UpdateAgent(GridRegion destination, AgentData cAgentData) 184 public bool UpdateAgent(GridRegion destination, AgentData cAgentData, EntityTransferContext ctx)
185 { 185 {
186 if (destination == null) 186 if (destination == null)
187 return false; 187 return false;
188 188
189 // Try local first 189 // Try local first
190 if (m_localBackend.IsLocalRegion(destination.RegionID)) 190 if (m_localBackend.IsLocalRegion(destination.RegionID))
191 return m_localBackend.UpdateAgent(destination, cAgentData); 191 return m_localBackend.UpdateAgent(destination, cAgentData, ctx);
192 192
193 return m_remoteConnector.UpdateAgent(destination, cAgentData); 193 return m_remoteConnector.UpdateAgent(destination, cAgentData, ctx);
194 } 194 }
195 195
196 public bool UpdateAgent(GridRegion destination, AgentPosition cAgentData) 196 public bool UpdateAgent(GridRegion destination, AgentPosition cAgentData)
@@ -236,7 +236,6 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
236 return false; 236 return false;
237 } 237 }
238 238
239
240 public bool CloseAgent(GridRegion destination, UUID id, string auth_token) 239 public bool CloseAgent(GridRegion destination, UUID id, string auth_token)
241 { 240 {
242 if (destination == null) 241 if (destination == null)
@@ -249,7 +248,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Simulation
249 // else do the remote thing 248 // else do the remote thing
250 if (!m_localBackend.IsLocalRegion(destination.RegionID)) 249 if (!m_localBackend.IsLocalRegion(destination.RegionID))
251 return m_remoteConnector.CloseAgent(destination, id, auth_token); 250 return m_remoteConnector.CloseAgent(destination, id, auth_token);
252 251
253 return false; 252 return false;
254 } 253 }
255 254
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs
index 6d4ac39..77fd70b 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/LocalUserAccountServiceConnector.cs
@@ -59,7 +59,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
59 59
60 #region ISharedRegionModule 60 #region ISharedRegionModule
61 61
62 public Type ReplaceableInterface 62 public Type ReplaceableInterface
63 { 63 {
64 get { return null; } 64 get { return null; }
65 } 65 }
@@ -129,6 +129,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
129 // FIXME: Why do we bother setting this module and caching up if we just end up registering the inner 129 // FIXME: Why do we bother setting this module and caching up if we just end up registering the inner
130 // user account service?! 130 // user account service?!
131 scene.RegisterModuleInterface<IUserAccountService>(UserAccountService); 131 scene.RegisterModuleInterface<IUserAccountService>(UserAccountService);
132 scene.RegisterModuleInterface<IUserAccountCacheModule>(m_Cache);
132 } 133 }
133 134
134 public void RemoveRegion(Scene scene) 135 public void RemoveRegion(Scene scene)
@@ -152,7 +153,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
152 public UserAccount GetUserAccount(UUID scopeID, UUID userID) 153 public UserAccount GetUserAccount(UUID scopeID, UUID userID)
153 { 154 {
154 bool inCache = false; 155 bool inCache = false;
155 UserAccount account = m_Cache.Get(userID, out inCache); 156 UserAccount account;
157 account = m_Cache.Get(userID, out inCache);
156 if (inCache) 158 if (inCache)
157 return account; 159 return account;
158 160
@@ -165,7 +167,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
165 public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) 167 public UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
166 { 168 {
167 bool inCache = false; 169 bool inCache = false;
168 UserAccount account = m_Cache.Get(firstName + " " + lastName, out inCache); 170 UserAccount account;
171 account = m_Cache.Get(firstName + " " + lastName, out inCache);
169 if (inCache) 172 if (inCache)
170 return account; 173 return account;
171 174
@@ -181,6 +184,50 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
181 return UserAccountService.GetUserAccount(scopeID, Email); 184 return UserAccountService.GetUserAccount(scopeID, Email);
182 } 185 }
183 186
187 public List<UserAccount> GetUserAccounts(UUID scopeID, List<string> IDs)
188 {
189 List<UserAccount> ret = new List<UserAccount>();
190 List<string> missing = new List<string>();
191
192 // still another cache..
193 bool inCache = false;
194 UUID uuid = UUID.Zero;
195 UserAccount account;
196 foreach(string id in IDs)
197 {
198 if(UUID.TryParse(id, out uuid))
199 {
200 account = m_Cache.Get(uuid, out inCache);
201 if (inCache)
202 ret.Add(account);
203 else
204 missing.Add(id);
205 }
206 }
207
208 if(missing.Count == 0)
209 return ret;
210
211 List<UserAccount> ext = UserAccountService.GetUserAccounts(scopeID, missing);
212 if(ext != null && ext.Count > 0)
213 {
214 foreach(UserAccount acc in ext)
215 {
216 if(acc != null)
217 {
218 ret.Add(acc);
219 m_Cache.Cache(acc.PrincipalID, acc);
220 }
221 }
222 }
223 return ret;
224 }
225
226 public List<UserAccount> GetUserAccountsWhere(UUID scopeID, string query)
227 {
228 return null;
229 }
230
184 public List<UserAccount> GetUserAccounts(UUID scopeID, string query) 231 public List<UserAccount> GetUserAccounts(UUID scopeID, string query)
185 { 232 {
186 return UserAccountService.GetUserAccounts(scopeID, query); 233 return UserAccountService.GetUserAccounts(scopeID, query);
@@ -203,4 +250,4 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
203 250
204 #endregion 251 #endregion
205 } 252 }
206} \ No newline at end of file 253}
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs
index 5aa87d3..b510d0a 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/RemoteUserAccountServiceConnector.cs
@@ -26,6 +26,8 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections;
30using System.Collections.Generic;
29using Nini.Config; 31using Nini.Config;
30using log4net; 32using log4net;
31using Mono.Addins; 33using Mono.Addins;
@@ -34,6 +36,7 @@ using OpenSim.Region.Framework.Interfaces;
34using OpenSim.Region.Framework.Scenes; 36using OpenSim.Region.Framework.Scenes;
35using OpenSim.Services.Interfaces; 37using OpenSim.Services.Interfaces;
36using OpenSim.Services.Connectors; 38using OpenSim.Services.Connectors;
39using OpenSim.Framework;
37 40
38using OpenMetaverse; 41using OpenMetaverse;
39 42
@@ -50,7 +53,7 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
50 private bool m_Enabled = false; 53 private bool m_Enabled = false;
51 private UserAccountCache m_Cache; 54 private UserAccountCache m_Cache;
52 55
53 public Type ReplaceableInterface 56 public Type ReplaceableInterface
54 { 57 {
55 get { return null; } 58 get { return null; }
56 } 59 }
@@ -103,6 +106,9 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
103 return; 106 return;
104 107
105 scene.RegisterModuleInterface<IUserAccountService>(this); 108 scene.RegisterModuleInterface<IUserAccountService>(this);
109 scene.RegisterModuleInterface<IUserAccountCacheModule>(m_Cache);
110
111 scene.EventManager.OnNewClient += OnNewClient;
106 } 112 }
107 113
108 public void RemoveRegion(Scene scene) 114 public void RemoveRegion(Scene scene)
@@ -117,12 +123,21 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
117 return; 123 return;
118 } 124 }
119 125
126 // When a user actually enters the sim, clear them from
127 // cache so the sim will have the current values for
128 // flags, title, etc. And country, don't forget country!
129 private void OnNewClient(IClientAPI client)
130 {
131 m_Cache.Remove(client.Name);
132 }
133
120 #region Overwritten methods from IUserAccountService 134 #region Overwritten methods from IUserAccountService
121 135
122 public override UserAccount GetUserAccount(UUID scopeID, UUID userID) 136 public override UserAccount GetUserAccount(UUID scopeID, UUID userID)
123 { 137 {
124 bool inCache = false; 138 bool inCache = false;
125 UserAccount account = m_Cache.Get(userID, out inCache); 139 UserAccount account;
140 account = m_Cache.Get(userID, out inCache);
126 if (inCache) 141 if (inCache)
127 return account; 142 return account;
128 143
@@ -135,7 +150,8 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
135 public override UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName) 150 public override UserAccount GetUserAccount(UUID scopeID, string firstName, string lastName)
136 { 151 {
137 bool inCache = false; 152 bool inCache = false;
138 UserAccount account = m_Cache.Get(firstName + " " + lastName, out inCache); 153 UserAccount account;
154 account = m_Cache.Get(firstName + " " + lastName, out inCache);
139 if (inCache) 155 if (inCache)
140 return account; 156 return account;
141 157
@@ -146,6 +162,45 @@ namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
146 return account; 162 return account;
147 } 163 }
148 164
165 public override List<UserAccount> GetUserAccounts(UUID scopeID, List<string> IDs)
166 {
167 List<UserAccount> accs = new List<UserAccount>();
168 List<string> missing = new List<string>();
169
170 UUID uuid = UUID.Zero;
171 UserAccount account;
172 bool inCache = false;
173
174 foreach(string id in IDs)
175 {
176 if(UUID.TryParse(id, out uuid))
177 {
178 account = m_Cache.Get(uuid, out inCache);
179 if (inCache)
180 accs.Add(account);
181 else
182 missing.Add(id);
183 }
184 }
185
186 if(missing.Count > 0)
187 {
188 List<UserAccount> ext = base.GetUserAccounts(scopeID, missing);
189 if(ext != null && ext.Count >0 )
190 {
191 foreach(UserAccount acc in ext)
192 {
193 if(acc != null)
194 {
195 accs.Add(acc);
196 m_Cache.Cache(acc.PrincipalID, acc);
197 }
198 }
199 }
200 }
201 return accs;
202 }
203
149 public override bool StoreUserAccount(UserAccount data) 204 public override bool StoreUserAccount(UserAccount data)
150 { 205 {
151 // This remote connector refuses to serve this method 206 // This remote connector refuses to serve this method
diff --git a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
index ed52e48..f3572a2 100644
--- a/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
+++ b/OpenSim/Region/CoreModules/ServiceConnectorsOut/UserAccounts/UserAccountCache.cs
@@ -34,68 +34,119 @@ using log4net;
34 34
35namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts 35namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.UserAccounts
36{ 36{
37 public class UserAccountCache 37 public class UserAccountCache : IUserAccountCacheModule
38 { 38 {
39 private const double CACHE_EXPIRATION_SECONDS = 120000.0; // 33 hours! 39 private const double CACHE_ALIEN_EXPIRATION_SECONDS = 172800; // 48 hours
40 private const double CACHE_EXPIRATION_SECONDS = 3600.0; // 1 hour!
41 private const double CACHE_NULL_EXPIRATION_SECONDS = 600; // 10minutes
40 42
41// private static readonly ILog m_log = 43// private static readonly ILog m_log =
42// LogManager.GetLogger( 44// LogManager.GetLogger(
43// MethodBase.GetCurrentMethod().DeclaringType); 45// MethodBase.GetCurrentMethod().DeclaringType);
44 46
45 private ExpiringCache<UUID, UserAccount> m_UUIDCache; 47 private ExpiringCache<UUID, UserAccount> m_UUIDCache;
46 private ExpiringCache<string, UUID> m_NameCache; 48 private ExpiringCache<string, UUID> m_NameCache;
49 private object accessLock = new object();
47 50
48 public UserAccountCache() 51 public UserAccountCache()
49 { 52 {
50 m_UUIDCache = new ExpiringCache<UUID, UserAccount>(); 53 m_UUIDCache = new ExpiringCache<UUID, UserAccount>();
51 m_NameCache = new ExpiringCache<string, UUID>(); 54 m_NameCache = new ExpiringCache<string, UUID>();
52 } 55 }
53 56
54 public void Cache(UUID userID, UserAccount account) 57 public void Cache(UUID userID, UserAccount account)
55 { 58 {
56 // Cache even null accounts 59 // Cache even null accounts
57 m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS); 60 lock(accessLock)
58 if (account != null) 61 {
59 m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS); 62 if (account == null)
60 63 m_UUIDCache.AddOrUpdate(userID, null, CACHE_NULL_EXPIRATION_SECONDS);
64 else if(account.LocalToGrid)
65 {
66 m_UUIDCache.AddOrUpdate(userID, account, CACHE_EXPIRATION_SECONDS);
67 m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_EXPIRATION_SECONDS);
68 }
69 else
70 {
71 m_UUIDCache.AddOrUpdate(userID, account, CACHE_ALIEN_EXPIRATION_SECONDS);
72 m_NameCache.AddOrUpdate(account.Name, account.PrincipalID, CACHE_ALIEN_EXPIRATION_SECONDS);
73 }
61 //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID); 74 //m_log.DebugFormat("[USER CACHE]: cached user {0}", userID);
75 }
62 } 76 }
63 77
64 public void Invalidate(UUID userID)
65 {
66 m_UUIDCache.Remove(userID);
67 }
68 78
69 public UserAccount Get(UUID userID, out bool inCache) 79 public UserAccount Get(UUID userID, out bool inCache)
70 { 80 {
71 UserAccount account = null; 81 UserAccount account = null;
72 inCache = false; 82 inCache = false;
73 if (m_UUIDCache.TryGetValue(userID, out account)) 83 lock(accessLock)
74 { 84 {
75 //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName); 85 if (m_UUIDCache.TryGetValue(userID, out account))
76 inCache = true; 86 {
77 return account; 87 //m_log.DebugFormat("[USER CACHE]: Account {0} {1} found in cache", account.FirstName, account.LastName);
88 inCache = true;
89 return account;
90 }
78 } 91 }
79
80 return null; 92 return null;
81 } 93 }
82 94
83 public UserAccount Get(string name, out bool inCache) 95 public UserAccount Get(string name, out bool inCache)
84 { 96 {
85 inCache = false; 97 inCache = false;
86 if (!m_NameCache.Contains(name)) 98 lock(accessLock)
87 return null; 99 {
100 if (!m_NameCache.Contains(name))
101 return null;
88 102
89 UserAccount account = null; 103 UserAccount account = null;
90 UUID uuid = UUID.Zero; 104 UUID uuid = UUID.Zero;
91 if (m_NameCache.TryGetValue(name, out uuid)) 105 if (m_NameCache.TryGetValue(name, out uuid))
92 if (m_UUIDCache.TryGetValue(uuid, out account))
93 { 106 {
94 inCache = true; 107 if (m_UUIDCache.TryGetValue(uuid, out account))
95 return account; 108 {
109 inCache = true;
110 return account;
111 }
96 } 112 }
97 113 }
98 return null; 114 return null;
99 } 115 }
116
117 public void Invalidate(UUID userID)
118 {
119 m_UUIDCache.Remove(userID);
120 }
121
122 public void Remove(UUID id)
123 {
124 lock(accessLock)
125 {
126 if (!m_UUIDCache.Contains(id))
127 return;
128
129 UserAccount account = null;
130 if (m_UUIDCache.TryGetValue(id, out account) && account != null)
131 m_NameCache.Remove(account.Name);
132 m_UUIDCache.Remove(id);
133 }
134 }
135
136 public void Remove(string name)
137 {
138 lock(accessLock)
139 {
140 if (!m_NameCache.Contains(name))
141 return;
142
143 UUID uuid = UUID.Zero;
144 if (m_NameCache.TryGetValue(name, out uuid))
145 {
146 m_NameCache.Remove(name);
147 m_UUIDCache.Remove(uuid);
148 }
149 }
150 }
100 } 151 }
101} 152}