aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs
diff options
context:
space:
mode:
authorMW2008-02-04 12:04:02 +0000
committerMW2008-02-04 12:04:02 +0000
commit755ad9e3e0447b60299b08a18624064d1d64141b (patch)
tree89859180b5ba7ef47defbf6a1d6640177ecb1326 /OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs
parent* Whole buncha stuff. (diff)
downloadopensim-SC-755ad9e3e0447b60299b08a18624064d1d64141b.zip
opensim-SC-755ad9e3e0447b60299b08a18624064d1d64141b.tar.gz
opensim-SC-755ad9e3e0447b60299b08a18624064d1d64141b.tar.bz2
opensim-SC-755ad9e3e0447b60299b08a18624064d1d64141b.tar.xz
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.
Diffstat (limited to 'OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs')
-rw-r--r--OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs64
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;
35using OpenSim.Framework.Console; 35using OpenSim.Framework.Console;
36using OpenSim.Region.Environment.Interfaces; 36using OpenSim.Region.Environment.Interfaces;
37using OpenSim.Region.Environment.Scenes; 37using OpenSim.Region.Environment.Scenes;
38using OpenSim.Framework.Data;
39using TribalMedia.Framework.Data;
38 40
39namespace OpenSim.Region.Environment.Modules 41namespace 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 }