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.
This commit is contained in:
MW
2008-02-04 12:04:02 +00:00
parent 6fbc64af5e
commit 755ad9e3e0
21 changed files with 403 additions and 52 deletions

View File

@@ -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<LLUUID, AvatarAppearance> m_avatarsAppearance = new Dictionary<LLUUID, AvatarAppearance>();
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);
}
}
}
}