Merge branch 'master' of melanie@opensimulator.org:/var/git/opensim

0.7.4.1
Melanie 2012-03-28 02:46:31 +01:00
commit a43e804e59
5 changed files with 175 additions and 16 deletions

View File

@ -214,6 +214,11 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
public virtual void RegionLoaded(Scene scene) public virtual void RegionLoaded(Scene scene)
{ {
scene.AddCommand(
"Friends", this, "friends show cache",
"friends show cache [<first-name> <last-name>]",
"Show the friends cache for the given user",
HandleFriendsShowCacheCommand);
} }
public void RemoveRegion(Scene scene) public void RemoveRegion(Scene scene)
@ -890,7 +895,9 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
/// Get friends from local cache only /// Get friends from local cache only
/// </summary> /// </summary>
/// <param name="agentID"></param> /// <param name="agentID"></param>
/// <returns></returns> /// <returns>
/// An empty array if the user has no friends or friends have not been cached.
/// </returns>
protected FriendInfo[] GetFriends(UUID agentID) protected FriendInfo[] GetFriends(UUID agentID)
{ {
UserFriendData friendsData; UserFriendData friendsData;
@ -939,6 +946,17 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
} }
} }
/// <summary>
/// Are friends cached on this simulator for a particular user?
/// </summary>
/// <param name="userID"></param>
/// <returns></returns>
protected bool AreFriendsCached(UUID userID)
{
lock (m_Friends)
return m_Friends.ContainsKey(userID);
}
protected virtual bool StoreRights(UUID agentID, UUID friendID, int rights) protected virtual bool StoreRights(UUID agentID, UUID friendID, int rights)
{ {
FriendsService.StoreFriend(agentID.ToString(), friendID.ToString(), rights); FriendsService.StoreFriend(agentID.ToString(), friendID.ToString(), rights);
@ -964,5 +982,61 @@ namespace OpenSim.Region.CoreModules.Avatar.Friends
} }
#endregion #endregion
protected void HandleFriendsShowCacheCommand(string module, string[] cmd)
{
if (cmd.Length != 5)
{
MainConsole.Instance.OutputFormat("Usage: friends show cache [<first-name> <last-name>]");
return;
}
string firstName = cmd[3];
string lastName = cmd[4];
IUserManagement umModule = m_Scenes[0].RequestModuleInterface<IUserManagement>();
UUID userId = umModule.GetUserIdByName(firstName, lastName);
// UserAccount ua
// = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, firstName, lastName);
if (userId == UUID.Zero)
{
MainConsole.Instance.OutputFormat("No such user as {0} {1}", firstName, lastName);
return;
}
if (!AreFriendsCached(userId))
{
MainConsole.Instance.OutputFormat("No friends cached on this simulator for {0} {1}", firstName, lastName);
return;
}
MainConsole.Instance.OutputFormat("Cached friends for {0} {1}:", firstName, lastName);
MainConsole.Instance.OutputFormat("UUID\n");
FriendInfo[] friends = GetFriends(userId);
foreach (FriendInfo friend in friends)
{
// MainConsole.Instance.OutputFormat(friend.PrincipalID.ToString());
// string friendFirstName, friendLastName;
//
// UserAccount friendUa
// = m_Scenes[0].UserAccountService.GetUserAccount(m_Scenes[0].RegionInfo.ScopeID, friend.PrincipalID);
UUID friendId;
string friendName;
if (UUID.TryParse(friend.Friend, out friendId))
friendName = umModule.GetUserName(friendId);
else
friendName = friend.Friend;
MainConsole.Instance.OutputFormat("{0} {1} {2}", friendName, friend.MyFlags, friend.TheirFlags);
}
}
} }
} }

View File

