IAvatarService.cs 11 KB

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