From 755ad9e3e0447b60299b08a18624064d1d64141b Mon Sep 17 00:00:00 2001 From: MW Date: Mon, 4 Feb 2008 12:04:02 +0000 Subject: First part of avatar persistence, currently only really works in standalone mode (with accounts_authenticate set to true), it also only currently has a mysql database connector. (sqlite one will follow soon). It also uses the tribalmedia database system, so this needs checking to see if the old problems with mono have been fixed. To use, see the appearance section in opensim.ini.example, set "persist = true", then add the correct connection string for your database.(see mysql-AvatarAppearance.sql in share folder for a example of the table mysql table structure). This could possible be used in a very small grid, but would mean each region server would need to connect to the same mysql database. But the work to move the code to one of the grid servers shouldn't be too much. --- OpenSim/Region/Environment/ModuleLoader.cs | 1 + .../Environment/Modules/AppearanceTableMapper.cs | 216 +++++++++++++++++++++ .../Environment/Modules/AvatarFactoryModule.cs | 64 ++++-- OpenSim/Region/Environment/PermissionManager.cs | 49 ++--- .../Region/Environment/Scenes/AvatarAppearance.cs | 12 ++ .../Region/Environment/Scenes/SceneObjectPart.cs | 3 + 6 files changed, 310 insertions(+), 35 deletions(-) create mode 100644 OpenSim/Region/Environment/Modules/AppearanceTableMapper.cs (limited to 'OpenSim/Region/Environment') diff --git a/OpenSim/Region/Environment/ModuleLoader.cs b/OpenSim/Region/Environment/ModuleLoader.cs index 41d8cac..76ba14b 100644 --- a/OpenSim/Region/Environment/ModuleLoader.cs +++ b/OpenSim/Region/Environment/ModuleLoader.cs @@ -135,6 +135,7 @@ namespace OpenSim.Region.Environment m_loadedSharedModules.Add(xmlRpcMod.Name, xmlRpcMod); } //TextureDownloadModule textureModule = new TextureDownloadModule(); + //LoadedSharedModules.Add(textureModule.Name, textureModule); } diff --git a/OpenSim/Region/Environment/Modules/AppearanceTableMapper.cs b/OpenSim/Region/Environment/Modules/AppearanceTableMapper.cs new file mode 100644 index 0000000..ec82145 --- /dev/null +++ b/OpenSim/Region/Environment/Modules/AppearanceTableMapper.cs @@ -0,0 +1,216 @@ +using System; +using System.Collections.Generic; +using System.Text; +using OpenSim.Region.Environment.Scenes; +using OpenSim.Framework; +using TribalMedia.Framework.Data; + +namespace OpenSim.Region.Environment.Modules +{ + public class AppearanceRowMapper : BaseRowMapper + { + + public AppearanceRowMapper(BaseSchema schema, AvatarAppearance obj) + : base(schema, obj) + { + } + } + + public class AppearanceTableMapper : BaseTableMapper + { + public AppearanceTableMapper(BaseDatabaseConnector database, string tableName) + : base(database, tableName) + { + BaseSchema rowMapperSchema = new BaseSchema(this); + m_schema = rowMapperSchema; + + m_keyFieldMapper = rowMapperSchema.AddMapping("UUID", + delegate(AppearanceRowMapper mapper) { return mapper.Object.ScenePresenceID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.ScenePresenceID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("Serial", + delegate(AppearanceRowMapper mapper) { return (uint)mapper.Object.WearablesSerial; }, + delegate(AppearanceRowMapper mapper, uint value) { mapper.Object.WearablesSerial = (int)value; }); + + rowMapperSchema.AddMapping("WearableItem0", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[0].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { + if (mapper.Object.Wearables == null) + { + mapper.Object.Wearables = new OpenSim.Framework.AvatarWearable[13]; + for (int i = 0; i < 13; i++) + { + mapper.Object.Wearables[i] = new AvatarWearable(); + } + } + mapper.Object.Wearables[0].ItemID = new libsecondlife.LLUUID(value.ToString()); + }); + + rowMapperSchema.AddMapping("WearableAsset0", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[0].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[0].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableItem1", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[1].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[1].ItemID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableAsset1", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[1].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[1].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableItem2", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[2].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[2].ItemID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableAsset2", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[2].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[2].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableItem3", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[3].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[3].ItemID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableAsset3", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[3].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[3].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableItem4", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[4].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[4].ItemID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableAsset4", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[4].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[4].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableItem5", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[5].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[5].ItemID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableAsset5", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[5].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[5].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableItem6", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[6].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[6].ItemID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableAsset6", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[6].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[6].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableItem7", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[7].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[7].ItemID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableAsset7", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[7].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[7].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableItem8", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[8].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[8].ItemID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableAsset8", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[8].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[8].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableItem9", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[9].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[9].ItemID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableAsset9", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[9].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[9].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableItem10", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[10].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[10].ItemID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableAsset10", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[10].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[10].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableItem11", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[11].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[11].ItemID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableAsset11", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[11].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[11].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableItem12", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[12].ItemID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[12].ItemID = new libsecondlife.LLUUID(value.ToString()); }); + + rowMapperSchema.AddMapping("WearableAsset12", + delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[12].AssetID.UUID; }, + delegate(AppearanceRowMapper mapper, Guid value) + { mapper.Object.Wearables[12].AssetID = new libsecondlife.LLUUID(value.ToString()); }); + + } + + public bool Add(Guid userID, AvatarAppearance appearance) + { + AppearanceRowMapper mapper = CreateRowMapper(appearance); + return Add(mapper); + } + + public bool Update(Guid userID, AvatarAppearance appearance) + { + AppearanceRowMapper mapper = CreateRowMapper(appearance); + return Update(appearance.ScenePresenceID.UUID, mapper); + } + + protected AppearanceRowMapper CreateRowMapper(AvatarAppearance appearance) + { + return new AppearanceRowMapper(m_schema, appearance); + } + + protected AppearanceRowMapper CreateRowMapper() + { + return CreateRowMapper(new AvatarAppearance()); + } + + protected AppearanceRowMapper FromReader(BaseDataReader reader, AvatarAppearance appearance) + { + AppearanceRowMapper mapper = CreateRowMapper(appearance); + mapper.FillObject(reader); + return mapper; + } + + public override AppearanceRowMapper FromReader(BaseDataReader reader) + { + AppearanceRowMapper mapper = CreateRowMapper(); + mapper.FillObject(reader); + return mapper; + } + + public bool TryGetValue(Guid presenceID, out AvatarAppearance val) + { + AppearanceRowMapper mapper; + if (TryGetValue(presenceID, out mapper)) + { + val = mapper.Object; + return true; + } + else + { + val = null; + return false; + } + } + } +} diff --git a/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs b/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs index 4dd1cb1..19ebdb8 100644 --- a/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs +++ b/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs @@ -35,6 +35,8 @@ using OpenSim.Framework.Communications.Cache; using OpenSim.Framework.Console; using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Scenes; +using OpenSim.Framework.Data; +using TribalMedia.Framework.Data; namespace OpenSim.Region.Environment.Modules { @@ -43,6 +45,12 @@ namespace OpenSim.Region.Environment.Modules private Scene m_scene = null; private readonly Dictionary m_avatarsAppearance = new Dictionary(); + private bool m_enablePersist = false; + private string m_connectionString; + private bool m_configured = false; + private BaseDatabaseConnector m_databaseMapper; + private AppearanceTableMapper m_appearanceMapper; + public bool TryGetAvatarAppearance(LLUUID avatarId, out AvatarAppearance appearance) { if (m_avatarsAppearance.ContainsKey(avatarId)) @@ -50,22 +58,31 @@ namespace OpenSim.Region.Environment.Modules appearance = m_avatarsAppearance[avatarId]; return true; } - else + + if (m_enablePersist) { - AvatarWearable[] wearables; - byte[] visualParams; - GetDefaultAvatarAppearance(out wearables, out visualParams); - appearance = new AvatarAppearance(avatarId, wearables, visualParams); - try + if (m_appearanceMapper.TryGetValue(avatarId.UUID, out appearance)) { + appearance.VisualParams = GetDefaultVisualParams(); + appearance.TextureEntry = AvatarAppearance.GetDefaultTextureEntry(); m_avatarsAppearance[avatarId] = appearance; + return true; } - catch (NullReferenceException) - { - MainLog.Instance.Error("AVATAR", "Unable to load appearance for uninitialized avatar"); - } - return true; } + + + //not found a appearance for user, so create a new one + AvatarWearable[] wearables; + byte[] visualParams; + GetDefaultAvatarAppearance(out wearables, out visualParams); + appearance = new AvatarAppearance(avatarId, wearables, visualParams); + + m_avatarsAppearance[avatarId] = appearance; + if (m_enablePersist) + { + m_appearanceMapper.Add(avatarId.UUID, appearance); + } + return true; } public void Initialise(Scene scene, IConfigSource source) @@ -77,6 +94,24 @@ namespace OpenSim.Region.Environment.Modules { m_scene = scene; } + + if (!m_configured) + { + m_configured = true; + try + { + m_enablePersist = source.Configs["Appearance"].GetBoolean("persist", false); + m_connectionString = source.Configs["Appearance"].GetString("connection_string", ""); + } + catch (Exception) + { + } + if (m_enablePersist) + { + m_databaseMapper = new MySQLDatabaseMapper(m_connectionString); + m_appearanceMapper = new AppearanceTableMapper(m_databaseMapper, "AvatarAppearance"); + } + } } public void PostInitialise() @@ -109,7 +144,7 @@ namespace OpenSim.Region.Environment.Modules public void AvatarIsWearing(Object sender, AvatarWearingArgs e) { - IClientAPI clientView = (IClientAPI) sender; + IClientAPI clientView = (IClientAPI)sender; CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(clientView.AgentId); if (profile != null) { @@ -134,6 +169,11 @@ namespace OpenSim.Region.Environment.Modules AvatarAppearance avatAppearance = m_avatarsAppearance[clientView.AgentId]; avatAppearance.Wearables[wear.Type].AssetID = assetId; avatAppearance.Wearables[wear.Type].ItemID = wear.ItemID; + + if (m_enablePersist) + { + m_appearanceMapper.Update(clientView.AgentId.UUID, avatAppearance); + } } } } diff --git a/OpenSim/Region/Environment/PermissionManager.cs b/OpenSim/Region/Environment/PermissionManager.cs index 9640ed7..6c49586 100644 --- a/OpenSim/Region/Environment/PermissionManager.cs +++ b/OpenSim/Region/Environment/PermissionManager.cs @@ -170,31 +170,9 @@ namespace OpenSim.Region.Environment // the administrator object permissions to take effect. LLUUID objectOwner = task.OwnerID; - //return task.RootPart.ObjectFlags;task.RootPart.ObjectFlags | - uint objectOwnerMask = task.RootPart.ObjectFlags; + objectOwnerMask = ApplyObjectModifyMasks(task.RootPart.OwnerMask, objectOwnerMask); - if((task.RootPart.OwnerMask & (uint)PermissionMask.Copy) != 0) - { - objectOwnerMask |= (uint)LLObject.ObjectFlags.ObjectCopy; - } - - if ((task.RootPart.OwnerMask & (uint) PermissionMask.Move) != 0) - { - objectOwnerMask |= (uint)LLObject.ObjectFlags.ObjectMove; - } - - if ((task.RootPart.OwnerMask & (uint) PermissionMask.Modify) != 0) - { - objectOwnerMask |= (uint)LLObject.ObjectFlags.ObjectModify; - } - - if ((task.RootPart.OwnerMask & (uint) PermissionMask.Transfer) != 0) - { - objectOwnerMask |= (uint)LLObject.ObjectFlags.ObjectTransfer; - } - - uint objectGroupMask = task.RootPart.ObjectFlags | task.RootPart.GroupMask; uint objectEveryoneMask = task.RootPart.ObjectFlags | task.RootPart.EveryoneMask; if (m_bypassPermissions) @@ -240,6 +218,31 @@ namespace OpenSim.Region.Environment return objectEveryoneMask; } + + private uint ApplyObjectModifyMasks(uint parentMask, uint objectOwnerMask) + { + if ((parentMask & (uint)PermissionMask.Copy) != 0) + { + objectOwnerMask |= (uint)LLObject.ObjectFlags.ObjectCopy; + } + + if ((parentMask & (uint)PermissionMask.Move) != 0) + { + objectOwnerMask |= (uint)LLObject.ObjectFlags.ObjectMove; + } + + if ((parentMask & (uint)PermissionMask.Modify) != 0) + { + objectOwnerMask |= (uint)LLObject.ObjectFlags.ObjectModify; + } + + if ((parentMask & (uint)PermissionMask.Transfer) != 0) + { + objectOwnerMask |= (uint)LLObject.ObjectFlags.ObjectTransfer; + } + return objectOwnerMask; + } + protected virtual bool GenericObjectPermission(LLUUID currentUser, LLUUID objId) { // Default: deny diff --git a/OpenSim/Region/Environment/Scenes/AvatarAppearance.cs b/OpenSim/Region/Environment/Scenes/AvatarAppearance.cs index 1583124..b54f777 100644 --- a/OpenSim/Region/Environment/Scenes/AvatarAppearance.cs +++ b/OpenSim/Region/Environment/Scenes/AvatarAppearance.cs @@ -35,8 +35,20 @@ namespace OpenSim.Region.Environment.Scenes public class AvatarAppearance { protected LLUUID m_scenePresenceID; + + public LLUUID ScenePresenceID + { + get { return m_scenePresenceID; } + set { m_scenePresenceID = value; } + } protected int m_wearablesSerial = 1; + public int WearablesSerial + { + get { return m_wearablesSerial; } + set { m_wearablesSerial = value; } + } + protected byte[] m_visualParams; public byte[] VisualParams diff --git a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs index 043b094..159eaf1 100644 --- a/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs +++ b/OpenSim/Region/Environment/Scenes/SceneObjectPart.cs @@ -72,6 +72,7 @@ namespace OpenSim.Region.Environment.Scenes public partial class SceneObjectPart : IScriptHost { + [XmlIgnore] public PhysicsActor PhysActor = null; public LLUUID LastOwnerID; @@ -764,11 +765,13 @@ namespace OpenSim.Region.Environment.Scenes public void TrimPermissions() { + BaseMask &= (uint)PermissionMask.All; OwnerMask &= (uint)PermissionMask.All; GroupMask &= (uint)PermissionMask.All; EveryoneMask &= (uint)PermissionMask.All; NextOwnerMask &= (uint)PermissionMask.All; + } /// -- cgit v1.1