aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorMW2008-03-25 18:48:07 +0000
committerMW2008-03-25 18:48:07 +0000
commitc2ea7b99e1cdbc06035e12306a71712f763b0818 (patch)
treee25876965e745f65917e7a740b2617961ee4b325 /OpenSim/Region
parent* Tear down CAPS and http handlers when an agent leaves a region (via crossin... (diff)
downloadopensim-SC_OLD-c2ea7b99e1cdbc06035e12306a71712f763b0818.zip
opensim-SC_OLD-c2ea7b99e1cdbc06035e12306a71712f763b0818.tar.gz
opensim-SC_OLD-c2ea7b99e1cdbc06035e12306a71712f763b0818.tar.bz2
opensim-SC_OLD-c2ea7b99e1cdbc06035e12306a71712f763b0818.tar.xz
Moved Avatar appearance Factory to its own project so that the reference to MySQLDatabaseMapper could be removed from Region.Environment.
Added a using OpenSim.Framework.Data statement to MySQLDatabaseMapper , to try to fix the build problem that has been reported on the mailing list.
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/Environment/ModuleLoader.cs18
-rw-r--r--OpenSim/Region/Environment/Modules/AppearanceTableMapper.cs7
-rw-r--r--OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs4
-rw-r--r--OpenSim/Region/Environment/Scenes/Scene.cs22
-rw-r--r--OpenSim/Region/Modules/AvatarFactory/AppearanceTableMapper.cs242
-rw-r--r--OpenSim/Region/Modules/AvatarFactory/AvatarFactoryModule.cs337
-rw-r--r--OpenSim/Region/Modules/AvatarFactory/Properties/AssemblyInfo.cs36
7 files changed, 652 insertions, 14 deletions
diff --git a/OpenSim/Region/Environment/ModuleLoader.cs b/OpenSim/Region/Environment/ModuleLoader.cs
index 4a8bf7b..7fb8d8a 100644
--- a/OpenSim/Region/Environment/ModuleLoader.cs
+++ b/OpenSim/Region/Environment/ModuleLoader.cs
@@ -114,15 +114,15 @@ namespace OpenSim.Region.Environment
114 m_loadedSharedModules.Add(loadMod.Name, loadMod); 114 m_loadedSharedModules.Add(loadMod.Name, loadMod);
115 } 115 }
116 116
117 AvatarFactoryModule avatarFactory = new AvatarFactoryModule(); 117 // AvatarFactoryModule avatarFactory = new AvatarFactoryModule();
118 if (m_loadedSharedModules.ContainsKey(avatarFactory.Name)) 118 // if (m_loadedSharedModules.ContainsKey(avatarFactory.Name))
119 { 119 // {
120 m_log.ErrorFormat("[MODULES]: Module name \"{0}\" already exists in module list. Module type {1} not added!", avatarFactory.Name, "AvarFactoryModule"); 120 // m_log.ErrorFormat("[MODULES]: Module name \"{0}\" already exists in module list. Module type {1} not added!", avatarFactory.Name, "AvarFactoryModule");
121 } 121 // }
122 else 122 // else
123 { 123 // {
124 m_loadedSharedModules.Add(avatarFactory.Name, avatarFactory); 124 // m_loadedSharedModules.Add(avatarFactory.Name, avatarFactory);
125 } 125 // }
126 126
127 XMLRPCModule xmlRpcMod = new XMLRPCModule(); 127 XMLRPCModule xmlRpcMod = new XMLRPCModule();
128 if (m_loadedSharedModules.ContainsKey(xmlRpcMod.Name)) 128 if (m_loadedSharedModules.ContainsKey(xmlRpcMod.Name))
diff --git a/OpenSim/Region/Environment/Modules/AppearanceTableMapper.cs b/OpenSim/Region/Environment/Modules/AppearanceTableMapper.cs
index 0dc43a6..eab6528 100644
--- a/OpenSim/Region/Environment/Modules/AppearanceTableMapper.cs
+++ b/OpenSim/Region/Environment/Modules/AppearanceTableMapper.cs
@@ -24,8 +24,7 @@
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27/*using System;
28using System;
29using System.Collections.Generic; 28using System.Collections.Generic;
30using System.Text; 29using System.Text;
31using OpenSim.Region.Environment.Scenes; 30using OpenSim.Region.Environment.Scenes;
@@ -34,6 +33,7 @@ using OpenSim.Framework.Data.Base;
34 33
35namespace OpenSim.Region.Environment.Modules 34namespace OpenSim.Region.Environment.Modules
36{ 35{
36 /*
37 public class AppearanceRowMapper : BaseRowMapper<AvatarAppearance> 37 public class AppearanceRowMapper : BaseRowMapper<AvatarAppearance>
38 { 38 {
39 public AppearanceRowMapper(BaseSchema schema, AvatarAppearance obj) 39 public AppearanceRowMapper(BaseSchema schema, AvatarAppearance obj)
@@ -239,4 +239,5 @@ namespace OpenSim.Region.Environment.Modules
239 } 239 }
240 } 240 }
241 } 241 }
242} 242
243}*/
diff --git a/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs b/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs
index da33726..6758d41 100644
--- a/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs
+++ b/OpenSim/Region/Environment/Modules/AvatarFactoryModule.cs
@@ -25,6 +25,7 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28/*
28using System; 29using System;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using System.Threading; 31using System.Threading;
@@ -39,6 +40,7 @@ using OpenSim.Framework.Data.Base;
39 40
40namespace OpenSim.Region.Environment.Modules 41namespace OpenSim.Region.Environment.Modules
41{ 42{
43 /*
42 public class AvatarFactoryModule : IAvatarFactory 44 public class AvatarFactoryModule : IAvatarFactory
43 { 45 {
44 private Scene m_scene = null; 46 private Scene m_scene = null;
@@ -334,4 +336,4 @@ namespace OpenSim.Region.Environment.Modules
334 return visualParams; 336 return visualParams;
335 } 337 }
336 } 338 }
337} 339}*/
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index f02f038..6644299 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -1461,7 +1461,7 @@ namespace OpenSim.Region.Environment.Scenes
1461 m_log.Warn("[AVATAR DEBUGGING]: Couldn't fetch avatar appearance from factory, please report this to the opensim mantis"); 1461 m_log.Warn("[AVATAR DEBUGGING]: Couldn't fetch avatar appearance from factory, please report this to the opensim mantis");
1462 byte[] visualParams; 1462 byte[] visualParams;
1463 AvatarWearable[] wearables; 1463 AvatarWearable[] wearables;
1464 AvatarFactoryModule.GetDefaultAvatarAppearance(out wearables, out visualParams); 1464 GetDefaultAvatarAppearance(out wearables, out visualParams);
1465 appearance = new AvatarAppearance(client.AgentId, wearables, visualParams); 1465 appearance = new AvatarAppearance(client.AgentId, wearables, visualParams);
1466 } 1466 }
1467 } 1467 }
@@ -2723,5 +2723,25 @@ namespace OpenSim.Region.Environment.Scenes
2723 } 2723 }
2724 2724
2725 #endregion 2725 #endregion
2726
2727 #region Avatar Appearance Default
2728
2729 public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams)
2730 {
2731 visualParams = GetDefaultVisualParams();
2732 wearables = AvatarWearable.DefaultWearables;
2733 }
2734
2735 private static byte[] GetDefaultVisualParams()
2736 {
2737 byte[] visualParams;
2738 visualParams = new byte[218];
2739 for (int i = 0; i < 218; i++)
2740 {
2741 visualParams[i] = 100;
2742 }
2743 return visualParams;
2744 }
2745 #endregion
2726 } 2746 }
2727} 2747}
diff --git a/OpenSim/Region/Modules/AvatarFactory/AppearanceTableMapper.cs b/OpenSim/Region/Modules/AvatarFactory/AppearanceTableMapper.cs
new file mode 100644
index 0000000..579ee01
--- /dev/null
+++ b/OpenSim/Region/Modules/AvatarFactory/AppearanceTableMapper.cs
@@ -0,0 +1,242 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Text;
31using OpenSim.Region.Environment.Scenes;
32using OpenSim.Framework;
33using OpenSim.Framework.Data.Base;
34
35namespace OpenSim.Region.Modules.AvatarFactory
36{
37 public class AppearanceRowMapper : BaseRowMapper<AvatarAppearance>
38 {
39 public AppearanceRowMapper(BaseSchema schema, AvatarAppearance obj)
40 : base(schema, obj)
41 {
42 }
43 }
44
45 public class AppearanceTableMapper : BaseTableMapper<AppearanceRowMapper, Guid>
46 {
47 public AppearanceTableMapper(BaseDatabaseConnector database, string tableName)
48 : base(database, tableName)
49 {
50 BaseSchema<AppearanceRowMapper> rowMapperSchema = new BaseSchema<AppearanceRowMapper>(this);
51 m_schema = rowMapperSchema;
52
53 m_keyFieldMapper = rowMapperSchema.AddMapping<Guid>("UUID",
54 delegate(AppearanceRowMapper mapper) { return mapper.Object.ScenePresenceID.UUID; },
55 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.ScenePresenceID = new libsecondlife.LLUUID(value.ToString()); });
56
57 rowMapperSchema.AddMapping<uint>("Serial",
58 delegate(AppearanceRowMapper mapper) { return (uint)mapper.Object.WearablesSerial; },
59 delegate(AppearanceRowMapper mapper, uint value) { mapper.Object.WearablesSerial = (int)value; });
60
61 rowMapperSchema.AddMapping<Guid>("WearableItem0",
62 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[0].ItemID.UUID; },
63 delegate(AppearanceRowMapper mapper, Guid value)
64 {
65 if (mapper.Object.Wearables == null)
66 {
67 mapper.Object.Wearables = new OpenSim.Framework.AvatarWearable[13];
68 for (int i = 0; i < 13; i++)
69 {
70 mapper.Object.Wearables[i] = new AvatarWearable();
71 }
72 }
73 mapper.Object.Wearables[0].ItemID = new libsecondlife.LLUUID(value.ToString());
74 });
75
76 rowMapperSchema.AddMapping<Guid>("WearableAsset0",
77 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[0].AssetID.UUID; },
78 delegate(AppearanceRowMapper mapper, Guid value)
79 { mapper.Object.Wearables[0].AssetID = new libsecondlife.LLUUID(value.ToString()); });
80
81 rowMapperSchema.AddMapping<Guid>("WearableItem1",
82 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[1].ItemID.UUID; },
83 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[1].ItemID = new libsecondlife.LLUUID(value.ToString()); });
84
85 rowMapperSchema.AddMapping<Guid>("WearableAsset1",
86 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[1].AssetID.UUID; },
87 delegate(AppearanceRowMapper mapper, Guid value)
88 { mapper.Object.Wearables[1].AssetID = new libsecondlife.LLUUID(value.ToString()); });
89
90 rowMapperSchema.AddMapping<Guid>("WearableItem2",
91 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[2].ItemID.UUID; },
92 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[2].ItemID = new libsecondlife.LLUUID(value.ToString()); });
93
94 rowMapperSchema.AddMapping<Guid>("WearableAsset2",
95 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[2].AssetID.UUID; },
96 delegate(AppearanceRowMapper mapper, Guid value)
97 { mapper.Object.Wearables[2].AssetID = new libsecondlife.LLUUID(value.ToString()); });
98
99 rowMapperSchema.AddMapping<Guid>("WearableItem3",
100 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[3].ItemID.UUID; },
101 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[3].ItemID = new libsecondlife.LLUUID(value.ToString()); });
102
103 rowMapperSchema.AddMapping<Guid>("WearableAsset3",
104 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[3].AssetID.UUID; },
105 delegate(AppearanceRowMapper mapper, Guid value)
106 { mapper.Object.Wearables[3].AssetID = new libsecondlife.LLUUID(value.ToString()); });
107
108 rowMapperSchema.AddMapping<Guid>("WearableItem4",
109 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[4].ItemID.UUID; },
110 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[4].ItemID = new libsecondlife.LLUUID(value.ToString()); });
111
112 rowMapperSchema.AddMapping<Guid>("WearableAsset4",
113 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[4].AssetID.UUID; },
114 delegate(AppearanceRowMapper mapper, Guid value)
115 { mapper.Object.Wearables[4].AssetID = new libsecondlife.LLUUID(value.ToString()); });
116
117 rowMapperSchema.AddMapping<Guid>("WearableItem5",
118 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[5].ItemID.UUID; },
119 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[5].ItemID = new libsecondlife.LLUUID(value.ToString()); });
120
121 rowMapperSchema.AddMapping<Guid>("WearableAsset5",
122 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[5].AssetID.UUID; },
123 delegate(AppearanceRowMapper mapper, Guid value)
124 { mapper.Object.Wearables[5].AssetID = new libsecondlife.LLUUID(value.ToString()); });
125
126 rowMapperSchema.AddMapping<Guid>("WearableItem6",
127 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[6].ItemID.UUID; },
128 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[6].ItemID = new libsecondlife.LLUUID(value.ToString()); });
129
130 rowMapperSchema.AddMapping<Guid>("WearableAsset6",
131 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[6].AssetID.UUID; },
132 delegate(AppearanceRowMapper mapper, Guid value)
133 { mapper.Object.Wearables[6].AssetID = new libsecondlife.LLUUID(value.ToString()); });
134
135 rowMapperSchema.AddMapping<Guid>("WearableItem7",
136 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[7].ItemID.UUID; },
137 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[7].ItemID = new libsecondlife.LLUUID(value.ToString()); });
138
139 rowMapperSchema.AddMapping<Guid>("WearableAsset7",
140 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[7].AssetID.UUID; },
141 delegate(AppearanceRowMapper mapper, Guid value)
142 { mapper.Object.Wearables[7].AssetID = new libsecondlife.LLUUID(value.ToString()); });
143
144 rowMapperSchema.AddMapping<Guid>("WearableItem8",
145 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[8].ItemID.UUID; },
146 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[8].ItemID = new libsecondlife.LLUUID(value.ToString()); });
147
148 rowMapperSchema.AddMapping<Guid>("WearableAsset8",
149 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[8].AssetID.UUID; },
150 delegate(AppearanceRowMapper mapper, Guid value)
151 { mapper.Object.Wearables[8].AssetID = new libsecondlife.LLUUID(value.ToString()); });
152
153 rowMapperSchema.AddMapping<Guid>("WearableItem9",
154 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[9].ItemID.UUID; },
155 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[9].ItemID = new libsecondlife.LLUUID(value.ToString()); });
156
157 rowMapperSchema.AddMapping<Guid>("WearableAsset9",
158 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[9].AssetID.UUID; },
159 delegate(AppearanceRowMapper mapper, Guid value)
160 { mapper.Object.Wearables[9].AssetID = new libsecondlife.LLUUID(value.ToString()); });
161
162 rowMapperSchema.AddMapping<Guid>("WearableItem10",
163 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[10].ItemID.UUID; },
164 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[10].ItemID = new libsecondlife.LLUUID(value.ToString()); });
165
166 rowMapperSchema.AddMapping<Guid>("WearableAsset10",
167 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[10].AssetID.UUID; },
168 delegate(AppearanceRowMapper mapper, Guid value)
169 { mapper.Object.Wearables[10].AssetID = new libsecondlife.LLUUID(value.ToString()); });
170
171 rowMapperSchema.AddMapping<Guid>("WearableItem11",
172 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[11].ItemID.UUID; },
173 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[11].ItemID = new libsecondlife.LLUUID(value.ToString()); });
174
175 rowMapperSchema.AddMapping<Guid>("WearableAsset11",
176 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[11].AssetID.UUID; },
177 delegate(AppearanceRowMapper mapper, Guid value)
178 { mapper.Object.Wearables[11].AssetID = new libsecondlife.LLUUID(value.ToString()); });
179
180 rowMapperSchema.AddMapping<Guid>("WearableItem12",
181 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[12].ItemID.UUID; },
182 delegate(AppearanceRowMapper mapper, Guid value) { mapper.Object.Wearables[12].ItemID = new libsecondlife.LLUUID(value.ToString()); });
183
184 rowMapperSchema.AddMapping<Guid>("WearableAsset12",
185 delegate(AppearanceRowMapper mapper) { return mapper.Object.Wearables[12].AssetID.UUID; },
186 delegate(AppearanceRowMapper mapper, Guid value)
187 { mapper.Object.Wearables[12].AssetID = new libsecondlife.LLUUID(value.ToString()); });
188
189 }
190
191 public bool Add(Guid userID, AvatarAppearance appearance)
192 {
193 AppearanceRowMapper mapper = CreateRowMapper(appearance);
194 return Add(mapper);
195 }
196
197 public bool Update(Guid userID, AvatarAppearance appearance)
198 {
199 AppearanceRowMapper mapper = CreateRowMapper(appearance);
200 return Update(appearance.ScenePresenceID.UUID, mapper);
201 }
202
203 protected AppearanceRowMapper CreateRowMapper(AvatarAppearance appearance)
204 {
205 return new AppearanceRowMapper(m_schema, appearance);
206 }
207
208 protected AppearanceRowMapper CreateRowMapper()
209 {
210 return CreateRowMapper(new AvatarAppearance());
211 }
212
213 protected AppearanceRowMapper FromReader(BaseDataReader reader, AvatarAppearance appearance)
214 {
215 AppearanceRowMapper mapper = CreateRowMapper(appearance);
216 mapper.FillObject(reader);
217 return mapper;
218 }
219
220 public override AppearanceRowMapper FromReader(BaseDataReader reader)
221 {
222 AppearanceRowMapper mapper = CreateRowMapper();
223 mapper.FillObject(reader);
224 return mapper;
225 }
226
227 public bool TryGetValue(Guid presenceID, out AvatarAppearance val)
228 {
229 AppearanceRowMapper mapper;
230 if (TryGetValue(presenceID, out mapper))
231 {
232 val = mapper.Object;
233 return true;
234 }
235 else
236 {
237 val = null;
238 return false;
239 }
240 }
241 }
242}
diff --git a/OpenSim/Region/Modules/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/Modules/AvatarFactory/AvatarFactoryModule.cs
new file mode 100644
index 0000000..1f99a72
--- /dev/null
+++ b/OpenSim/Region/Modules/AvatarFactory/AvatarFactoryModule.cs
@@ -0,0 +1,337 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSim Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Collections.Generic;
30using System.Threading;
31using libsecondlife;
32using Nini.Config;
33using OpenSim.Framework;
34using OpenSim.Framework.Communications.Cache;
35using OpenSim.Framework.Data.MySQLMapper;
36using OpenSim.Region.Environment.Interfaces;
37using OpenSim.Region.Environment.Scenes;
38using OpenSim.Framework.Data.Base;
39
40namespace OpenSim.Region.Modules.AvatarFactory
41{
42 public class AvatarFactoryModule : IAvatarFactory
43 {
44 private Scene m_scene = null;
45 private readonly Dictionary<LLUUID, AvatarAppearance> m_avatarsAppearance = new Dictionary<LLUUID, AvatarAppearance>();
46
47 private bool m_enablePersist = false;
48 private string m_connectionString;
49 private bool m_configured = false;
50 private BaseDatabaseConnector m_databaseMapper;
51 private AppearanceTableMapper m_appearanceMapper;
52
53 private Dictionary<LLUUID, EventWaitHandle> m_fetchesInProgress = new Dictionary<LLUUID, EventWaitHandle>();
54 private object m_syncLock = new object();
55
56 public bool TryGetAvatarAppearance(LLUUID avatarId, out AvatarAppearance appearance)
57 {
58
59 //should only let one thread at a time do this part
60 EventWaitHandle waitHandle = null;
61 bool fetchInProgress = false;
62 lock (m_syncLock)
63 {
64 appearance = CheckCache(avatarId);
65 if (appearance != null)
66 {
67 return true;
68 }
69
70 //not in cache so check to see if another thread is already fetching it
71 if (m_fetchesInProgress.TryGetValue(avatarId, out waitHandle))
72 {
73 fetchInProgress = true;
74 }
75 else
76 {
77 fetchInProgress = false;
78
79 //no thread already fetching this appearance, so add a wait handle to list
80 //for any following threads that want the same appearance
81 waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
82 m_fetchesInProgress.Add(avatarId, waitHandle);
83 }
84 }
85
86 if (fetchInProgress)
87 {
88 waitHandle.WaitOne();
89 appearance = CheckCache(avatarId);
90 if (appearance != null)
91 {
92 waitHandle = null;
93 return true;
94 }
95 else
96 {
97 waitHandle = null;
98 return false;
99 }
100 }
101 else
102 {
103 Thread.Sleep(5000);
104
105 //this is the first thread to request this appearance
106 //so let it check the db and if not found then create a default appearance
107 //and add that to the cache
108 appearance = CheckDatabase(avatarId);
109 if (appearance != null)
110 {
111 //appearance has now been added to cache so lets pulse any waiting threads
112 lock (m_syncLock)
113 {
114 m_fetchesInProgress.Remove(avatarId);
115 waitHandle.Set();
116 }
117 // waitHandle.Close();
118 waitHandle = null;
119 return true;
120 }
121
122 //not found a appearance for the user, so create a new default one
123 appearance = CreateDefault(avatarId);
124 if (appearance != null)
125 {
126 //update database
127 if (m_enablePersist)
128 {
129 m_appearanceMapper.Add(avatarId.UUID, appearance);
130 }
131
132 //add appearance to dictionary cache
133 lock (m_avatarsAppearance)
134 {
135 m_avatarsAppearance[avatarId] = appearance;
136 }
137
138 //appearance has now been added to cache so lets pulse any waiting threads
139 lock (m_syncLock)
140 {
141 m_fetchesInProgress.Remove(avatarId);
142 waitHandle.Set();
143 }
144 // waitHandle.Close();
145 waitHandle = null;
146 return true;
147 }
148 else
149 {
150 //something went wrong, so release the wait handle and remove it
151 //all waiting threads will fail to find cached appearance
152 //but its better for them to fail than wait for ever
153 lock (m_syncLock)
154 {
155 m_fetchesInProgress.Remove(avatarId);
156 waitHandle.Set();
157 }
158 //waitHandle.Close();
159 waitHandle = null;
160 return false;
161 }
162 }
163 }
164
165 private AvatarAppearance CreateDefault(LLUUID avatarId)
166 {
167 AvatarAppearance appearance = null;
168 AvatarWearable[] wearables;
169 byte[] visualParams;
170 GetDefaultAvatarAppearance(out wearables, out visualParams);
171 appearance = new AvatarAppearance(avatarId, wearables, visualParams);
172
173 return appearance;
174 }
175
176 private AvatarAppearance CheckDatabase(LLUUID avatarId)
177 {
178 AvatarAppearance appearance = null;
179 if (m_enablePersist)
180 {
181 if (m_appearanceMapper.TryGetValue(avatarId.UUID, out appearance))
182 {
183 appearance.VisualParams = GetDefaultVisualParams();
184 appearance.TextureEntry = AvatarAppearance.GetDefaultTextureEntry();
185 lock (m_avatarsAppearance)
186 {
187 m_avatarsAppearance[avatarId] = appearance;
188 }
189 }
190 }
191 return appearance;
192 }
193
194 private AvatarAppearance CheckCache(LLUUID avatarId)
195 {
196 AvatarAppearance appearance = null;
197 lock (m_avatarsAppearance)
198 {
199 if (m_avatarsAppearance.ContainsKey(avatarId))
200 {
201 appearance = m_avatarsAppearance[avatarId];
202 }
203 }
204 return appearance;
205 }
206
207 public void Initialise(Scene scene, IConfigSource source)
208 {
209 scene.RegisterModuleInterface<IAvatarFactory>(this);
210 scene.EventManager.OnNewClient += NewClient;
211
212 if (m_scene == null)
213 {
214 m_scene = scene;
215 }
216
217 if (!m_configured)
218 {
219 m_configured = true;
220 try
221 {
222 m_enablePersist = source.Configs["Startup"].GetBoolean("appearance_persist", false);
223 m_connectionString = source.Configs["Startup"].GetString("appearance_connection_string", "");
224 }
225 catch (Exception)
226 {
227 }
228 if (m_enablePersist)
229 {
230 m_databaseMapper = new MySQLDatabaseMapper(m_connectionString);
231 m_appearanceMapper = new AppearanceTableMapper(m_databaseMapper, "AvatarAppearance");
232 }
233 }
234 }
235
236 public void PostInitialise()
237 {
238 }
239
240 public void Close()
241 {
242 }
243
244 public string Name
245 {
246 get { return "Default Avatar Factory"; }
247 }
248
249 public bool IsSharedModule
250 {
251 get { return true; }
252 }
253
254 public void NewClient(IClientAPI client)
255 {
256 client.OnAvatarNowWearing += AvatarIsWearing;
257 }
258
259 public void RemoveClient(IClientAPI client)
260 {
261 // client.OnAvatarNowWearing -= AvatarIsWearing;
262 }
263
264 public void AvatarIsWearing(Object sender, AvatarWearingArgs e)
265 {
266 IClientAPI clientView = (IClientAPI)sender;
267 CachedUserInfo profile = m_scene.CommsManager.UserProfileCacheService.GetUserDetails(clientView.AgentId);
268 if (profile != null)
269 {
270 if (profile.RootFolder != null)
271 {
272 if (m_avatarsAppearance.ContainsKey(clientView.AgentId))
273 {
274 AvatarAppearance avatAppearance = null;
275 lock (m_avatarsAppearance)
276 {
277 avatAppearance = m_avatarsAppearance[clientView.AgentId];
278 }
279
280 foreach (AvatarWearingArgs.Wearable wear in e.NowWearing)
281 {
282 if (wear.Type < 13)
283 {
284 if (wear.ItemID == LLUUID.Zero)
285 {
286 avatAppearance.Wearables[wear.Type].ItemID = LLUUID.Zero;
287 avatAppearance.Wearables[wear.Type].AssetID = LLUUID.Zero;
288
289 UpdateDatabase(clientView.AgentId, avatAppearance);
290 }
291 else
292 {
293 LLUUID assetId;
294
295 InventoryItemBase baseItem = profile.RootFolder.HasItem(wear.ItemID);
296 if (baseItem != null)
297 {
298 assetId = baseItem.assetID;
299 avatAppearance.Wearables[wear.Type].AssetID = assetId;
300 avatAppearance.Wearables[wear.Type].ItemID = wear.ItemID;
301
302 UpdateDatabase(clientView.AgentId, avatAppearance);
303 }
304 }
305 }
306 }
307 }
308 }
309 }
310 }
311
312 public void UpdateDatabase(LLUUID userID, AvatarAppearance avatAppearance)
313 {
314 if (m_enablePersist)
315 {
316 m_appearanceMapper.Update(userID.UUID, avatAppearance);
317 }
318 }
319
320 public static void GetDefaultAvatarAppearance(out AvatarWearable[] wearables, out byte[] visualParams)
321 {
322 visualParams = GetDefaultVisualParams();
323 wearables = AvatarWearable.DefaultWearables;
324 }
325
326 private static byte[] GetDefaultVisualParams()
327 {
328 byte[] visualParams;
329 visualParams = new byte[218];
330 for (int i = 0; i < 218; i++)
331 {
332 visualParams[i] = 100;
333 }
334 return visualParams;
335 }
336 }
337}
diff --git a/OpenSim/Region/Modules/AvatarFactory/Properties/AssemblyInfo.cs b/OpenSim/Region/Modules/AvatarFactory/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..5707990
--- /dev/null
+++ b/OpenSim/Region/Modules/AvatarFactory/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
1using System.Reflection;
2using System.Runtime.CompilerServices;
3using System.Runtime.InteropServices;
4
5// General Information about an assembly is controlled through the following
6// set of attributes. Change these attribute values to modify the information
7// associated with an assembly.
8[assembly: AssemblyTitle("OpenSim.Region.Modules.AvatarFactory")]
9[assembly: AssemblyDescription("")]
10[assembly: AssemblyConfiguration("")]
11[assembly: AssemblyCompany("")]
12[assembly: AssemblyProduct("OpenSim.Region.Modules.AvatarFactory")]
13[assembly: AssemblyCopyright("Copyright © 2008")]
14[assembly: AssemblyTrademark("")]
15[assembly: AssemblyCulture("")]
16
17// Setting ComVisible to false makes the types in this assembly not visible
18// to COM components. If you need to access a type in this assembly from
19// COM, set the ComVisible attribute to true on that type.
20[assembly: ComVisible(false)]
21
22// The following GUID is for the ID of the typelib if this project is exposed to COM
23[assembly: Guid("8e369713-faf5-4e55-a789-f8f1a087d3ed")]
24
25// Version information for an assembly consists of the following four values:
26//
27// Major Version
28// Minor Version
29// Build Number
30// Revision
31//
32// You can specify all the values or you can default the Build and Revision Numbers
33// by using the '*' as shown below:
34// [assembly: AssemblyVersion("1.0.*")]
35[assembly: AssemblyVersion("1.0.0.0")]
36[assembly: AssemblyFileVersion("1.0.0.0")]