@ -30,6 +30,7 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Framework.Client;
using OpenSim.Region.Framework.Interfaces; using OpenSim.Region.Framework.Interfaces;
using OpenSim.Region.Framework.Scenes; using OpenSim.Region.Framework.Scenes;
using OpenSim.Services.Connectors.Hypergrid; using OpenSim.Services.Connectors.Hypergrid;
@ -177,9 +178,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
logout = success; // flag for later logout from this grid; this is an HG TP logout = success; // flag for later logout from this grid; this is an HG TP
if (success && m_RestrictInventoryAccessAbroad) if (success && m_RestrictInventoryAccessAbroad)
{ RemoveRootFolderContents(sp.ControllingClient);
// TODO tell the viewer to remove the root folder
}
return success; return success;
} }
@ -299,13 +298,7 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
base.Fail(sp, finalDestination, logout); base.Fail(sp, finalDestination, logout);
if (logout && m_RestrictInventoryAccessAbroad) if (logout && m_RestrictInventoryAccessAbroad)
{ {
// Restore the user's inventory, because we removed it earlier on RestoreRootFolderContents(sp.ControllingClient);
InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(sp.UUID);
if (root != null)
{
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Restoring");
sp.ControllingClient.SendBulkUpdateInventory(root);
}
} }
} }
@ -363,6 +356,47 @@ namespace OpenSim.Region.CoreModules.Framework.EntityTransfer
#endregion #endregion
private void RemoveRootFolderContents(IClientAPI client)
{
// TODO tell the viewer to remove the root folder's content
if (client is IClientCore)
{
IClientCore core = (IClientCore)client;
IClientInventory inv;
if (core.TryGet<IClientInventory>(out inv))
{
InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
if (root != null)
{
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Removing root inventory");
InventoryCollection content = m_Scenes[0].InventoryService.GetFolderContent(client.AgentId, root.ID);
UUID[] ids = new UUID[content.Folders.Count];
int i = 0;
foreach (InventoryFolderBase f in content.Folders)
ids[i++] = f.ID;
inv.SendRemoveInventoryFolders(ids);
ids = new UUID[content.Items.Count];
i = 0;
foreach (InventoryItemBase it in content.Items)
ids[i++] = it.ID;
inv.SendRemoveInventoryItems(ids);
}
}
}
}
private void RestoreRootFolderContents(IClientAPI client)
{
// Restore the user's inventory, because we removed it earlier on
InventoryFolderBase root = m_Scenes[0].InventoryService.GetRootFolder(client.AgentId);
if (root != null)
{
m_log.DebugFormat("[HG ENTITY TRANSFER MODULE]: Restoring root inventory");
client.SendBulkUpdateInventory(root);
}
}
private GridRegion MakeRegion(AgentCircuitData aCircuit) private GridRegion MakeRegion(AgentCircuitData aCircuit)
{ {
GridRegion region = new GridRegion(); GridRegion region = new GridRegion();

View File

@ -297,6 +297,35 @@ namespace OpenSim.Region.CoreModules.Framework.UserManagement
#region IUserManagement #region IUserManagement
public UUID GetUserIdByName(string name)
{
string[] parts = name.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 2)
throw new Exception("Name must have 2 components");
return GetUserIdByName(parts[0], parts[1]);
}
public UUID GetUserIdByName(string firstName, string lastName)
{
// TODO: Optimize for reverse lookup if this gets used by non-console commands.
lock (m_UserCache)
{
foreach (UserData user in m_UserCache.Values)
{
if (user.FirstName == firstName && user.LastName == lastName)
return user.Id;
}
}
UserAccount account = m_Scenes[0].UserAccountService.GetUserAccount(UUID.Zero, firstName, lastName);
if (account != null)
return account.PrincipalID;
return UUID.Zero;
}
public string GetUserName(UUID uuid) public string GetUserName(UUID uuid)
{ {
string[] names = GetUserNames(uuid); string[] names = GetUserNames(uuid);

View File

@ -15,6 +15,21 @@ namespace OpenSim.Region.Framework.Interfaces
string GetUserUUI(UUID uuid); string GetUserUUI(UUID uuid);
string GetUserServerURL(UUID uuid, string serverType); string GetUserServerURL(UUID uuid, string serverType);
/// <summary>
/// Get user ID by the given name.
/// </summary>
/// <param name="name"></param>
/// <returns>UUID.Zero if no user with that name is found or if the name is "Unknown User"</returns>
UUID GetUserIdByName(string name);
/// <summary>
/// Get user ID by the given name.
/// </summary>
/// <param name="firstName"></param>
/// <param name="lastName"></param>
/// <returns>UUID.Zero if no user with that name is found or if the name is "Unknown User"</returns>
UUID GetUserIdByName(string firstName, string lastName);
/// <summary> /// <summary>
/// Add a user. /// Add a user.
/// </summary> /// </summary>

View File

@ -2675,12 +2675,19 @@ namespace OpenSim.Region.Framework.Scenes
// Cache the user's name // Cache the user's name
CacheUserName(sp, aCircuit); CacheUserName(sp, aCircuit);
// Let's send the Suitcase folder for incoming HG agents // Let's send the Suitcase or the real root folder folder for incoming HG agents
// Visiting agents get their suitcase contents; incoming local users get their real root folder's content
if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0) if ((aCircuit.teleportFlags & (uint)Constants.TeleportFlags.ViaHGLogin) != 0)
{ {
m_log.DebugFormat("[SCENE]: Sending root folder to viewer..."); // HACK FOR NOW. JUST TESTING, SO KEEPING EVERYONE ELSE OUT OF THESE TESTS
InventoryFolderBase suitcase = InventoryService.GetRootFolder(client.AgentId); IConfig config = m_config.Configs["HGEntityTransfer"];
client.SendBulkUpdateInventory(suitcase); if (config != null && config.GetBoolean("RestrictInventoryAccessAbroad", false))
{
m_log.DebugFormat("[SCENE]: Sending root folder to viewer...");
InventoryFolderBase root = InventoryService.GetRootFolder(client.AgentId);
//InventoryCollection rootContents = InventoryService.GetFolderContent(client.AgentId, root.ID);
client.SendBulkUpdateInventory(root);
}
} }
EventManager.TriggerOnNewClient(client); EventManager.TriggerOnNewClient(client);