29 using System.Collections.Generic;
30 using System.Reflection;
32 using OpenSim.Framework;
33 using OpenSim.Framework.Client;
34 using OpenSim.Region.Framework.Interfaces;
35 using OpenSim.Region.Framework.Scenes;
36 using OpenSim.Services.Connectors.Hypergrid;
37 using OpenSim.Services.Interfaces;
38 using OpenSim.Server.Base;
47 namespace OpenSim.
Region.CoreModules.Framework.InventoryAccess
49 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"HGInventoryAccessModule")]
52 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
57 get {
return m_assMapper; }
60 private string m_HomeURI;
61 private bool m_OutboundPermission;
62 private string m_ThisGatekeeper;
63 private bool m_RestrictInventoryAccessAbroad;
65 private bool m_bypassPermissions =
true;
73 private bool m_CheckSeparateAssets =
false;
74 private string m_LocalAssetsURL = string.Empty;
78 #region INonSharedRegionModule
80 public override string Name
82 get {
return "HGInventoryAccessModule"; }
87 IConfig moduleConfig = source.Configs[
"Modules"];
88 if (moduleConfig != null)
90 string name = moduleConfig.GetString(
"InventoryAccessModule",
"");
95 InitialiseCommon(source);
97 m_log.InfoFormat(
"[HG INVENTORY ACCESS MODULE]: {0} enabled.", Name);
99 IConfig thisModuleConfig = source.Configs[
"HGInventoryAccessModule"];
100 if (thisModuleConfig != null)
102 m_HomeURI = Util.GetConfigVarFromSections<
string>(source,
"HomeURI",
103 new string[] {
"Startup",
"Hypergrid",
"HGInventoryAccessModule" }, String.Empty);
104 m_ThisGatekeeper = Util.GetConfigVarFromSections<
string>(source,
"GatekeeperURI",
105 new string[] {
"Startup",
"Hypergrid",
"HGInventoryAccessModule" }, String.Empty);
107 m_ThisGatekeeper = thisModuleConfig.GetString(
"Gatekeeper", m_ThisGatekeeper);
109 m_OutboundPermission = thisModuleConfig.GetBoolean(
"OutboundPermission",
true);
110 m_RestrictInventoryAccessAbroad = thisModuleConfig.GetBoolean(
"RestrictInventoryAccessAbroad",
true);
111 m_CheckSeparateAssets = thisModuleConfig.GetBoolean(
"CheckSeparateAssets",
false);
112 m_LocalAssetsURL = thisModuleConfig.GetString(
"RegionHGAssetServerURI", string.Empty);
113 m_LocalAssetsURL = m_LocalAssetsURL.Trim(
new char[] {
'/' });
117 m_log.Warn(
"[HG INVENTORY ACCESS MODULE]: HGInventoryAccessModule configs not found. ProfileServerURI not set!");
119 m_bypassPermissions = !Util.GetConfigVarFromSections<
bool>(source,
"serverside_object_permissions",
120 new string[] {
"Startup",
"Permissions" },
true);
131 base.AddRegion(scene);
133 scene.EventManager.OnNewInventoryItemUploadComplete += PostInventoryAsset;
134 scene.EventManager.OnTeleportStart += TeleportStart;
135 scene.EventManager.OnTeleportFail += TeleportFail;
138 scene.Permissions.OnTakeObject += CanTakeObject;
139 scene.Permissions.OnTakeCopyObject += CanTakeObject;
140 scene.Permissions.OnTransferUserInventory += OnTransferUserInventory;
145 #region Event handlers
149 base.OnNewClient(client);
150 client.OnCompleteMovementToRegion +=
new Action<IClientAPI, bool>(OnCompleteMovementToRegion);
161 AgentCircuitData aCircuit = ((ScenePresence)sp).Scene.AuthenticateHandler.GetAgentCircuitData(client.AgentId);
162 if (aCircuit != null && (aCircuit.
teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0)
164 if (m_RestrictInventoryAccessAbroad)
168 ProcessInventoryForComingHome(client);
170 ProcessInventoryForArriving(client);
179 if (gridLogout && m_RestrictInventoryAccessAbroad)
185 ProcessInventoryForHypergriding(client);
190 ProcessInventoryForLeaving(client);
198 if (gridLogout && m_RestrictInventoryAccessAbroad)
203 ProcessInventoryForComingHome(client);
207 ProcessInventoryForArriving(client);
212 public void PostInventoryAsset(UUID avatarID, AssetType type, UUID assetID,
string name,
int userlevel)
214 if (type == AssetType.Link)
217 string userAssetServer = string.Empty;
218 if (IsForeignUser(avatarID, out userAssetServer) && userAssetServer !=
string.Empty && m_OutboundPermission)
220 m_assMapper.Post(assetID, avatarID, userAssetServer);
226 #region Overrides of Basic Inventory Access methods
230 if (UserManagementModule != null && !UserManagementModule.IsLocalGridUser(presence.
UUID))
233 prefix = string.Empty;
234 suffix =
" @ " + m_ThisGatekeeper;
235 Vector3 pos = presence.AbsolutePosition;
236 return String.Format(
"Landmark version 2\nregion_id {0}\nlocal_pos {1} {2} {3}\nregion_handle {4}\ngatekeeper {5}\n",
237 presence.Scene.RegionInfo.RegionID,
239 presence.RegionHandle,
249 UUID newAssetID = base.CapsUpdateInventoryItemAsset(remoteClient, itemID, data);
251 PostInventoryAsset(remoteClient.AgentId, AssetType.Unknown, newAssetID,
"", 0);
261 if (base.UpdateInventoryItemAsset(ownerID, item, asset))
263 PostInventoryAsset(ownerID, (AssetType)asset.
Type, asset.
FullID, asset.
Name, 0);
275 if (!assetID.Equals(
UUID.Zero))
276 PostInventoryAsset(agentID, AssetType.Unknown, assetID,
"", 0);
278 m_log.Debug(
"[HGScene]: Scene.Inventory did not create asset");
285 UUID RayTargetID, byte BypassRayCast,
bool RayEndIsIntersection,
286 bool RezSelected,
bool RemoveItem, UUID fromTaskID,
bool attachment)
288 m_log.DebugFormat(
"[HGScene]: RezObject itemID={0} fromTaskID={1}", itemID, fromTaskID);
293 item.Owner = remoteClient.AgentId;
294 item = m_Scene.InventoryService.GetItem(item);
302 string userAssetServer = string.Empty;
303 if (item != null && IsForeignUser(remoteClient.
AgentId, out userAssetServer))
305 m_assMapper.Get(item.AssetID, remoteClient.AgentId, userAssetServer);
311 SceneObjectGroup sog = base.RezObject(remoteClient, itemID, RayEnd, RayStart, RayTargetID, BypassRayCast, RayEndIsIntersection,
312 RezSelected, RemoveItem, fromTaskID, attachment);
320 string senderAssetServer = string.Empty;
321 string receiverAssetServer = string.Empty;
322 bool isForeignSender, isForeignReceiver;
323 isForeignSender = IsForeignUser(sender, out senderAssetServer);
324 isForeignReceiver = IsForeignUser(receiver, out receiverAssetServer);
327 if (!isForeignSender && !isForeignReceiver)
332 if (senderAssetServer.Equals(receiverAssetServer))
334 m_log.DebugFormat(
"[HGScene]: Asset transfer between foreign users, but they have the same server. No transfer.");
338 if (isForeignSender && senderAssetServer !=
string.Empty)
339 m_assMapper.Get(item.AssetID, sender, senderAssetServer);
341 if (isForeignReceiver && receiverAssetServer !=
string.Empty && m_OutboundPermission)
342 m_assMapper.Post(item.AssetID, receiver, receiverAssetServer);
347 assetServerURL = string.Empty;
349 if (UserManagementModule != null)
351 if (!m_CheckSeparateAssets)
353 if (!UserManagementModule.IsLocalGridUser(userID))
356 if (m_Scene.TryGetScenePresence(userID, out sp))
358 AgentCircuitData aCircuit = m_Scene.AuthenticateHandler.GetAgentCircuitData(sp.ControllingClient.CircuitCode);
359 if (aCircuit != null && aCircuit.
ServiceURLs != null && aCircuit.
ServiceURLs.ContainsKey(
"AssetServerURI"))
361 assetServerURL = aCircuit.ServiceURLs[
"AssetServerURI"].ToString();
362 assetServerURL = assetServerURL.Trim(
new char[] {
'/' });
367 assetServerURL = UserManagementModule.GetUserServerURL(userID,
"AssetServerURI");
368 assetServerURL = assetServerURL.Trim(
new char[] {
'/' });
375 if (IsLocalInventoryAssetsUser(userID, out assetServerURL))
377 m_log.DebugFormat(
"[HGScene]: user {0} has local assets {1}", userID, assetServerURL);
382 m_log.DebugFormat(
"[HGScene]: user {0} has foreign assets {1}", userID, assetServerURL);
390 private bool IsLocalInventoryAssetsUser(UUID uuid, out
string assetsURL)
392 assetsURL = UserManagementModule.GetUserServerURL(uuid,
"AssetServerURI");
393 if (assetsURL ==
string.Empty)
395 AgentCircuitData agent = m_Scene.AuthenticateHandler.GetAgentCircuitData(uuid);
398 assetsURL = agent.ServiceURLs[
"AssetServerURI"].ToString();
399 assetsURL = assetsURL.Trim(
new char[] {
'/' });
402 return m_LocalAssetsURL.Equals(assetsURL);
412 string userAssetServer = string.Empty;
413 if (IsForeignUser(agentID, out userAssetServer))
414 m_assMapper.Get(item.
AssetID, agentID, userAssetServer);
421 #region Inventory manipulation upon arriving/leaving
427 private void ProcessInventoryForComingHome(
IClientAPI client)
429 m_log.DebugFormat(
"[HG INVENTORY ACCESS MODULE]: Restoring root folder for local user {0}", client.Name);
432 IClientCore core = (IClientCore)client;
438 InventoryCollection content = m_Scene.InventoryService.GetFolderContent(client.AgentId, root.ID);
440 List<InventoryFolderBase> keep =
new List<InventoryFolderBase>();
444 if (f.
Name !=
"My Suitcase" && f.
Name !=
"Current Outfit")
448 inv.SendBulkUpdateInventory(keep.ToArray(), content.Items.ToArray());
453 private void ProcessInventoryForArriving(
IClientAPI client)
462 private void ProcessInventoryForHypergriding(
IClientAPI client)
464 if (client is IClientCore)
466 IClientCore core = (IClientCore)client;
474 m_log.DebugFormat(
"[HG INVENTORY ACCESS MODULE]: Changing root inventory for user {0}", client.Name);
475 InventoryCollection content = m_Scene.InventoryService.GetFolderContent(client.AgentId, root.ID);
477 List<InventoryFolderBase> keep =
new List<InventoryFolderBase>();
481 if (f.
Name !=
"My Suitcase" && f.
Name !=
"Current Outfit")
483 f.Name = f.Name +
" (Unavailable)";
490 it.Name = it.Name +
" (Unavailable)"; ;
493 inv.SendBulkUpdateInventory(keep.ToArray(), content.Items.ToArray());
500 private void ProcessInventoryForLeaving(
IClientAPI client)
509 private bool CanTakeObject(UUID objectID, UUID stealer,
Scene scene)
511 if (m_bypassPermissions)
return true;
513 if (!m_OutboundPermission && !UserManagementModule.IsLocalGridUser(stealer))
516 if (m_Scene.TryGetSceneObjectGroup(objectID, out sog) && sog.OwnerID == stealer)
525 private bool OnTransferUserInventory(UUID itemID, UUID userID, UUID recipientID)
527 if (m_bypassPermissions)
return true;
529 if (!m_OutboundPermission && !UserManagementModule.IsLocalGridUser(recipientID))
override void TransferInventoryAssets(InventoryItemBase item, UUID sender, UUID receiver)
override InventoryItemBase GetItem(UUID agentID, UUID itemID)
OpenSim.Services.Interfaces.GridRegion GridRegion
override void OnNewClient(IClientAPI client)
override void ExportAsset(UUID agentID, UUID assetID)
A scene object group is conceptually an object in the scene. The object is constituted of SceneObject...
Dictionary< string, object > ServiceURLs
sbyte Type
(sbyte) AssetType enum
bool IsLocalGridUser(UUID uuid)
void OnCompleteMovementToRegion(IClientAPI client, bool arg2)
Asset class. All Assets are reference by this class or a class derived from this class ...
override UUID CapsUpdateInventoryItemAsset(IClientAPI remoteClient, UUID itemID, byte[] data)
override void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
Circuit data for an agent. Connection information shared between regions that accept UDP connections ...
Inventory Item - contains all the properties associated with an individual inventory piece...
override bool IsForeignUser(UUID userID, out string assetServerURL)
void PostInventoryAsset(UUID avatarID, AssetType type, UUID assetID, string name, int userlevel)
override SceneObjectGroup RezObject(IClientAPI remoteClient, UUID itemID, Vector3 RayEnd, Vector3 RayStart, UUID RayTargetID, byte BypassRayCast, bool RayEndIsIntersection, bool RezSelected, bool RemoveItem, UUID fromTaskID, bool attachment)
override string GenerateLandmark(ScenePresence presence, out string prefix, out string suffix)
override void Initialise(IConfigSource source)
This is called to initialize the region module. For shared modules, this is called exactly once...
override bool UpdateInventoryItemAsset(UUID ownerID, InventoryItemBase item, AssetBase asset)
void TeleportStart(IClientAPI client, GridRegion destination, GridRegion finalDestination, uint teleportFlags, bool gridLogout)
virtual string Name
The name of the node (64 characters or less)
void TeleportFail(IClientAPI client, bool gridLogout)
bool TryGetScenePresence(UUID agentID, out object scenePresence)
uint teleportFlags
How this agent got here
This maintains the relationship between a UUID and a user name.
Used to serialize a whole inventory for transfer over the network.