aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Services/Interfaces/IAvatarService.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Services/Interfaces/IAvatarService.cs')
-rw-r--r--OpenSim/Services/Interfaces/IAvatarService.cs241
1 files changed, 241 insertions, 0 deletions
diff --git a/OpenSim/Services/Interfaces/IAvatarService.cs b/OpenSim/Services/Interfaces/IAvatarService.cs
new file mode 100644
index 0000000..de3bcf9
--- /dev/null
+++ b/OpenSim/Services/Interfaces/IAvatarService.cs
@@ -0,0 +1,241 @@
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 OpenSimulator 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;
30using System.Collections.Generic;
31
32using OpenSim.Framework;
33
34using OpenMetaverse;
35
36namespace OpenSim.Services.Interfaces
37{
38 public interface IAvatarService
39 {
40 /// <summary>
41 /// Called by the login service
42 /// </summary>
43 /// <param name="userID"></param>
44 /// <returns></returns>
45 AvatarData GetAvatar(UUID userID);
46
47 /// <summary>
48 /// Called by everyone who can change the avatar data (so, regions)
49 /// </summary>
50 /// <param name="userID"></param>
51 /// <param name="avatar"></param>
52 /// <returns></returns>
53 bool SetAvatar(UUID userID, AvatarData avatar);
54
55 /// <summary>
56 /// Not sure if it's needed
57 /// </summary>
58 /// <param name="userID"></param>
59 /// <returns></returns>
60 bool ResetAvatar(UUID userID);
61
62 /// <summary>
63 /// These methods raison d'etre:
64 /// No need to send the entire avatar data (SetAvatar) for changing attachments
65 /// </summary>
66 /// <param name="userID"></param>
67 /// <param name="attach"></param>
68 /// <returns></returns>
69 bool SetItems(UUID userID, string[] names, string[] values);
70 bool RemoveItems(UUID userID, string[] names);
71 }
72
73 /// <summary>
74 /// Each region/client that uses avatars will have a data structure
75 /// of this type representing the avatars.
76 /// </summary>
77 public class AvatarData
78 {
79 // This pretty much determines which name/value pairs will be
80 // present below. The name/value pair describe a part of
81 // the avatar. For SL avatars, these would be "shape", "texture1",
82 // etc. For other avatars, they might be "mesh", "skin", etc.
83 // The value portion is a URL that is expected to resolve to an
84 // asset of the type required by the handler for that field.
85 // It is required that regions can access these URLs. Allowing
86 // direct access by a viewer is not required, and, if provided,
87 // may be read-only. A "naked" UUID can be used to refer to an
88 // asset int he current region's asset service, which is not
89 // portable, but allows legacy appearance to continue to
90 // function. Closed, LL-based grids will never need URLs here.
91
92 public int AvatarType;
93 public Dictionary<string,string> Data;
94
95 public AvatarData()
96 {
97 }
98
99 public AvatarData(Dictionary<string, object> kvp)
100 {
101 Data = new Dictionary<string, string>();
102
103 if (kvp.ContainsKey("AvatarType"))
104 Int32.TryParse(kvp["AvatarType"].ToString(), out AvatarType);
105
106 foreach (KeyValuePair<string, object> _kvp in kvp)
107 {
108 if (_kvp.Value != null)
109 Data[_kvp.Key] = _kvp.Value.ToString();
110 }
111 }
112
113 /// <summary>
114 /// </summary>
115 /// <returns></returns>
116 public Dictionary<string, object> ToKeyValuePairs()
117 {
118 Dictionary<string, object> result = new Dictionary<string, object>();
119
120 result["AvatarType"] = AvatarType.ToString();
121 foreach (KeyValuePair<string, string> _kvp in Data)
122 {
123 if (_kvp.Value != null)
124 result[_kvp.Key] = _kvp.Value;
125 }
126 return result;
127 }
128
129 public AvatarData(AvatarAppearance appearance)
130 {
131 AvatarType = 1; // SL avatars
132 Data = new Dictionary<string, string>();
133
134 Data["Serial"] = appearance.Serial.ToString();
135 // Wearables
136 Data["AvatarHeight"] = appearance.AvatarHeight.ToString();
137 Data["BodyItem"] = appearance.BodyItem.ToString();
138 Data["EyesItem"] = appearance.EyesItem.ToString();
139 Data["GlovesItem"] = appearance.GlovesItem.ToString();
140 Data["HairItem"] = appearance.HairItem.ToString();
141 Data["JacketItem"] = appearance.JacketItem.ToString();
142 Data["PantsItem"] = appearance.PantsItem.ToString();
143 Data["ShirtItem"] = appearance.ShirtItem.ToString();
144 Data["ShoesItem"] = appearance.ShoesItem.ToString();
145 Data["SkinItem"] = appearance.SkinItem.ToString();
146 Data["SkirtItem"] = appearance.SkirtItem.ToString();
147 Data["SocksItem"] = appearance.SocksItem.ToString();
148 Data["UnderPantsItem"] = appearance.UnderPantsItem.ToString();
149 Data["UnderShirtItem"] = appearance.UnderShirtItem.ToString();
150
151 Data["BodyAsset"] = appearance.BodyAsset.ToString();
152 Data["EyesAsset"] = appearance.EyesAsset.ToString();
153 Data["GlovesAsset"] = appearance.GlovesAsset.ToString();
154 Data["HairAsset"] = appearance.HairAsset.ToString();
155 Data["JacketAsset"] = appearance.JacketAsset.ToString();
156 Data["PantsAsset"] = appearance.PantsAsset.ToString();
157 Data["ShirtAsset"] = appearance.ShirtAsset.ToString();
158 Data["ShoesAsset"] = appearance.ShoesAsset.ToString();
159 Data["SkinAsset"] = appearance.SkinAsset.ToString();
160 Data["SkirtAsset"] = appearance.SkirtAsset.ToString();
161 Data["SocksAsset"] = appearance.SocksAsset.ToString();
162 Data["UnderPantsAsset"] = appearance.UnderPantsAsset.ToString();
163 Data["UnderShirtAsset"] = appearance.UnderShirtAsset.ToString();
164
165 // Attachments
166 Hashtable attachs = appearance.GetAttachments();
167 if (attachs != null)
168 foreach (DictionaryEntry dentry in attachs)
169 {
170 if (dentry.Value != null)
171 {
172 Hashtable tab = (Hashtable)dentry.Value;
173 if (tab.ContainsKey("item") && tab["item"] != null)
174 Data["_ap_" + dentry.Key] = tab["item"].ToString();
175 }
176 }
177 }
178
179 public AvatarAppearance ToAvatarAppearance(UUID owner)
180 {
181 AvatarAppearance appearance = new AvatarAppearance(owner);
182 try
183 {
184 appearance.Serial = Int32.Parse(Data["Serial"]);
185
186 // Wearables
187 appearance.BodyItem = UUID.Parse(Data["BodyItem"]);
188 appearance.EyesItem = UUID.Parse(Data["EyesItem"]);
189 appearance.GlovesItem = UUID.Parse(Data["GlovesItem"]);
190 appearance.HairItem = UUID.Parse(Data["HairItem"]);
191 appearance.JacketItem = UUID.Parse(Data["JacketItem"]);
192 appearance.PantsItem = UUID.Parse(Data["PantsItem"]);
193 appearance.ShirtItem = UUID.Parse(Data["ShirtItem"]);
194 appearance.ShoesItem = UUID.Parse(Data["ShoesItem"]);
195 appearance.SkinItem = UUID.Parse(Data["SkinItem"]);
196 appearance.SkirtItem = UUID.Parse(Data["SkirtItem"]);
197 appearance.SocksItem = UUID.Parse(Data["SocksItem"]);
198 appearance.UnderPantsItem = UUID.Parse(Data["UnderPantsItem"]);
199 appearance.UnderShirtItem = UUID.Parse(Data["UnderShirtItem"]);
200
201 appearance.BodyAsset = UUID.Parse(Data["BodyAsset"]);
202 appearance.EyesAsset = UUID.Parse(Data["EyesAsset"]);
203 appearance.GlovesAsset = UUID.Parse(Data["GlovesAsset"]);
204 appearance.HairAsset = UUID.Parse(Data["HairAsset"]);
205 appearance.JacketAsset = UUID.Parse(Data["JacketAsset"]);
206 appearance.PantsAsset = UUID.Parse(Data["PantsAsset"]);
207 appearance.ShirtAsset = UUID.Parse(Data["ShirtAsset"]);
208 appearance.ShoesAsset = UUID.Parse(Data["ShoesAsset"]);
209 appearance.SkinAsset = UUID.Parse(Data["SkinAsset"]);
210 appearance.SkirtAsset = UUID.Parse(Data["SkirtAsset"]);
211 appearance.SocksAsset = UUID.Parse(Data["SocksAsset"]);
212 appearance.UnderPantsAsset = UUID.Parse(Data["UnderPantsAsset"]);
213 appearance.UnderShirtAsset = UUID.Parse(Data["UnderShirtAsset"]);
214
215 // Attachments
216 Dictionary<string, string> attchs = new Dictionary<string, string>();
217 foreach (KeyValuePair<string, string> _kvp in Data)
218 if (_kvp.Key.StartsWith("_ap_"))
219 attchs[_kvp.Key] = _kvp.Value;
220 Hashtable aaAttachs = new Hashtable();
221 foreach (KeyValuePair<string, string> _kvp in attchs)
222 {
223 string pointStr = _kvp.Key.Substring(4);
224 int point = 0;
225 if (!Int32.TryParse(pointStr, out point))
226 continue;
227 Hashtable tmp = new Hashtable();
228 UUID uuid = UUID.Zero;
229 UUID.TryParse(_kvp.Value, out uuid);
230 tmp["item"] = uuid;
231 tmp["asset"] = UUID.Zero.ToString();
232 aaAttachs[point] = tmp;
233 }
234 appearance.SetAttachments(aaAttachs);
235 }
236 catch { }
237
238 return appearance;
239 }
240 }
241}