corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * Copyright (c) 2006-2014, openmetaverse.org |
||
3 | * All rights reserved. |
||
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 | * |
||
8 | * - Redistributions of source code must retain the above copyright notice, this |
||
9 | * list of conditions and the following disclaimer. |
||
10 | * - Neither the name of the openmetaverse.org nor the names |
||
11 | * of its contributors may be used to endorse or promote products derived from |
||
12 | * this software without specific prior written permission. |
||
13 | * |
||
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
24 | * POSSIBILITY OF SUCH DAMAGE. |
||
25 | */ |
||
26 | |||
27 | using System; |
||
28 | using System.Net; |
||
29 | using System.Collections.Generic; |
||
30 | using System.Threading; |
||
31 | using OpenMetaverse.Packets; |
||
32 | using OpenMetaverse.StructuredData; |
||
33 | using System.Reflection; |
||
34 | |||
35 | namespace OpenMetaverse |
||
36 | { |
||
37 | #region Enums |
||
38 | |||
39 | /// <summary> |
||
40 | /// Avatar profile flags |
||
41 | /// </summary> |
||
42 | [Flags] |
||
43 | public enum ProfileFlags : uint |
||
44 | { |
||
45 | AllowPublish = 1, |
||
46 | MaturePublish = 2, |
||
47 | Identified = 4, |
||
48 | Transacted = 8, |
||
49 | Online = 16 |
||
50 | } |
||
51 | |||
52 | #endregion Enums |
||
53 | |||
54 | /// <summary> |
||
55 | /// Represents an avatar (other than your own) |
||
56 | /// </summary> |
||
57 | public class Avatar : Primitive |
||
58 | { |
||
59 | #region Subclasses |
||
60 | |||
61 | /// <summary> |
||
62 | /// Positive and negative ratings |
||
63 | /// </summary> |
||
64 | public struct Statistics |
||
65 | { |
||
66 | /// <summary>Positive ratings for Behavior</summary> |
||
67 | public int BehaviorPositive; |
||
68 | /// <summary>Negative ratings for Behavior</summary> |
||
69 | public int BehaviorNegative; |
||
70 | /// <summary>Positive ratings for Appearance</summary> |
||
71 | public int AppearancePositive; |
||
72 | /// <summary>Negative ratings for Appearance</summary> |
||
73 | public int AppearanceNegative; |
||
74 | /// <summary>Positive ratings for Building</summary> |
||
75 | public int BuildingPositive; |
||
76 | /// <summary>Negative ratings for Building</summary> |
||
77 | public int BuildingNegative; |
||
78 | /// <summary>Positive ratings given by this avatar</summary> |
||
79 | public int GivenPositive; |
||
80 | /// <summary>Negative ratings given by this avatar</summary> |
||
81 | public int GivenNegative; |
||
82 | |||
83 | public OSD GetOSD() |
||
84 | { |
||
85 | OSDMap tex = new OSDMap(8); |
||
86 | tex["behavior_positive"] = OSD.FromInteger(BehaviorPositive); |
||
87 | tex["behavior_negative"] = OSD.FromInteger(BehaviorNegative); |
||
88 | tex["appearance_positive"] = OSD.FromInteger(AppearancePositive); |
||
89 | tex["appearance_negative"] = OSD.FromInteger(AppearanceNegative); |
||
90 | tex["buildings_positive"] = OSD.FromInteger(BuildingPositive); |
||
91 | tex["buildings_negative"] = OSD.FromInteger(BuildingNegative); |
||
92 | tex["given_positive"] = OSD.FromInteger(GivenPositive); |
||
93 | tex["given_negative"] = OSD.FromInteger(GivenNegative); |
||
94 | return tex; |
||
95 | } |
||
96 | |||
97 | public static Statistics FromOSD(OSD O) |
||
98 | { |
||
99 | Statistics S = new Statistics(); |
||
100 | OSDMap tex = (OSDMap)O; |
||
101 | |||
102 | S.BehaviorPositive = tex["behavior_positive"].AsInteger(); |
||
103 | S.BuildingNegative = tex["behavior_negative"].AsInteger(); |
||
104 | S.AppearancePositive = tex["appearance_positive"].AsInteger(); |
||
105 | S.AppearanceNegative = tex["appearance_negative"].AsInteger(); |
||
106 | S.BuildingPositive = tex["buildings_positive"].AsInteger(); |
||
107 | S.BuildingNegative = tex["buildings_negative"].AsInteger(); |
||
108 | S.GivenPositive = tex["given_positive"].AsInteger(); |
||
109 | S.GivenNegative = tex["given_negative"].AsInteger(); |
||
110 | |||
111 | |||
112 | return S; |
||
113 | |||
114 | } |
||
115 | } |
||
116 | |||
117 | /// <summary> |
||
118 | /// Avatar properties including about text, profile URL, image IDs and |
||
119 | /// publishing settings |
||
120 | /// </summary> |
||
121 | public struct AvatarProperties |
||
122 | { |
||
123 | /// <summary>First Life about text</summary> |
||
124 | public string FirstLifeText; |
||
125 | /// <summary>First Life image ID</summary> |
||
126 | public UUID FirstLifeImage; |
||
127 | /// <summary></summary> |
||
128 | public UUID Partner; |
||
129 | /// <summary></summary> |
||
130 | public string AboutText; |
||
131 | /// <summary></summary> |
||
132 | public string BornOn; |
||
133 | /// <summary></summary> |
||
134 | public string CharterMember; |
||
135 | /// <summary>Profile image ID</summary> |
||
136 | public UUID ProfileImage; |
||
137 | /// <summary>Flags of the profile</summary> |
||
138 | public ProfileFlags Flags; |
||
139 | /// <summary>Web URL for this profile</summary> |
||
140 | public string ProfileURL; |
||
141 | |||
142 | #region Properties |
||
143 | |||
144 | /// <summary>Should this profile be published on the web</summary> |
||
145 | public bool AllowPublish |
||
146 | { |
||
147 | get { return ((Flags & ProfileFlags.AllowPublish) != 0); } |
||
148 | set |
||
149 | { |
||
150 | if (value == true) |
||
151 | Flags |= ProfileFlags.AllowPublish; |
||
152 | else |
||
153 | Flags &= ~ProfileFlags.AllowPublish; |
||
154 | } |
||
155 | } |
||
156 | /// <summary>Avatar Online Status</summary> |
||
157 | public bool Online |
||
158 | { |
||
159 | get { return ((Flags & ProfileFlags.Online) != 0); } |
||
160 | set |
||
161 | { |
||
162 | if (value == true) |
||
163 | Flags |= ProfileFlags.Online; |
||
164 | else |
||
165 | Flags &= ~ProfileFlags.Online; |
||
166 | } |
||
167 | } |
||
168 | /// <summary>Is this a mature profile</summary> |
||
169 | public bool MaturePublish |
||
170 | { |
||
171 | get { return ((Flags & ProfileFlags.MaturePublish) != 0); } |
||
172 | set |
||
173 | { |
||
174 | if (value == true) |
||
175 | Flags |= ProfileFlags.MaturePublish; |
||
176 | else |
||
177 | Flags &= ~ProfileFlags.MaturePublish; |
||
178 | } |
||
179 | } |
||
180 | /// <summary></summary> |
||
181 | public bool Identified |
||
182 | { |
||
183 | get { return ((Flags & ProfileFlags.Identified) != 0); } |
||
184 | set |
||
185 | { |
||
186 | if (value == true) |
||
187 | Flags |= ProfileFlags.Identified; |
||
188 | else |
||
189 | Flags &= ~ProfileFlags.Identified; |
||
190 | } |
||
191 | } |
||
192 | /// <summary></summary> |
||
193 | public bool Transacted |
||
194 | { |
||
195 | get { return ((Flags & ProfileFlags.Transacted) != 0); } |
||
196 | set |
||
197 | { |
||
198 | if (value == true) |
||
199 | Flags |= ProfileFlags.Transacted; |
||
200 | else |
||
201 | Flags &= ~ProfileFlags.Transacted; |
||
202 | } |
||
203 | } |
||
204 | |||
205 | public OSD GetOSD() |
||
206 | { |
||
207 | OSDMap tex = new OSDMap(9); |
||
208 | tex["first_life_text"] = OSD.FromString(FirstLifeText); |
||
209 | tex["first_life_image"] = OSD.FromUUID(FirstLifeImage); |
||
210 | tex["partner"] = OSD.FromUUID(Partner); |
||
211 | tex["about_text"] = OSD.FromString(AboutText); |
||
212 | tex["born_on"] = OSD.FromString(BornOn); |
||
213 | tex["charter_member"] = OSD.FromString(CharterMember); |
||
214 | tex["profile_image"] = OSD.FromUUID(ProfileImage); |
||
215 | tex["flags"] = OSD.FromInteger((byte)Flags); |
||
216 | tex["profile_url"] = OSD.FromString(ProfileURL); |
||
217 | return tex; |
||
218 | } |
||
219 | |||
220 | public static AvatarProperties FromOSD(OSD O) |
||
221 | { |
||
222 | AvatarProperties A = new AvatarProperties(); |
||
223 | OSDMap tex = (OSDMap)O; |
||
224 | |||
225 | A.FirstLifeText = tex["first_life_text"].AsString(); |
||
226 | A.FirstLifeImage = tex["first_life_image"].AsUUID(); |
||
227 | A.Partner = tex["partner"].AsUUID(); |
||
228 | A.AboutText = tex["about_text"].AsString(); |
||
229 | A.BornOn = tex["born_on"].AsString(); |
||
230 | A.CharterMember = tex["chart_member"].AsString(); |
||
231 | A.ProfileImage = tex["profile_image"].AsUUID(); |
||
232 | A.Flags = (ProfileFlags)tex["flags"].AsInteger(); |
||
233 | A.ProfileURL = tex["profile_url"].AsString(); |
||
234 | |||
235 | return A; |
||
236 | |||
237 | } |
||
238 | |||
239 | #endregion Properties |
||
240 | } |
||
241 | |||
242 | /// <summary> |
||
243 | /// Avatar interests including spoken languages, skills, and "want to" |
||
244 | /// choices |
||
245 | /// </summary> |
||
246 | public struct Interests |
||
247 | { |
||
248 | /// <summary>Languages profile field</summary> |
||
249 | public string LanguagesText; |
||
250 | /// <summary></summary> |
||
251 | // FIXME: |
||
252 | public uint SkillsMask; |
||
253 | /// <summary></summary> |
||
254 | public string SkillsText; |
||
255 | /// <summary></summary> |
||
256 | // FIXME: |
||
257 | public uint WantToMask; |
||
258 | /// <summary></summary> |
||
259 | public string WantToText; |
||
260 | |||
261 | public OSD GetOSD() |
||
262 | { |
||
263 | OSDMap InterestsOSD = new OSDMap(5); |
||
264 | InterestsOSD["languages_text"] = OSD.FromString(LanguagesText); |
||
265 | InterestsOSD["skills_mask"] = OSD.FromUInteger(SkillsMask); |
||
266 | InterestsOSD["skills_text"] = OSD.FromString(SkillsText); |
||
267 | InterestsOSD["want_to_mask"] = OSD.FromUInteger(WantToMask); |
||
268 | InterestsOSD["want_to_text"] = OSD.FromString(WantToText); |
||
269 | return InterestsOSD; |
||
270 | } |
||
271 | |||
272 | public static Interests FromOSD(OSD O) |
||
273 | { |
||
274 | Interests I = new Interests(); |
||
275 | OSDMap tex = (OSDMap)O; |
||
276 | |||
277 | I.LanguagesText = tex["languages_text"].AsString(); |
||
278 | I.SkillsMask = tex["skills_mask"].AsUInteger(); |
||
279 | I.SkillsText = tex["skills_text"].AsString(); |
||
280 | I.WantToMask = tex["want_to_mask"].AsUInteger(); |
||
281 | I.WantToText = tex["want_to_text"].AsString(); |
||
282 | |||
283 | return I; |
||
284 | |||
285 | } |
||
286 | } |
||
287 | |||
288 | #endregion Subclasses |
||
289 | |||
290 | #region Public Members |
||
291 | |||
292 | /// <summary>Groups that this avatar is a member of</summary> |
||
293 | public List<UUID> Groups = new List<UUID>(); |
||
294 | /// <summary>Positive and negative ratings</summary> |
||
295 | public Statistics ProfileStatistics; |
||
296 | /// <summary>Avatar properties including about text, profile URL, image IDs and |
||
297 | /// publishing settings</summary> |
||
298 | public AvatarProperties ProfileProperties; |
||
299 | /// <summary>Avatar interests including spoken languages, skills, and "want to" |
||
300 | /// choices</summary> |
||
301 | public Interests ProfileInterests; |
||
302 | /// <summary>Movement control flags for avatars. Typically not set or used by |
||
303 | /// clients. To move your avatar, use Client.Self.Movement instead</summary> |
||
304 | public AgentManager.ControlFlags ControlFlags; |
||
305 | |||
306 | /// <summary> |
||
307 | /// Contains the visual parameters describing the deformation of the avatar |
||
308 | /// </summary> |
||
309 | public byte[] VisualParameters = null; |
||
310 | |||
311 | /// <summary> |
||
312 | /// Appearance version. Value greater than 0 indicates using server side baking |
||
313 | /// </summary> |
||
314 | public byte AppearanceVersion = 0; |
||
315 | |||
316 | /// <summary> |
||
317 | /// Version of the Current Outfit Folder that the appearance is based on |
||
318 | /// </summary> |
||
319 | public int COFVersion = 0; |
||
320 | |||
321 | /// <summary> |
||
322 | /// Appearance flags. Introduced with server side baking, currently unused. |
||
323 | /// </summary> |
||
324 | public AppearanceFlags AppearanceFlags = AppearanceFlags.None; |
||
325 | |||
326 | /// <summary> |
||
327 | /// List of current avatar animations |
||
328 | /// </summary> |
||
329 | public List<Animation> Animations; |
||
330 | |||
331 | #endregion Public Members |
||
332 | |||
333 | protected string name; |
||
334 | protected string groupName; |
||
335 | |||
336 | #region Properties |
||
337 | |||
338 | /// <summary>First name</summary> |
||
339 | public string FirstName |
||
340 | { |
||
341 | get |
||
342 | { |
||
343 | for (int i = 0; i < NameValues.Length; i++) |
||
344 | { |
||
345 | if (NameValues[i].Name == "FirstName" && NameValues[i].Type == NameValue.ValueType.String) |
||
346 | return (string)NameValues[i].Value; |
||
347 | } |
||
348 | |||
349 | return String.Empty; |
||
350 | } |
||
351 | } |
||
352 | |||
353 | /// <summary>Last name</summary> |
||
354 | public string LastName |
||
355 | { |
||
356 | get |
||
357 | { |
||
358 | for (int i = 0; i < NameValues.Length; i++) |
||
359 | { |
||
360 | if (NameValues[i].Name == "LastName" && NameValues[i].Type == NameValue.ValueType.String) |
||
361 | return (string)NameValues[i].Value; |
||
362 | } |
||
363 | |||
364 | return String.Empty; |
||
365 | } |
||
366 | } |
||
367 | |||
368 | /// <summary>Full name</summary> |
||
369 | public string Name |
||
370 | { |
||
371 | get |
||
372 | { |
||
373 | if (!String.IsNullOrEmpty(name)) |
||
374 | { |
||
375 | return name; |
||
376 | } |
||
377 | else if (NameValues != null && NameValues.Length > 0) |
||
378 | { |
||
379 | lock (NameValues) |
||
380 | { |
||
381 | string firstName = String.Empty; |
||
382 | string lastName = String.Empty; |
||
383 | |||
384 | for (int i = 0; i < NameValues.Length; i++) |
||
385 | { |
||
386 | if (NameValues[i].Name == "FirstName" && NameValues[i].Type == NameValue.ValueType.String) |
||
387 | firstName = (string)NameValues[i].Value; |
||
388 | else if (NameValues[i].Name == "LastName" && NameValues[i].Type == NameValue.ValueType.String) |
||
389 | lastName = (string)NameValues[i].Value; |
||
390 | } |
||
391 | |||
392 | if (firstName != String.Empty && lastName != String.Empty) |
||
393 | { |
||
394 | name = String.Format("{0} {1}", firstName, lastName); |
||
395 | return name; |
||
396 | } |
||
397 | else |
||
398 | { |
||
399 | return String.Empty; |
||
400 | } |
||
401 | } |
||
402 | } |
||
403 | else |
||
404 | { |
||
405 | return String.Empty; |
||
406 | } |
||
407 | } |
||
408 | } |
||
409 | |||
410 | /// <summary>Active group</summary> |
||
411 | public string GroupName |
||
412 | { |
||
413 | get |
||
414 | { |
||
415 | if (!String.IsNullOrEmpty(groupName)) |
||
416 | { |
||
417 | return groupName; |
||
418 | } |
||
419 | else |
||
420 | { |
||
421 | if (NameValues == null || NameValues.Length == 0) |
||
422 | { |
||
423 | return String.Empty; |
||
424 | } |
||
425 | else |
||
426 | { |
||
427 | lock (NameValues) |
||
428 | { |
||
429 | for (int i = 0; i < NameValues.Length; i++) |
||
430 | { |
||
431 | if (NameValues[i].Name == "Title" && NameValues[i].Type == NameValue.ValueType.String) |
||
432 | { |
||
433 | groupName = (string)NameValues[i].Value; |
||
434 | return groupName; |
||
435 | } |
||
436 | } |
||
437 | } |
||
438 | return String.Empty; |
||
439 | } |
||
440 | } |
||
441 | } |
||
442 | } |
||
443 | |||
444 | public override OSD GetOSD() |
||
445 | { |
||
446 | OSDMap Avi = (OSDMap)base.GetOSD(); |
||
447 | |||
448 | OSDArray grp = new OSDArray(); |
||
449 | Groups.ForEach(delegate(UUID u) { grp.Add(OSD.FromUUID(u)); }); |
||
450 | |||
451 | OSDArray vp = new OSDArray(); |
||
452 | |||
453 | for (int i = 0; i < VisualParameters.Length; i++) |
||
454 | { |
||
455 | vp.Add(OSD.FromInteger(VisualParameters[i])); |
||
456 | } |
||
457 | |||
458 | Avi["groups"] = grp; |
||
459 | Avi["profile_statistics"] = ProfileStatistics.GetOSD(); |
||
460 | Avi["profile_properties"] = ProfileProperties.GetOSD(); |
||
461 | Avi["profile_interest"] = ProfileInterests.GetOSD(); |
||
462 | Avi["control_flags"] = OSD.FromInteger((byte)ControlFlags); |
||
463 | Avi["visual_parameters"] = vp; |
||
464 | Avi["first_name"] = OSD.FromString(FirstName); |
||
465 | Avi["last_name"] = OSD.FromString(LastName); |
||
466 | Avi["group_name"] = OSD.FromString(GroupName); |
||
467 | |||
468 | return Avi; |
||
469 | |||
470 | } |
||
471 | |||
472 | public static new Avatar FromOSD(OSD O) |
||
473 | { |
||
474 | |||
475 | OSDMap tex = (OSDMap)O; |
||
476 | |||
477 | Avatar A = new Avatar(); |
||
478 | |||
479 | Primitive P = Primitive.FromOSD(O); |
||
480 | |||
481 | Type Prim = typeof(Primitive); |
||
482 | |||
483 | FieldInfo[] Fields = Prim.GetFields(); |
||
484 | |||
485 | for (int x = 0; x < Fields.Length; x++) |
||
486 | { |
||
487 | Logger.Log("Field Matched in FromOSD: "+Fields[x].Name, Helpers.LogLevel.Debug); |
||
488 | Fields[x].SetValue(A, Fields[x].GetValue(P)); |
||
489 | } |
||
490 | |||
491 | A.Groups = new List<UUID>(); |
||
492 | |||
493 | foreach (OSD U in (OSDArray)tex["groups"]) |
||
494 | { |
||
495 | A.Groups.Add(U.AsUUID()); |
||
496 | } |
||
497 | |||
498 | A.ProfileStatistics = Statistics.FromOSD(tex["profile_statistics"]); |
||
499 | A.ProfileProperties = AvatarProperties.FromOSD(tex["profile_properties"]); |
||
500 | A.ProfileInterests = Interests.FromOSD(tex["profile_interest"]); |
||
501 | A.ControlFlags = (AgentManager.ControlFlags)tex["control_flags"].AsInteger(); |
||
502 | |||
503 | OSDArray vp = (OSDArray)tex["visual_parameters"]; |
||
504 | A.VisualParameters = new byte[vp.Count]; |
||
505 | |||
506 | for (int i = 0; i < vp.Count; i++) |
||
507 | { |
||
508 | A.VisualParameters[i] = (byte)vp[i].AsInteger(); |
||
509 | } |
||
510 | |||
511 | // *********************From Code Above ******************************* |
||
512 | /*if (NameValues[i].Name == "FirstName" && NameValues[i].Type == NameValue.ValueType.String) |
||
513 | firstName = (string)NameValues[i].Value; |
||
514 | else if (NameValues[i].Name == "LastName" && NameValues[i].Type == NameValue.ValueType.String) |
||
515 | lastName = (string)NameValues[i].Value;*/ |
||
516 | // ******************************************************************** |
||
517 | |||
518 | A.NameValues = new NameValue[3]; |
||
519 | |||
520 | NameValue First = new NameValue(); |
||
521 | First.Name = "FirstName"; |
||
522 | First.Type = NameValue.ValueType.String; |
||
523 | First.Value = tex["first_name"].AsString(); |
||
524 | |||
525 | NameValue Last = new NameValue(); |
||
526 | Last.Name = "LastName"; |
||
527 | Last.Type = NameValue.ValueType.String; |
||
528 | Last.Value = tex["last_name"].AsString(); |
||
529 | |||
530 | // ***************From Code Above*************** |
||
531 | // if (NameValues[i].Name == "Title" && NameValues[i].Type == NameValue.ValueType.String) |
||
532 | // ********************************************* |
||
533 | |||
534 | NameValue Group = new NameValue(); |
||
535 | Group.Name = "Title"; |
||
536 | Group.Type = NameValue.ValueType.String; |
||
537 | Group.Value = tex["group_name"].AsString(); |
||
538 | |||
539 | |||
540 | |||
541 | A.NameValues[0] = First; |
||
542 | A.NameValues[1] = Last; |
||
543 | A.NameValues[2] = Group; |
||
544 | |||
545 | return A; |
||
546 | |||
547 | |||
548 | } |
||
549 | |||
550 | #endregion Properties |
||
551 | |||
552 | #region Constructors |
||
553 | |||
554 | /// <summary> |
||
555 | /// Default constructor |
||
556 | /// </summary> |
||
557 | public Avatar() |
||
558 | { |
||
559 | } |
||
560 | |||
561 | #endregion Constructors |
||
562 | } |
||
563 | } |