diff options
author | MW | 2008-02-04 12:04:02 +0000 |
---|---|---|
committer | MW | 2008-02-04 12:04:02 +0000 |
commit | 755ad9e3e0447b60299b08a18624064d1d64141b (patch) | |
tree | 89859180b5ba7ef47defbf6a1d6640177ecb1326 /OpenSim/Region/Environment/Modules | |
parent | * Whole buncha stuff. (diff) | |
download | opensim-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')
-rw-r--r-- | OpenSim/Region/Environment/Modules/AppearanceTableMapper.cs | 216 | ||||
-rw-r--r-- | OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs | 64 |
2 files changed, 268 insertions, 12 deletions
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 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.Text; | ||
4 | using OpenSim.Region.Environment.Scenes; | ||
5 | using OpenSim.Framework; | ||
6 | using TribalMedia.Framework.Data; | ||
7 | |||
8 | namespace OpenSim.Region.Environment.Modules | ||
9 | { | ||
10 | public class AppearanceRowMapper : BaseRowMapper<AvatarAppearance> | ||
11 | { | ||
12 | |||
13 | public AppearanceRowMapper(BaseSchema schema, AvatarAppearance obj) | ||
14 | : base(schema, obj) | ||
15 | { | ||
16 | } | ||
17 | } | ||
18 | |||
19 | public class AppearanceTableMapper : BaseTableMapper<AppearanceRowMapper, Guid> | ||
20 | { | ||
21 | public AppearanceTableMapper(BaseDatabaseConnector database, string tableName) | ||
22 | : base(database, tableName) | ||
23 | { | ||
24 | BaseSchema<AppearanceRowMapper> rowMapperSchema = new BaseSchema<AppearanceRowMapper>(this); | ||
25 | m_schema = rowMapperSchema; | ||
26 | |||
27 | m_keyFieldMapper = rowMapperSchema.AddMapping<Guid>("UUID", | ||
28 | delegate(AppearanceRowMapper mapper) { return mapper.Object.ScenePresenceID.UUID; }, | ||
29 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.ScenePresenceID = new libsecondlife.LLUUID(value.ToString()); }); | ||
30 | |||
31 | rowMapperSchema.AddMapping<uint>("Serial", | ||
32 | delegate(AppearanceRowMapper mapper) { return (uint)mapper.Object.WearablesSerial; }, | ||
33 | delegate(AppearanceRowMapper mapper, uint value) { mapper.Object.WearablesSerial = (int)value; }); | ||
34 | |||
35 | rowMapperSchema.AddMapping<Guid>("WearableItem0", | ||
36 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[0].ItemID.UUID; }, | ||
37 | delegate(AppearanceRowMapper mapper, Guid value) | ||
38 | { | ||
39 | if (mapper.Object.Wearables == null) | ||
40 | { | ||
41 | mapper.Object.Wearables = new OpenSim.Framework.AvatarWearable[13]; | ||
42 | for (int i = 0; i < 13; i++) | ||
43 | { | ||
44 | mapper.Object.Wearables[i] = new AvatarWearable(); | ||
45 | } | ||
46 | } | ||
47 | mapper.Object.Wearables[0].ItemID = new libsecondlife.LLUUID(value.ToString()); | ||
48 | }); | ||
49 | |||
50 | rowMapperSchema.AddMapping<Guid>("WearableAsset0", | ||
51 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[0].AssetID.UUID; }, | ||
52 | delegate(AppearanceRowMapper mapper, Guid value) | ||
53 | { mapper.Object.Wearables[0].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
54 | |||
55 | rowMapperSchema.AddMapping<Guid>("WearableItem1", | ||
56 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[1].ItemID.UUID; }, | ||
57 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[1].ItemID = new libsecondlife.LLUUID(value.ToString()); }); | ||
58 | |||
59 | rowMapperSchema.AddMapping<Guid>("WearableAsset1", | ||
60 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[1].AssetID.UUID; }, | ||
61 | delegate(AppearanceRowMapper mapper, Guid value) | ||
62 | { mapper.Object.Wearables[1].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
63 | |||
64 | rowMapperSchema.AddMapping<Guid>("WearableItem2", | ||
65 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[2].ItemID.UUID; }, | ||
66 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[2].ItemID = new libsecondlife.LLUUID(value.ToString()); }); | ||
67 | |||
68 | rowMapperSchema.AddMapping<Guid>("WearableAsset2", | ||
69 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[2].AssetID.UUID; }, | ||
70 | delegate(AppearanceRowMapper mapper, Guid value) | ||
71 | { mapper.Object.Wearables[2].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
72 | |||
73 | rowMapperSchema.AddMapping<Guid>("WearableItem3", | ||
74 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[3].ItemID.UUID; }, | ||
75 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[3].ItemID = new libsecondlife.LLUUID(value.ToString()); }); | ||
76 | |||
77 | rowMapperSchema.AddMapping<Guid>("WearableAsset3", | ||
78 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[3].AssetID.UUID; }, | ||
79 | delegate(AppearanceRowMapper mapper, Guid value) | ||
80 | { mapper.Object.Wearables[3].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
81 | |||
82 | rowMapperSchema.AddMapping<Guid>("WearableItem4", | ||
83 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[4].ItemID.UUID; }, | ||
84 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[4].ItemID = new libsecondlife.LLUUID(value.ToString()); }); | ||
85 | |||
86 | rowMapperSchema.AddMapping<Guid>("WearableAsset4", | ||
87 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[4].AssetID.UUID; }, | ||
88 | delegate(AppearanceRowMapper mapper, Guid value) | ||
89 | { mapper.Object.Wearables[4].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
90 | |||
91 | rowMapperSchema.AddMapping<Guid>("WearableItem5", | ||
92 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[5].ItemID.UUID; }, | ||
93 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[5].ItemID = new libsecondlife.LLUUID(value.ToString()); }); | ||
94 | |||
95 | rowMapperSchema.AddMapping<Guid>("WearableAsset5", | ||
96 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[5].AssetID.UUID; }, | ||
97 | delegate(AppearanceRowMapper mapper, Guid value) | ||
98 | { mapper.Object.Wearables[5].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
99 | |||
100 | rowMapperSchema.AddMapping<Guid>("WearableItem6", | ||
101 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[6].ItemID.UUID; }, | ||
102 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[6].ItemID = new libsecondlife.LLUUID(value.ToString()); }); | ||
103 | |||
104 | rowMapperSchema.AddMapping<Guid>("WearableAsset6", | ||
105 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[6].AssetID.UUID; }, | ||
106 | delegate(AppearanceRowMapper mapper, Guid value) | ||
107 | { mapper.Object.Wearables[6].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
108 | |||
109 | rowMapperSchema.AddMapping<Guid>("WearableItem7", | ||
110 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[7].ItemID.UUID; }, | ||
111 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[7].ItemID = new libsecondlife.LLUUID(value.ToString()); }); | ||
112 | |||
113 | rowMapperSchema.AddMapping<Guid>("WearableAsset7", | ||
114 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[7].AssetID.UUID; }, | ||
115 | delegate(AppearanceRowMapper mapper, Guid value) | ||
116 | { mapper.Object.Wearables[7].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
117 | |||
118 | rowMapperSchema.AddMapping<Guid>("WearableItem8", | ||
119 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[8].ItemID.UUID; }, | ||
120 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[8].ItemID = new libsecondlife.LLUUID(value.ToString()); }); | ||
121 | |||
122 | rowMapperSchema.AddMapping<Guid>("WearableAsset8", | ||
123 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[8].AssetID.UUID; }, | ||
124 | delegate(AppearanceRowMapper mapper, Guid value) | ||
125 | { mapper.Object.Wearables[8].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
126 | |||
127 | rowMapperSchema.AddMapping<Guid>("WearableItem9", | ||
128 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[9].ItemID.UUID; }, | ||
129 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[9].ItemID = new libsecondlife.LLUUID(value.ToString()); }); | ||
130 | |||
131 | rowMapperSchema.AddMapping<Guid>("WearableAsset9", | ||
132 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[9].AssetID.UUID; }, | ||
133 | delegate(AppearanceRowMapper mapper, Guid value) | ||
134 | { mapper.Object.Wearables[9].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
135 | |||
136 | rowMapperSchema.AddMapping<Guid>("WearableItem10", | ||
137 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[10].ItemID.UUID; }, | ||
138 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[10].ItemID = new libsecondlife.LLUUID(value.ToString()); }); | ||
139 | |||
140 | rowMapperSchema.AddMapping<Guid>("WearableAsset10", | ||
141 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[10].AssetID.UUID; }, | ||
142 | delegate(AppearanceRowMapper mapper, Guid value) | ||
143 | { mapper.Object.Wearables[10].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
144 | |||
145 | rowMapperSchema.AddMapping<Guid>("WearableItem11", | ||
146 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[11].ItemID.UUID; }, | ||
147 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[11].ItemID = new libsecondlife.LLUUID(value.ToString()); }); | ||
148 | |||
149 | rowMapperSchema.AddMapping<Guid>("WearableAsset11", | ||
150 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[11].AssetID.UUID; }, | ||
151 | delegate(AppearanceRowMapper mapper, Guid value) | ||
152 | { mapper.Object.Wearables[11].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
153 | |||
154 | rowMapperSchema.AddMapping<Guid>("WearableItem12", | ||
155 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[12].ItemID.UUID; }, | ||
156 | delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[12].ItemID = new libsecondlife.LLUUID(value.ToString()); }); | ||
157 | |||
158 | rowMapperSchema.AddMapping<Guid>("WearableAsset12", | ||
159 | delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[12].AssetID.UUID; }, | ||
160 | delegate(AppearanceRowMapper mapper, Guid value) | ||
161 | { mapper.Object.Wearables[12].AssetID = new libsecondlife.LLUUID(value.ToString()); }); | ||
162 | |||
163 | } | ||
164 | |||
165 | public bool Add(Guid userID, AvatarAppearance appearance) | ||
166 | { | ||
167 | AppearanceRowMapper mapper = CreateRowMapper(appearance); | ||
168 | return Add(mapper); | ||
169 | } | ||
170 | |||
171 | public bool Update(Guid userID, AvatarAppearance appearance) | ||
172 | { | ||
173 | AppearanceRowMapper mapper = CreateRowMapper(appearance); | ||
174 | return Update(appearance.ScenePresenceID.UUID, mapper); | ||
175 | } | ||
176 | |||
177 | protected AppearanceRowMapper CreateRowMapper(AvatarAppearance appearance) | ||
178 | { | ||
179 | return new AppearanceRowMapper(m_schema, appearance); | ||
180 | } | ||
181 | |||
182 | protected AppearanceRowMapper CreateRowMapper() | ||
183 | { | ||
184 | return CreateRowMapper(new AvatarAppearance()); | ||
185 | } | ||
186 | |||
187 | protected AppearanceRowMapper FromReader(BaseDataReader reader, AvatarAppearance appearance) | ||
188 | { | ||
189 | AppearanceRowMapper mapper = CreateRowMapper(appearance); | ||
190 | mapper.FillObject(reader); | ||
191 | return mapper; | ||
192 | } | ||
193 | |||
194 | public override AppearanceRowMapper FromReader(BaseDataReader reader) | ||
195 | { | ||
196 | AppearanceRowMapper mapper = CreateRowMapper(); | ||
197 | mapper.FillObject(reader); | ||
198 | return mapper; | ||
199 | } | ||
200 | |||
201 | public bool TryGetValue(Guid presenceID, out AvatarAppearance val) | ||
202 | { | ||
203 | AppearanceRowMapper mapper; | ||
204 | if (TryGetValue(presenceID, out mapper)) | ||
205 | { | ||
206 | val = mapper.Object; | ||
207 | return true; | ||
208 | } | ||
209 | else | ||
210 | { | ||
211 | val = null; | ||
212 | return false; | ||
213 | } | ||
214 | } | ||
215 | } | ||
216 | } | ||
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 | } |