diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs | 64 |
1 files changed, 52 insertions, 12 deletions
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; | |||
35 | using OpenSim.Framework.Console; | 35 | using OpenSim.Framework.Console; |
36 | using OpenSim.Region.Environment.Interfaces; | 36 | using OpenSim.Region.Environment.Interfaces; |
37 | using OpenSim.Region.Environment.Scenes; | 37 | using OpenSim.Region.Environment.Scenes; |
38 | using OpenSim.Framework.Data; | ||
39 | using TribalMedia.Framework.Data; | ||
38 | 40 | ||
39 | namespace OpenSim.Region.Environment.Modules | 41 | namespace OpenSim.Region.Environment.Modules |
40 | { | 42 | { |
@@ -43,6 +45,12 @@ namespace OpenSim.Region.Environment.Modules | |||
43 | private Scene m_scene = null; | 45 | private Scene m_scene = null; |
44 | private readonly Dictionary<LLUUID, AvatarAppearance> m_avatarsAppearance = new Dictionary<LLUUID, AvatarAppearance>(); | 46 | private readonly Dictionary<LLUUID, AvatarAppearance> m_avatarsAppearance = new Dictionary<LLUUID, AvatarAppearance>(); |
45 | 47 | ||
48 | private bool m_enablePersist = false; | ||
49 | private string m_connectionString; | ||
50 | private bool m_configured = false; | ||
51 | private BaseDatabaseConnector m_databaseMapper; | ||
52 | private AppearanceTableMapper m_appearanceMapper; | ||
53 | |||
46 | public bool TryGetAvatarAppearance(LLUUID avatarId, out AvatarAppearance appearance) | 54 | public bool TryGetAvatarAppearance(LLUUID avatarId, out AvatarAppearance appearance) |
47 | { | 55 | { |
48 | if (m_avatarsAppearance.ContainsKey(avatarId)) | 56 | if (m_avatarsAppearance.ContainsKey(avatarId)) |
@@ -50,22 +58,31 @@ namespace OpenSim.Region.Environment.Modules | |||
50 | appearance = m_avatarsAppearance[avatarId]; | 58 | appearance = m_avatarsAppearance[avatarId]; |
51 | return true; | 59 | return true; |
52 | } | 60 | } |
53 | else | 61 | |
62 | if (m_enablePersist) | ||
54 | { | 63 | { |
55 | AvatarWearable[] wearables; | 64 | if (m_appearanceMapper.TryGetValue(avatarId.UUID, out appearance)) |
56 | byte[] visualParams; | ||
57 | GetDefaultAvatarAppearance(out wearables, out visualParams); | ||
58 | appearance = new AvatarAppearance(avatarId, wearables, visualParams); | ||
59 | try | ||
60 | { | 65 | { |
66 | appearance.VisualParams = GetDefaultVisualParams(); | ||
67 | appearance.TextureEntry = AvatarAppearance.GetDefaultTextureEntry(); | ||
61 | m_avatarsAppearance[avatarId] = appearance; | 68 | m_avatarsAppearance[avatarId] = appearance; |
69 | return true; | ||
62 | } | 70 | } |
63 | catch (NullReferenceException) | ||
64 | { | ||
65 | MainLog.Instance.Error("AVATAR", "Unable to load appearance for uninitialized avatar"); | ||
66 | } | ||
67 | return true; | ||
68 | } | 71 | } |
72 | |||
73 | |||
74 | //not found a appearance for user, so create a new one | ||
75 | AvatarWearable[] wearables; | ||
76 | byte[] visualParams; | ||
77 | GetDefaultAvatarAppearance(out wearables, out visualParams); | ||
78 | appearance = new AvatarAppearance(avatarId, wearables, visualParams); | ||
79 | |||
80 | m_avatarsAppearance[avatarId] = appearance; | ||
81 | if (m_enablePersist) | ||
82 | { | ||
83 | m_appearanceMapper.Add(avatarId.UUID, appearance); | ||
84 | } | ||
85 | return true; | ||
69 | } | 86 | } |
70 | 87 | ||
71 | public void Initialise(Scene scene, IConfigSource source) | 88 | public void Initialise(Scene scene, IConfigSource source) |
@@ -77,6 +94,24 @@ namespace OpenSim.Region.Environment.Modules | |||
77 | { | 94 | { |
78 | m_scene = scene; | 95 | m_scene = scene; |
79 | } | 96 | } |
97 | |||
98 | if (!m_configured) | ||
99 | { | ||
100 | m_configured = true; | ||
101 | try | ||
102 | { | ||
103 | m_enablePersist = source.Configs["Appearance"].GetBoolean("persist", false); | ||
104 | m_connectionString = source.Configs["Appearance"].GetString("connection_string", ""); | ||
105 | } | ||
106 | catch (Exception) | ||
107 | { | ||
108 | } | ||
109 | if (m_enablePersist) | ||
110 | { | ||
111 | m_databaseMapper = new MySQLDatabaseMapper(m_connectionString); | ||
112 | m_appearanceMapper = new AppearanceTableMapper(m_databaseMapper, "AvatarAppearance"); | ||
113 | } | ||
114 | } | ||
80 | } | 115 | } |
81 | 116 | ||
82 | public void PostInitialise() | 117 | public void PostInitialise() |
@@ -109,7 +144,7 @@ namespace OpenSim.Region.Environment.Modules | |||
109 | 144 | ||
110 | public void AvatarIsWearing(Object sender, AvatarWearingArgs e) | 145 | public void AvatarIsWearing(Object sender, AvatarWearingArgs e) |
111 | { | 146 | { |
112 | IClientAPI clientView = (IClientAPI) sender; | 147 | IClientAPI clientView = (IClientAPI)sender; |
113 | CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(clientView.AgentId); | 148 | CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(clientView.AgentId); |
114 | if (profile != null) | 149 | if (profile != null) |
115 | { | 150 | { |
@@ -134,6 +169,11 @@ namespace OpenSim.Region.Environment.Modules | |||
134 | AvatarAppearance avatAppearance = m_avatarsAppearance[clientView.AgentId]; | 169 | AvatarAppearance avatAppearance = m_avatarsAppearance[clientView.AgentId]; |
135 | avatAppearance.Wearables[wear.Type].AssetID = assetId; | 170 | avatAppearance.Wearables[wear.Type].AssetID = assetId; |
136 | avatAppearance.Wearables[wear.Type].ItemID = wear.ItemID; | 171 | avatAppearance.Wearables[wear.Type].ItemID = wear.ItemID; |
172 | |||
173 | if (m_enablePersist) | ||
174 | { | ||
175 | m_appearanceMapper.Update(clientView.AgentId.UUID, avatAppearance); | ||
176 | } | ||
137 | } | 177 | } |
138 | } | 178 | } |
139 | } | 179 | } |